| 1 |
#include "Python.h" |
| 2 |
|
| 3 |
static PyObject * |
| 4 |
test_with_docstring(PyObject *self) |
| 5 |
{ |
| 6 |
Py_RETURN_NONE; |
| 7 |
} |
| 8 |
|
| 9 |
PyDoc_STRVAR(empty_doc, |
| 10 |
"" |
| 11 |
); |
| 12 |
|
| 13 |
PyDoc_STRVAR(no_sig, |
| 14 |
"This docstring has no signature." |
| 15 |
); |
| 16 |
|
| 17 |
PyDoc_STRVAR(invalid_sig, |
| 18 |
"invalid_sig($module, /, boo)\n" |
| 19 |
"\n" |
| 20 |
"This docstring has an invalid signature." |
| 21 |
); |
| 22 |
|
| 23 |
PyDoc_STRVAR(invalid_sig2, |
| 24 |
"invalid_sig2($module, /, boo)\n" |
| 25 |
"\n" |
| 26 |
"--\n" |
| 27 |
"\n" |
| 28 |
"This docstring also has an invalid signature." |
| 29 |
); |
| 30 |
|
| 31 |
PyDoc_STRVAR(with_sig, |
| 32 |
"with_sig($module, /, sig)\n" |
| 33 |
"--\n" |
| 34 |
"\n" |
| 35 |
"This docstring has a valid signature." |
| 36 |
); |
| 37 |
|
| 38 |
PyDoc_STRVAR(with_sig_but_no_doc, |
| 39 |
"with_sig_but_no_doc($module, /, sig)\n" |
| 40 |
"--\n" |
| 41 |
"\n" |
| 42 |
); |
| 43 |
|
| 44 |
PyDoc_STRVAR(with_signature_and_extra_newlines, |
| 45 |
"with_signature_and_extra_newlines($module, /, parameter)\n" |
| 46 |
"--\n" |
| 47 |
"\n" |
| 48 |
"\n" |
| 49 |
"This docstring has a valid signature and some extra newlines." |
| 50 |
); |
| 51 |
|
| 52 |
|
| 53 |
static PyMethodDef methods[] = { |
| 54 |
{"no_doc", |
| 55 |
(PyCFunction)test_with_docstring, METH_NOARGS}, |
| 56 |
{"empty_doc", |
| 57 |
(PyCFunction)test_with_docstring, METH_NOARGS, |
| 58 |
empty_doc}, |
| 59 |
{"no_sig", |
| 60 |
(PyCFunction)test_with_docstring, METH_NOARGS, |
| 61 |
no_sig}, |
| 62 |
{"invalid_sig", |
| 63 |
(PyCFunction)test_with_docstring, METH_NOARGS, |
| 64 |
invalid_sig}, |
| 65 |
{"invalid_sig2", |
| 66 |
(PyCFunction)test_with_docstring, METH_NOARGS, |
| 67 |
invalid_sig2}, |
| 68 |
{"with_sig", |
| 69 |
(PyCFunction)test_with_docstring, METH_NOARGS, |
| 70 |
with_sig}, |
| 71 |
{"with_sig_but_no_doc", |
| 72 |
(PyCFunction)test_with_docstring, METH_NOARGS, |
| 73 |
with_sig_but_no_doc}, |
| 74 |
{"with_signature_and_extra_newlines", |
| 75 |
(PyCFunction)test_with_docstring, METH_NOARGS, |
| 76 |
with_signature_and_extra_newlines}, |
| 77 |
{NULL, NULL} |
| 78 |
}; |
| 79 |
|
| 80 |
|
| 81 |
static PyType_Slot HeapType_slots[] = { |
| 82 |
{Py_tp_doc, "HeapType()\n--\n\nA type with a signature"}, |
| 83 |
{0, 0}, |
| 84 |
}; |
| 85 |
|
| 86 |
static PyType_Spec HeapType_spec = { |
| 87 |
"docstrings.HeapType", |
| 88 |
sizeof(PyObject), |
| 89 |
0, |
| 90 |
Py_TPFLAGS_DEFAULT, |
| 91 |
HeapType_slots |
| 92 |
}; |
| 93 |
|
| 94 |
static PyTypeObject SomeType = { |
| 95 |
PyVarObject_HEAD_INIT(NULL, 0) |
| 96 |
"docstrings.SomeType", |
| 97 |
sizeof(PyObject), |
| 98 |
0, |
| 99 |
0, |
| 100 |
0, |
| 101 |
0, |
| 102 |
0, |
| 103 |
0, |
| 104 |
0, |
| 105 |
0, |
| 106 |
0, |
| 107 |
0, |
| 108 |
0, |
| 109 |
0, |
| 110 |
0, |
| 111 |
0, |
| 112 |
0, |
| 113 |
0, |
| 114 |
Py_TPFLAGS_DEFAULT, |
| 115 |
"SomeType()\n--\n\nA type with a signature", |
| 116 |
}; |
| 117 |
|
| 118 |
|
| 119 |
static struct PyModuleDef def = { |
| 120 |
PyModuleDef_HEAD_INIT, |
| 121 |
"docstrings", |
| 122 |
NULL, |
| 123 |
-1, |
| 124 |
methods, |
| 125 |
NULL, |
| 126 |
NULL, |
| 127 |
NULL, |
| 128 |
NULL |
| 129 |
}; |
| 130 |
|
| 131 |
|
| 132 |
PyMODINIT_FUNC |
| 133 |
PyInit_docstrings(void) |
| 134 |
{ |
| 135 |
PyObject *m, *tmp; |
| 136 |
m = PyModule_Create(&def); |
| 137 |
if (m == NULL) |
| 138 |
return NULL; |
| 139 |
tmp = PyType_FromSpec(&HeapType_spec); |
| 140 |
if (tmp == NULL) |
| 141 |
return NULL; |
| 142 |
if (PyModule_AddObject(m, "HeapType", tmp) != 0) |
| 143 |
return NULL; |
| 144 |
if (PyType_Ready(&SomeType) < 0) |
| 145 |
return NULL; |
| 146 |
if (PyModule_AddObject(m, "SomeType", (PyObject*)&SomeType) != 0) |
| 147 |
return NULL; |
| 148 |
return m; |
| 149 |
} |