Saturday 15 August 2015

c++ - PyModule_AddObject Crashing -


I have participated in a problem that is just trying to find out. In event_init , I found that calling does not matter what type of module I do to build. Trying to isolate the problem further, I have found out that it is only adding your custom type in case that the accident causes that (link Py_True runs fine), and that In order to actually do this, manipulation of the dictionary of the dictionary module is causing the accident (internal call to PyDict_SetItem )

  #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 [] = { "at {", (PyCFunction) pyKey_on, METH_STATIC, "a keyboard event handler Bind one or more events. "}, {NULL}}; High PyTypeObject pyKey_Type = {PyVarObject_HEAD_INIT (zero, 0) "key", sizeof (pyEventProxy), 0, 0, 0, / * tp_print * / 0, / * tp_getattr * / 0, / * tp_setattr * / 0, / * tp_reserved * / 0, / * Tp_repr * / 0, / * Tp_as_nanbr * / 0, / * Tp_as_sicvens * / 0, / * Tp_as_maping * / 0, / * Tp_has * / 0, / * Tp_col * / 0, / * Tp_str * / 0, / * tp_getattro * / 0, / * tp_setattro * / 0, / * tp_as_buffer * / Py_TPFLAGS_DEFAULT, "proxy object specific event to use the functions.", 0, / * tp_traverse * / 0, / * tp_clear * / 0, / * Tp_rickpre * / 0, / * Tp_veaklistofafaset * / 0, / * Tp_itr * / 0, / * Tp_itrnest * / Pike_methds, / * Tp_methds * /}; Static PyModuleDef pyEvent_Module = {PyModuleDef_HEAD_INIT, "Event", "Interact with event handling of sandboxes.", -1, 0, 0, 0, 0, 0}; // function in another file called module to start zero event_init () {printf ("start typing proxy type \ n"); If (PETIP_REDI (and PKKIHIPEP) & lt; 0) {printf ("key preparation failed \ n"); Return; } Printf ("Creating Module \ n"); PyObject * module = PyModule_Create (and pyEvent_Module); If (! Module) {return; } Printf ("Adding Proxy Proxy \ n"); Py_INCREF (& amp; pyKey_Type); // It crashes PyModule_AddObject (module, "key", (PyObject *) and pyKey_Type); }   

I am working on preparing it for the week, yet it is still behind me, what is wrong, one more thing, an example of bare bones from the Python extension tutorial As soon as crashes, but not for later examples.

(If this is familiar, I had asked this question a week ago and I got a "TamilWood" badge ... then ...)

The module initialization function should return the module object in Python 3.x. Your code will not work this way A proper init function for your module looks like this:

  PyMODINIT_FUNC PyInit_event (zero) {PyObject * module; Module = pyramodlclery (& amp; pyEvent_Module); ... return module; }    

No comments:

Post a Comment