Mercurial > cpython-lru_cache-weakref
annotate Modules/_ctypes/callbacks.c @ 51749:1408feec0084 3.0
Merged revisions 69798 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r69798 | benjamin.peterson | 2009-02-19 22:02:38 -0600 (Thu, 19 Feb 2009) | 13 lines
Merged revisions 69769,69776 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r69769 | georg.brandl | 2009-02-19 02:30:06 -0600 (Thu, 19 Feb 2009) | 1 line
#5310, #3558: fix operator precedence table.
........
r69776 | georg.brandl | 2009-02-19 10:34:51 -0600 (Thu, 19 Feb 2009) | 2 lines
#5317: update IronPython URL.
........
................
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Fri, 20 Feb 2009 04:05:32 +0000 |
| parents | 87fbbf22adf3 |
| children | a63b46ade2b7 |
| rev | line source |
|---|---|
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1 #include "Python.h" |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
2 #include "frameobject.h" |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
3 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
4 #include <ffi.h> |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
5 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
6 #include <windows.h> |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
7 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
8 #include "ctypes.h" |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
9 |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
10 /**************************************************************/ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
11 |
|
46605
948bea96dd20
Merged revisions 60056-60071,60073-60127,60129-60261,60263-60284,60286-62589,62591-62594 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
46549
diff
changeset
|
12 static void |
|
948bea96dd20
Merged revisions 60056-60071,60073-60127,60129-60261,60263-60284,60286-62589,62591-62594 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
46549
diff
changeset
|
13 CThunkObject_dealloc(PyObject *_self) |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
14 { |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
15 CThunkObject *self = (CThunkObject *)_self; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
16 Py_XDECREF(self->converters); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
17 Py_XDECREF(self->callable); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
18 Py_XDECREF(self->restype); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
19 if (self->pcl) |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
20 FreeClosure(self->pcl); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
21 PyObject_Del(self); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
22 } |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
23 |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
24 static int |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
25 CThunkObject_traverse(PyObject *_self, visitproc visit, void *arg) |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
26 { |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
27 CThunkObject *self = (CThunkObject *)_self; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
28 Py_VISIT(self->converters); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
29 Py_VISIT(self->callable); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
30 Py_VISIT(self->restype); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
31 return 0; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
32 } |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
33 |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
34 static int |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
35 CThunkObject_clear(PyObject *_self) |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
36 { |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
37 CThunkObject *self = (CThunkObject *)_self; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
38 Py_CLEAR(self->converters); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
39 Py_CLEAR(self->callable); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
40 Py_CLEAR(self->restype); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
41 return 0; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
42 } |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
43 |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
44 PyTypeObject CThunk_Type = { |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
45 PyVarObject_HEAD_INIT(NULL, 0) |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
46 "_ctypes.CThunkObject", |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
47 sizeof(CThunkObject), /* tp_basicsize */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
48 sizeof(ffi_type), /* tp_itemsize */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
49 CThunkObject_dealloc, /* tp_dealloc */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
50 0, /* tp_print */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
51 0, /* tp_getattr */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
52 0, /* tp_setattr */ |
|
51271
87fbbf22adf3
Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
47492
diff
changeset
|
53 0, /* tp_reserved */ |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
54 0, /* tp_repr */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
55 0, /* tp_as_number */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
56 0, /* tp_as_sequence */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
57 0, /* tp_as_mapping */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
58 0, /* tp_hash */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
59 0, /* tp_call */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
60 0, /* tp_str */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
61 0, /* tp_getattro */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
62 0, /* tp_setattro */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
63 0, /* tp_as_buffer */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
64 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
65 "CThunkObject", /* tp_doc */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
66 CThunkObject_traverse, /* tp_traverse */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
67 CThunkObject_clear, /* tp_clear */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
68 0, /* tp_richcompare */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
69 0, /* tp_weaklistoffset */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
70 0, /* tp_iter */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
71 0, /* tp_iternext */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
72 0, /* tp_methods */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
73 0, /* tp_members */ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
74 }; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
75 |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
76 /**************************************************************/ |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
77 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
78 static void |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
79 PrintError(char *msg, ...) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
80 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
81 char buf[512]; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
82 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
|
83 va_list marker; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
84 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
85 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
|
86 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
|
87 va_end(marker); |
|
43855
ee081609cee8
Added some additional checks for sys.std?? is None, see #1440
Christian Heimes <christian@cheimes.de>
parents:
43663
diff
changeset
|
88 if (f != NULL && f != Py_None) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
89 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
|
90 PyErr_Print(); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
91 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
92 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
93 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
94 /* 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
|
95 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
|
96 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
42560
diff
changeset
|
105 py_srcfile = PyUnicode_DecodeFSDefault(filename); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
106 if (!py_srcfile) goto bad; |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
42560
diff
changeset
|
107 py_funcname = PyUnicode_FromString(funcname); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 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
|
112 if (!empty_tuple) goto bad; |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46605
diff
changeset
|
113 empty_string = PyBytes_FromString(""); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
114 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
|
115 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
|
116 0, /*int argcount,*/ |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
117 0, /*int kwonlyargcount,*/ |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
118 0, /*int nlocals,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
119 0, /*int stacksize,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
120 0, /*int flags,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 lineno, /*int firstlineno,*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
130 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
|
131 ); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 0 /*PyObject *locals*/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
138 ); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 bad: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
151 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
152 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
153 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
154 * 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
|
155 * 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
|
156 * 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
|
157 * |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
158 * 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
|
159 * 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
|
160 * 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
|
161 * slower. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
162 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
163 static void |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
164 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
|
165 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
166 IUnknown *punk; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
167 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
168 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
|
169 return; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
170 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
171 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
|
172 if (punk) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
173 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
|
174 return; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
175 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
176 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
177 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
178 /****************************************************************************** |
|
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 * 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
|
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 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
|
184 ffi_type *restype, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
185 SETFUNC setfunc, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
186 PyObject *callable, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
187 PyObject *converters, |
|
47492
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
188 int flags, |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
189 void **pArgs) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
190 { |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
191 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
|
192 PyObject *result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
193 PyObject *arglist = NULL; |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
194 Py_ssize_t nArgs; |
|
47492
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
195 PyObject *error_object = NULL; |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
196 int *space; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
197 #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
|
198 PyGILState_STATE state = PyGILState_Ensure(); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
199 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
200 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
201 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
|
202 /* 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
|
203 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
|
204 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
205 if (nArgs < 0) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
206 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
|
207 goto Done; |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
210 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
|
211 if (!arglist) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
212 PrintError("PyTuple_New()"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
213 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
214 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
215 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
|
216 /* Note: new reference! */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
217 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
|
218 StgDictObject *dict; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
219 if (cnv) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
220 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
|
221 else { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
222 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
|
223 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
224 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
225 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
226 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
|
227 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
|
228 if (!v) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
229 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
|
230 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
231 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
232 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
233 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
|
234 /* XXX XXX XX |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
235 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
|
236 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
|
237 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
|
238 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
239 } else if (dict) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
240 /* 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
|
241 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
|
242 if (!obj) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
243 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
|
244 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
245 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
246 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
247 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
|
248 Py_DECREF(obj); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
249 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
250 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
|
251 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
252 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
253 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
|
254 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
|
255 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
256 TryAddRef(dict, obj); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
257 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
258 } else { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
259 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
|
260 "cannot build parameter"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
261 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
|
262 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
263 goto Done; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
264 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
265 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
266 /* XXX error handling! */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
267 pArgs++; |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
270 #define CHECK(what, x) \ |
|
44604
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44441
diff
changeset
|
271 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
|
272 |
|
47492
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
273 if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) { |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
274 error_object = get_error_object(&space); |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
275 if (error_object == NULL) |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
276 goto Done; |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
277 if (flags & FUNCFLAG_USE_ERRNO) { |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
278 int temp = space[0]; |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
279 space[0] = errno; |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
280 errno = temp; |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
281 } |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
282 #ifdef MS_WIN32 |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
283 if (flags & FUNCFLAG_USE_LASTERROR) { |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
284 int temp = space[1]; |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
285 space[1] = GetLastError(); |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
286 SetLastError(temp); |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
287 } |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
288 #endif |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
289 } |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
290 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
291 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
|
292 CHECK("'calling callback function'", result); |
|
47492
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
293 |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
294 #ifdef MS_WIN32 |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
295 if (flags & FUNCFLAG_USE_LASTERROR) { |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
296 int temp = space[1]; |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
297 space[1] = GetLastError(); |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
298 SetLastError(temp); |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
299 } |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
300 #endif |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
301 if (flags & FUNCFLAG_USE_ERRNO) { |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
302 int temp = space[0]; |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
303 space[0] = errno; |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
304 errno = temp; |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
305 } |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
306 Py_XDECREF(error_object); |
|
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
307 |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
308 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
|
309 PyObject *keep; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
310 assert(setfunc); |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
311 #ifdef WORDS_BIGENDIAN |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
312 /* See the corresponding code in callproc.c, around line 961 */ |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
313 if (restype->type != FFI_TYPE_FLOAT && restype->size < sizeof(ffi_arg)) |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
314 mem = (char *)mem + sizeof(ffi_arg) - restype->size; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
315 #endif |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
316 keep = setfunc(mem, result, 0); |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
317 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
|
318 /* 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
|
319 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
|
320 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
|
321 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 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
|
326 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
327 if (keep == NULL) /* Could not convert callback result. */ |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
328 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
|
329 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
|
330 Py_DECREF(keep); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
331 else if (setfunc != getentry("O")->setfunc) { |
|
42560
0fcc18aba385
PyErr_Warn is deprecated in 2.5 - goes away for 3.0
Skip Montanaro <skip@pobox.com>
parents:
42309
diff
changeset
|
332 if (-1 == PyErr_WarnEx(PyExc_RuntimeWarning, |
|
0fcc18aba385
PyErr_Warn is deprecated in 2.5 - goes away for 3.0
Skip Montanaro <skip@pobox.com>
parents:
42309
diff
changeset
|
333 "memory leak in callback function.", |
|
0fcc18aba385
PyErr_Warn is deprecated in 2.5 - goes away for 3.0
Skip Montanaro <skip@pobox.com>
parents:
42309
diff
changeset
|
334 1)) |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
335 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
|
336 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
337 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
338 Py_XDECREF(result); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
339 Done: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
340 Py_XDECREF(arglist); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
341 #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
|
342 PyGILState_Release(state); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
343 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
344 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
345 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
346 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
|
347 void *resp, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
348 void **args, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
349 void *userdata) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
350 { |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
351 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
|
352 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
353 _CallPythonObject(resp, |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
354 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
|
355 p->setfunc, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
356 p->callable, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
357 p->converters, |
|
47492
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
358 p->flags, |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
359 args); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
360 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
361 |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
362 static CThunkObject* CThunkObject_new(Py_ssize_t nArgs) |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
363 { |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
364 CThunkObject *p; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
365 int i; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
366 |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
367 p = PyObject_NewVar(CThunkObject, &CThunk_Type, nArgs); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
368 if (p == NULL) { |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
369 PyErr_NoMemory(); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
370 return NULL; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
371 } |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
372 |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
373 p->pcl = NULL; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
374 memset(&p->cif, 0, sizeof(p->cif)); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
375 p->converters = NULL; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
376 p->callable = NULL; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
377 p->setfunc = NULL; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
378 p->ffi_restype = NULL; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
379 |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
380 for (i = 0; i < nArgs + 1; ++i) |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
381 p->atypes[i] = NULL; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
382 return p; |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
383 } |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
384 |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
385 CThunkObject *AllocFunctionCallback(PyObject *callable, |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
386 PyObject *converters, |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
387 PyObject *restype, |
|
47492
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
388 int flags) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
389 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
390 int result; |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
391 CThunkObject *p; |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
392 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
|
393 ffi_abi cc; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
394 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
395 nArgs = PySequence_Size(converters); |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
396 p = CThunkObject_new(nArgs); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
397 if (p == NULL) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
398 return NULL; |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
399 |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
400 assert(CThunk_CheckExact((PyObject *)p)); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
401 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
402 p->pcl = MallocClosure(); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
403 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
|
404 PyErr_NoMemory(); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36897
diff
changeset
|
405 goto error; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
406 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
407 |
|
47492
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
408 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
|
409 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
|
410 PyObject *cnv = PySequence_GetItem(converters, i); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36897
diff
changeset
|
411 if (cnv == NULL) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36897
diff
changeset
|
412 goto error; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
413 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
|
414 Py_DECREF(cnv); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
415 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
416 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
|
417 |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
418 Py_INCREF(restype); |
|
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
419 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
|
420 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
|
421 p->setfunc = NULL; |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
422 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
|
423 } else { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
424 StgDictObject *dict = PyType_stgdict(restype); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
425 if (dict == NULL || dict->setfunc == NULL) { |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
426 PyErr_SetString(PyExc_TypeError, |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
427 "invalid result type for callback function"); |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
428 goto error; |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
429 } |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
430 p->setfunc = dict->setfunc; |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
431 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
|
432 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
433 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
434 cc = FFI_DEFAULT_ABI; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
435 #if defined(MS_WIN32) && !defined(_WIN32_WCE) && !defined(MS_WIN64) |
|
47492
ebbf011550cd
Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
47301
diff
changeset
|
436 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
|
437 cc = FFI_STDCALL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
438 #endif |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
439 result = ffi_prep_cif(&p->cif, cc, |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
440 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
|
441 GetType(restype), |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
442 &p->atypes[0]); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
443 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
|
444 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
|
445 "ffi_prep_cif failed with %d", result); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36897
diff
changeset
|
446 goto error; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
447 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
448 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
|
449 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
|
450 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
|
451 "ffi_prep_closure failed with %d", result); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36897
diff
changeset
|
452 goto error; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
453 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
454 |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
455 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
|
456 p->converters = converters; |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
457 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
|
458 p->callable = callable; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36897
diff
changeset
|
459 return p; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
460 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36897
diff
changeset
|
461 error: |
|
46549
90e2146cb8a3
Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents:
45029
diff
changeset
|
462 Py_XDECREF(p); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36897
diff
changeset
|
463 return NULL; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
464 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
465 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
466 /**************************************************************************** |
|
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 * callback objects: initialization |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
469 */ |
|
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 void init_callbacks_in_module(PyObject *m) |
|
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 (PyType_Ready((PyTypeObject *)&PyType_Type) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
474 return; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
475 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
476 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
477 #ifdef MS_WIN32 |
|
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 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
|
480 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
481 if (!Py_IsInitialized()) { |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
482 #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
|
483 PyEval_InitThreads(); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
484 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
485 Py_Initialize(); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
486 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
487 } |
|
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 /******************************************************************/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
490 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
491 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
|
492 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
493 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
|
494 long retval; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
495 static PyObject *context; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
496 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
497 if (context == NULL) |
|
45029
ef2d3bf8383d
Merged revisions 60379-60382 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44604
diff
changeset
|
498 context = PyUnicode_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
|
499 |
|
44441
b91ca87e6f32
Merged revisions 59666-59679 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
500 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
|
501 if (!mod) { |
|
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 /* 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
|
504 return E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
505 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
506 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
507 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
|
508 Py_DECREF(mod); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
509 if (!func) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
510 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
|
511 return E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
512 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
513 |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
514 { |
|
41969
9d02a4adf574
Merged revisions 55631-55794 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
515 PyObject *py_rclsid = PyLong_FromVoidPtr((void *)rclsid); |
|
9d02a4adf574
Merged revisions 55631-55794 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41716
diff
changeset
|
516 PyObject *py_riid = PyLong_FromVoidPtr((void *)riid); |
|
41716
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
517 PyObject *py_ppv = PyLong_FromVoidPtr(ppv); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
518 if (!py_rclsid || !py_riid || !py_ppv) { |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
519 Py_XDECREF(py_rclsid); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
520 Py_XDECREF(py_riid); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
521 Py_XDECREF(py_ppv); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
522 Py_DECREF(func); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
523 PyErr_WriteUnraisable(context ? context : Py_None); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
524 return E_FAIL; |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
525 } |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
526 result = PyObject_CallFunctionObjArgs(func, |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
527 py_rclsid, |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
528 py_riid, |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
529 py_ppv, |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
530 NULL); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
531 Py_DECREF(py_rclsid); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
532 Py_DECREF(py_riid); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
533 Py_DECREF(py_ppv); |
|
00c02c4488ce
Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
534 } |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
535 Py_DECREF(func); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
536 if (!result) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
537 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
|
538 return E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
539 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
540 |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43855
diff
changeset
|
541 retval = PyLong_AsLong(result); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
542 if (PyErr_Occurred()) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
543 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
|
544 retval = E_FAIL; |
|
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 Py_DECREF(result); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
547 return retval; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
548 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
549 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
550 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
|
551 REFIID riid, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
552 LPVOID *ppv) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
553 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
554 long result; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
555 #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
|
556 PyGILState_STATE state; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
557 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
558 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
559 LoadPython(); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
560 #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
|
561 state = PyGILState_Ensure(); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
562 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
563 result = Call_GetClassObject(rclsid, riid, ppv); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
564 #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
|
565 PyGILState_Release(state); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
566 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
567 return result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
568 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
569 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
570 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
|
571 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
572 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
|
573 long retval; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
574 static PyObject *context; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
575 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
576 if (context == NULL) |
|
45029
ef2d3bf8383d
Merged revisions 60379-60382 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44604
diff
changeset
|
577 context = PyUnicode_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
|
578 |
|
44441
b91ca87e6f32
Merged revisions 59666-59679 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
579 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
|
580 if (!mod) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
581 /* 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
|
582 /* 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
|
583 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
|
584 PyErr_Clear(); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
585 return E_FAIL; |
|
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 /* 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
|
588 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
|
589 Py_DECREF(mod); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
590 if (!func) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
591 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
|
592 return E_FAIL; |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
595 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
|
596 Py_DECREF(func); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
597 if (!result) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
598 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
|
599 return E_FAIL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
600 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
601 |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43855
diff
changeset
|
602 retval = PyLong_AsLong(result); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
603 if (PyErr_Occurred()) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
604 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
|
605 retval = E_FAIL; |
|
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 Py_DECREF(result); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
608 return retval; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
609 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
610 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
611 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
612 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
|
613 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
614 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
615 STDAPI DllCanUnloadNow(void) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
616 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
617 long result; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
618 #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
|
619 PyGILState_STATE state = PyGILState_Ensure(); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
620 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
621 result = Call_CanUnloadNow(); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
622 #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
|
623 PyGILState_Release(state); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
624 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
625 return result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
626 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
627 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
628 #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
|
629 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
|
630 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
631 switch(fdwReason) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
632 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
|
633 DisableThreadLibraryCalls(hinstDLL); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
634 break; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
635 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
636 return TRUE; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
637 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
638 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
639 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
640 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
641 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
642 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
643 Local Variables: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
644 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
|
645 End: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
646 */ |
