From f6f427039aff3e668543724bb951d42733d3ab83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Catarino=20Fran=C3=A7a?= Date: Sat, 14 May 2022 13:20:25 -0300 Subject: [PATCH] Fix functors --- src/bindgen/cdecl.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/bindgen/cdecl.rs b/src/bindgen/cdecl.rs index 3176cb255..8f8a3f0a2 100644 --- a/src/bindgen/cdecl.rs +++ b/src/bindgen/cdecl.rs @@ -220,6 +220,7 @@ impl CDecl { // Write the left part of declarators before the identifier let mut iter_rev = self.declarators.iter().rev().peekable(); + let mut is_functors = false; #[allow(clippy::while_let_on_iterator)] while let Some(declarator) = iter_rev.next() { @@ -249,11 +250,7 @@ impl CDecl { out.write("const "); } } - if !is_nullable - && !is_ref - && config.language != Language::Cython - && config.language != Language::Zig - { + if !is_nullable && !is_ref && config.language != Language::Cython { if let Some(attr) = &config.pointer.non_null_attribute { write!(out, "{} ", attr); } @@ -268,6 +265,7 @@ impl CDecl { if next_is_pointer && config.language != Language::Zig { out.write("("); } + is_functors = true; } } } @@ -293,19 +291,21 @@ impl CDecl { while let Some(declarator) = iter.next() { match *declarator { CDeclarator::Ptr { .. } => { + last_was_pointer = true; + if config.language == Language::Zig { if self.type_name.contains("u8") + || self.type_name.contains("const u8") || self.type_name.contains("CStr") || self.type_name.contains("c_char") { write!(out, ": ?[*:0]{}", self.type_name); - } else if self.type_name.contains("const u8") { - write!(out, ": ?[*:0]{}", self.type_name); + } else if is_functors { + out.write(": ?fn"); } else { write!(out, ": ?*{}", self.type_name); } } - last_was_pointer = true; } CDeclarator::Array(ref constant) => { if last_was_pointer { @@ -331,6 +331,7 @@ impl CDecl { if last_was_pointer && config.language != Language::Zig { out.write(")"); } + is_functors = true; out.write("("); if args.is_empty() && config.language == Language::C {