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

Skip to content

Commit 9a69112

Browse files
committed
Jim Fulton's change to support doc strings
1 parent 1e05402 commit 9a69112

5 files changed

Lines changed: 30 additions & 4 deletions

File tree

Tools/modulator/Templates/module_method

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
static char $abbrev$_$method$__doc__[] =
3+
""
4+
;
5+
26
static PyObject *
37
$abbrev$_$method$(self, args)
48
PyObject *self; /* Not used */

Tools/modulator/Templates/module_tail

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ static struct PyMethodDef $abbrev$_methods[] = {
99

1010
/* Initialization function for the module (*must* be called init$name$) */
1111

12+
static char $name$_module_documentation[] =
13+
""
14+
;
15+
1216
void
1317
init$name$()
1418
{
1519
PyObject *m, *d;
1620

1721
/* Create the module and add the functions */
18-
m = Py_InitModule("$name$", $abbrev$_methods);
22+
m = Py_InitModule4("$name$", $abbrev$_methods,
23+
$name$_module_documentation,
24+
(PyObject*)NULL,PYTHON_API_VERSION);
1925

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

Tools/modulator/Templates/object_method

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
static char $abbrev$_$method$__doc__[] =
3+
""
4+
;
5+
26
static PyObject *
37
$abbrev$_$method$(self, args)
48
$abbrev$object *self;

Tools/modulator/Templates/object_tail

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
static char $Abbrev$type__doc__[] =
3+
""
4+
;
5+
26
static PyTypeObject $Abbrev$type = {
37
PyObject_HEAD_INIT(&PyType_Type)
48
0, /*ob_size*/
@@ -16,6 +20,12 @@ static PyTypeObject $Abbrev$type = {
1620
$tp_as_sequence$, /*tp_as_sequence*/
1721
$tp_as_mapping$, /*tp_as_mapping*/
1822
(hashfunc)$tp_hash$, /*tp_hash*/
23+
(binaryfunc)$tp_call$, /*tp_call*/
24+
(reprfunc)$tp_str$, /*tp_str*/
25+
26+
/* Space for future expansion */
27+
0L,0L,0L,0L,
28+
$Abbrev$type__doc__ /* Documentation string */
1929
};
2030

2131
/* End of code for $name$ objects */

Tools/modulator/genmodule.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# Names of functions in the object-description struct.
2929
#
3030
FUNCLIST = ['new', 'tp_dealloc', 'tp_print', 'tp_getattr', 'tp_setattr',
31-
'tp_compare', 'tp_repr', 'tp_hash']
31+
'tp_compare', 'tp_repr', 'tp_hash', 'tp_call', 'tp_str']
3232
TYPELIST = ['tp_as_number', 'tp_as_sequence', 'tp_as_mapping', 'structure']
3333

3434
#
@@ -81,7 +81,8 @@ def writecode(self, fp):
8181
for fn in self.methodlist:
8282
self.method = fn
8383
self.addcode('module_method', fp)
84-
new_ml = new_ml + ('{"%s",\t%s_%s,\t1},\n'%(fn, self.abbrev, fn))
84+
new_ml = new_ml + ('{"%s",\t%s_%s,\t1,\t%s_%s__doc__},\n'
85+
%(fn, self.abbrev, fn, self.abbrev, fn))
8586
self.methodlist = new_ml
8687
self.addcode('module_tail', fp)
8788

@@ -106,7 +107,8 @@ def writebody(self, fp):
106107
for fn in self.methodlist:
107108
self.method = fn
108109
self.addcode('object_method', fp)
109-
new_ml = new_ml + ('{"%s",\t%s_%s,\t1},\n'%(fn, self.abbrev, fn))
110+
new_ml = new_ml + ('{"%s",\t%s_%s,\t1,\t%s_%s__doc__},\n'
111+
%(fn, self.abbrev, fn, self.abbrev, fn))
110112
self.methodlist = new_ml
111113
self.addcode('object_mlist', fp)
112114

0 commit comments

Comments
 (0)