Mercurial > cpython-lru_cache-weakref
annotate Modules/_ctypes/callbacks.c @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 92f7a460ff82 |
| children | e2a4445b0e7c d51e4f62bc8c |
| 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) |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
25 FreeClosure(self->pcl); |
|
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 |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
49 PyTypeObject CThunk_Type = { |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
98 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
99 /* after code that pyrex generates */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
100 void _AddTraceback(char *funcname, char *filename, int lineno) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
101 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
102 PyObject *py_srcfile = 0; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
103 PyObject *py_funcname = 0; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
104 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
|
105 PyObject *empty_tuple = 0; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
106 PyObject *empty_string = 0; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
107 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
|
108 PyFrameObject *py_frame = 0; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
109 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47488
diff
changeset
|
110 py_srcfile = PyString_FromString(filename); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
111 if (!py_srcfile) goto bad; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47488
diff
changeset
|
112 py_funcname = PyString_FromString(funcname); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
113 if (!py_funcname) goto bad; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
114 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
|
115 if (!py_globals) goto bad; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
116 empty_tuple = PyTuple_New(0); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
117 if (!empty_tuple) goto bad; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47488
diff
changeset
|
118 empty_string = PyString_FromString(""); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
119 if (!empty_string) goto bad; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
120 py_code = PyCode_New( |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
121 0, /*int argcount,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
122 0, /*int nlocals,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
123 0, /*int stacksize,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
124 0, /*int flags,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
125 empty_string, /*PyObject *code,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
126 empty_tuple, /*PyObject *consts,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
127 empty_tuple, /*PyObject *names,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
128 empty_tuple, /*PyObject *varnames,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
129 empty_tuple, /*PyObject *freevars,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
130 empty_tuple, /*PyObject *cellvars,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
131 py_srcfile, /*PyObject *filename,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
132 py_funcname, /*PyObject *name,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
133 lineno, /*int firstlineno,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
134 empty_string /*PyObject *lnotab*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
135 ); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 0 /*PyObject *locals*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
142 ); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 bad: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
147 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
|
148 Py_XDECREF(py_srcfile); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
149 Py_XDECREF(py_funcname); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
150 Py_XDECREF(empty_tuple); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
151 Py_XDECREF(empty_string); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
152 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
|
153 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
|
154 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
155 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
156 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
157 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
158 * 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
|
159 * 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
|
160 * 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
|
161 * |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
162 * 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
|
163 * 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
|
164 * 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
|
165 * slower. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
166 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
167 static void |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
168 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
|
169 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
170 IUnknown *punk; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
171 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
172 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
|
173 return; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
174 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
175 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
|
176 if (punk) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
177 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
|
178 return; |
|
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 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
181 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
182 /****************************************************************************** |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
183 * |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
184 * 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
|
185 * |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
186 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
187 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
|
188 ffi_type *restype, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
189 SETFUNC setfunc, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
190 PyObject *callable, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
191 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
|
192 int flags, |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
193 void **pArgs) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
194 { |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41912
diff
changeset
|
195 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
|
196 PyObject *result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 int *space; |
|
39074
892b7ac26d3b
A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents:
38963
diff
changeset
|
201 #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
|
202 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
|
203 #endif |
|
36897
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 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
|
206 /* 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
|
207 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
|
208 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
209 if (nArgs < 0) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
210 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
|
211 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
212 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
213 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
214 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
|
215 if (!arglist) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
216 PrintError("PyTuple_New()"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
217 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
218 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
219 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
|
220 /* Note: new reference! */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
221 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
|
222 StgDictObject *dict; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
223 if (cnv) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
224 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
|
225 else { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
226 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
|
227 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
228 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
229 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
230 if (dict && dict->getfunc && !IsSimpleSubType(cnv)) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
231 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
|
232 if (!v) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
233 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
|
234 Py_DECREF(cnv); |
|
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 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
|
238 /* XXX XXX XX |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
243 } else if (dict) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
244 /* Hm, shouldn't we use CData_AtAddress() or something like that instead? */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
245 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
|
246 if (!obj) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
247 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
|
248 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
249 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
250 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
251 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
|
252 Py_DECREF(obj); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
253 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
254 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
|
255 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
256 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
257 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
|
258 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
|
259 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
260 TryAddRef(dict, obj); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
261 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
262 } else { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
263 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
|
264 "cannot build parameter"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
265 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
|
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 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
270 /* XXX error handling! */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
271 pArgs++; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
272 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
273 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
274 #define CHECK(what, x) \ |
|
44597
5fb9b2f6bacb
Use relative instead of absolute filenames in the C-level tracebacks.
Thomas Heller <theller@ctypes.org>
parents:
44439
diff
changeset
|
275 if (x == NULL) _AddTraceback(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
|
276 |
|
47488
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
277 if (flags & (FUNCFLAG_USE_ERRNO | 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
|
278 error_object = get_error_object(&space); |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
279 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
|
280 goto Done; |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
281 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
|
282 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
|
283 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
|
284 errno = temp; |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
285 } |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
286 #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
|
287 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
|
288 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
|
289 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
|
290 SetLastError(temp); |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
291 } |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
292 #endif |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
293 } |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
294 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
295 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
|
296 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
|
297 |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
298 #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
|
299 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
|
300 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
|
301 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
|
302 SetLastError(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 #endif |
|
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_ERRNO) { |
|
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[0]; |
|
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
307 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
|
308 errno = 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 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
|
311 |
|
39526
ffe7d3ab35a8
Remove the special casing of Py_None when converting the return value
Thomas Heller <theller@ctypes.org>
parents:
39486
diff
changeset
|
312 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
|
313 PyObject *keep; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
314 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
|
315 #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
|
316 /* 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
|
317 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
|
318 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
|
319 #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
|
320 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
|
321 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
|
322 /* 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
|
323 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
|
324 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
|
325 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
326 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
|
327 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
|
328 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
|
329 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
|
330 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
331 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
|
332 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
|
333 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
|
334 Py_DECREF(keep); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
335 else if (setfunc != getentry("O")->setfunc) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
336 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
|
337 "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
|
338 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
|
339 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
340 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
341 Py_XDECREF(result); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
342 Done: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
343 Py_XDECREF(arglist); |
|
39074
892b7ac26d3b
A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents:
38963
diff
changeset
|
344 #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
|
345 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
|
346 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
347 } |
|
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 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
|
350 void *resp, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
351 void **args, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
352 void *userdata) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
353 { |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
354 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
|
355 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
356 _CallPythonObject(resp, |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
357 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
|
358 p->setfunc, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
359 p->callable, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
360 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
|
361 p->flags, |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
362 args); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
363 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
364 |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
365 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
|
366 { |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
367 CThunkObject *p; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
368 int i; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
369 |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
370 p = PyObject_NewVar(CThunkObject, &CThunk_Type, nArgs); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
371 if (p == NULL) { |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
372 PyErr_NoMemory(); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
373 return NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
374 } |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
375 |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
376 p->pcl = NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
377 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
|
378 p->converters = NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
379 p->callable = NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
380 p->setfunc = NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
381 p->ffi_restype = NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
382 |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
383 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
|
384 p->atypes[i] = NULL; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
385 return p; |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
386 } |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
387 |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
388 CThunkObject *AllocFunctionCallback(PyObject *callable, |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
389 PyObject *converters, |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
390 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
|
391 int flags) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
392 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
393 int result; |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
394 CThunkObject *p; |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41912
diff
changeset
|
395 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
|
396 ffi_abi cc; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
397 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
398 nArgs = PySequence_Size(converters); |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
399 p = CThunkObject_new(nArgs); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
400 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
|
401 return NULL; |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
402 |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
403 assert(CThunk_CheckExact(p)); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
404 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
405 p->pcl = MallocClosure(); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
406 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
|
407 PyErr_NoMemory(); |
|
37030
a253958bfa4c
Rewrite the AllocFunctionCallback function for better error handling.
Thomas Heller <theller@ctypes.org>
parents:
36897
diff
changeset
|
408 goto error; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
409 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
410 |
|
47488
4f5e6aaf5a6a
Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents:
47469
diff
changeset
|
411 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
|
412 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
|
413 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
|
414 if (cnv == NULL) |
|
a253958bfa4c
Rewrite the AllocFunctionCallback function for better error handling.
Thomas Heller <theller@ctypes.org>
parents:
36897
diff
changeset
|
415 goto error; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
416 p->atypes[i] = GetType(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
417 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
418 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
419 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
|
420 |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
421 Py_INCREF(restype); |
|
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
422 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
|
423 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
|
424 p->setfunc = NULL; |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
425 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
|
426 } else { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
427 StgDictObject *dict = PyType_stgdict(restype); |
|
40141
52fe0ecf55c1
ctypes callback functions only support 'fundamental' result types.
Thomas Heller <theller@ctypes.org>
parents:
39679
diff
changeset
|
428 if (dict == NULL || dict->setfunc == NULL) { |
|
52fe0ecf55c1
ctypes callback functions only support 'fundamental' result types.
Thomas Heller <theller@ctypes.org>
parents:
39679
diff
changeset
|
429 PyErr_SetString(PyExc_TypeError, |
|
52fe0ecf55c1
ctypes callback functions only support 'fundamental' result types.
Thomas Heller <theller@ctypes.org>
parents:
39679
diff
changeset
|
430 "invalid result type for callback function"); |
|
52fe0ecf55c1
ctypes callback functions only support 'fundamental' result types.
Thomas Heller <theller@ctypes.org>
parents:
39679
diff
changeset
|
431 goto error; |
|
52fe0ecf55c1
ctypes callback functions only support 'fundamental' result types.
Thomas Heller <theller@ctypes.org>
parents:
39679
diff
changeset
|
432 } |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
433 p->setfunc = dict->setfunc; |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
434 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
|
435 } |
|
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 cc = FFI_DEFAULT_ABI; |
|
39679
3bfc8bb4e726
Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents:
39526
diff
changeset
|
438 #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
|
439 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
|
440 cc = FFI_STDCALL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
441 #endif |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41912
diff
changeset
|
442 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
|
443 Py_SAFE_DOWNCAST(nArgs, Py_ssize_t, int), |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
444 GetType(restype), |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
445 &p->atypes[0]); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
446 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
|
447 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
|
448 "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
|
449 goto error; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
450 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
451 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
|
452 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
|
453 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
|
454 "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
|
455 goto error; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
456 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
457 |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
458 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
|
459 p->converters = converters; |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
460 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
|
461 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
|
462 return p; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
463 |
|
37030
a253958bfa4c
Rewrite the AllocFunctionCallback function for better error handling.
Thomas Heller <theller@ctypes.org>
parents:
36897
diff
changeset
|
464 error: |
|
46546
4ff8dfaec3fc
Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents:
45028
diff
changeset
|
465 Py_XDECREF(p); |
|
37030
a253958bfa4c
Rewrite the AllocFunctionCallback function for better error handling.
Thomas Heller <theller@ctypes.org>
parents:
36897
diff
changeset
|
466 return NULL; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
467 } |
|
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 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
470 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
471 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
|
472 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
473 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
|
474 #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
|
475 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
|
476 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
477 Py_Initialize(); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
478 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
479 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
480 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
481 /******************************************************************/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
482 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
483 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
|
484 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
485 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
|
486 long retval; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
487 static PyObject *context; |
|
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 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
|
490 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
|
491 |
|
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
|
492 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
|
493 if (!mod) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
494 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
|
495 /* 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
|
496 return E_FAIL; |
|
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 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
|
500 Py_DECREF(mod); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
501 if (!func) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
502 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
|
503 return E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
504 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
505 |
|
41582
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
506 { |
|
41912
ddf0471a6de3
Fix compiler warnings.
Thomas Heller <theller@ctypes.org>
parents:
41582
diff
changeset
|
507 PyObject *py_rclsid = PyLong_FromVoidPtr((void *)rclsid); |
|
ddf0471a6de3
Fix compiler warnings.
Thomas Heller <theller@ctypes.org>
parents:
41582
diff
changeset
|
508 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
|
509 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
|
510 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
|
511 Py_XDECREF(py_rclsid); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
512 Py_XDECREF(py_riid); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
513 Py_XDECREF(py_ppv); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
514 Py_DECREF(func); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
515 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
|
516 return E_FAIL; |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
517 } |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
518 result = PyObject_CallFunctionObjArgs(func, |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
519 py_rclsid, |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
520 py_riid, |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
521 py_ppv, |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
522 NULL); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
523 Py_DECREF(py_rclsid); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
524 Py_DECREF(py_riid); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
525 Py_DECREF(py_ppv); |
|
25cc1cee5e69
Don't truncate pointers to integers (on win64 platform).
Thomas Heller <theller@ctypes.org>
parents:
40141
diff
changeset
|
526 } |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
527 Py_DECREF(func); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
528 if (!result) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
529 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
|
530 return E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
531 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
532 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
533 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
|
534 if (PyErr_Occurred()) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
535 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
|
536 retval = E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
537 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
538 Py_DECREF(result); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
539 return retval; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
540 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
541 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
542 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
|
543 REFIID riid, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
544 LPVOID *ppv) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
545 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
546 long result; |
|
39074
892b7ac26d3b
A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents:
38963
diff
changeset
|
547 #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
|
548 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
|
549 #endif |
|
36897
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 LoadPython(); |
|
39074
892b7ac26d3b
A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents:
38963
diff
changeset
|
552 #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
|
553 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
|
554 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
555 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
|
556 #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
|
557 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
|
558 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
559 return result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
560 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
561 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
562 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
|
563 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
564 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
|
565 long retval; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
566 static PyObject *context; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
567 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
568 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
|
569 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
|
570 |
|
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
|
571 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
|
572 if (!mod) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
573 /* 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
|
574 /* 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
|
575 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
|
576 PyErr_Clear(); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
577 return E_FAIL; |
|
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 /* 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
|
580 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
|
581 Py_DECREF(mod); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
582 if (!func) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
583 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
|
584 return E_FAIL; |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
587 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
|
588 Py_DECREF(func); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
589 if (!result) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
590 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
|
591 return E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
592 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
593 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
594 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
|
595 if (PyErr_Occurred()) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
596 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
|
597 retval = E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
598 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
599 Py_DECREF(result); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
600 return retval; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
601 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
602 |
|
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 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
|
605 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
606 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
607 STDAPI DllCanUnloadNow(void) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
608 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
609 long result; |
|
39074
892b7ac26d3b
A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents:
38963
diff
changeset
|
610 #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
|
611 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
|
612 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
613 result = Call_CanUnloadNow(); |
|
39074
892b7ac26d3b
A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents:
38963
diff
changeset
|
614 #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
|
615 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
|
616 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
617 return result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
618 } |
|
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 #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
|
621 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
|
622 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
623 switch(fdwReason) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
624 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
|
625 DisableThreadLibraryCalls(hinstDLL); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
626 break; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
627 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
628 return TRUE; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
629 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
630 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
631 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
632 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
633 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
634 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
635 Local Variables: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
636 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
|
637 End: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
638 */ |
