annotate Modules/_ctypes/callbacks.c @ 58664:993f703a61ba

Merged revisions 77484,77487,77561,77570,77593,77603,77608,77667,77702-77703,77739,77858,77887,77889 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77484 | skip.montanaro | 2010-01-13 19:12:34 -0600 (Wed, 13 Jan 2010) | 4 lines Update PyEval_EvalFrame to PyEval_EvalFrameEx. This looks to have been done partially before. Also add a comment describing how this might have to work with different versions of the interpreter. ........ r77487 | ezio.melotti | 2010-01-14 05:34:10 -0600 (Thu, 14 Jan 2010) | 1 line Fixed typo ........ r77561 | georg.brandl | 2010-01-17 02:42:30 -0600 (Sun, 17 Jan 2010) | 1 line #7699: improve datetime docs: straightforward linking to strftime/strptime section, mark classmethods as such. ........ r77570 | georg.brandl | 2010-01-17 06:14:42 -0600 (Sun, 17 Jan 2010) | 1 line Add note about usage of STRINGLIB_EMPTY. ........ r77593 | georg.brandl | 2010-01-17 17:33:53 -0600 (Sun, 17 Jan 2010) | 1 line Fix internal reference. ........ r77603 | benjamin.peterson | 2010-01-18 17:07:56 -0600 (Mon, 18 Jan 2010) | 8 lines data descriptors do not override the class dictionary if __get__ is not defined Adjust documentation and add a test to verify this behavior. See http://mail.python.org/pipermail/python-dev/2010-January/095637.html for discussion. ........ r77608 | gregory.p.smith | 2010-01-19 02:19:03 -0600 (Tue, 19 Jan 2010) | 6 lines Do not compile stubs for the sha2 series hashes in the openssl hashlib module when the openssl version is too old to support them. That leads both compiled code bloat and to unittests attempting to test implementations that don't exist for comparison purposes on such platforms. ........ r77667 | mark.dickinson | 2010-01-21 12:32:27 -0600 (Thu, 21 Jan 2010) | 1 line Add two more test_strtod test values. ........ r77702 | georg.brandl | 2010-01-23 02:43:31 -0600 (Sat, 23 Jan 2010) | 1 line #7762: fix refcount annotation of PyUnicode_Tailmatch(). ........ r77703 | georg.brandl | 2010-01-23 02:47:54 -0600 (Sat, 23 Jan 2010) | 1 line #7725: fix referencing issue. ........ r77739 | benjamin.peterson | 2010-01-24 21:52:52 -0600 (Sun, 24 Jan 2010) | 1 line mention from_float() in error message ........ r77858 | georg.brandl | 2010-01-30 11:57:48 -0600 (Sat, 30 Jan 2010) | 1 line #7802: fix invalid example (heh). ........ r77887 | georg.brandl | 2010-01-31 12:51:49 -0600 (Sun, 31 Jan 2010) | 5 lines Fix-up ftplib documentation: move exception descriptions to toplevel, not inside a class remove attribution in "versionadded" spell and grammar check docstring of FTP_TLS ........ r77889 | michael.foord | 2010-01-31 13:59:26 -0600 (Sun, 31 Jan 2010) | 1 line Minor modification to unittest documentation. ........
author Benjamin Peterson <benjamin@python.org>
date Wed, 03 Feb 2010 02:35:45 +0000
parents 79718ee03986
children 9fd803abe141
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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)
53366
02f3f85e3936 Merged revisions 71853 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 53181
diff changeset
20 _ctypes_free_closure(self->pcl);
46549
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
53366
02f3f85e3936 Merged revisions 71853 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 53181
diff changeset
44 PyTypeObject PyCThunk_Type = {
46549
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 */
53366
02f3f85e3936 Merged revisions 71853 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 53181
diff changeset
95 void _ctypes_add_traceback(char *funcname, char *filename, int lineno)
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
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_globals = 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
98 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
99 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
100
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
101 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
102 if (!py_globals) goto bad;
55372
79718ee03986 Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 53366
diff changeset
103 py_code = PyCode_NewEmpty(filename, funcname, lineno);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
104 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
105 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
106 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
107 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
108 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
109 0 /*PyObject *locals*/
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
110 );
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
111 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
112 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
113 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
114 bad:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
115 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
116 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
117 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
118 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
119
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
120 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
121 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
122 * 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
123 * 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
124 * 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
125 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
126 * 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
127 * 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
128 * 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
129 * slower.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
130 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
131 static void
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
132 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
133 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
134 IUnknown *punk;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
135
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
136 if (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
137 return;
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 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
140 if (punk)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
141 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
142 return;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
143 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
144 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
145
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
146 /******************************************************************************
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
147 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
148 * 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
149 *
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 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
152 ffi_type *restype,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
153 SETFUNC setfunc,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
154 PyObject *callable,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
155 PyObject *converters,
47492
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
156 int flags,
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
157 void **pArgs)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
158 {
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41969
diff changeset
159 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
160 PyObject *result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
161 PyObject *arglist = NULL;
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41969
diff changeset
162 Py_ssize_t nArgs;
47492
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
163 PyObject *error_object = NULL;
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
164 int *space;
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
165 #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
166 PyGILState_STATE state = PyGILState_Ensure();
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
167 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
168
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
169 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
170 /* 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
171 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
172 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
173 if (nArgs < 0) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
174 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
175 goto Done;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
176 }
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 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
179 if (!arglist) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
180 PrintError("PyTuple_New()");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
181 goto Done;
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 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
184 /* Note: new reference! */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
185 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
186 StgDictObject *dict;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
187 if (cnv)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
188 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
189 else {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
190 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
191 goto Done;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
192 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
193
53366
02f3f85e3936 Merged revisions 71853 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 53181
diff changeset
194 if (dict && dict->getfunc && !_ctypes_simple_instance(cnv)) {
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
195 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
196 if (!v) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
197 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
198 Py_DECREF(cnv);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
199 goto Done;
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 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
202 /* XXX XXX XX
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
203 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
204 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
205 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
206 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
207 } else if (dict) {
53366
02f3f85e3936 Merged revisions 71853 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 53181
diff changeset
208 /* Hm, shouldn't we use PyCData_AtAddress() or something like that instead? */
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
209 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
210 if (!obj) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
211 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
212 Py_DECREF(cnv);
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 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
216 Py_DECREF(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
217 Py_DECREF(cnv);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
218 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
219 goto Done;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
220 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
221 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
222 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
223 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
224 TryAddRef(dict, obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
225 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
226 } else {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
227 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
228 "cannot build parameter");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
229 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
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 Py_DECREF(cnv);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
234 /* XXX error handling! */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
235 pArgs++;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
236 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
237
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
238 #define CHECK(what, x) \
53366
02f3f85e3936 Merged revisions 71853 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 53181
diff changeset
239 if (x == NULL) _ctypes_add_traceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_Print()
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
240
47492
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
241 if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) {
53366
02f3f85e3936 Merged revisions 71853 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 53181
diff changeset
242 error_object = _ctypes_get_errobj(&space);
47492
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
243 if (error_object == NULL)
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
244 goto Done;
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
245 if (flags & FUNCFLAG_USE_ERRNO) {
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
246 int temp = space[0];
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
247 space[0] = errno;
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
248 errno = temp;
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
249 }
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
250 #ifdef MS_WIN32
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
251 if (flags & FUNCFLAG_USE_LASTERROR) {
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
252 int temp = space[1];
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
253 space[1] = GetLastError();
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
254 SetLastError(temp);
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
255 }
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
256 #endif
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
257 }
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
258
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
259 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
260 CHECK("'calling callback function'", result);
47492
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
261
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
262 #ifdef MS_WIN32
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
263 if (flags & FUNCFLAG_USE_LASTERROR) {
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
264 int temp = space[1];
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
265 space[1] = GetLastError();
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
266 SetLastError(temp);
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
267 }
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
268 #endif
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
269 if (flags & FUNCFLAG_USE_ERRNO) {
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
270 int temp = space[0];
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
271 space[0] = errno;
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
272 errno = temp;
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
273 }
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
274 Py_XDECREF(error_object);
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
275
39610
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
276 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
277 PyObject *keep;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
278 assert(setfunc);
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
279 #ifdef WORDS_BIGENDIAN
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
280 /* 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
281 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
282 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
283 #endif
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
284 keep = setfunc(mem, result, 0);
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
285 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
286 /* 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
287 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
288 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
289
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
290 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
291 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
292 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
293 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
294 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
295 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
296 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
297 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
298 Py_DECREF(keep);
53366
02f3f85e3936 Merged revisions 71853 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 53181
diff changeset
299 else if (setfunc != _ctypes_get_fielddesc("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
300 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
301 "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
302 1))
39610
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
303 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
304 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
305 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
306 Py_XDECREF(result);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
307 Done:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
308 Py_XDECREF(arglist);
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
309 #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
310 PyGILState_Release(state);
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
311 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
312 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
313
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
314 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
315 void *resp,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
316 void **args,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
317 void *userdata)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
318 {
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
319 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
320
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
321 _CallPythonObject(resp,
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
322 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
323 p->setfunc,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
324 p->callable,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
325 p->converters,
47492
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
326 p->flags,
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
327 args);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
328 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
329
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
330 static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
331 {
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
332 CThunkObject *p;
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
333 int i;
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
334
53366
02f3f85e3936 Merged revisions 71853 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 53181
diff changeset
335 p = PyObject_NewVar(CThunkObject, &PyCThunk_Type, nArgs);
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
336 if (p == NULL) {
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
337 PyErr_NoMemory();
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
338 return NULL;
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
339 }
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
340
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
341 p->pcl = NULL;
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
342 memset(&p->cif, 0, sizeof(p->cif));
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
343 p->converters = NULL;
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
344 p->callable = NULL;
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
345 p->setfunc = NULL;
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
346 p->ffi_restype = NULL;
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
347
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
348 for (i = 0; i < nArgs + 1; ++i)
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
349 p->atypes[i] = NULL;
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
350 return p;
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
351 }
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
352
53366
02f3f85e3936 Merged revisions 71853 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 53181
diff changeset
353 CThunkObject *_ctypes_alloc_callback(PyObject *callable,
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
354 PyObject *converters,
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
355 PyObject *restype,
47492
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
356 int flags)
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
357 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
358 int result;
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
359 CThunkObject *p;
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41969
diff changeset
360 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
361 ffi_abi cc;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
362
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
363 nArgs = PySequence_Size(converters);
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
364 p = CThunkObject_new(nArgs);
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
365 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
366 return NULL;
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
367
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
368 assert(CThunk_CheckExact((PyObject *)p));
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
369
53366
02f3f85e3936 Merged revisions 71853 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 53181
diff changeset
370 p->pcl = _ctypes_alloc_closure();
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
371 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
372 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
373 goto error;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
374 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
375
47492
ebbf011550cd Merged revisions 63977 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 47301
diff changeset
376 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
377 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
378 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
379 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
380 goto error;
53366
02f3f85e3936 Merged revisions 71853 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 53181
diff changeset
381 p->atypes[i] = _ctypes_get_ffi_type(cnv);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
382 Py_DECREF(cnv);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
383 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
384 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
385
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
386 Py_INCREF(restype);
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
387 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
388 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
389 p->setfunc = NULL;
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
390 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
391 } else {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
392 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
393 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
394 PyErr_SetString(PyExc_TypeError,
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 40215
diff changeset
395 "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
396 goto error;
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 40215
diff changeset
397 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
398 p->setfunc = dict->setfunc;
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
399 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
400 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
401
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
402 cc = FFI_DEFAULT_ABI;
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 40215
diff changeset
403 #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
404 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
405 cc = FFI_STDCALL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
406 #endif
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41969
diff changeset
407 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
408 Py_SAFE_DOWNCAST(nArgs, Py_ssize_t, int),
53366
02f3f85e3936 Merged revisions 71853 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 53181
diff changeset
409 _ctypes_get_ffi_type(restype),
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
410 &p->atypes[0]);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
411 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
412 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
413 "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
414 goto error;
36897
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 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
417 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
418 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
419 "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
420 goto error;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
421 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
422
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
423 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
424 p->converters = converters;
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
425 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
426 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
427 return p;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
428
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
429 error:
46549
90e2146cb8a3 Merged revisions 62481 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 45029
diff changeset
430 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
431 return NULL;
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 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
435
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
436 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
437 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
438 if (!Py_IsInitialized()) {
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
439 #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
440 PyEval_InitThreads();
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
441 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
442 Py_Initialize();
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
443 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
444 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
445
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
446 /******************************************************************/
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 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
449 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
450 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
451 long retval;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
452 static PyObject *context;
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 if (context == NULL)
45029
ef2d3bf8383d Merged revisions 60379-60382 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44604
diff changeset
455 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
456
44441
b91ca87e6f32 Merged revisions 59666-59679 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
457 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
458 if (!mod) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
459 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
460 /* 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
461 return E_FAIL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
462 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
463
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
464 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
465 Py_DECREF(mod);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
466 if (!func) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
467 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
468 return E_FAIL;
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
41716
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
471 {
41969
9d02a4adf574 Merged revisions 55631-55794 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41716
diff changeset
472 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
473 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
474 PyObject *py_ppv = PyLong_FromVoidPtr(ppv);
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
475 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
476 Py_XDECREF(py_rclsid);
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
477 Py_XDECREF(py_riid);
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
478 Py_XDECREF(py_ppv);
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
479 Py_DECREF(func);
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
480 PyErr_WriteUnraisable(context ? context : Py_None);
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
481 return E_FAIL;
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
482 }
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
483 result = PyObject_CallFunctionObjArgs(func,
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
484 py_rclsid,
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
485 py_riid,
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
486 py_ppv,
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
487 NULL);
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
488 Py_DECREF(py_rclsid);
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
489 Py_DECREF(py_riid);
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
490 Py_DECREF(py_ppv);
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
491 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
492 Py_DECREF(func);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
493 if (!result) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
494 PyErr_WriteUnraisable(context ? context : Py_None);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
495 return E_FAIL;
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
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
498 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
499 if (PyErr_Occurred()) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
500 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
501 retval = E_FAIL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
502 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
503 Py_DECREF(result);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
504 return retval;
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 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
508 REFIID riid,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
509 LPVOID *ppv)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
510 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
511 long result;
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
512 #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
513 PyGILState_STATE state;
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
514 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
515
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
516 LoadPython();
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
517 #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
518 state = PyGILState_Ensure();
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
519 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
520 result = Call_GetClassObject(rclsid, riid, ppv);
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
521 #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
522 PyGILState_Release(state);
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
523 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
524 return result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
525 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
526
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
527 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
528 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
529 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
530 long retval;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
531 static PyObject *context;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
532
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
533 if (context == NULL)
45029
ef2d3bf8383d Merged revisions 60379-60382 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44604
diff changeset
534 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
535
44441
b91ca87e6f32 Merged revisions 59666-59679 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
536 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
537 if (!mod) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
538 /* 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
539 /* 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
540 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
541 PyErr_Clear();
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
542 return E_FAIL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
543 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
544 /* 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
545 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
546 Py_DECREF(mod);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
547 if (!func) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
548 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
549 return E_FAIL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
550 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
551
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
552 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
553 Py_DECREF(func);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
554 if (!result) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
555 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
556 return E_FAIL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
557 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
558
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
559 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
560 if (PyErr_Occurred()) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
561 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
562 retval = E_FAIL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
563 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
564 Py_DECREF(result);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
565 return retval;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
566 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
567
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
568 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
569 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
570 */
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 STDAPI DllCanUnloadNow(void)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
573 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
574 long result;
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
575 #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
576 PyGILState_STATE state = PyGILState_Ensure();
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
577 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
578 result = Call_CanUnloadNow();
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
579 #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
580 PyGILState_Release(state);
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
581 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
582 return result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
583 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
584
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
585 #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
586 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
587 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
588 switch(fdwReason) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
589 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
590 DisableThreadLibraryCalls(hinstDLL);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
591 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
592 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
593 return TRUE;
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 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
596
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
597 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
598
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
599 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
600 Local Variables:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
601 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
602 End:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
603 */