Add better error reporting for MemoryErrors caused by str->float conversions.
[python.git] / Tools / framer / framer / template.py
blob41f95371b85b0d7d003ab3bd64892d2aa046dac7
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
8 """
10 module_start = '#include "Python.h"'
11 member_include = '#include "structmember.h"'
13 module_doc = """\
14 PyDoc_STRVAR(%(ModuleName)s_doc,
15 %(ModuleDocstring)s);
16 """
18 methoddef_start = """\
19 static struct PyMethodDef %(MethodDefName)s[] = {"""
21 methoddef_def = """\
22 {"%(PythonName)s", (PyCFunction)%(CName)s, %(MethType)s},"""
24 methoddef_def_doc = """\
25 {"%(PythonName)s", (PyCFunction)%(CName)s, %(MethType)s,
26 %(DocstringVar)s},"""
28 methoddef_end = """\
29 {NULL, NULL}
31 """
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,
40 %(Docstring)s},"""
42 memberdef_def = """\
43 {"%(PythonName)s", %(Type)s, OFF(%(CName)s), %(Flags)s},"""
45 memberdef_end = """\
46 {NULL}
49 #undef OFF
50 """
52 dealloc_func = """static void
53 %(name)s(PyObject *ob)
56 """
58 docstring = """\
59 PyDoc_STRVAR(%(DocstringVar)s,
60 %(Docstring)s);
61 """
63 funcdef_start = """\
64 static PyObject *
65 %(name)s(%(args)s)
66 {"""
68 funcdef_end = """\
70 """
72 varargs = """\
73 if (!PyArg_ParseTuple(args, \"%(ArgParse)s:%(PythonName)s\",
74 %(ArgTargets)s))
75 return NULL;"""
77 module_init_start = """\
78 PyMODINIT_FUNC
79 init%(ModuleName)s(void)
81 PyObject *mod;
83 mod = Py_InitModule3("%(ModuleName)s", %(MethodDefName)s,
84 %(ModuleName)s_doc);
85 if (mod == NULL)
86 return;
87 """
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))
93 return;
94 """
96 type_struct_start = """\
97 static PyTypeObject %(CTypeName)s = {
98 PyObject_HEAD_INIT(0)"""
100 type_struct_end = """\