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
PyObject_HEAD_INIT(NULL)
51
"_ctypes.CThunkObject",
52
sizeof(CThunkObject), /* tp_basicsize */
53
sizeof(ffi_type), /* tp_itemsize */
54
CThunkObject_dealloc, /* tp_dealloc */
61
0, /* tp_as_sequence */
62
0, /* tp_as_mapping */
69
Py_TPFLAGS_DEFAULT, /* tp_flags */
70
"CThunkObject", /* tp_doc */
71
CThunkObject_traverse, /* tp_traverse */
72
CThunkObject_clear, /* tp_clear */
73
0, /* tp_richcompare */
74
0, /* tp_weaklistoffset */
81
/**************************************************************/
16
84
PrintError(char *msg, ...)
250
ffi_info *p = userdata;
318
CThunkObject *p = (CThunkObject *)userdata;
252
320
_CallPythonObject(resp,
260
ffi_info *AllocFunctionCallback(PyObject *callable,
261
PyObject *converters,
328
static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
333
p = PyObject_NewVar(CThunkObject, &CThunk_Type, nArgs);
340
memset(&p->cif, 0, sizeof(p->cif));
341
p->converters = NULL;
344
p->ffi_restype = NULL;
346
for (i = 0; i < nArgs + 1; ++i)
351
CThunkObject *AllocFunctionCallback(PyObject *callable,
352
PyObject *converters,
270
361
nArgs = PySequence_Size(converters);
271
p = (ffi_info *)PyMem_Malloc(sizeof(ffi_info) + sizeof(ffi_type) * (nArgs));
362
p = CThunkObject_new(nArgs);
366
assert(CThunk_CheckExact(p));
276
368
p->pcl = MallocClosure();
277
369
if (p->pcl == NULL) {
278
370
PyErr_NoMemory();
289
381
p->atypes[i] = NULL;
384
p->restype = restype;
291
385
if (restype == Py_None) {
292
386
p->setfunc = NULL;
293
p->restype = &ffi_type_void;
387
p->ffi_restype = &ffi_type_void;
295
389
StgDictObject *dict = PyType_stgdict(restype);
296
390
if (dict == NULL || dict->setfunc == NULL) {