This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2008年12月08日 15:00 by blakemadden, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| python.cpp | blakemadden, 2008年12月08日 15:00 | |||
| embedding_example.patch | amaury.forgeotdarc, 2008年12月09日 23:24 | |||
| Messages (9) | |||
|---|---|---|---|
| msg77307 - (view) | Author: blake madden (blakemadden) | Date: 2008年12月08日 15:00 | |
Following an example of how to extend and embed that I found in patch file r67655 (the website is out of date [issue4586]), PyModule_Create appears to not work (or example is not complete). When I run r67655 (attached also) I get an error saying that "emb" is not a module. |
|||
| msg77322 - (view) | Author: blake madden (blakemadden) | Date: 2008年12月08日 16:24 | |
It seems that a call to "PyDict_SetItemString" is what is missing from r67655: 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 things. |
|||
| msg77326 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) | Date: 2008年12月08日 16:50 | |
In python2.6, Py_InitModule4() calls PyImport_AddModule(). Why doesn't python3.0's PyModule_Create() do the same? 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); |
|||
| msg77445 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2008年12月09日 20:53 | |
Because the init function for extension modules are supposed to return the module now and the import machinery adds the module itself. |
|||
| msg77449 - (view) | Author: blake madden (blakemadden) | Date: 2008年12月09日 21:00 | |
So, does that mean that Python is fine and there is a problem in the example? How do I get that example to work, there seems to be something missing in it. Thanks. |
|||
| msg77453 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2008年12月09日 21:05 | |
The example is broken. And the example under discussion is http://docs.python.org/dev/3.0/extending/embedding.html#extending-embedded-python . I have changed the title to be more descriptive and assigned to Martin to find out what the proper way is to handle this case. |
|||
| msg77464 - (view) | Author: Martin v. Löwis (loewis) * (Python committer) | Date: 2008年12月09日 22:22 | |
The proper way of extending embedded Python can be seen in Demo/embed/demo.c. I can't contribute to the documentation, so I'm unassigning myself. |
|||
| msg77471 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) | Date: 2008年12月09日 23:24 | |
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.
I'll try to add an item to howto/cporting.rst.
|
|||
| msg77474 - (view) | Author: Georg Brandl (georg.brandl) * (Python committer) | Date: 2008年12月09日 23:49 | |
Applied in r67682. Please don't add things directly to cporting.rst, rather amend the PortingExtensionModulesToPy3k wiki page. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:42 | admin | set | github: 48842 |
| 2008年12月09日 23:49:19 | georg.brandl | set | status: open -> closed resolution: fixed messages: + msg77474 |
| 2008年12月09日 23:24:21 | amaury.forgeotdarc | set | keywords:
+ needs review, patch files: + embedding_example.patch messages: + msg77471 |
| 2008年12月09日 22:22:41 | loewis | set | assignee: loewis -> messages: + msg77464 |
| 2008年12月09日 21:05:24 | brett.cannon | set | priority: critical assignee: georg.brandl -> loewis title: Example patch is missing something -> Embedding example does not add created module messages: + msg77453 stage: needs patch |
| 2008年12月09日 21:00:25 | blakemadden | set | messages: + msg77449 |
| 2008年12月09日 20:53:10 | brett.cannon | set | nosy:
+ brett.cannon messages: + msg77445 |
| 2008年12月08日 16:50:00 | amaury.forgeotdarc | set | nosy:
+ amaury.forgeotdarc, loewis messages: + msg77326 |
| 2008年12月08日 16:24:42 | blakemadden | set | title: PyModule_Create doesn't work (or example is missing something) -> Example patch is missing something |
| 2008年12月08日 16:24:01 | blakemadden | set | assignee: georg.brandl messages: + msg77322 components: + Documentation, - Extension Modules nosy: + georg.brandl |
| 2008年12月08日 15:00:51 | blakemadden | create | |