Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef6373a

Browse files
committed
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.
1 parent 50ecc15 commit ef6373a

3 files changed

Lines changed: 25 additions & 19 deletions

File tree

Doc/ext/embedding.tex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,10 @@ \section{Extending Embedded Python
231231
return Py_BuildValue("i", numargs);
232232
}
233233
234-
static PyMethodDef EmbMethods[]={
235-
{"numargs", emb_numargs, METH_VARARGS},
236-
{NULL, NULL}
234+
static PyMethodDef EmbMethods[] = {
235+
{"numargs", emb_numargs, METH_VARARGS,
236+
"Return the number of arguments received by the process."},
237+
{NULL, NULL, 0, NULL}
237238
};
238239
\end{verbatim}
239240

Doc/ext/extending.tex

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ \section{Intermezzo: Errors and Exceptions
215215

216216
\begin{verbatim}
217217
void
218-
initspam()
218+
initspam(void)
219219
{
220220
PyObject *m, *d;
221221
@@ -308,9 +308,10 @@ \section{The Module's Method Table and Initialization Function
308308
\begin{verbatim}
309309
static PyMethodDef SpamMethods[] = {
310310
...
311-
{"system", spam_system, METH_VARARGS},
311+
{"system", spam_system, METH_VARARGS,
312+
"Execute a shell command."},
312313
...
313-
{NULL, NULL} /* Sentinel */
314+
{NULL, NULL, 0, NULL} /* Sentinel */
314315
};
315316
\end{verbatim}
316317

@@ -340,7 +341,7 @@ \section{The Module's Method Table and Initialization Function
340341

341342
\begin{verbatim}
342343
void
343-
initspam()
344+
initspam(void)
344345
{
345346
(void) Py_InitModule("spam", SpamMethods);
346347
}
@@ -992,12 +993,13 @@ \section{Keyword Parameters for Extension Functions
992993
* only take two PyObject* parameters, and keywdarg_parrot() takes
993994
* three.
994995
*/
995-
{"parrot", (PyCFunction)keywdarg_parrot, METH_VARARGS|METH_KEYWORDS},
996-
{NULL, NULL} /* sentinel */
996+
{"parrot", (PyCFunction)keywdarg_parrot, METH_VARARGS|METH_KEYWORDS,
997+
"Print a lovely skit to standard output."},
998+
{NULL, NULL, 0, NULL} /* sentinel */
997999
};
9981000
9991001
void
1000-
initkeywdarg()
1002+
initkeywdarg(void)
10011003
{
10021004
/* Create the module and add the functions */
10031005
Py_InitModule("keywdarg", keywdarg_methods);
@@ -1590,7 +1592,7 @@ \section{Providing a C API for an Extension Module
15901592

15911593
\begin{verbatim}
15921594
void
1593-
initspam()
1595+
initspam(void)
15941596
{
15951597
PyObject *m;
15961598
static void *PySpam_API[PySpam_API_pointers];
@@ -1614,8 +1616,8 @@ \section{Providing a C API for an Extension Module
16141616
}
16151617
\end{verbatim}
16161618

1617-
Note that \code{PySpam_API} is declared \code{static}; otherwise
1618-
the pointer array would disappear when \code{initspam} terminates!
1619+
Note that \code{PySpam_API} is declared \keyword{static}; otherwise
1620+
the pointer array would disappear when \function{initspam()} terminates!
16191621

16201622
The bulk of the work is in the header file \file{spammodule.h},
16211623
which looks like this:
@@ -1679,7 +1681,7 @@ \section{Providing a C API for an Extension Module
16791681

16801682
\begin{verbatim}
16811683
void
1682-
initclient()
1684+
initclient(void)
16831685
{
16841686
PyObject *m;
16851687

Doc/ext/newtypes.tex

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ \section{The Basics
7777
};
7878
7979
static PyMethodDef noddy_methods[] = {
80-
{ "new_noddy", noddy_new_noddy, METH_VARARGS },
81-
{NULL, NULL}
80+
{"new_noddy", noddy_new_noddy, METH_VARARGS,
81+
"Create a new Noddy object."},
82+
{NULL, NULL, 0, NULL}
8283
};
8384
8485
DL_EXPORT(void)
@@ -581,9 +582,11 @@ \subsection{Attribute Management Functions}
581582

582583
\begin{verbatim}
583584
static PyMethodDef newdatatype_methods[] = {
584-
{"getSize", (PyCFunction)newdatatype_getSize, METH_VARARGS},
585-
{"setSize", (PyCFunction)newdatatype_setSize, METH_VARARGS},
586-
{NULL, NULL} /* sentinel */
585+
{"getSize", (PyCFunction)newdatatype_getSize, METH_VARARGS,
586+
"Return the current size."},
587+
{"setSize", (PyCFunction)newdatatype_setSize, METH_VARARGS,
588+
"Set the size."},
589+
{NULL, NULL, 0, NULL} /* sentinel */
587590
};
588591
589592
static PyObject *

0 commit comments

Comments
 (0)