diff --git a/bindgen/src/gen_go/mod.rs b/bindgen/src/gen_go/mod.rs index 1c1c638..181827f 100644 --- a/bindgen/src/gen_go/mod.rs +++ b/bindgen/src/gen_go/mod.rs @@ -465,31 +465,19 @@ pub mod filters { } /// FFI type name to be used to reference cgo types - pub fn ffi_type_name>(type_: &T) -> Result { + pub fn ffi_type_name(type_: &Type) -> Result { let ffi_type: FfiType = type_.clone().into(); let result = match ffi_type { FfiType::RustArcPtr(_) => "unsafe.Pointer".into(), - FfiType::RustBuffer(_) => "RustBufferI".into(), + FfiType::RustBuffer(_) => match type_ { + Type::External { namespace, .. } => format!("{}.RustBufferI", namespace), + _ => "RustBufferI".into(), + }, _ => format!("C.{}", oracle().ffi_type_label(&ffi_type)), }; Ok(result) } - // Return the Go package name for the given type, if it has one, followed by a '.' - // Returns the empty string if the type has no package name associated with it e.g primitive types. - // - // for multi-package bindings, it may be required to specify which - // RustBufferI should be used when creating completeFunc. Failure to - // specify the right package here will result in compilation errors. - pub fn maybe_namespace(type_: &impl AsType) -> Result { - let type_label = oracle().find(type_).type_label(); - if let Some((package_name, _)) = type_label.split_once(".") { - Ok(format!("{}.", package_name)) - } else { - Ok(String::from("")) - } - } - /// FFI type name to be used to reference cgo types. Such that they exactly match to the cgo bindings and can be used with `//export`. pub fn ffi_type_name_cgo_safe>( type_: &T, diff --git a/bindgen/templates/macros.go b/bindgen/templates/macros.go index 855105c..0fbb555 100644 --- a/bindgen/templates/macros.go +++ b/bindgen/templates/macros.go @@ -60,7 +60,7 @@ {% macro return_type_decl_async(func) %} {%- match func.return_type() -%} {%- when Some with (return_type) -%} - {{return_type|maybe_namespace}}{{ return_type|ffi_type_name }} + {{ return_type|ffi_type_name }} {%- when None -%} {%- endmatch %} {%- endmacro %}