From acc68cc2b3e167ccc992be2ad616a5de0a04ac6e Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 9 Dec 2008 23:48:44 +0000 Subject: [PATCH] #4592: fix embedding example with new C API changes. --- Doc/extending/embedding.rst | 10 ++++++++-- Doc/extending/extending.rst | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Doc/extending/embedding.rst b/Doc/extending/embedding.rst index e5c7da19d9..5c4fde8464 100644 --- a/Doc/extending/embedding.rst +++ b/Doc/extending/embedding.rst @@ -223,11 +223,17 @@ Python extension. For example:: NULL, NULL, NULL, NULL }; + static PyObject* + PyInit_emb(void) + { + return PyModule_Create(&EmbModule); + } + Insert the above code just above the :cfunc:`main` function. Also, insert the -following two statements directly after :cfunc:`Py_Initialize`:: +following two statements before the call to :cfunc:`Py_Initialize`:: numargs = argc; - PyModule_Create(&EmbModule); + PyImport_AppendInittab("emb", &PyInit_emb); These two lines initialize the ``numargs`` variable, and make the :func:`emb.numargs` function accessible to the embedded Python interpreter. diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst index 851e99f6d6..c05bcfd7d4 100644 --- a/Doc/extending/extending.rst +++ b/Doc/extending/extending.rst @@ -342,7 +342,7 @@ satisfactorily. The init function must return the module object to its caller, so that it then gets inserted into ``sys.modules``. When embedding Python, the :cfunc:`PyInit_spam` function is not called -automatically unless there's an entry in the :cdata:`_PyImport_Inittab` table. +automatically unless there's an entry in the :cdata:`PyImport_Inittab` table. To add the module to the initialization table, use :cfunc:`PyImport_AppendInittab`, optionally followed by an import of the module:: -- 2.40.0