Note that there are some explanatory texts on larger screens.

plurals
  1. POPyModule_AddObject Crashing
    primarykey
    data
    text
    <p>I've run into a problem that has just been hell trying to figure out. In <code>event_init</code>, I found that calling <code>PyModule_AddObject</code> fails no matter what I do to the types and module creation. Trying to further isolate the problem, I figured out that it's only my custom types being added that cases it to crash (adding <code>Py_True</code> runs fine), and it's the manipulation of the module's dictionary that's actually causing it to crash (the internal call to <code>PyDict_SetItem</code>)</p> <pre><code>#include &lt;Python.h&gt; #include &lt;structmember.h&gt; struct pyEventProxy{ PyObject_HEAD }; static PyObject* pyKey_on(PyObject*,PyObject* args,PyObject* kwargs){ /* ... */ } static PyMethodDef pyKey_Methods[]={ {"on",(PyCFunction)pyKey_on,METH_STATIC,"Bind a keyboard event handler for one or more events."}, {NULL} }; static PyTypeObject pyKey_Type={ PyVarObject_HEAD_INIT(NULL,0) "key", sizeof(pyEventProxy), 0, 0, 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, "Proxy object to access specific event functions.", 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ pyKey_Methods, /* tp_methods */ }; static PyModuleDef pyEvent_Module={ PyModuleDef_HEAD_INIT, "event", "Interact with Sandblox's event handling.", -1, 0, 0, 0, 0, 0 }; //Function called in another file to initialize the module void event_init(){ printf("Initializing key proxy type\n"); if(PyType_Ready(&amp;pyKey_Type)&lt;0){ printf("Key preparation failed\n"); return; } printf("Creating module\n"); PyObject* module=PyModule_Create(&amp;pyEvent_Module); if(!module){ return; } printf("Adding key proxy\n"); Py_INCREF(&amp;pyKey_Type); //This crashes PyModule_AddObject(module,"key",(PyObject*)&amp;pyKey_Type); } </code></pre> <p>I've been working on figuring this out for weeks, yet it's still beyond me what's even wrong. Another thing, the bare-bones example from the Python extension tutorial crashes just like mine does, but not for later examples. What am I doing wrong here?</p> <p>(in case this seems familiar, I asked this question a week ago and got a "tumbleweed" badge. So...)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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