Skip to content

Commit

Permalink
Fix functors
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed May 14, 2022
1 parent a4ac8ce commit f6f4270
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/bindgen/cdecl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}
Expand All @@ -268,6 +265,7 @@ impl CDecl {
if next_is_pointer && config.language != Language::Zig {
out.write("(");
}
is_functors = true;
}
}
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit f6f4270

Please sign in to comment.