@@ -147,7 +147,7 @@ impl RustNativeGeneratedElement for SmartPtr<'_, '_> {
147147 let rust_as_raw_mut = type_ref. rust_as_raw_name ( Constness :: Mut ) ;
148148
149149 let ctor = if gen_ctor ( & pointee_kind) {
150- let extern_new = method_new ( smartptr_class. clone ( ) , type_ref, pointee_type. as_ref ( ) . clone ( ) ) . identifier ( ) ;
150+ let extern_new = method_new ( smartptr_class. clone ( ) , type_ref. clone ( ) , pointee_type. as_ref ( ) . clone ( ) ) . identifier ( ) ;
151151 CTOR_TPL . interpolate ( & HashMap :: from ( [
152152 ( "inner_rust_full" , inner_rust_full. as_ref ( ) ) ,
153153 ( "extern_new" , & extern_new) ,
@@ -156,13 +156,15 @@ impl RustNativeGeneratedElement for SmartPtr<'_, '_> {
156156 "" . to_string ( )
157157 } ;
158158
159+ let extern_new_null = method_new_null ( smartptr_class. clone ( ) , type_ref) . identifier ( ) ;
159160 let extern_delete = FuncDesc :: method_delete ( smartptr_class) . identifier ( ) ;
160161 TPL . interpolate ( & HashMap :: from ( [
161162 ( "rust_localalias" , rust_localalias. as_ref ( ) ) ,
162163 ( "rust_as_raw_const" , & rust_as_raw_const) ,
163164 ( "rust_as_raw_mut" , & rust_as_raw_mut) ,
164165 ( "rust_full" , & rust_full) ,
165166 ( "inner_rust_full" , & inner_rust_full) ,
167+ ( "extern_new_null" , & extern_new_null) ,
166168 ( "extern_delete" , & extern_delete) ,
167169 ( "extern_get_inner_ptr" , & extern_get_inner_ptr) ,
168170 ( "extern_get_inner_ptr_mut" , & extern_get_inner_ptr_mut) ,
@@ -197,6 +199,7 @@ fn extern_functions<'tu, 'ge>(ptr: &SmartPtr<'tu, 'ge>) -> Vec<Func<'tu, 'ge>> {
197199 smartptr_class. clone ( ) ,
198200 pointee_type. as_ref ( ) . clone ( ) . with_inherent_constness ( Constness :: Mut ) ,
199201 ) ) ;
202+ out. push ( method_new_null ( smartptr_class. clone ( ) , type_ref. clone ( ) ) ) ;
200203 out. push ( FuncDesc :: method_delete ( smartptr_class. clone ( ) ) ) ;
201204 if let Some ( cls) = pointee_kind. as_class ( ) . filter ( |cls| cls. kind ( ) . is_trait ( ) ) {
202205 for base in all_bases ( & cls) {
@@ -297,6 +300,21 @@ fn method_new<'tu, 'ge>(
297300 )
298301}
299302
303+ fn method_new_null < ' tu , ' ge > ( smartptr_class : Class < ' tu , ' ge > , smartptr_type_ref : TypeRef < ' tu , ' ge > ) -> Func < ' tu , ' ge > {
304+ Func :: new_desc (
305+ FuncDesc :: new (
306+ FuncKind :: Constructor ( smartptr_class) ,
307+ Constness :: Const ,
308+ ReturnKind :: InfallibleNaked ,
309+ "new_null" ,
310+ "<unused>" ,
311+ [ ] ,
312+ smartptr_type_ref,
313+ )
314+ . cpp_body ( FuncCppBody :: ManualCallReturn ( "return new {{ret_type}}(NULL);" . into ( ) ) ) ,
315+ )
316+ }
317+
300318fn method_cast_to_base < ' tu , ' ge > (
301319 smartptr_class : Class < ' tu , ' ge > ,
302320 base_type_ref : TypeRef < ' tu , ' ge > ,
0 commit comments