annotate python/pydc/pydcext.c @ 28:edbbd467f50a

python binding: - update to dyncall 1.1 - Python 3 support (supports both, Python 2 and 3) - using the Capsule API over PyCObject, when available - support for python unicode strings (for both, Python 2 and 3) - doc cleanup ruby binding: - doc cleanup
author Tassilo Philipp
date Tue, 07 Apr 2020 21:16:37 +0200
parents a40084782546
children 6cc2b7fc7ea2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /******************************************************************************
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 **
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 ** pydc - python dyncall package
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 **
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 ** python extension package in C
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
6 ** Copyright 2007-2016 Daniel Adler
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
7 ** 2018-2020 Tassilo Philipp
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 **
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
9 ** December 04, 2007: initial
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
10 ** March 22, 2016: update to dyncall 0.9, includes breaking sig char changes
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
11 ** April 19, 2018: update to dyncall 1.0
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
12 ** April 7, 2020: update to dyncall 1.1, Python 3 support, using the Capsule
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
13 ** API, as well as support for python unicode strings
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 **
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 *****************************************************************************/
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 #include <Python.h>
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 #include "dynload.h"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 #include <limits.h>
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
21
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
22
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
23 #if ( (PY_VERSION_HEX < 0x02070000) \
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
24 || ((PY_VERSION_HEX >= 0x03000000) \
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
25 && (PY_VERSION_HEX < 0x03010000)) )
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
26 # define DcPyCObject_FromVoidPtr(ptr, dtor) PyCObject_FromVoidPtr((ptr), (dtor))
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
27 # define DcPyCObject_AsVoidPtr(ppobj) PyCObject_AsVoidPtr((ppobj))
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
28 # define DcPyCObject_SetVoidPtr(ppobj, ptr) PyCObject_SetVoidPtr((ppobj), (ptr))
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
29 #else
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
30 # define USE_CAPSULE_API
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
31 # define DcPyCObject_FromVoidPtr(ptr, dtor) PyCapsule_New((ptr), NULL, (dtor))
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
32 # define DcPyCObject_AsVoidPtr(ppobj) PyCapsule_GetPointer((ppobj), NULL)
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
33 # define DcPyCObject_SetVoidPtr(ppobj, ptr) PyCapsule_SetPointer((ppobj), (ptr)) // this might need to call the dtor to behave like PyCObject_SetVoidPtr?
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
34 #endif
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
35
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
36 #if PY_MAJOR_VERSION >= 3
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
37 # define DcPyString_GET_SIZE PyBytes_GET_SIZE
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
38 # define DcPyString_Check PyBytes_Check
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
39 # define DcPyString_AsString PyBytes_AsString
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
40 # define DcPyInt_Check PyLong_Check
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
41 # define DcPyInt_AsLong PyLong_AsLong
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
42 # define DcPyInt_AS_LONG PyLong_AS_LONG
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
43 #else
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
44 # define DcPyString_GET_SIZE PyString_GET_SIZE
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
45 # define DcPyString_Check PyString_Check
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
46 # define DcPyString_AsString PyString_AsString
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
47 # define DcPyInt_Check PyInt_Check
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
48 # define DcPyInt_AsLong PyInt_AsLong
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
49 # define DcPyInt_AS_LONG PyInt_AS_LONG
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
50 #endif
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
51
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52 /* PyCObject destructor callback for libhandle */
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
54 #if defined(USE_CAPSULE_API)
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
55 void free_library(PyObject* capsule)
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
56 {
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
57 void* libhandle = PyCapsule_GetPointer(capsule, NULL);
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
58 #else
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
59 void free_library(void* libhandle)
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 {
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
61 #endif
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 if (libhandle != 0)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 dlFreeLibrary(libhandle);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
66
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 /* load function */
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 static PyObject*
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 pydc_load(PyObject* self, PyObject* args)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72 const char* libpath;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73 void* libhandle;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
75 if (!PyArg_ParseTuple(args,"s", &libpath))
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
76 return PyErr_Format(PyExc_RuntimeError, "libpath argument (string) missing");
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
78 libhandle = dlLoadLibrary(libpath);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
79
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
80 if (!libhandle)
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
81 return PyErr_Format(PyExc_RuntimeError, "dlLoadLibrary('%s') failed", libpath);
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
83 return DcPyCObject_FromVoidPtr(libhandle, &free_library);
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
84 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
85
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
86 /* find function */
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
87
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
88 static PyObject*
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
89 pydc_find(PyObject* self, PyObject* args)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
90 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
91 PyObject* pcobj;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
92 const char* symbol;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
93 void* libhandle;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
94 void* funcptr;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
95
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
96 if (!PyArg_ParseTuple(args, "Os", &pcobj, &symbol))
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
97 return PyErr_Format(PyExc_RuntimeError, "argument mismatch");
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
98
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
99 libhandle = DcPyCObject_AsVoidPtr(pcobj);
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
100 if (!libhandle)
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
101 return PyErr_Format(PyExc_RuntimeError, "libhandle is null");
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
102
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
103 funcptr = dlFindSymbol(libhandle, symbol);
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
104 if (!funcptr)
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
105 return PyErr_Format(PyExc_RuntimeError, "symbol '%s' not found", symbol);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
106
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
107 return DcPyCObject_FromVoidPtr(funcptr, NULL);
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
108 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
109
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
110 /* free function */
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112 static PyObject*
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
113 pydc_free(PyObject* self, PyObject* args)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
114 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
115 PyObject* pcobj;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
116 void* libhandle;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
117
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
118 if (!PyArg_ParseTuple(args, "o", &pcobj))
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
119 return PyErr_Format(PyExc_RuntimeError, "argument mismatch");
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
120
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
121 libhandle = DcPyCObject_AsVoidPtr(pcobj);
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
122 if (!libhandle)
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
123 return PyErr_Format(PyExc_RuntimeError, "libhandle is NULL");
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
124
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
125 dlFreeLibrary(libhandle);
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
126 DcPyCObject_SetVoidPtr(pcobj, NULL);
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
127
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
128 Py_RETURN_NONE;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
129 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
130
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
131
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
132 #include "dyncall.h"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
133 #include "dyncall_signature.h"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
134
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
135 DCCallVM* gpCall;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
136
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
137 /* call function */
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
138
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
139 static PyObject*
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
140 pydc_call(PyObject* self, PyObject* in_args)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
141 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
142 PyObject* pcobj_funcptr;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
143 const char* signature;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
144 PyObject* args;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
145 int l;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
146 const char* ptr;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
147 char ch;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
148 int pos;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
149 void* pfunc;
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
150
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
151 if (!PyArg_ParseTuple(in_args,"OsO", &pcobj_funcptr, &signature, &args))
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
152 return PyErr_Format(PyExc_RuntimeError, "argument mismatch");
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
153
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
154 pfunc = DcPyCObject_AsVoidPtr(pcobj_funcptr);
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
155 if (!pfunc)
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
156 return PyErr_Format( PyExc_RuntimeError, "function pointer is NULL" );
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
157
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
158 l = PyTuple_Size(args);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
159
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
160 ptr = signature;
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
161 pos = 0;
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
162
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
163 dcReset(gpCall);
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
164
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
165 while ( (ch = *ptr) != '\0' && ch != ')' )
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
166 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
167 PyObject* po;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
168
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
169 int index = pos+1;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
170
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
171 if (pos > l) return PyErr_Format( PyExc_RuntimeError, "expecting more arguments" );
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
172
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
173 po = PyTuple_GetItem(args,pos);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
174
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
175 switch(ch)
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
176 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
177 case DC_SIGCHAR_BOOL:
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
178 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
179 DCbool b;
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
180 if ( !PyBool_Check(po) ) return PyErr_Format( PyExc_RuntimeError, "argument mismatch at pos %d - expecting a bool", index );
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
181 b = (Py_True == po) ? DC_TRUE : DC_FALSE;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
182 dcArgBool(gpCall, b);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
183 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
184 break;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
185 case DC_SIGCHAR_CHAR:
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
186 case DC_SIGCHAR_UCHAR:
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
187 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
188 DCchar c;
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
189 if ( DcPyString_Check(po) )
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
190 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
191 // Py_ssize_t l;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
192 size_t l;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
193 char* s;
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
194 l = DcPyString_GET_SIZE(po);
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
195 if (l != 1) return PyErr_Format( PyExc_RuntimeError, "argument mismatch at pos %d - expecting a string with length of 1 (a char string)", index );
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
196 s = DcPyString_AsString(po);
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
197 c = (DCchar) s[0];
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
198 }
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
199 else if ( DcPyInt_Check(po) )
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
200 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
201 long l;
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
202 l = DcPyInt_AsLong(po);
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
203 if ( (l > CHAR_MAX) || (l < CHAR_MIN)) return PyErr_Format( PyExc_RuntimeError, "value out of range at argument %d - expecting a char code", index );
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
204 c = (DCchar) l;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
205 }
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
206 else return PyErr_Format( PyExc_RuntimeError, "argument mismatch at pos %d - expecting a char", index );
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
207 dcArgChar(gpCall, c);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
208 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
209 break;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
210 case DC_SIGCHAR_SHORT:
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
211 case DC_SIGCHAR_USHORT:
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
212 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
213 DCshort s;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
214 long v;
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
215 if ( !DcPyInt_Check(po) )
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
216 return PyErr_Format( PyExc_RuntimeError, "argument mismatch at pos %d - expecting a short int", index );
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
217 v = DcPyInt_AS_LONG(po);
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
218 if ( (v < SHRT_MIN) || (v > SHRT_MAX) )
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
219 return PyErr_Format( PyExc_RuntimeError, "value out of range at argument %d - expecting a short value", index );
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
220 s = (DCshort) v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
221 dcArgShort(gpCall, s);
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
222 }
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
223 break;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
224 case DC_SIGCHAR_INT:
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
225 case DC_SIGCHAR_UINT:
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
226 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
227 long v;
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
228 if ( !DcPyInt_Check(po) ) return PyErr_Format( PyExc_RuntimeError, "argument mismatch at pos %d - expecting an int", index );
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
229 v = DcPyInt_AS_LONG(po);
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
230 dcArgInt(gpCall, (DCint) v );
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
231 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
232 break;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
233 case DC_SIGCHAR_LONG:
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
234 case DC_SIGCHAR_ULONG:
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
235 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
236 long v;
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
237 if ( !DcPyInt_Check(po) ) return PyErr_Format( PyExc_RuntimeError, "argument mismatch at pos %d - expecting an int", index );
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
238 v = DcPyInt_AsLong(po);
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
239
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
240 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
241 break;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
242 case DC_SIGCHAR_LONGLONG:
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
243 case DC_SIGCHAR_ULONGLONG:
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
244 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
245 PY_LONG_LONG pl;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
246 DClonglong dl;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
247 if ( !PyLong_Check(po) ) return PyErr_Format( PyExc_RuntimeError, "argument mismatch at pos %d - expecting a long long", index );
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
248 pl = PyLong_AsLongLong(po);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
249 dl = (DClonglong) pl;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
250 dcArgLongLong(gpCall, dl );
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
251 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
252 break;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
253 case DC_SIGCHAR_FLOAT:
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
254 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
255 DCfloat f;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
256 if (!PyFloat_Check(po)) return PyErr_Format( PyExc_RuntimeError, "argument mismatch at pos %d - expeecting a float", index );
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
257 f = (float) PyFloat_AsDouble(po);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
258 dcArgFloat(gpCall, f);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
259 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
260 break;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
261 case DC_SIGCHAR_DOUBLE:
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
262 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
263 double d;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
264 if (!PyFloat_Check(po)) return PyErr_Format( PyExc_RuntimeError, "argument mismatch at pos %d - expeecting a float", index );
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
265 d = PyFloat_AsDouble(po);
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
266 dcArgDouble(gpCall, d);
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
267 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
268 break;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
269 case DC_SIGCHAR_POINTER:
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
270 {
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
271 DCpointer p;
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
272 if ( PyUnicode_Check(po) ) {
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
273 PyObject* bo = PyUnicode_AsEncodedString(po, "utf-8", "strict"); // Owned reference @@@
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
274 if (bo) {
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
275 p = PyBytes_AS_STRING(bo); // Borrowed pointer
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
276 //p = strdup(my_result);
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
277 //Py_DECREF(bo);
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
278 }
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
279 } else if ( DcPyString_Check(po) ) {
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
280 p = (DCpointer) DcPyString_AsString(po);
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
281 } else if ( PyLong_Check(po) ) {
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
282 p = (DCpointer) PyLong_AsVoidPtr(po);
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
283 } else {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
284 return PyErr_Format( PyExc_RuntimeError, "argument mismatch at pos %d - expecting a promoting pointer-type (int,string)", index );
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
285 }
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
286 dcArgPointer(gpCall, p);
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
287 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
288 break;
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
289 case DC_SIGCHAR_STRING:
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
290 {
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
291 const char* p;
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
292 if ( PyUnicode_Check(po) ) {
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
293 PyObject* bo = PyUnicode_AsEncodedString(po, "utf-8", "strict"); // Owned reference @@@
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
294 if (bo) {
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
295 p = PyBytes_AS_STRING(bo); // Borrowed pointer
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
296 //p = strdup(my_result);
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
297 //Py_DECREF(bo);
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
298 }
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
299 } else if ( DcPyString_Check(po) ) {
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
300 p = DcPyString_AsString(po);
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
301 } else {
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
302 return PyErr_Format( PyExc_RuntimeError, "argument mismatch at pos %d - expecting a string", index );
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
303 }
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
304 dcArgPointer(gpCall, (DCpointer) p);
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
305 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
306 break;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
307 default: return PyErr_Format( PyExc_RuntimeError, "unknown signature character '%c'", ch);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
308 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
309
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
310 ++pos; ++ptr;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
311
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
312 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
313
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
314 if (pos != l) return PyErr_Format( PyExc_RuntimeError, "too many arguments");
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
315
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
316 if (ch == '\0') return PyErr_Format( PyExc_RuntimeError, "return value missing in signature");
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
317
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
318 ch = *++ptr;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
319
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
320 switch(ch)
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
321 {
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
322 case DC_SIGCHAR_VOID: dcCallVoid (gpCall, pfunc); Py_RETURN_NONE;
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
323 case DC_SIGCHAR_BOOL: return Py_BuildValue("i", dcCallBool (gpCall, pfunc));
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
324 case DC_SIGCHAR_CHAR: return Py_BuildValue("b", dcCallChar (gpCall, pfunc));
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
325 case DC_SIGCHAR_UCHAR: return Py_BuildValue("B", dcCallChar (gpCall, pfunc));
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
326 case DC_SIGCHAR_SHORT: return Py_BuildValue("h", dcCallShort (gpCall, pfunc));
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
327 case DC_SIGCHAR_USHORT: return Py_BuildValue("H", dcCallShort (gpCall, pfunc));
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
328 case DC_SIGCHAR_INT: return Py_BuildValue("i", dcCallInt (gpCall, pfunc));
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
329 case DC_SIGCHAR_UINT: return Py_BuildValue("I", dcCallInt (gpCall, pfunc));
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
330 case DC_SIGCHAR_LONG: return Py_BuildValue("l", dcCallLong (gpCall, pfunc));
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
331 case DC_SIGCHAR_ULONG: return Py_BuildValue("k", dcCallLong (gpCall, pfunc));
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
332 case DC_SIGCHAR_LONGLONG: return Py_BuildValue("L", dcCallLongLong(gpCall, pfunc));
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
333 case DC_SIGCHAR_ULONGLONG: return Py_BuildValue("K", dcCallLongLong(gpCall, pfunc));
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
334 case DC_SIGCHAR_FLOAT: return Py_BuildValue("f", dcCallFloat (gpCall, pfunc));
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
335 case DC_SIGCHAR_DOUBLE: return Py_BuildValue("d", dcCallDouble (gpCall, pfunc));
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
336 case DC_SIGCHAR_STRING: return Py_BuildValue("s", dcCallPointer (gpCall, pfunc));
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
337 case DC_SIGCHAR_POINTER: return Py_BuildValue("n", dcCallPointer (gpCall, pfunc)); // @@@test, this used to be 'p' which doesn't exist, 'n' is for "Py_ssize_t"
16
a40084782546 - added support for more return values to python binding
cslag
parents: 5
diff changeset
338 default: return PyErr_Format(PyExc_RuntimeError, "invalid return type signature");
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
339 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
340 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
341
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
342
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
343
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
344
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
345
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
346 #define PYDC_TO_STR_(x) #x
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
347 #define PYDC_TO_STR(x) PYDC_TO_STR_(x)
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
348 #define PYDC_CONCAT_(x, y) x ## y
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
349 #define PYDC_CONCAT(x, y) PYDC_CONCAT_(x, y)
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
350
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
351 #define PYDC_MOD_NAME pydcext
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
352 #define PYDC_MOD_NAME_STR PYDC_TO_STR(PYDC_MOD_NAME)
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
353 #define PYDC_MOD_DESC_STR "dyncall bindings for python"
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
354
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
355 #if PY_MAJOR_VERSION >= 3
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
356 # define PY_MOD_INIT_FUNC_NAME PYDC_CONCAT(PyInit_, PYDC_MOD_NAME)
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
357 #else
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
358 # define PY_MOD_INIT_FUNC_NAME PYDC_CONCAT(init, PYDC_MOD_NAME)
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
359 #endif
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
360
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
361
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
362 PyMODINIT_FUNC
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
363 PY_MOD_INIT_FUNC_NAME(void)
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
364 {
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
365 static PyMethodDef pydcMethods[] = {
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
366 {"load", pydc_load, METH_VARARGS, "load library"},
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
367 {"find", pydc_find, METH_VARARGS, "find symbols"},
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
368 {"free", pydc_free, METH_VARARGS, "free library"},
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
369 {"call", pydc_call, METH_VARARGS, "call function"},
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
370 {NULL,NULL,0,NULL}
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
371 };
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
372
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
373 PyObject* m;
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
374 #if PY_MAJOR_VERSION >= 3
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
375 static struct PyModuleDef moddef = { PyModuleDef_HEAD_INIT, PYDC_MOD_NAME_STR, PYDC_MOD_DESC_STR, -1, pydcMethods, NULL, NULL, NULL, NULL };
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
376 m = PyModule_Create(&moddef);
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
377 #else
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
378 m = Py_InitModule3(PYDC_MOD_NAME_STR, pydcMethods, PYDC_MOD_DESC_STR);
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
379 #endif
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
380
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
381 if(m)
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
382 gpCall = dcNewCallVM(4096);
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
383
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
384 #if PY_MAJOR_VERSION >= 3
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
385 return m;
edbbd467f50a python binding:
Tassilo Philipp
parents: 16
diff changeset
386 #endif
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
387 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
388