Skip to content

Commit acc68cc

Browse files
committed
python#4592: fix embedding example with new C API changes.
1 parent a872787 commit acc68cc

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Doc/extending/embedding.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,17 @@ Python extension. For example::
223223
NULL, NULL, NULL, NULL
224224
};
225225

226+
static PyObject*
227+
PyInit_emb(void)
228+
{
229+
return PyModule_Create(&EmbModule);
230+
}
231+
226232
Insert the above code just above the :cfunc:`main` function. Also, insert the
227-
following two statements directly after :cfunc:`Py_Initialize`::
233+
following two statements before the call to :cfunc:`Py_Initialize`::
228234

229235
numargs = argc;
230-
PyModule_Create(&EmbModule);
236+
PyImport_AppendInittab("emb", &PyInit_emb);
231237

232238
These two lines initialize the ``numargs`` variable, and make the
233239
:func:`emb.numargs` function accessible to the embedded Python interpreter.

Doc/extending/extending.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ satisfactorily. The init function must return the module object to its caller,
342342
so that it then gets inserted into ``sys.modules``.
343343

344344
When embedding Python, the :cfunc:`PyInit_spam` function is not called
345-
automatically unless there's an entry in the :cdata:`_PyImport_Inittab` table.
345+
automatically unless there's an entry in the :cdata:`PyImport_Inittab` table.
346346
To add the module to the initialization table, use :cfunc:`PyImport_AppendInittab`,
347347
optionally followed by an import of the module::
348348

0 commit comments

Comments
 (0)