From: SourceForge.net <no...@so...> - 2010-05-26 08:00:54
|
Bugs item #1821415, was opened at 2007-10-28 13:14 Message generated for change (Settings changed) made by olly You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=1821415&group_id=1645 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. >Category: python Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: nitro (nitrogenycs) Assigned to: Nobody/Anonymous (nobody) Summary: Python directors & dirvtable bug Initial Comment: The following text is almost identical to this one: http://thread.gmane.org/gmane.comp.programming.swig/11560 ------------------------------------- Hello guys, there seems to be a bug in swig regarding python directors. Attached is a minimal interface file which reproduces the problem. Swig generates code like this: #if defined(SWIG_PYTHON_DIRECTOR_VTABLE) const size_t swig_method_index = 0; const char * const swig_method_name = "my_method"; PyObject* method = swig_get_method(swig_method_index, swig_method_name); swig::PyObject_var result = PyObject_CallFunctionObjArgs(method ,(PyObject *)obj0, NULL); #else swig::PyObject_var swig_method_name = PyString_FromString((char *)"Render"); swig::PyObject_var result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name ,(PyObject *)obj0, NULL); #endif In my case SWIG_PYTHON_DIRECTOR_VTABLE is defined, so only the first branch is executed. This includes the call to swig_get_method. This function is generated for each python director class. It tries to retrieve the python method called "my_method" from the current object. If this fails, because the method wasn't defined in python it triggers this line within swig_get_method: Swig::DirectorMethodException::raise(msg.c_str()); Unfortunately I don't think there is any way to capture this exception or to override it somehow. My program just crashes :(. I am already using %feature("director:except") and %exception. However, these are useless as they don't enclose the position where the DirectorMethodException is raised. Notice that if SWIG_PYTHON_DIRECTOR_VTABLE is not defined (alas, running swig without -dirvtable and/or without -O) the swig code will rise a DirectorMethodException a bit later. By using %feature("director:except") I can override this behaviour though. Overriding just doesn't work in the case where SWIG_PYTHON_DIRECTOR_VTABLE is defined. One solution I can see is to make swig_get_method return 0 instead of throwing an exception. The calling code would look like this: #if defined(SWIG_PYTHON_DIRECTOR_VTABLE) const size_t swig_method_index = 0; const char * const swig_method_name = "my_method"; PyObject* method = swig_get_method(swig_method_index, swig_method_name); swig::PyObject_var result = method ? PyObject_CallFunctionObjArgs(method ,(PyObject *)obj0, NULL) : 0; #else swig::PyObject_var swig_method_name = PyString_FromString((char *)"Render"); swig::PyObject_var result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name ,(PyObject *)obj0, NULL); #endif ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=1821415&group_id=1645 |