1 /**
2   Mirror _modsupport.h
3 
4   Module support interface
5   */
6 module deimos.python.modsupport;
7 
8 import core.stdc.stdio;
9 import deimos.python.pyport;
10 import deimos.python.object;
11 import deimos.python.methodobject;
12 import deimos.python.moduleobject;
13 
14 extern(C):
15 // Python-header-file: Include/modsupport.h:
16 
17 version(Python_2_5_Or_Later){
18     /// _
19     enum PYTHON_API_VERSION = 1013;
20     /// _
21     enum PYTHON_API_STRING = "1013";
22 }else version(Python_2_4_Or_Later){
23     /// _
24     enum PYTHON_API_VERSION = 1012;
25     /// _
26     enum PYTHON_API_STRING = "1012";
27 }
28 
29 /// _
30 int PyArg_Parse(PyObject*, const(char)*, ...);
31 /// _
32 int PyArg_ParseTuple(PyObject*, const(char)*, ...);
33 /// _
34 int PyArg_ParseTupleAndKeywords(PyObject*, PyObject*,
35         const(char)*, char**, ...);
36 /// _
37 int PyArg_UnpackTuple(PyObject*, const(char)*, Py_ssize_t, Py_ssize_t, ...);
38 /// _
39 PyObject * Py_BuildValue(const(char)*, ...);
40 
41 /// _
42 int PyModule_AddObject(PyObject*, const(char)*, PyObject*);
43 /// _
44 int PyModule_AddIntConstant(PyObject*, const(char)*, C_long);
45 /// _
46 int PyModule_AddStringConstant(PyObject*, const(char)*, const(char)*);
47 
48 version(Python_3_0_Or_Later) {
49 }else{
50     version(Python_2_5_Or_Later){
51         version(X86_64){
52             enum Py_InitModuleSym = "Py_InitModule4_64";
53         }else{
54             enum Py_InitModuleSym = "Py_InitModule4";
55         }
56     }else{
57         enum Py_InitModuleSym = "Py_InitModule4";
58     }
59     mixin("
60             /// Availability: >= 2.5, specific to 32 or 64 bitness
61             PyObject_BorrowedRef* "~Py_InitModuleSym~"(const(char) *name, PyMethodDef *methods, const(char) *doc,
62         PyObject *self, int apiver);
63 
64             /// Availability: >= 2.5
65             PyObject_BorrowedRef* Py_InitModule()(string name, PyMethodDef *methods)
66             {
67             return "~Py_InitModuleSym~"(name.ptr, methods, null,
68         null, PYTHON_API_VERSION);
69             }
70 
71             /// Availability: >= 2.5
72             PyObject_BorrowedRef* Py_InitModule3()(string name, PyMethodDef *methods, string doc) {
73             return "~Py_InitModuleSym~"(name.ptr, methods, doc.ptr, null,
74         PYTHON_API_VERSION);
75             }");
76 }
77 
78 
79 version(Python_3_0_Or_Later) {
80     /// _
81     enum PYTHON_ABI_VERSION = 3;
82     /// _
83     enum PYTHON_ABI_STRING = "3";
84     /// Availability: 3.*
85     PyObject* PyModule_Create2(PyModuleDef*, int apiver);
86 
87     /// Availability: 3.*
88     PyObject* PyModule_Create()(PyModuleDef* modul) {
89         return PyModule_Create2(modul, PYTHON_API_VERSION);
90     }
91 }