sample segfault puzzle

$ python -c "import wx;print wx.VERSION_STRING"
2.5.1.5

I'm fairly sure that I had it working with 2.5.1.5. You could try calling PyErr_Print() when wxPyCoreAPIPtr==NULL to see if there is a Python exception set that can give you any more information.

----------embedded.cpp------------------
void MyApp::Init_wxPython()
{
  std::cout << "---------222---------\n";
    // Initialize Python
    Py_Initialize();
    PyEval_InitThreads();

  std::cout << "---------444---------\n";
    // Load the wxPython core API. Imports the wx._core module and sets a
    // local pointer to a function table located there.
  std::cout << wxPyCoreAPIPtr ;
    wxPyCoreAPI_IMPORT();
  std::cout << "\n---------555---------\n";
  std::cout << wxPyCoreAPIPtr << "\n...after...\n";
  
  if (wxPyCoreAPIPtr==NULL){
    PyErr_Print();
  }

    // Save the current Python thread state and release the
    // Global Interpreter Lock.
    m_mainTState = wxPyBeginAllowThreads();
  std::cout << "---------555555555---------\n";
}

···

---------------------------

gives:

me@self:/c/d/wx/embedded$ ./embedded
---------111---------
---------222---------
---------444---------
(nil)
---------555---------
(nil)
...after...
ImportError: No module named _core
Segmentation fault

For Python code I use a variety of methods. For C/C++ on unix I use gdb although I have yet to find a front-end to gdb that I like. I usually just use the gdb/emacs integration. I've been thinking about trying TotalView (http://www.etnus.com/) but havn't yet.

The reason for my question was that I am trying to be friends w. DDD, but, well, I don't feel any chemistry yet...

Ok, I've finished downloading the CVS sources, I'll give that a try.

Thanks,
Vio

Vio wrote:

gives:

me@self:/c/d/wx/embedded$ ./embedded
---------111---------
---------222---------
---------444---------
(nil)
---------555---------
(nil)
...after...
ImportError: No module named _core

Oops, looks like my fall-back import is probably obscuring the real problem. I'll have to make wxPyCoreAPI_IMPORT more intelligent. In the meantime, change it to look like this (removing the fall-back) and try again. Or you could even just replace your call to wxPyCoreAPI_IMPORT with the guts of this version :wink:

static bool wxPyCoreAPI_IMPORT() {
     wxPyCoreAPIPtr = (wxPyCoreAPI*)PyCObject_Import("wx._core", "_wxPyCoreAPI");
     return wxPyCoreAPIPtr != NULL;
}

Segmentation fault

I'm changing the embedded sample to show how to recover more gracefully when there is an error doing the import.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!