swig / swig

SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages.
http://www.swig.org
Other
5.93k stars 1.26k forks source link

Comparison between info.deleteProc and SWIG_TclObjectDelete SWIG_Tcl_ConvertPtrFromString doesn't work well across modules #3071

Open Borfonius opened 4 months ago

Borfonius commented 4 months ago

Recently, an additional check was added to the SWIG_Tcl_ConvertPtrFromString function. This check compares the TclCommandInfo "deleteProc" attribute to make sure it is set to the SWIG_TclObjectDelete function. This is problematic when there are multiple modules in a wrapped API. This happens when the base class of a called method is not defined in the same module where the subclass constructor is defined. This is because each module gets its own locally scoped SWIG_TclObjectDelete function, and this function is not visible to other modules. So the code that does the following comparison: if (info.deleteProc == SWIG_Tcl_ObjectDelete) { Will fail, even though the referenced object is indeed a SWIG wrapped object.

ojwb commented 4 months ago

The change seems to be baf422e69e100f3b409a0e1a5c5bfd27b46dfdab, so this is probably a regression introduced in 4.2.1. @wsfulton That was one of yours

wsfulton commented 1 month ago

Seems to referring to this comment and code:

https://github.com/swig/swig/blob/892be2b8024d391dbc78028a2e99b7800db2ea99/Lib/tcl/tclrun.swg#L174-L178

@Borfonius , I think you have a better understanding of SWIG and multiple modules. I am not particularly familiar with Tcl, so will need some suggestions for detecting when deleteProc in Tcl_CmdInfo contains a SWIG object in the case of multiple modules. I don't know how to replicate your multiple modules problem, so a small cutdown example would help and more so if someone could debug what happens in such a case.