mirror of
https://github.com/python/cpython.git
synced 2025-12-10 11:00:14 +00:00
#4592: fix embedding example with new C API changes.
This commit is contained in:
parent
a872787f5f
commit
acc68cc2b3
2 changed files with 9 additions and 3 deletions
|
|
@ -223,11 +223,17 @@ Python extension. For example::
|
||||||
NULL, NULL, NULL, NULL
|
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
|
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;
|
numargs = argc;
|
||||||
PyModule_Create(&EmbModule);
|
PyImport_AppendInittab("emb", &PyInit_emb);
|
||||||
|
|
||||||
These two lines initialize the ``numargs`` variable, and make the
|
These two lines initialize the ``numargs`` variable, and make the
|
||||||
:func:`emb.numargs` function accessible to the embedded Python interpreter.
|
:func:`emb.numargs` function accessible to the embedded Python interpreter.
|
||||||
|
|
|
||||||
|
|
@ -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``.
|
so that it then gets inserted into ``sys.modules``.
|
||||||
|
|
||||||
When embedding Python, the :cfunc:`PyInit_spam` function is not called
|
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`,
|
To add the module to the initialization table, use :cfunc:`PyImport_AppendInittab`,
|
||||||
optionally followed by an import of the module::
|
optionally followed by an import of the module::
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue