New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Embedding example does not add created module #48842
Comments
Following an example of how to extend and embed that I found in patch |
It seems that a call to "PyDict_SetItemString" is what is missing from PyObject* m = PyModule_Create(&EmbModule);
PyDict_SetItemString(PyImport_GetModuleDict(), EmbModule.m_name, m); I am just guessing here though, don't know if this is correct way to do |
In python2.6, Py_InitModule4() calls PyImport_AddModule(). Index: Objects/moduleobject.c --- Objects/moduleobject.c (revision 67577)
+++ Objects/moduleobject.c (working copy)
@@ -103,8 +103,9 @@
_Py_PackageContext = NULL;
}
}
- if ((m = (PyModuleObject*)PyModule_New(name)) == NULL)
+ if ((m = (PyModuleObject*)PyImport_AddModule(name)) == NULL)
return NULL;
+ Py_INCREF(m); if (module->m_size > 0) {
m->md_state = PyMem_MALLOC(module->m_size); |
Because the init function for extension modules are supposed to return |
So, does that mean that Python is fine and there is a problem in the |
The example is broken. And the example under discussion is I have changed the title to be more descriptive and assigned to Martin |
The proper way of extending embedded Python can be seen in I can't contribute to the documentation, so I'm unassigning myself. |
See attached documentation patch. Instead of a direct call to PyModule_Create(), the main function must
use
PyImport_AppendInittab("emb", &PyInit_emb); Note that the same line also works for all 2.x versions. |
Applied in r67682. Please don't add things directly to cporting.rst, rather amend the |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: