Need to be able to disable `finalize` of wrapped c++ object
Closed this issue · 2 comments
In some toolkits or frameworks you need to be able to relinquish ownership of objects given to the framework. This is the case for example in Geant4 when providing to the G4RunManager
an object of type G4VUserDetectorConstruction
to setup detector geometry. The C++ G4runManager
takes care of deleting of object at finalization, so the Julia side should not try to delete the object. This is achieved by adding the argument false
in the constructor wrapper. Like this:
auto t59 = types.add_type<G4JLDetectorConstruction>("G4JLDetectorConstruction", jlcxx::julia_base_type<G4VUserDetectorConstruction>());
...
t59.constructor<jlcxx::SafeCFunction>(false);
So, what is needed is a mechanism to indicate to WrapIt what constructors to define with false
as argument.
Hello @peremato ,
Support to disable finalize
is brought by this commit.
It will be automatically disabled if the destructor of the class is not public or if it is deleted. In other cases, it can be disabled by adding the class name in the list specified with the new vetoed_finalizer_classes
configuration parameter.
Philippe.
@grasph we should be reopening this one. It is not working. Adding this printout
rcd.finalize = data.public_dtor && !finalize_vetoed;
+ std::cerr << "========> " << rcd.type_name << " finalize = " << rcd.finalize << std::endl;
I get:
========> G4PVPlacement finalize = 0
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
========> G4PVPlacement finalize = 1
Only the first time is correct finalize=0
not later. The question is by the method is called so many times? why the type is deleted from the list of finalize_vetoed
?