Commit 80d4c077 authored by Fred Drake's avatar Fred Drake

There was a real leak in the "export a C API" example; fix that one.

(There are too many initspam() functions; they need to be renamed
post-beta.)
parent ab357ecf
...@@ -1619,9 +1619,10 @@ the C API pointer array: ...@@ -1619,9 +1619,10 @@ the C API pointer array:
void void
initspam() initspam()
{ {
PyObject *m, *d; PyObject *m;
static void *PySpam_API[PySpam_API_pointers]; static void *PySpam_API[PySpam_API_pointers];
PyObject *c_api_object; PyObject *c_api_object;
m = Py_InitModule("spam", SpamMethods); m = Py_InitModule("spam", SpamMethods);
/* Initialize the C API pointer array */ /* Initialize the C API pointer array */
...@@ -1630,9 +1631,13 @@ initspam() ...@@ -1630,9 +1631,13 @@ initspam()
/* Create a CObject containing the API pointer array's address */ /* Create a CObject containing the API pointer array's address */
c_api_object = PyCObject_FromVoidPtr((void *)PySpam_API, NULL); c_api_object = PyCObject_FromVoidPtr((void *)PySpam_API, NULL);
/* Create a name for this object in the module's namespace */ if (c_api_object != NULL) {
d = PyModule_GetDict(m); /* Create a name for this object in the module's namespace */
PyDict_SetItemString(d, "_C_API", c_api_object); PyObject *d = PyModule_GetDict(m);
PyDict_SetItemString(d, "_C_API", c_api_object);
Py_DECREF(c_api_object);
}
} }
\end{verbatim} \end{verbatim}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment