1 """framer's C code templates.
3 Templates use the following variables:
5 FileName: name of the file that contains the C source code
6 ModuleName: name of the module, as in "import ModuleName"
7 ModuleDocstring: C string containing the module doc string
10 module_start
= '#include "Python.h"'
11 member_include
= '#include "structmember.h"'
14 PyDoc_STRVAR(%(ModuleName)s_doc,
18 methoddef_start
= """\
19 static struct PyMethodDef %(MethodDefName)s[] = {"""
22 {"%(PythonName)s", (PyCFunction)%(CName)s, %(MethType)s},"""
24 methoddef_def_doc
= """\
25 {"%(PythonName)s", (PyCFunction)%(CName)s, %(MethType)s,
33 memberdef_start
= """\
34 #define OFF(X) offsetof(%(StructName)s, X)
36 static struct PyMemberDef %(MemberDefName)s[] = {"""
38 memberdef_def_doc
= """\
39 {"%(PythonName)s", %(Type)s, OFF(%(CName)s), %(Flags)s,
43 {"%(PythonName)s", %(Type)s, OFF(%(CName)s), %(Flags)s},"""
52 dealloc_func
= """static void
53 %(name)s(PyObject *ob)
59 PyDoc_STRVAR(%(DocstringVar)s,
73 if (!PyArg_ParseTuple(args, \"%(ArgParse)s:%(PythonName)s\",
77 module_init_start
= """\
79 init%(ModuleName)s(void)
83 mod = Py_InitModule3("%(ModuleName)s", %(MethodDefName)s,
89 type_init_type
= " %(CTypeName)s.ob_type = &PyType_Type;"
90 module_add_type
= """\
91 if (!PyObject_SetAttrString(mod, "%(TypeName)s",
92 (PyObject *)&%(CTypeName)s))
96 type_struct_start
= """\
97 static PyTypeObject %(CTypeName)s = {
98 PyObject_HEAD_INIT(0)"""
100 type_struct_end
= """\