This brings over the memory leak fixes for pointers to structs with a %extend destructor from my Neha fork. The generator was not generating and connecting the needed code for the requested destructor to the v8 dtor finalizer.

I did not realize this branch has some JavaScriptCore stuff in it too. Unfortunately, it seems to have its own unique problems (like creating C++ files when it should be generating C files). My changes are targeted for v8, and I don't think my JSCore changes fully reach in this JSCore implementation so more work would need to be done to get this branch working. I think my Neha fork is in better shape at the moment.

Also, I did port over the 'NULL out the dtor function pointer' in the %nodefaultdtor fix to v8.

Usage case:
struct MyData {
%extend {
~MyData() {
FreeData($self);
}
}
};
%newobject CreateData;
struct MyData* CreateData(void);
%delobject FreeData;
void FreeData(struct MyData* the_data);

where the use case is something like:
var my_data = example.CreateData();
my_data = null;
This commit is contained in:
Eric Wing 2013-07-11 19:09:17 -07:00 committed by Oliver Buchtala
commit ed729f7d3a
3 changed files with 137 additions and 4 deletions

View file

@ -114,13 +114,32 @@ fail:
void $jswrapper(v8::Persistent< v8::Value > object, void *parameter) {
SWIGV8_Proxy* proxy = (SWIGV8_Proxy*) parameter;
if(proxy->swigCMemOwn && proxy->swigCObject) {
std::cout << "Deleting wrapped instance: " << proxy->info->name << std::endl;
// std::cout << "Deleting wrapped instance: " << proxy->info->name << std::endl;
$jsfree proxy->swigCObject;
}
delete proxy;
}
%}
/* -----------------------------------------------------------------------------
* js_dtoroverride: template for a destructor wrapper
* - $jsmangledname: mangled class name
* - $jstype: class type
* - ${destructor_action}: The custom destructor action to invoke.
* ----------------------------------------------------------------------------- */
%fragment ("js_dtoroverride", "templates")
%{
void $jswrapper(v8::Persistent< v8::Value > object, void *parameter) {
SWIGV8_Proxy* proxy = (SWIGV8_Proxy*) parameter;
if(proxy->swigCMemOwn && proxy->swigCObject) {
// std::cout << "Deleting wrapped instance: " << proxy->info->name << std::endl;
$jstype arg1 = ($jstype)t->swigCObject;
${destructor_action}
}
delete proxy;
}
%}
/* -----------------------------------------------------------------------------
* js_getter: template for getter function wrappers
* - $jswrapper: wrapper function name