Mercurial > cpython-lru_cache-weakref
annotate Modules/_ctypes/callbacks.c @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | e0409f03822f |
| children | b17814be05f1 |
| rev | line source |
|---|---|
|
38780
381a72ab5fb8
Add pep-291 compatibility markers.
Thomas Heller <theller@ctypes.org>
parents:
38634
diff
changeset
|
1 /***************************************************************** |
|
381a72ab5fb8
Add pep-291 compatibility markers.
Thomas Heller <theller@ctypes.org>
parents:
38634
diff
changeset
|
2 This file should be kept compatible with Python 2.3, see PEP 291. |
|
381a72ab5fb8
Add pep-291 compatibility markers.
Thomas Heller <theller@ctypes.org>
parents:
38634
diff
changeset
|
3 *****************************************************************/ |
|
381a72ab5fb8
Add pep-291 compatibility markers.
Thomas Heller <theller@ctypes.org>
parents:
38634
diff
changeset
|
4 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
5 #include "Python.h" |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
6 #include "compile.h" /* required only for 2.3, as it seems */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
7 #include "frameobject.h" |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
8 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
9 #include <ffi.h> |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
10 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
11 #include <windows.h> |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
12 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
13 #include "ctypes.h" |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
14 |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
15 /**************************************************************/ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
16 |
|
46569
ad3417503636
Add missing return type to dealloc.
Georg Brandl <georg@python.org>
parents:
46546
diff
changeset
|
17 static void |
|
ad3417503636
Add missing return type to dealloc.
Georg Brandl <georg@python.org>
parents:
46546
diff
changeset
|
18 CThunkObject_dealloc(PyObject *_self) |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
19 { |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
20 CThunkObject *self = (CThunkObject *)_self; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
21 Py_XDECREF(self->converters); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
22 Py_XDECREF(self->callable); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
23 Py_XDECREF(self->restype); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
24 if (self->pcl) |
|
53365
d51e4f62bc8c
Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents:
53182
diff
changeset
|
25 _ctypes_free_closure(self->pcl); |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
26 PyObject_Del(self); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
27 } |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
28 |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
29 static int |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
30 CThunkObject_traverse(PyObject *_self, visitproc visit, void *arg) |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
31 { |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
32 CThunkObject *self = (CThunkObject *)_self; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
33 Py_VISIT(self->converters); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
34 Py_VISIT(self->callable); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
35 Py_VISIT(self->restype); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
36 return 0; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
37 } |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
38 |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
39 static int |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
40 CThunkObject_clear(PyObject *_self) |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
41 { |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
42 CThunkObject *self = (CThunkObject *)_self; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
43 Py_CLEAR(self->converters); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
44 Py_CLEAR(self->callable); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
45 Py_CLEAR(self->restype); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
46 return 0; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
47 } |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
48 |
|
53365
d51e4f62bc8c
Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents:
53182
diff
changeset
|
49 PyTypeObject PyCThunk_Type = { |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
50 PyVarObject_HEAD_INIT(NULL, 0) |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
51 "_ctypes.CThunkObject", |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
52 sizeof(CThunkObject), /* tp_basicsize */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
53 sizeof(ffi_type), /* tp_itemsize */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
54 CThunkObject_dealloc, /* tp_dealloc */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
55 0, /* tp_print */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
56 0, /* tp_getattr */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
57 0, /* tp_setattr */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
58 0, /* tp_compare */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
59 0, /* tp_repr */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
60 0, /* tp_as_number */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
61 0, /* tp_as_sequence */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
62 0, /* tp_as_mapping */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
63 0, /* tp_hash */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
64 0, /* tp_call */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
65 0, /* tp_str */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
66 0, /* tp_getattro */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
67 0, /* tp_setattro */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
68 0, /* tp_as_buffer */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
69 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
70 "CThunkObject", /* tp_doc */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
71 CThunkObject_traverse, /* tp_traverse */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
72 CThunkObject_clear, /* tp_clear */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
73 0, /* tp_richcompare */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
74 0, /* tp_weaklistoffset */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
75 0, /* tp_iter */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
76 0, /* tp_iternext */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
77 0, /* tp_methods */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
78 0, /* tp_members */ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
79 }; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
80 |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
81 /**************************************************************/ |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
82 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
83 static void |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
84 PrintError(char *msg, ...) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
85 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
86 char buf[512]; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
87 PyObject *f = PySys_GetObject("stderr"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
88 va_list marker; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
89 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
90 va_start(marker, msg); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
91 vsnprintf(buf, sizeof(buf), msg, marker); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
92 va_end(marker); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
93 if (f) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
94 PyFile_WriteString(buf, f); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
95 PyErr_Print(); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
96 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
97 |
|
55889
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
98 #if (PY_VERSION_HEX < 0x02070000) |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
99 PyCodeObject * |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
100 PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno) |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
101 { |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
102 static PyObject *emptystring = NULL; |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
103 static PyObject *nulltuple = NULL; |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
104 PyObject *filename_ob = NULL; |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
105 PyObject *funcname_ob = NULL; |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
106 PyCodeObject *result = NULL; |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
107 if (emptystring == NULL) { |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
108 emptystring = PyString_FromString(""); |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
109 if (emptystring == NULL) |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
110 goto failed; |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
111 } |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
112 if (nulltuple == NULL) { |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
113 nulltuple = PyTuple_New(0); |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
114 if (nulltuple == NULL) |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
115 goto failed; |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
116 } |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
117 funcname_ob = PyString_FromString(funcname); |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
118 if (funcname_ob == NULL) |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
119 goto failed; |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
120 filename_ob = PyString_FromString(filename); |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
121 if (filename_ob == NULL) |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
122 goto failed; |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
123 |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
124 result = PyCode_New(0, /* argcount */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
125 0, /* nlocals */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
126 0, /* stacksize */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
127 0, /* flags */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
128 emptystring, /* code */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
129 nulltuple, /* consts */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
130 nulltuple, /* names */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
131 nulltuple, /* varnames */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
132 nulltuple, /* freevars */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
133 nulltuple, /* cellvars */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
134 filename_ob, /* filename */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
135 funcname_ob, /* name */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
136 firstlineno, /* firstlineno */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
137 emptystring /* lnotab */ |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
138 ); |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
139 |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
140 failed: |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
141 Py_XDECREF(funcname_ob); |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
142 Py_XDECREF(filename_ob); |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
143 return result; |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
144 } |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
145 #endif |
|
e0409f03822f
Make ctypes compile again with older Python versions.
Thomas Heller <theller@ctypes.org>
parents:
53930
diff
changeset
|
146 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
147 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
148 /* after code that pyrex generates */ |
|
53365
d51e4f62bc8c
Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents:
53182
diff
changeset
|
149 void _ctypes_add_traceback(char *funcname, char *filename, int lineno) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
150 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
151 PyObject *py_globals = 0; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
152 PyCodeObject *py_code = 0; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
153 PyFrameObject *py_frame = 0; |
| 53930 | 154 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
155 py_globals = PyDict_New(); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
156 if (!py_globals) goto bad; |
| 53930 | 157 py_code = PyCode_NewEmpty(filename, funcname, lineno); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
158 if (!py_code) goto bad; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
159 py_frame = PyFrame_New( |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
160 PyThreadState_Get(), /*PyThreadState *tstate,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
161 py_code, /*PyCodeObject *code,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
162 py_globals, /*PyObject *globals,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
163 0 /*PyObject *locals*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
164 ); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
165 if (!py_frame) goto bad; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
166 py_frame->f_lineno = lineno; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
167 PyTraceBack_Here(py_frame); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
168 bad: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
169 Py_XDECREF(py_globals); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
170 Py_XDECREF(py_code); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
171 Py_XDECREF(py_frame); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
172 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
173 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
174 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
175 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
176 * We must call AddRef() on non-NULL COM pointers we receive as arguments |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
177 * to callback functions - these functions are COM method implementations. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
178 * The Python instances we create have a __del__ method which calls Release(). |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
179 * |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
180 * The presence of a class attribute named '_needs_com_addref_' triggers this |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
181 * behaviour. It would also be possible to call the AddRef() Python method, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
182 * after checking for PyObject_IsTrue(), but this would probably be somewhat |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
183 * slower. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
184 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
185 static void |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
186 TryAddRef(StgDictObject *dict, CDataObject *obj) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
187 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
188 IUnknown *punk; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
189 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
190 if (NULL == PyDict_GetItemString((PyObject *)dict, "_needs_com_addref_")) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
191 return; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
192 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
193 punk = *(IUnknown **)obj->b_ptr; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
194 if (punk) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
195 punk->lpVtbl->AddRef(punk); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
196 return; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
197 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
198 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
199 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
200 /****************************************************************************** |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
201 * |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
202 * Call the python object with all arguments |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
203 * |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
204 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
205 static void _CallPythonObject(void *mem, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
206 ffi_type *restype, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
207 SETFUNC setfunc, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
208 PyObject *callable, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
209 PyObject *converters, |
|
47488
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
210 int flags, |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
211 void **pArgs) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
212 { |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41912
diff
changeset
|
213 Py_ssize_t i; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
214 PyObject *result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
215 PyObject *arglist = NULL; |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41912
diff
changeset
|
216 Py_ssize_t nArgs; |
|
47488
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
217 PyObject *error_object = NULL; |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
218 int *space; |
|
39074
892b7ac26d3b
A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents:
38963
diff
changeset
|
219 #ifdef WITH_THREAD |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
220 PyGILState_STATE state = PyGILState_Ensure(); |
|
38963
c6d04c9c3c4a
Protect the thread api calls in the _ctypes extension module within
Thomas Heller <theller@ctypes.org>
parents:
38780
diff
changeset
|
221 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
222 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
223 nArgs = PySequence_Length(converters); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
224 /* Hm. What to return in case of error? |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
225 For COM, 0xFFFFFFFF seems better than 0. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
226 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
227 if (nArgs < 0) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
228 PrintError("BUG: PySequence_Length"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
229 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
230 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
231 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
232 arglist = PyTuple_New(nArgs); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
233 if (!arglist) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
234 PrintError("PyTuple_New()"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
235 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
236 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
237 for (i = 0; i < nArgs; ++i) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
238 /* Note: new reference! */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
239 PyObject *cnv = PySequence_GetItem(converters, i); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
240 StgDictObject *dict; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
241 if (cnv) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
242 dict = PyType_stgdict(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
243 else { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
244 PrintError("Getting argument converter %d\n", i); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
245 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
246 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
247 |
|
53365
d51e4f62bc8c
Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents:
53182
diff
changeset
|
248 if (dict && dict->getfunc && !_ctypes_simple_instance(cnv)) { |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
249 PyObject *v = dict->getfunc(*pArgs, dict->size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
250 if (!v) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
251 PrintError("create argument %d:\n", i); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
252 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
253 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
254 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
255 PyTuple_SET_ITEM(arglist, i, v); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
256 /* XXX XXX XX |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
257 We have the problem that c_byte or c_short have dict->size of |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
258 1 resp. 4, but these parameters are pushed as sizeof(int) bytes. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
259 BTW, the same problem occurrs when they are pushed as parameters |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
260 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
261 } else if (dict) { |
|
53365
d51e4f62bc8c
Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents:
53182
diff
changeset
|
262 /* Hm, shouldn't we use PyCData_AtAddress() or something like that instead? */ |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
263 CDataObject *obj = (CDataObject *)PyObject_CallFunctionObjArgs(cnv, NULL); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
264 if (!obj) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
265 PrintError("create argument %d:\n", i); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
266 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
267 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
268 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
269 if (!CDataObject_Check(obj)) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
270 Py_DECREF(obj); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
271 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
272 PrintError("unexpected result of create argument %d:\n", i); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
273 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
274 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
275 memcpy(obj->b_ptr, *pArgs, dict->size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
276 PyTuple_SET_ITEM(arglist, i, (PyObject *)obj); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
277 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
278 TryAddRef(dict, obj); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
279 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
280 } else { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
281 PyErr_SetString(PyExc_TypeError, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
282 "cannot build parameter"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
283 PrintError("Parsing argument %d\n", i); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
284 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
285 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
286 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
287 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
288 /* XXX error handling! */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
289 pArgs++; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
290 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
291 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
292 #define CHECK(what, x) \ |
|
53365
d51e4f62bc8c
Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents:
53182
diff
changeset
|
293 if (x == NULL) _ctypes_add_traceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_Print() |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
294 |
|
47488
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
295 if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) { |
|
53365
d51e4f62bc8c
Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents:
53182
diff
changeset
|
296 error_object = _ctypes_get_errobj(&space); |
|
47488
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
297 if (error_object == NULL) |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
298 goto Done; |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
299 if (flags & FUNCFLAG_USE_ERRNO) { |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
300 int temp = space[0]; |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
301 space[0] = errno; |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
302 errno = temp; |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
303 } |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
304 #ifdef MS_WIN32 |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
305 if (flags & FUNCFLAG_USE_LASTERROR) { |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
306 int temp = space[1]; |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
307 space[1] = GetLastError(); |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
308 SetLastError(temp); |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
309 } |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
310 #endif |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
311 } |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
312 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
313 result = PyObject_CallObject(callable, arglist); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
314 CHECK("'calling callback function'", result); |
|
47488
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
315 |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
316 #ifdef MS_WIN32 |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
317 if (flags & FUNCFLAG_USE_LASTERROR) { |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
318 int temp = space[1]; |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
319 space[1] = GetLastError(); |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
320 SetLastError(temp); |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
321 } |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
322 #endif |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
323 if (flags & FUNCFLAG_USE_ERRNO) { |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
324 int temp = space[0]; |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
325 space[0] = errno; |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
326 errno = temp; |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
327 } |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
328 Py_XDECREF(error_object); |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
329 |
|
39526
ffe7d3ab35a8
Remove the special casing of Py_None when converting the return value
Thomas Heller <theller@ctypes.org>
parents:
39486
diff
changeset
|
330 if ((restype != &ffi_type_void) && result) { |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
331 PyObject *keep; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
332 assert(setfunc); |
|
39486
a6a6dff17935
Revert the change that tries to zero out a closure's result storage
Thomas Heller <theller@ctypes.org>
parents:
39444
diff
changeset
|
333 #ifdef WORDS_BIGENDIAN |
|
a6a6dff17935
Revert the change that tries to zero out a closure's result storage
Thomas Heller <theller@ctypes.org>
parents:
39444
diff
changeset
|
334 /* See the corresponding code in callproc.c, around line 961 */ |
|
a6a6dff17935
Revert the change that tries to zero out a closure's result storage
Thomas Heller <theller@ctypes.org>
parents:
39444
diff
changeset
|
335 if (restype->type != FFI_TYPE_FLOAT && restype->size < sizeof(ffi_arg)) |
|
a6a6dff17935
Revert the change that tries to zero out a closure's result storage
Thomas Heller <theller@ctypes.org>
parents:
39444
diff
changeset
|
336 mem = (char *)mem + sizeof(ffi_arg) - restype->size; |
|
a6a6dff17935
Revert the change that tries to zero out a closure's result storage
Thomas Heller <theller@ctypes.org>
parents:
39444
diff
changeset
|
337 #endif |
|
38634
7bfafdeffee2
Use the same big-endian hack as in _ctypes/callproc.c for callback functions.
Thomas Heller <theller@ctypes.org>
parents:
37848
diff
changeset
|
338 keep = setfunc(mem, result, 0); |
|
7bfafdeffee2
Use the same big-endian hack as in _ctypes/callproc.c for callback functions.
Thomas Heller <theller@ctypes.org>
parents:
37848
diff
changeset
|
339 CHECK("'converting callback result'", keep); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
340 /* keep is an object we have to keep alive so that the result |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
341 stays valid. If there is no such object, the setfunc will |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
342 have returned Py_None. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
343 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
344 If there is such an object, we have no choice than to keep |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
345 it alive forever - but a refcount and/or memory leak will |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
346 be the result. EXCEPT when restype is py_object - Python |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
347 itself knows how to manage the refcount of these objects. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
348 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
349 if (keep == NULL) /* Could not convert callback result. */ |
|
39444
b995e2760da4
When a ctypes C callback function is called, zero out the result
Thomas Heller <theller@ctypes.org>
parents:
39119
diff
changeset
|
350 PyErr_WriteUnraisable(callable); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
351 else if (keep == Py_None) /* Nothing to keep */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
352 Py_DECREF(keep); |
|
53365
d51e4f62bc8c
Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents:
53182
diff
changeset
|
353 else if (setfunc != _ctypes_get_fielddesc("O")->setfunc) { |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
354 if (-1 == PyErr_Warn(PyExc_RuntimeWarning, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
355 "memory leak in callback function.")) |
|
39444
b995e2760da4
When a ctypes C callback function is called, zero out the result
Thomas Heller <theller@ctypes.org>
parents:
39119
diff
changeset
|
356 PyErr_WriteUnraisable(callable); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
357 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
358 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
359 Py_XDECREF(result); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
360 Done: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
361 Py_XDECREF(arglist); |
|
39074
892b7ac26d3b
A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents:
38963
diff
changeset
|
362 #ifdef WITH_THREAD |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
363 PyGILState_Release(state); |
|
38963
c6d04c9c3c4a
Protect the thread api calls in the _ctypes extension module within
Thomas Heller <theller@ctypes.org>
parents:
38780
diff
changeset
|
364 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
365 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
366 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
367 static void closure_fcn(ffi_cif *cif, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
368 void *resp, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
369 void **args, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
370 void *userdata) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
371 { |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
372 CThunkObject *p = (CThunkObject *)userdata; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
373 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
374 _CallPythonObject(resp, |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
375 p->ffi_restype, |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
376 p->setfunc, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
377 p->callable, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
378 p->converters, |
|
47488
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
379 p->flags, |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
380 args); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
381 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
382 |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
383 static CThunkObject* CThunkObject_new(Py_ssize_t nArgs) |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
384 { |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
385 CThunkObject *p; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
386 int i; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
387 |
|
53365
d51e4f62bc8c
Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents:
53182
diff
changeset
|
388 p = PyObject_NewVar(CThunkObject, &PyCThunk_Type, nArgs); |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
389 if (p == NULL) { |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
390 PyErr_NoMemory(); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
391 return NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
392 } |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
393 |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
394 p->pcl = NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
395 memset(&p->cif, 0, sizeof(p->cif)); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
396 p->converters = NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
397 p->callable = NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
398 p->setfunc = NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
399 p->ffi_restype = NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
400 |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
401 for (i = 0; i < nArgs + 1; ++i) |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
402 p->atypes[i] = NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
403 return p; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
404 } |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
405 |
|
53365
d51e4f62bc8c
Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents:
53182
diff
changeset
|
406 CThunkObject *_ctypes_alloc_callback(PyObject *callable, |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
407 PyObject *converters, |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
408 PyObject *restype, |
|
47488
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
409 int flags) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
410 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
411 int result; |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
412 CThunkObject *p; |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41912
diff
changeset
|
413 Py_ssize_t nArgs, i; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
414 ffi_abi cc; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
415 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
416 nArgs = PySequence_Size(converters); |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
417 p = CThunkObject_new(nArgs); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
418 if (p == NULL) |
|
37147
0057862a3bdb
Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents:
37115
diff
changeset
|
419 return NULL; |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
420 |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
421 assert(CThunk_CheckExact(p)); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
422 |
|
53365
d51e4f62bc8c
Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents:
53182
diff
changeset
|
423 p->pcl = _ctypes_alloc_closure(); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
424 if (p->pcl == NULL) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
425 PyErr_NoMemory(); |
|
37030
a253958bfa4c
Rewrite the AllocFunctionCallback function for better error handling.
Thomas Heller <theller@ctypes.org>
parents:
36897
diff
changeset
|
426 goto error; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
427 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
428 |
|
47488
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
429 p->flags = flags; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
430 for (i = 0; i < nArgs; ++i) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
431 PyObject *cnv = PySequence_GetItem(converters, i); |
|
37030
a253958bfa4c
Rewrite the AllocFunctionCallback function for better error handling.
Thomas Heller <theller@ctypes.org>
parents:
36897
diff
changeset
|
432 if (cnv == NULL) |
|
a253958bfa4c
Rewrite the AllocFunctionCallback function for better error handling.
Thomas Heller <theller@ctypes.org>
parents:
36897
diff
changeset
|
433 goto error; |
|
53365
d51e4f62bc8c
Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents:
53182
diff
changeset
|
434 p->atypes[i] = _ctypes_get_ffi_type(cnv); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
435 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
436 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
437 p->atypes[i] = NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
438 |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
439 Py_INCREF(restype); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
440 p->restype = restype; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
441 if (restype == Py_None) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
442 p->setfunc = NULL; |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
443 p->ffi_restype = &ffi_type_void; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
444 } else { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
445 StgDictObject *dict = PyType_stgdict(restype); |
|
40141
52fe0ecf55c1
ctypes callback functions only support 'fundamental' result types.
Thomas Heller <theller@ctypes.org>
parents:
39679
diff
changeset
|
446 if (dict == NULL || dict->setfunc == NULL) { |
|
52fe0ecf55c1
ctypes callback functions only support 'fundamental' result types.
Thomas Heller <theller@ctypes.org>
parents:
39679
diff
changeset
|
447 PyErr_SetString(PyExc_TypeError, |
|
52fe0ecf55c1
ctypes callback functions only support 'fundamental' result types.
Thomas Heller <theller@ctypes.org>
parents:
39679
diff
changeset
|
448 "invalid result type for callback function"); |
|
52fe0ecf55c1
ctypes callback functions only support 'fundamental' result types.
Thomas Heller <theller@ctypes.org>
parents:
39679
diff
changeset
|
449 goto error; |
|
52fe0ecf55c1
ctypes callback functions only support 'fundamental' result types.
Thomas Heller <theller@ctypes.org>
parents:
39679
diff
changeset
|
450 } |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
451 p->setfunc = dict->setfunc; |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
452 p->ffi_restype = &dict->ffi_type_pointer; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
453 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
454 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
455 cc = FFI_DEFAULT_ABI; |
|
39679
3bfc8bb4e726
Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents:
39526
diff
changeset
|
456 #if defined(MS_WIN32) && !defined(_WIN32_WCE) && !defined(MS_WIN64) |
|
47488
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
457 if ((flags & FUNCFLAG_CDECL) == 0) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
458 cc = FFI_STDCALL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
459 #endif |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41912
diff
changeset
|
460 result = ffi_prep_cif(&p->cif, cc, |
|
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41912
diff
changeset
|
461 Py_SAFE_DOWNCAST(nArgs, Py_ssize_t, int), |
|
53365
d51e4f62bc8c
Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents:
53182
diff
changeset
|
462 _ctypes_get_ffi_type(restype), |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
463 &p->atypes[0]); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
464 if (result != FFI_OK) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
465 PyErr_Format(PyExc_RuntimeError, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
466 "ffi_prep_cif failed with %d", result); |
|
37030
a253958bfa4c
Rewrite the AllocFunctionCallback function for better error handling.
Thomas Heller <theller@ctypes.org>
parents:
36897
diff
changeset
|
467 goto error; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
468 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
469 result = ffi_prep_closure(p->pcl, &p->cif, closure_fcn, p); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
470 if (result != FFI_OK) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
471 PyErr_Format(PyExc_RuntimeError, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
472 "ffi_prep_closure failed with %d", result); |
|
37030
a253958bfa4c
Rewrite the AllocFunctionCallback function for better error handling.
Thomas Heller <theller@ctypes.org>
parents:
36897
diff
changeset
|
473 goto error; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
474 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
475 |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
476 Py_INCREF(converters); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
477 p->converters = converters; |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
478 Py_INCREF(callable); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
479 p->callable = callable; |
|
37147
0057862a3bdb
Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents:
37115
diff
changeset
|
480 return p; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
481 |
|
37030
a253958bfa4c
Rewrite the AllocFunctionCallback function for better error handling.
Thomas Heller <theller@ctypes.org>
parents:
36897
diff
changeset
|
482 error: |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
483 Py_XDECREF(p); |
|
37030
a253958bfa4c
Rewrite the AllocFunctionCallback function for better error handling.
Thomas Heller <theller@ctypes.org>
parents:
36897
diff
changeset
|
484 return NULL; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
485 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
486 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
487 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
488 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
489 static void LoadPython(void) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
490 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
491 if (!Py_IsInitialized()) { |
|
39119
c5759b5a57f0
Make sure the _ctypes extension can be compiled when WITH_THREAD is
Thomas Heller <theller@ctypes.org>
parents:
39074
diff
changeset
|
492 #ifdef WITH_THREAD |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
493 PyEval_InitThreads(); |
|
39119
c5759b5a57f0
Make sure the _ctypes extension can be compiled when WITH_THREAD is
Thomas Heller <theller@ctypes.org>
parents:
39074
diff
changeset
|
494 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
495 Py_Initialize(); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
496 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
497 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
498 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
499 /******************************************************************/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
500 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
501 long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
502 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
503 PyObject *mod, *func, *result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
504 long retval; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
505 static PyObject *context; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
506 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
507 if (context == NULL) |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47488
diff
changeset
|
508 context = PyString_InternFromString("_ctypes.DllGetClassObject"); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
509 |
|
44439
0cbe94bea2c7
Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0
Christian Heimes <christian@cheimes.de>
parents:
42266
diff
changeset
|
510 mod = PyImport_ImportModuleNoBlock("ctypes"); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
511 if (!mod) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
512 PyErr_WriteUnraisable(context ? context : Py_None); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
513 /* There has been a warning before about this already */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
514 return E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
515 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
516 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
517 func = PyObject_GetAttrString(mod, "DllGetClassObject"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
518 Py_DECREF(mod); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
519 if (!func) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
520 PyErr_WriteUnraisable(context ? context : Py_None); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
521 return E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
522 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
523 |
|
41582
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
524 { |
|
41912
ddf0471a6de3
Fix compiler warnings.
Thomas Heller <theller@ctypes.org>
parents:
41582
diff
changeset
|
525 PyObject *py_rclsid = PyLong_FromVoidPtr((void *)rclsid); |
|
ddf0471a6de3
Fix compiler warnings.
Thomas Heller <theller@ctypes.org>
parents:
41582
diff
changeset
|
526 PyObject *py_riid = PyLong_FromVoidPtr((void *)riid); |
|
41582
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
527 PyObject *py_ppv = PyLong_FromVoidPtr(ppv); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
528 if (!py_rclsid || !py_riid || !py_ppv) { |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
529 Py_XDECREF(py_rclsid); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
530 Py_XDECREF(py_riid); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
531 Py_XDECREF(py_ppv); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
532 Py_DECREF(func); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
533 PyErr_WriteUnraisable(context ? context : Py_None); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
534 return E_FAIL; |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
535 } |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
536 result = PyObject_CallFunctionObjArgs(func, |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
537 py_rclsid, |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
538 py_riid, |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
539 py_ppv, |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
540 NULL); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
541 Py_DECREF(py_rclsid); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
542 Py_DECREF(py_riid); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
543 Py_DECREF(py_ppv); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
544 } |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
545 Py_DECREF(func); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
546 if (!result) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
547 PyErr_WriteUnraisable(context ? context : Py_None); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
548 return E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
549 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
550 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
551 retval = PyInt_AsLong(result); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
552 if (PyErr_Occurred()) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
553 PyErr_WriteUnraisable(context ? context : Py_None); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
554 retval = E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
555 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
556 Py_DECREF(result); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
557 return retval; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
558 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
559 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
560 STDAPI DllGetClassObject(REFCLSID rclsid, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
561 REFIID riid, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
562 LPVOID *ppv) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
563 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
564 long result; |
|
39074
892b7ac26d3b
A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents:
38963
diff
changeset
|
565 #ifdef WITH_THREAD |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
566 PyGILState_STATE state; |
|
38963
c6d04c9c3c4a
Protect the thread api calls in the _ctypes extension module within
Thomas Heller <theller@ctypes.org>
parents:
38780
diff
changeset
|
567 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
568 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
569 LoadPython(); |
|
39074
892b7ac26d3b
A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents:
38963
diff
changeset
|
570 #ifdef WITH_THREAD |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
571 state = PyGILState_Ensure(); |
|
38963
c6d04c9c3c4a
Protect the thread api calls in the _ctypes extension module within
Thomas Heller <theller@ctypes.org>
parents:
38780
diff
changeset
|
572 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
573 result = Call_GetClassObject(rclsid, riid, ppv); |
|
39074
892b7ac26d3b
A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents:
38963
diff
changeset
|
574 #ifdef WITH_THREAD |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
575 PyGILState_Release(state); |
|
38963
c6d04c9c3c4a
Protect the thread api calls in the _ctypes extension module within
Thomas Heller <theller@ctypes.org>
parents:
38780
diff
changeset
|
576 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
577 return result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
578 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
579 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
580 long Call_CanUnloadNow(void) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
581 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
582 PyObject *mod, *func, *result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
583 long retval; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
584 static PyObject *context; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
585 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
586 if (context == NULL) |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47488
diff
changeset
|
587 context = PyString_InternFromString("_ctypes.DllCanUnloadNow"); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
588 |
|
44439
0cbe94bea2c7
Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0
Christian Heimes <christian@cheimes.de>
parents:
42266
diff
changeset
|
589 mod = PyImport_ImportModuleNoBlock("ctypes"); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
590 if (!mod) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
591 /* OutputDebugString("Could not import ctypes"); */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
592 /* We assume that this error can only occur when shutting |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
593 down, so we silently ignore it */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
594 PyErr_Clear(); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
595 return E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
596 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
597 /* Other errors cannot be raised, but are printed to stderr */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
598 func = PyObject_GetAttrString(mod, "DllCanUnloadNow"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
599 Py_DECREF(mod); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
600 if (!func) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
601 PyErr_WriteUnraisable(context ? context : Py_None); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
602 return E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
603 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
604 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
605 result = PyObject_CallFunction(func, NULL); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
606 Py_DECREF(func); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
607 if (!result) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
608 PyErr_WriteUnraisable(context ? context : Py_None); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
609 return E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
610 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
611 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
612 retval = PyInt_AsLong(result); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
613 if (PyErr_Occurred()) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
614 PyErr_WriteUnraisable(context ? context : Py_None); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
615 retval = E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
616 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
617 Py_DECREF(result); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
618 return retval; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
619 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
620 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
621 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
622 DllRegisterServer and DllUnregisterServer still missing |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
623 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
624 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
625 STDAPI DllCanUnloadNow(void) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
626 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
627 long result; |
|
39074
892b7ac26d3b
A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents:
38963
diff
changeset
|
628 #ifdef WITH_THREAD |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
629 PyGILState_STATE state = PyGILState_Ensure(); |
|
38963
c6d04c9c3c4a
Protect the thread api calls in the _ctypes extension module within
Thomas Heller <theller@ctypes.org>
parents:
38780
diff
changeset
|
630 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
631 result = Call_CanUnloadNow(); |
|
39074
892b7ac26d3b
A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents:
38963
diff
changeset
|
632 #ifdef WITH_THREAD |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
633 PyGILState_Release(state); |
|
38963
c6d04c9c3c4a
Protect the thread api calls in the _ctypes extension module within
Thomas Heller <theller@ctypes.org>
parents:
38780
diff
changeset
|
634 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
635 return result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
636 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
637 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
638 #ifndef Py_NO_ENABLE_SHARED |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
639 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvRes) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
640 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
641 switch(fdwReason) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
642 case DLL_PROCESS_ATTACH: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
643 DisableThreadLibraryCalls(hinstDLL); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
644 break; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
645 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
646 return TRUE; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
647 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
648 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
649 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
650 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
651 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
652 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
653 Local Variables: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
654 compile-command: "cd .. && python setup.py -q build_ext" |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
655 End: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
656 */ |
