Would someone be kind enough to remind me why the following code segfaults
(and why I should kick my ass in-between 2 keystrokes ... violence, violence ;-).
Running the mentionned script standalone works as expected.
Cheers,
Vio
···
--------------------------------------
/*
kicking...
*/
#include <Python.h>
#include <stdio.h>
#define error(msg) do { printf("%s\n", msg); exit(1); } while (1)
char* python_script = "# --- the samples/simple.py script --- \n\
import wx\n\
print 'dir()>',dir()\n\
\n\
class MyFrame(wx.Frame):\n\
def __init__(self, parent, title):\n\
wx.Frame.__init__(self, parent, -1, title,pos=(150, 150), size=(350, 200))\n\
menuBar = wx.MenuBar()\n\
menu = wx.Menu()\n\
menu.Append(wx.ID_EXIT, 'E&xit\tAlt-X', 'Exit this simple sample')\n\
self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT)\n\
menuBar.Append(menu, '&File')\n\
self.SetMenuBar(menuBar)\n\
self.CreateStatusBar()\n\
panel = wx.Panel(self)\n\
text = wx.StaticText(panel, -1, 'Hello World!')\n\
text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))\n\
text.SetSize(text.GetBestSize())\n\
btn = wx.Button(panel, -1, 'Close')\n\
funbtn = wx.Button(panel, -1, 'Just for fun...')\n\
self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, btn)\n\
self.Bind(wx.EVT_BUTTON, self.OnFunButton, funbtn)\n\
sizer = wx.BoxSizer(wx.VERTICAL)\n\
sizer.Add(text, 0, wx.ALL, 10)\n\
sizer.Add(btn, 0, wx.ALL, 10)\n\
sizer.Add(funbtn, 0, wx.ALL, 10)\n\
panel.SetSizer(sizer)\n\
panel.Layout()\n\
def OnTimeToClose(self, evt):\n\
print 'See ya later!'\n\
self.Close()\n\
def OnFunButton(self, evt):\n\
print 'Having fun yet?'\n\
class MyApp(wx.App):\n\
def OnInit(self):\n\
frame = MyFrame(None, 'Simple wxPython App')\n\
frame.Show(True)\n\
self.SetTopWindow(frame)\n\
return True\n\
def main():\n\
print 'about to segfault...'\n\
# return
app = MyApp(True)\n\
print 'are we still alive...'\n\
app.MainLoop()\n\
\n\
main()\n\
\n\
";
main() {
PyObject *pmod, *pycomp;
Py_Initialize();
pycomp = Py_CompileString(python_script,"filename", Py_file_input);
if (pycomp == NULL){
PyErr_Print();
error("[pycomp]> Error in compiling py script");
}
pmod = PyImport_ExecCodeModule("bozo",pycomp);
if (pmod == NULL){
PyErr_Print();
error("Can't load module whatever");
}
}
--------------------------------------