PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 939 - Shiboken::importModule must verify if PyImport_ImportModule succeeds
: Shiboken::importModule must verify if PyImport_ImportModule succeeds
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: Shiboken
: HEAD
: PC Linux
: P2 normal
Assigned To: Hugo Parente Lima
:
:
:
  Show dependency treegraph
 
Reported: 2011-07-20 01:04 EEST by Bruno Araujo
Modified: 2011-07-22 22:12 EEST (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bruno Araujo 2011-07-20 01:04:20 EEST
The following snippet is present in the function importModule @
libshiboken/basewrapper.cpp:

    if (!module)
       module = PyImport_ImportModule(moduleName);
    else
       Py_INCREF(module);

   Shiboken::AutoDecRef cppApi(PyObject_GetAttrString(module, "_Cpp_Api"));

The problem is that if the PyImport_ImportModule() call fails for any reason it
returns NULL to the module variable [1], and when module is passed to
PyObject_GetAttrString() a SIGSEGV follows.

A (maybe not ideal) fix would be just verify the module variable again and
return false if it is still NULL:

    if (!module) {
       module = PyImport_ImportModule(moduleName);
       if (!module)
           return false;
    }
    else
       Py_INCREF(module);

That way the initSomeModule() function that called importModule will know that
the importing failed, and take the already present appropriate steps.

[1] http://docs.python.org/c-api/import.html#PyImport_ImportModule
Comment 1 Hugo Parente Lima 2011-07-21 22:14:22 EEST
Fixed in commit:

shiboken/02d16c7a72ddb1de2ab02d19c03f0759a66461ea
Comment 2 renato filho 2011-07-22 22:12:51 EEST
release 1.0.5