Commit ef6373a4 authored by Fred Drake's avatar Fred Drake

Exhibit good form in C code: always provide docstrings in method tables, and

always fill in all slots of table entries.
Fixed a few minor markup errors.
parent 50ecc15d
...@@ -231,9 +231,10 @@ emb_numargs(PyObject *self, PyObject *args) ...@@ -231,9 +231,10 @@ emb_numargs(PyObject *self, PyObject *args)
return Py_BuildValue("i", numargs); return Py_BuildValue("i", numargs);
} }
static PyMethodDef EmbMethods[]={ static PyMethodDef EmbMethods[] = {
{"numargs", emb_numargs, METH_VARARGS}, {"numargs", emb_numargs, METH_VARARGS,
{NULL, NULL} "Return the number of arguments received by the process."},
{NULL, NULL, 0, NULL}
}; };
\end{verbatim} \end{verbatim}
......
...@@ -215,7 +215,7 @@ the error checking for now): ...@@ -215,7 +215,7 @@ the error checking for now):
\begin{verbatim} \begin{verbatim}
void void
initspam() initspam(void)
{ {
PyObject *m, *d; PyObject *m, *d;
...@@ -308,9 +308,10 @@ table'': ...@@ -308,9 +308,10 @@ table'':
\begin{verbatim} \begin{verbatim}
static PyMethodDef SpamMethods[] = { static PyMethodDef SpamMethods[] = {
... ...
{"system", spam_system, METH_VARARGS}, {"system", spam_system, METH_VARARGS,
"Execute a shell command."},
... ...
{NULL, NULL} /* Sentinel */ {NULL, NULL, 0, NULL} /* Sentinel */
}; };
\end{verbatim} \end{verbatim}
...@@ -340,7 +341,7 @@ the module file: ...@@ -340,7 +341,7 @@ the module file:
\begin{verbatim} \begin{verbatim}
void void
initspam() initspam(void)
{ {
(void) Py_InitModule("spam", SpamMethods); (void) Py_InitModule("spam", SpamMethods);
} }
...@@ -992,12 +993,13 @@ static PyMethodDef keywdarg_methods[] = { ...@@ -992,12 +993,13 @@ static PyMethodDef keywdarg_methods[] = {
* only take two PyObject* parameters, and keywdarg_parrot() takes * only take two PyObject* parameters, and keywdarg_parrot() takes
* three. * three.
*/ */
{"parrot", (PyCFunction)keywdarg_parrot, METH_VARARGS|METH_KEYWORDS}, {"parrot", (PyCFunction)keywdarg_parrot, METH_VARARGS|METH_KEYWORDS,
{NULL, NULL} /* sentinel */ "Print a lovely skit to standard output."},
{NULL, NULL, 0, NULL} /* sentinel */
}; };
void void
initkeywdarg() initkeywdarg(void)
{ {
/* Create the module and add the functions */ /* Create the module and add the functions */
Py_InitModule("keywdarg", keywdarg_methods); Py_InitModule("keywdarg", keywdarg_methods);
...@@ -1590,7 +1592,7 @@ the C API pointer array: ...@@ -1590,7 +1592,7 @@ the C API pointer array:
\begin{verbatim} \begin{verbatim}
void void
initspam() initspam(void)
{ {
PyObject *m; PyObject *m;
static void *PySpam_API[PySpam_API_pointers]; static void *PySpam_API[PySpam_API_pointers];
...@@ -1614,8 +1616,8 @@ initspam() ...@@ -1614,8 +1616,8 @@ initspam()
} }
\end{verbatim} \end{verbatim}
Note that \code{PySpam_API} is declared \code{static}; otherwise Note that \code{PySpam_API} is declared \keyword{static}; otherwise
the pointer array would disappear when \code{initspam} terminates! the pointer array would disappear when \function{initspam()} terminates!
The bulk of the work is in the header file \file{spammodule.h}, The bulk of the work is in the header file \file{spammodule.h},
which looks like this: which looks like this:
...@@ -1679,7 +1681,7 @@ function: ...@@ -1679,7 +1681,7 @@ function:
\begin{verbatim} \begin{verbatim}
void void
initclient() initclient(void)
{ {
PyObject *m; PyObject *m;
......
...@@ -77,8 +77,9 @@ static PyTypeObject noddy_NoddyType = { ...@@ -77,8 +77,9 @@ static PyTypeObject noddy_NoddyType = {
}; };
static PyMethodDef noddy_methods[] = { static PyMethodDef noddy_methods[] = {
{ "new_noddy", noddy_new_noddy, METH_VARARGS }, {"new_noddy", noddy_new_noddy, METH_VARARGS,
{NULL, NULL} "Create a new Noddy object."},
{NULL, NULL, 0, NULL}
}; };
DL_EXPORT(void) DL_EXPORT(void)
...@@ -581,9 +582,11 @@ Here is an example: ...@@ -581,9 +582,11 @@ Here is an example:
\begin{verbatim} \begin{verbatim}
static PyMethodDef newdatatype_methods[] = { static PyMethodDef newdatatype_methods[] = {
{"getSize", (PyCFunction)newdatatype_getSize, METH_VARARGS}, {"getSize", (PyCFunction)newdatatype_getSize, METH_VARARGS,
{"setSize", (PyCFunction)newdatatype_setSize, METH_VARARGS}, "Return the current size."},
{NULL, NULL} /* sentinel */ {"setSize", (PyCFunction)newdatatype_setSize, METH_VARARGS,
"Set the size."},
{NULL, NULL, 0, NULL} /* sentinel */
}; };
static PyObject * static PyObject *
......
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