Properly handle const pointer to Ptr's internal data, move extern declarations to the module level (fixes warnings in beta)
MODIFY
binding-generator/src/writer/rust_native/smart_ptr.rs
binding-generator/src/writer/rust_native/smart_ptr.rs
@@ -80,16 +80,26 @@ impl RustNativeGeneratedElement for SmartPtr<'_> {
let pointee_type = self.pointee();
let mut inner_cpp_extern = pointee_type.cpp_extern_return();
+ let mut extern_return_const_renderer = type_ref::CppExternReturnRenderer::new();
+ extern_return_const_renderer.constness_override = ConstnessOverride::Yes(Constness::Const);
+ let mut inner_cpp_extern_const = pointee_type.render(extern_return_const_renderer);
if !pointee_type.is_by_ptr() {
inner_cpp_extern.to_mut().push('*');
+ inner_cpp_extern_const.to_mut().push('*');
}
+ let mut const_renderer = type_ref::CppReferenceRenderer::new("", true);
+ const_renderer.constness_override = ConstnessOverride::Yes(Constness::Const);
+ let cpp_full_const = type_ref.render(const_renderer);
+
let mut inter_vars = hashmap! {
"rust_localalias" => self.rust_localalias(),
"cpp_extern" => type_ref.cpp_extern(),
"cpp_full" => type_ref.cpp_full(),
+ "cpp_full_const" => cpp_full_const.into(),
"inner_cpp_full" => pointee_type.cpp_full(),
"inner_cpp_extern" => inner_cpp_extern,
+ "inner_cpp_extern_const" => inner_cpp_extern_const,
};
let pointee_primitive = pointee_type.is_primitive();

MODIFY
binding-generator/src/writer/rust_native/tpl/smart_ptr/cpp.tpl.cpp
binding-generator/src/writer/rust_native/tpl/smart_ptr/cpp.tpl.cpp
@@ -4,7 +4,11 @@ extern "C" {
delete instance;
}
- {{inner_cpp_extern}} cv_{{rust_localalias}}_get_inner_ptr({{cpp_full}}* instance) {
+ {{inner_cpp_extern_const}} cv_{{rust_localalias}}_get_inner_ptr({{cpp_full_const}}* instance) {
+ return instance->get();
+ }
+
+ {{inner_cpp_extern}} cv_{{rust_localalias}}_get_inner_ptr_mut({{cpp_full}}* instance) {
return instance->get();
}
}

MODIFY
binding-generator/src/writer/rust_native/tpl/smart_ptr/rust.tpl.rs
binding-generator/src/writer/rust_native/tpl/smart_ptr/rust.tpl.rs
pub type {{rust_localalias}} = {{rust_full}};
ptr_extern! { {{inner_rust_full}},
- cv_{{rust_localalias}}_delete, cv_{{rust_localalias}}_get_inner_ptr
+ cv_{{rust_localalias}}_delete, cv_{{rust_localalias}}_get_inner_ptr, cv_{{rust_localalias}}_get_inner_ptr_mut
}
{{ctor}}

