13
13
#include "ctypes.h"
15
/**************************************************************/
17
static CThunkObject_dealloc(PyObject *_self)
19
CThunkObject *self = (CThunkObject *)_self;
20
Py_XDECREF(self->converters);
21
Py_XDECREF(self->callable);
22
Py_XDECREF(self->restype);
24
FreeClosure(self->pcl);
29
CThunkObject_traverse(PyObject *_self, visitproc visit, void *arg)
31
CThunkObject *self = (CThunkObject *)_self;
32
Py_VISIT(self->converters);
33
Py_VISIT(self->callable);
34
Py_VISIT(self->restype);
39
CThunkObject_clear(PyObject *_self)
41
CThunkObject *self = (CThunkObject *)_self;
42
Py_CLEAR(self->converters);
43
Py_CLEAR(self->callable);
44
Py_CLEAR(self->restype);
48
PyTypeObject CThunk_Type = {
49
PyVarObject_HEAD_INIT(NULL, 0)
50
"_ctypes.CThunkObject",
51
sizeof(CThunkObject), /* tp_basicsize */
52
sizeof(ffi_type), /* tp_itemsize */
53
CThunkObject_dealloc, /* tp_dealloc */
60
0, /* tp_as_sequence */
61
0, /* tp_as_mapping */
68
Py_TPFLAGS_DEFAULT, /* tp_flags */
69
"CThunkObject", /* tp_doc */
70
CThunkObject_traverse, /* tp_traverse */
71
CThunkObject_clear, /* tp_clear */
72
0, /* tp_richcompare */
73
0, /* tp_weaklistoffset */
80
/**************************************************************/
16
83
PrintError(char *msg, ...)
250
ffi_info *p = userdata;
317
CThunkObject *p = (CThunkObject *)userdata;
252
319
_CallPythonObject(resp,
260
ffi_info *AllocFunctionCallback(PyObject *callable,
261
PyObject *converters,
327
static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
332
p = PyObject_NewVar(CThunkObject, &CThunk_Type, nArgs);
339
memset(&p->cif, 0, sizeof(p->cif));
340
p->converters = NULL;
343
p->ffi_restype = NULL;
345
for (i = 0; i < nArgs + 1; ++i)
350
CThunkObject *AllocFunctionCallback(PyObject *callable,
351
PyObject *converters,
267
357
Py_ssize_t nArgs, i;
270
360
nArgs = PySequence_Size(converters);
271
p = (ffi_info *)PyMem_Malloc(sizeof(ffi_info) + sizeof(ffi_type) * (nArgs));
361
p = CThunkObject_new(nArgs);
365
assert(CThunk_CheckExact(p));
276
367
p->pcl = MallocClosure();
277
368
if (p->pcl == NULL) {
278
369
PyErr_NoMemory();
289
380
p->atypes[i] = NULL;
383
p->restype = restype;
291
384
if (restype == Py_None) {
292
385
p->setfunc = NULL;
293
p->restype = &ffi_type_void;
386
p->ffi_restype = &ffi_type_void;
295
388
StgDictObject *dict = PyType_stgdict(restype);
296
389
if (dict == NULL || dict->setfunc == NULL) {