classification
Title: Py_InitModule* is still referenced in docs
Type: Stage:
Components: Documentation Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: amaury.forgeotdarc, benjamin.peterson, erickt, georg.brandl, idadesub, loewis
Priority: high Keywords: needs review, patch

Created on 2008-08-28 20:48 by erickt, last changed 2008-10-17 15:55 by loewis. This issue is now closed.

Files
File name Uploaded Description Edit
embed.diff loewis, 2008-10-17 14:37
Messages (6)
msg72111 - (view) Author: Erick Tryzelaar (erickt) Date: 2008-08-28 20:48
The docs still reference Py_InitModule*, which was removed in r64107. 
Also,  Demo/embed/demo.c still use Py_InitModule, and thus doesn't 
compile.
msg72113 - (view) Author: Erick Tryzelaar (idadesub) Date: 2008-08-28 21:27
On Thu, Aug 28, 2008 at 1:48 PM, Erick Tryzelaar <report@bugs.python.org> wrote:
>
> New submission from Erick Tryzelaar <idadesub@users.sourceforge.net>:
>
> The docs still reference Py_InitModule*, which was removed in r64107.
> Also,  Demo/embed/demo.c still use Py_InitModule, and thus doesn't
> compile.

Here's a patch to get demo.c working, though it's acting a little
strange. Printing out sys.argv results in japanese characters for some
reason.

Index: Demo/embed/demo.c
===================================================================
--- Demo/embed/demo.c	(revision 66055)
+++ Demo/embed/demo.c	(working copy)
@@ -2,9 +2,9 @@

 #include "Python.h"

-void initxyzzy(void); /* Forward */
+PyObject* PyInit_xyzzy(void); /* Forward */

-main(int argc, char **argv)
+main(int argc, wchar_t **argv)
 {
 	/* Pass argv[0] to the Python interpreter */
 	Py_SetProgramName(argv[0]);
@@ -13,7 +13,7 @@
 	Py_Initialize();

 	/* Add a static module */
-	initxyzzy();
+	PyInit_xyzzy();

 	/* Define sys.argv.  It is up to the application if you
 	   want this; you can also let it undefined (since the Python
@@ -26,10 +26,10 @@

 	/* Execute some Python statements (in module __main__) */
 	PyRun_SimpleString("import sys\n");
-	PyRun_SimpleString("print sys.builtin_module_names\n");
-	PyRun_SimpleString("print sys.modules.keys()\n");
-	PyRun_SimpleString("print sys.executable\n");
-	PyRun_SimpleString("print sys.argv\n");
+	PyRun_SimpleString("print(sys.builtin_module_names)\n");
+	PyRun_SimpleString("print(sys.modules.keys())\n");
+	PyRun_SimpleString("print(sys.executable)\n");
+	PyRun_SimpleString("print(sys.argv)\n");

 	/* Note that you can call any public function of the Python
 	   interpreter here, e.g. call_object(). */
@@ -57,9 +57,22 @@
 	{NULL,		NULL}		/* sentinel */
 };

-void
-initxyzzy(void)
+static struct PyModuleDef xyzzymodule = {
+	{}, /* m_base */
+	"xyzzy",  /* m_name */
+	0,  /* m_doc */
+	0,  /* m_size */
+	xyzzy_methods,  /* m_methods */
+	0,  /* m_reload */
+	0,  /* m_traverse */
+	0,  /* m_clear */
+	0,  /* m_free */
+};
+
+PyObject*
+PyInit_xyzzy(void)
 {
-	PyImport_AddModule("xyzzy");
-	Py_InitModule("xyzzy", xyzzy_methods);
+	PyObject* res = PyModule_Create(&xyzzymodule);
+	if (!res) return NULL;
+	return res;
 }

With loop.c, there are issues with char*/wchar_t* and I'm not sure
what the right approach is. Finally, importexc.c is segfaulting with:

#0  0x0005b2f3 in PyDict_SetItem (op=0x0, key=0x44bed0,
value=0x17d460) at Objects/dictobject.c:712
#1  0x0005ee02 in PyDict_SetItemString (v=0x0, key=0x16e860
"last_type", item=0x17d460) at Objects/dictobject.c:2090
#2  0x0012c23a in PySys_SetObject (name=0x16e860 "last_type",
v=0x17d460) at Python/sysmodule.c:67
#3  0x00122c99 in PyErr_PrintEx (set_sys_last_vars=1) at Python/pythonrun.c:1254
#4  0x001228bc in PyErr_Print () at Python/pythonrun.c:1150
#5  0x001223a1 in PyRun_SimpleStringFlags (command=0x157b80 "import
sys", flags=0x0) at Python/pythonrun.c:1075
#6  0x0000243b in main () at importexc.c:13
msg72128 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-08-29 12:11
In your patch, it is not correct to declare main as
    main(int argc, wchar_t **argv)
It is simply not the correct signature: the OS only supports "char** argv".

You have to perform the conversion yourself. Look for example at
Modules/python.c.

The problem with importexc.c is more serious; I've filled issue3723 for
this.
msg74912 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-10-17 14:37
Here is a patch that makes Demo/embed compile and run successfully.
msg74913 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-10-17 14:41
Looks good to me.
msg74921 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-10-17 15:55
Committed as r66961.
History
Date User Action Args
2008-10-17 15:55:15loewissetstatus: open -> closed
resolution: fixed
messages: + msg74921
keywords: + needs review
2008-10-17 14:41:15benjamin.petersonsetkeywords: - needs review
nosy: + benjamin.peterson
messages: + msg74913
2008-10-17 14:37:06loewissetkeywords: + patch, needs review
nosy: + loewis
messages: + msg74912
files: + embed.diff
2008-08-29 12:11:45amaury.forgeotdarcsetpriority: high
nosy: + amaury.forgeotdarc
messages: + msg72128
2008-08-28 21:27:24idadesubsetnosy: + idadesub
messages: + msg72113
2008-08-28 20:48:50ericktcreate