Skip to content

Commit

Permalink
Added doc strings, suggested by Charles G. Waldman (but massaged quit…
Browse files Browse the repository at this point in the history
…e a bit).
  • Loading branch information
gvanrossum committed Dec 19, 1997
1 parent 3c4bb80 commit 414fd48
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions Modules/structmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ PERFORMANCE OF THIS SOFTWARE.
/* New version supporting byte order, alignment and size options,
character strings, and unsigned numbers */

static char struct__doc__[] = "\
Functions to convert between Python values and C structs.\n\
Python strings are used to hold the data representing the C struct\n\
and also as format strings to describe the layout of data in the C struct.\n\
\n\
The optional first format char indicates byte ordering and alignment:\n\
@: native w/native alignment(default)\n\
=: native w/standard alignment\n\
<: little-endian, std. alignment\n\
>: big-endian, std. alignment\n\
!: network, std (same as >)\n\
\n\
The remaining chars indicate types of args and must match exactly;\n\
these can be preceded by a decimal repeat count:\n\
x: pad byte (no data); c:char; b:signed byte; B:unsigned byte;\n\
h:short; H:unsigned short; i:int; I:unsigned int;\n\
l:long; L:unsigned long; f:float; d:double.\n\
Special cases (preceding decimal count indicates length):\n\
s:string (array of char); p: pascal string (w. count byte).\n\
Whitespace between formats is ignored.\n\
\n\
The variable struct.error is an exception raised on errors.";

#include "Python.h"
#include "mymath.h"

Expand Down Expand Up @@ -1023,7 +1046,10 @@ calcsize(fmt, f)
}


/* pack(fmt, v1, v2, ...) --> string */
static char calcsize__doc__[] = "\
calcsize(fmt) -> int\n\
Return size of C struct described by format string fmt.\n\
See struct.__doc__ for more on format strings.";

static PyObject *
struct_calcsize(self, args)
Expand All @@ -1044,7 +1070,10 @@ struct_calcsize(self, args)
}


/* pack(fmt, v1, v2, ...) --> string */
static char pack__doc__[] = "\
pack(fmt, v1, v2, ...) -> string\n\
Return string containing values v1, v2, ... packed according to fmt.\n\
See struct.__doc__ for more on format strings.";

static PyObject *
struct_pack(self, args)
Expand Down Expand Up @@ -1179,7 +1208,11 @@ struct_pack(self, args)
}


/* unpack(fmt, string) --> (v1, v2, ...) */
static char unpack__doc__[] =
"unpack(fmt, string) -> (v1, v2, ...)
Unpack the string, containing packed C structure data, according\n"
"to fmt. Requires len(string)==calcsize(fmt).\n\
See struct.__doc__ for more on format strings.";

static PyObject *
struct_unpack(self, args)
Expand Down Expand Up @@ -1279,9 +1312,9 @@ struct_unpack(self, args)
/* List of functions */

static PyMethodDef struct_methods[] = {
{"calcsize", struct_calcsize, METH_VARARGS},
{"pack", struct_pack, METH_VARARGS},
{"unpack", struct_unpack, METH_VARARGS},
{"calcsize", struct_calcsize, METH_VARARGS, calcsize__doc__},
{"pack", struct_pack, METH_VARARGS, pack__doc__},
{"unpack", struct_unpack, METH_VARARGS, unpack__doc__},
{NULL, NULL} /* sentinel */
};

Expand All @@ -1294,7 +1327,8 @@ initstruct()
PyObject *m, *d;

/* Create the module and add the functions */
m = Py_InitModule("struct", struct_methods);
m = Py_InitModule4("struct", struct_methods, struct__doc__,
(PyObject*)NULL, PYTHON_API_VERSION);

/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
Expand Down

0 comments on commit 414fd48

Please sign in to comment.