File: docstrings.c

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (149 lines) | stat: -rw-r--r-- 3,610 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "Python.h"

static PyObject *
test_with_docstring(PyObject *self)
{
    Py_RETURN_NONE;
}

PyDoc_STRVAR(empty_doc,
""
);

PyDoc_STRVAR(no_sig,
"This docstring has no signature."
);

PyDoc_STRVAR(invalid_sig,
"invalid_sig($module, /, boo)\n"
"\n"
"This docstring has an invalid signature."
);

PyDoc_STRVAR(invalid_sig2,
"invalid_sig2($module, /, boo)\n"
"\n"
"--\n"
"\n"
"This docstring also has an invalid signature."
);

PyDoc_STRVAR(with_sig,
"with_sig($module, /, sig)\n"
"--\n"
"\n"
"This docstring has a valid signature."
);

PyDoc_STRVAR(with_sig_but_no_doc,
"with_sig_but_no_doc($module, /, sig)\n"
"--\n"
"\n"
);

PyDoc_STRVAR(with_signature_and_extra_newlines,
"with_signature_and_extra_newlines($module, /, parameter)\n"
"--\n"
"\n"
"\n"
"This docstring has a valid signature and some extra newlines."
);


static PyMethodDef methods[] = {
    {"no_doc",
        (PyCFunction)test_with_docstring, METH_NOARGS},
    {"empty_doc",
        (PyCFunction)test_with_docstring, METH_NOARGS,
        empty_doc},
    {"no_sig",
        (PyCFunction)test_with_docstring, METH_NOARGS,
        no_sig},
    {"invalid_sig",
        (PyCFunction)test_with_docstring, METH_NOARGS,
        invalid_sig},
    {"invalid_sig2",
        (PyCFunction)test_with_docstring, METH_NOARGS,
        invalid_sig2},
    {"with_sig",
        (PyCFunction)test_with_docstring, METH_NOARGS,
        with_sig},
    {"with_sig_but_no_doc",
        (PyCFunction)test_with_docstring, METH_NOARGS,
        with_sig_but_no_doc},
    {"with_signature_and_extra_newlines",
        (PyCFunction)test_with_docstring, METH_NOARGS,
        with_signature_and_extra_newlines},
    {NULL, NULL} /* sentinel */
};


static PyType_Slot HeapType_slots[] = {
    {Py_tp_doc, "HeapType()\n--\n\nA type with a signature"},
    {0, 0},
};

static PyType_Spec HeapType_spec = {
    "docstrings.HeapType",
    sizeof(PyObject),
    0,
    Py_TPFLAGS_DEFAULT,
    HeapType_slots
};

static PyTypeObject SomeType = {
    PyVarObject_HEAD_INIT(NULL, 0)
    "docstrings.SomeType",      /* tp_name */
    sizeof(PyObject),           /* tp_basicsize */
    0,                         /* tp_itemsize */
    0,                         /* tp_dealloc */
    0,                         /* tp_print */
    0,                         /* tp_getattr */
    0,                         /* tp_setattr */
    0,                         /* tp_reserved */
    0,                         /* tp_repr */
    0,                         /* tp_as_number */
    0,                         /* tp_as_sequence */
    0,                         /* tp_as_mapping */
    0,                         /* tp_hash  */
    0,                         /* tp_call */
    0,                         /* tp_str */
    0,                         /* tp_getattro */
    0,                         /* tp_setattro */
    0,                         /* tp_as_buffer */
    Py_TPFLAGS_DEFAULT,        /* tp_flags */
    "SomeType()\n--\n\nA type with a signature",    /* tp_doc */
};


static struct PyModuleDef def = {
    PyModuleDef_HEAD_INIT,
    "docstrings",
    NULL,
    -1,
    methods,
    NULL,
    NULL,
    NULL,
    NULL
};


PyMODINIT_FUNC
PyInit_docstrings(void)
{
    PyObject *m, *tmp;
    m = PyModule_Create(&def);
    if (m == NULL)
        return NULL;
    tmp = PyType_FromSpec(&HeapType_spec);
    if (tmp == NULL)
        return NULL;
    if (PyModule_AddObject(m, "HeapType", tmp) != 0)
        return NULL;
    if (PyType_Ready(&SomeType) < 0)
        return NULL;
    if (PyModule_AddObject(m, "SomeType", (PyObject*)&SomeType) != 0)
        return NULL;
    return m;
}