MODIFY
src/manual/core/ptr/ptr_extern.rs
src/manual/core/ptr/ptr_extern.rs
@@ -11,29 +11,32 @@ pub trait PtrExtern {
#[doc(hidden)]
pub trait PtrExternCtor<T: for<'a> OpenCVType<'a>>: Sized {
- #[doc(hidden)] unsafe fn extern_new<'a>(val: <<T as OpenCVType<'a>>::ExternContainer as OpenCVTypeExternContainer>::ExternSendMut) -> *mut c_void;
+ #[doc(hidden)] unsafe fn extern_new(val: <<T as OpenCVType>::ExternContainer as OpenCVTypeExternContainer>::ExternSendMut) -> *mut c_void;
}
#[macro_export]
macro_rules! ptr_extern {
- ($type: ty, $extern_delete: ident, $extern_inner_as_ptr: ident $(,)?) => {
+ ($type: ty, $extern_delete: ident, $extern_inner_as_ptr: ident, $extern_inner_as_ptr_mut: ident $(,)?) => {
+ extern "C" {
+ fn $extern_delete(instance: *mut std::ffi::c_void);
+ fn $extern_inner_as_ptr(instance: *const std::ffi::c_void) -> *const std::ffi::c_void;
+ fn $extern_inner_as_ptr_mut(instance: *mut std::ffi::c_void) -> *mut std::ffi::c_void;
+ }
+
impl $crate::manual::core::PtrExtern for $crate::manual::core::Ptr<$type> {
#[inline(always)]
unsafe fn extern_delete(&mut self) {
- extern "C" { fn $extern_delete(instance: *mut std::ffi::c_void); }
$extern_delete(self.as_raw_mut())
}
#[inline(always)]
unsafe fn extern_inner_as_ptr(&self) -> *const std::ffi::c_void {
- extern "C" { fn $extern_inner_as_ptr(instance: *const std::ffi::c_void) -> *mut std::ffi::c_void; }
$extern_inner_as_ptr(self.as_raw())
}
#[inline(always)]
unsafe fn extern_inner_as_ptr_mut(&mut self) -> *mut std::ffi::c_void {
- extern "C" { fn $extern_inner_as_ptr(instance: *mut std::ffi::c_void) -> *mut std::ffi::c_void; }
- $extern_inner_as_ptr(self.as_raw_mut())
+ $extern_inner_as_ptr_mut(self.as_raw_mut())
}
}
};
@@ -42,10 +45,11 @@ macro_rules! ptr_extern {
#[macro_export]
macro_rules! ptr_extern_ctor {
($type: ty, $extern_new: ident $(,)?) => {
+ extern "C" { fn $extern_new(val: <<$type as $crate::traits::OpenCVType>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSendMut) -> *mut std::ffi::c_void; }
+
impl $crate::manual::core::PtrExternCtor<$type> for $crate::manual::core::Ptr<$type> {
#[inline(always)]
- unsafe fn extern_new<'a>(val: <<$type as $crate::traits::OpenCVType<'a>>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSendMut) -> *mut std::ffi::c_void {
- extern "C" { fn $extern_new<'a>(val: <<$type as $crate::traits::OpenCVType<'a>>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSendMut) -> *mut std::ffi::c_void; }
+ unsafe fn extern_new(val: <<$type as $crate::traits::OpenCVType>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSendMut) -> *mut std::ffi::c_void {
$extern_new(val)
}
}

MODIFY
src/manual/core/vector/vector_extern.rs
src/manual/core/vector/vector_extern.rs
@@ -55,94 +55,96 @@ macro_rules! vector_extern {
$extern_push: ident,
$extern_insert: ident $(,)?
) => {
+ extern "C" {
+ fn $extern_new() -> $vector_extern_mut;
+ fn $extern_delete(instance: $vector_extern_mut);
+ fn $extern_len(instance: $vector_extern_const) -> $crate::platform_types::size_t;
+ fn $extern_is_empty(instance: $vector_extern_const) -> bool;
+ fn $extern_capacity(instance: $vector_extern_const) -> $crate::platform_types::size_t;
+ fn $extern_shrink_to_fit(instance: $vector_extern_mut);
+ fn $extern_reserve(instance: $vector_extern_mut, additional: $crate::platform_types::size_t);
+ fn $extern_remove(instance: $vector_extern_mut, index: $crate::platform_types::size_t);
+ fn $extern_swap(instance: $vector_extern_mut, index1: $crate::platform_types::size_t, index2: $crate::platform_types::size_t);
+ fn $extern_clear(instance: $vector_extern_mut);
+ fn $extern_get<'a>(instance: $vector_extern_const, index: $crate::platform_types::size_t) -> $crate::sys::Result<<$type as $crate::traits::OpenCVType<'a>>::ExternReceive>;
+ fn $extern_push<'a>(instance: $vector_extern_mut, val: <<<$type as $crate::traits::OpenCVType<'a>>::Arg as $crate::traits::OpenCVTypeArg<'a>>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSend);
+ fn $extern_insert<'a>(instance: $vector_extern_mut, index: $crate::platform_types::size_t, val: <<<$type as $crate::traits::OpenCVType<'a>>::Arg as $crate::traits::OpenCVTypeArg<'a>>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSend);
+ fn $extern_set<'a>(instance: $vector_extern_mut, index: $crate::platform_types::size_t, val: <<<$type as $crate::traits::OpenCVType<'a>>::Arg as $crate::traits::OpenCVTypeArg<'a>>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSend);
+ }
+
impl $crate::manual::core::VectorExtern<$type> for $crate::manual::core::Vector<$type> {
#[inline(always)]
unsafe fn extern_new() -> $vector_extern_mut {
- extern "C" { fn $extern_new() -> $vector_extern_mut; }
$extern_new()
}
#[inline(always)]
unsafe fn extern_delete(&mut self) {
- extern "C" { fn $extern_delete(instance: $vector_extern_mut); }
$extern_delete(self.as_raw_mut())
}
#[inline(always)]
unsafe fn extern_len(&self) -> $crate::platform_types::size_t {
- extern "C" { fn $extern_len(instance: $vector_extern_const) -> $crate::platform_types::size_t; }
$extern_len(self.as_raw())
}
#[inline(always)]
unsafe fn extern_is_empty(&self) -> bool {
- extern "C" { fn $extern_is_empty(instance: $vector_extern_const) -> bool; }
$extern_is_empty(self.as_raw())
}
#[inline(always)]
unsafe fn extern_capacity(&self) -> $crate::platform_types::size_t {
- extern "C" { fn $extern_capacity(instance: $vector_extern_const) -> $crate::platform_types::size_t; }
$extern_capacity(self.as_raw())
}
#[inline(always)]
unsafe fn extern_shrink_to_fit(&mut self) {
- extern "C" { fn $extern_shrink_to_fit(instance: $vector_extern_mut); }
$extern_shrink_to_fit(self.as_raw_mut())
}
#[inline(always)]
unsafe fn extern_reserve(&mut self, additional: $crate::platform_types::size_t) {
- extern "C" { fn $extern_reserve(instance: $vector_extern_mut, additional: $crate::platform_types::size_t); }
$extern_reserve(self.as_raw_mut(), additional)
}
#[inline(always)]
unsafe fn extern_remove(&mut self, index: $crate::platform_types::size_t) {
- extern "C" { fn $extern_remove(instance: $vector_extern_mut, index: $crate::platform_types::size_t); }
$extern_remove(self.as_raw_mut(), index)
}
#[inline(always)]
unsafe fn extern_swap(&mut self, index1: $crate::platform_types::size_t, index2: $crate::platform_types::size_t) {
- extern "C" { fn $extern_swap(instance: $vector_extern_mut, index1: $crate::platform_types::size_t, index2: $crate::platform_types::size_t); }
$extern_swap(self.as_raw_mut(), index1, index2)
}
#[inline(always)]
unsafe fn extern_clear(&mut self) {
- extern "C" { fn $extern_clear(instance: $vector_extern_mut); }
$extern_clear(self.as_raw_mut())
}
#[inline(always)]
unsafe fn extern_get(&self, index: $crate::platform_types::size_t) -> $crate::sys::Result<<$type as $crate::traits::OpenCVType<'_>>::ExternReceive> {
- extern "C" { fn $extern_get<'a>(instance: $vector_extern_const, index: $crate::platform_types::size_t) -> $crate::sys::Result<<$type as $crate::traits::OpenCVType<'a>>::ExternReceive>; }
$extern_get(self.as_raw(), index)
}
#[inline(always)]
unsafe fn extern_push<'a>(&mut self, val: <<<$type as $crate::traits::OpenCVType<'a>>::Arg as $crate::traits::OpenCVTypeArg<'a>>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSend) {
- extern "C" { fn $extern_push<'a>(instance: $vector_extern_mut, val: <<<$type as $crate::traits::OpenCVType<'a>>::Arg as $crate::traits::OpenCVTypeArg<'a>>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSend); }
$extern_push(self.as_raw_mut(), val)
}
#[inline(always)]
unsafe fn extern_push_owned(&mut self, val: <<$type as $crate::traits::OpenCVType>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSend) {
- extern "C" { fn $extern_push<'a>(instance: $vector_extern_mut, val: <<<$type as $crate::traits::OpenCVType<'a>>::Arg as $crate::traits::OpenCVTypeArg<'a>>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSend); }
$extern_push(self.as_raw_mut(), val)
}
#[inline(always)]
unsafe fn extern_insert<'a>(&mut self, index: $crate::platform_types::size_t, val: <<<$type as $crate::traits::OpenCVType<'a>>::Arg as $crate::traits::OpenCVTypeArg<'a>>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSend) {
- extern "C" { fn $extern_insert<'a>(instance: $vector_extern_mut, index: $crate::platform_types::size_t, val: <<<$type as $crate::traits::OpenCVType<'a>>::Arg as $crate::traits::OpenCVTypeArg<'a>>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSend); }
$extern_insert(self.as_raw_mut(), index, val)
}
#[inline(always)]
unsafe fn extern_set<'a>(&mut self, index: $crate::platform_types::size_t, val: <<<$type as $crate::traits::OpenCVType<'a>>::Arg as $crate::traits::OpenCVTypeArg<'a>>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSend) {
- extern "C" { fn $extern_set<'a>(instance: $vector_extern_mut, index: $crate::platform_types::size_t, val: <<<$type as $crate::traits::OpenCVType<'a>>::Arg as $crate::traits::OpenCVTypeArg<'a>>::ExternContainer as $crate::traits::OpenCVTypeExternContainer>::ExternSend); }
$extern_set(self.as_raw_mut(), index, val)
}
}

Properly handle const pointer to Ptr's internal data, move extern declarations to the module level (fixes warnings in beta)