Note that there are some explanatory texts on larger screens.

plurals
  1. POPyObject segfault on function call
    primarykey
    data
    text
    <p>I'm trying to use Python to open a dialog to accept input into my C++ application. </p> <p>Here is a very minimal representation of what I am trying to do:</p> <pre><code>#include &lt;iostream&gt; #include &lt;Python.h&gt; int main() { /* Begin Python Ititialization - only needs to be done once. */ PyObject *ip_module_name = NULL; PyObject *ip_module = NULL; PyObject *ip_module_contents = NULL; PyObject *ip_module_getip_func = NULL; Py_Initialize(); PyEval_InitThreads(); ip_module_name = PyString_FromString( "get_ip" ); ip_module = PyImport_Import( ip_module_name ); ip_module_contents = PyModule_GetDict( ip_module ); ip_module_getip_func = PyDict_GetItemString( ip_module_contents, "get_ip_address" ); /* End Initialization */ PyGILState_STATE state = PyGILState_Ensure(); PyObject *result = PyObject_CallObject( ip_module_getip_func, NULL ); if( result == Py_None ) printf( "None\n" ); else printf( "%s\n", PyString_AsString( result ) ); PyGILState_Release( state ); /* This is called when the progam exits. */ Py_Finalize(); } </code></pre> <p>However, when I call the function with PyObject_CallObject, the app segfaults. I'm guessing that it's because I'm using the Tk library. I've tried linking my app against _tkinter.lib, tk85.lib, tcl85.lib, tkstub85.lib, tclstub85.lib and none of that helps. I'm pretty stumped...</p> <p>Here's the script:</p> <pre><code>import Tkinter as tk from tkSimpleDialog import askstring from tkMessageBox import showerror def get_ip_address(): root = tk.Tk() root.withdraw() ip = askstring( 'Server Address', 'Enter IP:' ) if ip is None: return None ip = ip.strip() if ip is '': showerror( 'Error', 'Please enter a valid IP address' ) return get_ip_address() if len(ip.split(".")) is not 4: showerror( 'Error', 'Please enter a valid IP address' ) return get_ip_address() for octlet in ip.split("."): x = 0 if octlet.isdigit(): x = int(octlet) else: showerror( 'Error', 'Please enter a valid IP address' ) return get_ip_address() if not ( x &lt; 256 and x &gt;= 0 ): showerror( 'Error', 'Please enter a valid IP address' ) return get_ip_address() return ip </code></pre> <p>Edit: added my threading setup</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload