annotate Modules/_ctypes/callproc.c @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents 3c83a3cacd77
children d11fbc796499
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38780
381a72ab5fb8 Add pep-291 compatibility markers.
Thomas Heller <theller@ctypes.org>
parents: 38747
diff changeset
1 /*****************************************************************
381a72ab5fb8 Add pep-291 compatibility markers.
Thomas Heller <theller@ctypes.org>
parents: 38747
diff changeset
2 This file should be kept compatible with Python 2.3, see PEP 291.
381a72ab5fb8 Add pep-291 compatibility markers.
Thomas Heller <theller@ctypes.org>
parents: 38747
diff changeset
3 *****************************************************************/
381a72ab5fb8 Add pep-291 compatibility markers.
Thomas Heller <theller@ctypes.org>
parents: 38747
diff changeset
4
381a72ab5fb8 Add pep-291 compatibility markers.
Thomas Heller <theller@ctypes.org>
parents: 38747
diff changeset
5
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
6 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
7 * History: First version dated from 3/97, derived from my SCMLIB version
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
8 * for win16.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
9 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
10 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
11 * Related Work:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
12 * - calldll http://www.nightmare.com/software.html
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
13 * - libffi http://sourceware.cygnus.com/libffi/
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
14 * - ffcall http://clisp.cons.org/~haible/packages-ffcall.html
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
15 * and, of course, Don Beaudry's MESS package, but this is more ctypes
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
16 * related.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
17 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
18
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
19
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
20 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
21 How are functions called, and how are parameters converted to C ?
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
22
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
23 1. _ctypes.c::PyCFuncPtr_call receives an argument tuple 'inargs' and a
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
24 keyword dictionary 'kwds'.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
25
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
26 2. After several checks, _build_callargs() is called which returns another
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
27 tuple 'callargs'. This may be the same tuple as 'inargs', a slice of
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
28 'inargs', or a completely fresh tuple, depending on several things (is is a
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
29 COM method, are 'paramflags' available).
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
30
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
31 3. _build_callargs also calculates bitarrays containing indexes into
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
32 the callargs tuple, specifying how to build the return value(s) of
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
33 the function.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
34
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
35 4. _ctypes_callproc is then called with the 'callargs' tuple. _ctypes_callproc first
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
36 allocates two arrays. The first is an array of 'struct argument' items, the
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
37 second array has 'void *' entried.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
38
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
39 5. If 'converters' are present (converters is a sequence of argtypes'
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
40 from_param methods), for each item in 'callargs' converter is called and the
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
41 result passed to ConvParam. If 'converters' are not present, each argument
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
42 is directly passed to ConvParm.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
43
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
44 6. For each arg, ConvParam stores the contained C data (or a pointer to it,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
45 for structures) into the 'struct argument' array.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
46
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
47 7. Finally, a loop fills the 'void *' array so that each item points to the
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
48 data contained in or pointed to by the 'struct argument' array.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
49
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
50 8. The 'void *' argument array is what _call_function_pointer
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
51 expects. _call_function_pointer then has very little to do - only some
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
52 libffi specific stuff, then it calls ffi_call.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
53
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
54 So, there are 4 data structures holding processed arguments:
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
55 - the inargs tuple (in PyCFuncPtr_call)
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
56 - the callargs tuple (in PyCFuncPtr_call)
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
57 - the 'struct argguments' array
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
58 - the 'void *' array
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
59
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
60 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
61
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
62 #include "Python.h"
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
63 #include "structmember.h"
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
64
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
65 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
66 #include <windows.h>
41525
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 40152
diff changeset
67 #include <tchar.h>
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
68 #else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
69 #include "ctypes_dlfcn.h"
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
70 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
71
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
72 #ifdef MS_WIN32
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
73 #include <malloc.h>
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
74 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
75
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
76 #include <ffi.h>
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
77 #include "ctypes.h"
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
78
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
79 #if defined(_DEBUG) || defined(__MINGW32__)
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
80 /* Don't use structured exception handling on Windows if this is defined.
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
81 MingW, AFAIK, doesn't support it.
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
82 */
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
83 #define DONT_USE_SEH
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
84 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
85
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
86 /*
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
87 ctypes maintains thread-local storage that has space for two error numbers:
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
88 private copies of the system 'errno' value and, on Windows, the system error code
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
89 accessed by the GetLastError() and SetLastError() api functions.
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
90
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
91 Foreign functions created with CDLL(..., use_errno=True), when called, swap
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
92 the system 'errno' value with the private copy just before the actual
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
93 function call, and swapped again immediately afterwards. The 'use_errno'
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
94 parameter defaults to False, in this case 'ctypes_errno' is not touched.
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
95
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
96 On Windows, foreign functions created with CDLL(..., use_last_error=True) or
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
97 WinDLL(..., use_last_error=True) swap the system LastError value with the
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
98 ctypes private copy.
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
99
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
100 The values are also swapped immeditately before and after ctypes callback
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
101 functions are called, if the callbacks are constructed using the new
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
102 optional use_errno parameter set to True: CFUNCTYPE(..., use_errno=TRUE) or
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
103 WINFUNCTYPE(..., use_errno=True).
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
104
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
105 New ctypes functions are provided to access the ctypes private copies from
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
106 Python:
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
107
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
108 - ctypes.set_errno(value) and ctypes.set_last_error(value) store 'value' in
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
109 the private copy and returns the previous value.
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
110
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
111 - ctypes.get_errno() and ctypes.get_last_error() returns the current ctypes
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
112 private copies value.
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
113 */
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
114
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
115 /*
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
116 This function creates and returns a thread-local Python object that has
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
117 space to store two integer error numbers; once created the Python object is
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
118 kept alive in the thread state dictionary as long as the thread itself.
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
119 */
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
120 PyObject *
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
121 _ctypes_get_errobj(int **pspace)
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
122 {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
123 PyObject *dict = PyThreadState_GetDict();
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
124 PyObject *errobj;
47497
2210f42e7c89 Performance improvement: Use PyDict_Get/SetItem instead of
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
125 static PyObject *error_object_name;
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
126 if (dict == 0) {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
127 PyErr_SetString(PyExc_RuntimeError,
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
128 "cannot get thread state");
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
129 return NULL;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
130 }
47497
2210f42e7c89 Performance improvement: Use PyDict_Get/SetItem instead of
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
131 if (error_object_name == NULL) {
2210f42e7c89 Performance improvement: Use PyDict_Get/SetItem instead of
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
132 error_object_name = PyString_InternFromString("ctypes.error_object");
2210f42e7c89 Performance improvement: Use PyDict_Get/SetItem instead of
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
133 if (error_object_name == NULL)
2210f42e7c89 Performance improvement: Use PyDict_Get/SetItem instead of
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
134 return NULL;
2210f42e7c89 Performance improvement: Use PyDict_Get/SetItem instead of
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
135 }
2210f42e7c89 Performance improvement: Use PyDict_Get/SetItem instead of
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
136 errobj = PyDict_GetItem(dict, error_object_name);
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
137 if (errobj)
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
138 Py_INCREF(errobj);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
139 else {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
140 void *space = PyMem_Malloc(sizeof(int) * 2);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
141 if (space == NULL)
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
142 return NULL;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
143 memset(space, 0, sizeof(int) * 2);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
144 errobj = PyCObject_FromVoidPtr(space, PyMem_Free);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
145 if (errobj == NULL)
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
146 return NULL;
47497
2210f42e7c89 Performance improvement: Use PyDict_Get/SetItem instead of
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
147 if (-1 == PyDict_SetItem(dict, error_object_name,
2210f42e7c89 Performance improvement: Use PyDict_Get/SetItem instead of
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
148 errobj)) {
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
149 Py_DECREF(errobj);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
150 return NULL;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
151 }
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
152 }
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
153 *pspace = (int *)PyCObject_AsVoidPtr(errobj);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
154 return errobj;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
155 }
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
156
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
157 static PyObject *
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
158 get_error_internal(PyObject *self, PyObject *args, int index)
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
159 {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
160 int *space;
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
161 PyObject *errobj = _ctypes_get_errobj(&space);
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
162 PyObject *result;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
163
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
164 if (errobj == NULL)
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
165 return NULL;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
166 result = PyInt_FromLong(space[index]);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
167 Py_DECREF(errobj);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
168 return result;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
169 }
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
170
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
171 static PyObject *
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
172 set_error_internal(PyObject *self, PyObject *args, int index)
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
173 {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
174 int new_errno, old_errno;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
175 PyObject *errobj;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
176 int *space;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
177
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
178 if (!PyArg_ParseTuple(args, "i", &new_errno))
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
179 return NULL;
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
180 errobj = _ctypes_get_errobj(&space);
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
181 if (errobj == NULL)
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
182 return NULL;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
183 old_errno = space[index];
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
184 space[index] = new_errno;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
185 Py_DECREF(errobj);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
186 return PyInt_FromLong(old_errno);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
187 }
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
188
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
189 static PyObject *
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
190 get_errno(PyObject *self, PyObject *args)
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
191 {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
192 return get_error_internal(self, args, 0);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
193 }
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
194
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
195 static PyObject *
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
196 set_errno(PyObject *self, PyObject *args)
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
197 {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
198 return set_error_internal(self, args, 0);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
199 }
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
200
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
201 #ifdef MS_WIN32
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
202
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
203 static PyObject *
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
204 get_last_error(PyObject *self, PyObject *args)
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
205 {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
206 return get_error_internal(self, args, 1);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
207 }
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
208
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
209 static PyObject *
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
210 set_last_error(PyObject *self, PyObject *args)
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
211 {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
212 return set_error_internal(self, args, 1);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
213 }
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
214
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
215 PyObject *ComError;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
216
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
217 static TCHAR *FormatError(DWORD code)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
218 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
219 TCHAR *lpMsgBuf;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
220 DWORD n;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
221 n = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
222 NULL,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
223 code,
49930
c826e462fa51 Issue #4025 again
Christian Heimes <christian@cheimes.de>
parents: 47967
diff changeset
224 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
225 (LPTSTR) &lpMsgBuf,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
226 0,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
227 NULL);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
228 if (n) {
41525
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 40152
diff changeset
229 while (_istspace(lpMsgBuf[n-1]))
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
230 --n;
41525
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 40152
diff changeset
231 lpMsgBuf[n] = _T('\0'); /* rstrip() */
36897
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 return lpMsgBuf;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
234 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
235
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
236 #ifndef DONT_USE_SEH
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
237 static void SetException(DWORD code, EXCEPTION_RECORD *pr)
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
238 {
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
239 /* The 'code' is a normal win32 error code so it could be handled by
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
240 PyErr_SetFromWindowsErr(). However, for some errors, we have additional
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
241 information not included in the error code. We handle those here and
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
242 delegate all others to the generic function. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
243 switch (code) {
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
244 case EXCEPTION_ACCESS_VIOLATION:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
245 /* The thread attempted to read from or write
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
246 to a virtual address for which it does not
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
247 have the appropriate access. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
248 if (pr->ExceptionInformation[0] == 0)
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
249 PyErr_Format(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
250 "exception: access violation reading %p",
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
251 pr->ExceptionInformation[1]);
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
252 else
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
253 PyErr_Format(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
254 "exception: access violation writing %p",
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
255 pr->ExceptionInformation[1]);
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
256 break;
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
257
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
258 case EXCEPTION_BREAKPOINT:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
259 /* A breakpoint was encountered. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
260 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
261 "exception: breakpoint encountered");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
262 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
263
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
264 case EXCEPTION_DATATYPE_MISALIGNMENT:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
265 /* The thread attempted to read or write data that is
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
266 misaligned on hardware that does not provide
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
267 alignment. For example, 16-bit values must be
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
268 aligned on 2-byte boundaries, 32-bit values on
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
269 4-byte boundaries, and so on. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
270 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
271 "exception: datatype misalignment");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
272 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
273
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
274 case EXCEPTION_SINGLE_STEP:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
275 /* A trace trap or other single-instruction mechanism
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
276 signaled that one instruction has been executed. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
277 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
278 "exception: single step");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
279 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
280
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
281 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
282 /* The thread attempted to access an array element
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
283 that is out of bounds, and the underlying hardware
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
284 supports bounds checking. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
285 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
286 "exception: array bounds exceeded");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
287 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
288
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
289 case EXCEPTION_FLT_DENORMAL_OPERAND:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
290 /* One of the operands in a floating-point operation
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
291 is denormal. A denormal value is one that is too
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
292 small to represent as a standard floating-point
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
293 value. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
294 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
295 "exception: floating-point operand denormal");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
296 break;
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
297
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
298 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
299 /* The thread attempted to divide a floating-point
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
300 value by a floating-point divisor of zero. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
301 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
302 "exception: float divide by zero");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
303 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
304
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
305 case EXCEPTION_FLT_INEXACT_RESULT:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
306 /* The result of a floating-point operation cannot be
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
307 represented exactly as a decimal fraction. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
308 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
309 "exception: float inexact");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
310 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
311
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
312 case EXCEPTION_FLT_INVALID_OPERATION:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
313 /* This exception represents any floating-point
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
314 exception not included in this list. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
315 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
316 "exception: float invalid operation");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
317 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
318
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
319 case EXCEPTION_FLT_OVERFLOW:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
320 /* The exponent of a floating-point operation is
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
321 greater than the magnitude allowed by the
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
322 corresponding type. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
323 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
324 "exception: float overflow");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
325 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
326
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
327 case EXCEPTION_FLT_STACK_CHECK:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
328 /* The stack overflowed or underflowed as the result
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
329 of a floating-point operation. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
330 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
331 "exception: stack over/underflow");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
332 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
333
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
334 case EXCEPTION_STACK_OVERFLOW:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
335 /* The stack overflowed or underflowed as the result
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
336 of a floating-point operation. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
337 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
338 "exception: stack overflow");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
339 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
340
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
341 case EXCEPTION_FLT_UNDERFLOW:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
342 /* The exponent of a floating-point operation is less
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
343 than the magnitude allowed by the corresponding
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
344 type. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
345 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
346 "exception: float underflow");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
347 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
348
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
349 case EXCEPTION_INT_DIVIDE_BY_ZERO:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
350 /* The thread attempted to divide an integer value by
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
351 an integer divisor of zero. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
352 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
353 "exception: integer divide by zero");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
354 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
355
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
356 case EXCEPTION_INT_OVERFLOW:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
357 /* The result of an integer operation caused a carry
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
358 out of the most significant bit of the result. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
359 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
360 "exception: integer overflow");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
361 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
362
53410
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
363 case EXCEPTION_PRIV_INSTRUCTION:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
364 /* The thread attempted to execute an instruction
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
365 whose operation is not allowed in the current
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
366 machine mode. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
367 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
368 "exception: priviledged instruction");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
369 break;
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
370
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
371 case EXCEPTION_NONCONTINUABLE_EXCEPTION:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
372 /* The thread attempted to continue execution after a
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
373 noncontinuable exception occurred. */
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
374 PyErr_SetString(PyExc_WindowsError,
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
375 "exception: nocontinuable");
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
376 break;
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
377
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
378 default:
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
379 PyErr_SetFromWindowsErr(code);
2480ea75068f Issue #5078: Avoid redundant call to FormatError()
Thomas Heller <theller@ctypes.org>
parents: 53365
diff changeset
380 break;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
381 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
382 }
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 static DWORD HandleException(EXCEPTION_POINTERS *ptrs,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
385 DWORD *pdw, EXCEPTION_RECORD *record)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
386 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
387 *pdw = ptrs->ExceptionRecord->ExceptionCode;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
388 *record = *ptrs->ExceptionRecord;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
389 return EXCEPTION_EXECUTE_HANDLER;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
390 }
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
391 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
392
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
393 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
394 check_hresult(PyObject *self, PyObject *args)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
395 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
396 HRESULT hr;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
397 if (!PyArg_ParseTuple(args, "i", &hr))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
398 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
399 if (FAILED(hr))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
400 return PyErr_SetFromWindowsErr(hr);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
401 return PyInt_FromLong(hr);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
402 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
403
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
404 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
405
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
406 /**************************************************************/
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
407
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
408 PyCArgObject *
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
409 PyCArgObject_new(void)
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
410 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
411 PyCArgObject *p;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
412 p = PyObject_New(PyCArgObject, &PyCArg_Type);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
413 if (p == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
414 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
415 p->pffi_type = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
416 p->tag = '\0';
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
417 p->obj = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
418 memset(&p->value, 0, sizeof(p->value));
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
419 return p;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
420 }
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 static void
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
423 PyCArg_dealloc(PyCArgObject *self)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
424 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
425 Py_XDECREF(self->obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
426 PyObject_Del(self);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
427 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
428
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
429 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
430 PyCArg_repr(PyCArgObject *self)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
431 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
432 char buffer[256];
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
433 switch(self->tag) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
434 case 'b':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
435 case 'B':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
436 sprintf(buffer, "<cparam '%c' (%d)>",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
437 self->tag, self->value.b);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
438 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
439 case 'h':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
440 case 'H':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
441 sprintf(buffer, "<cparam '%c' (%d)>",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
442 self->tag, self->value.h);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
443 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
444 case 'i':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
445 case 'I':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
446 sprintf(buffer, "<cparam '%c' (%d)>",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
447 self->tag, self->value.i);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
448 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
449 case 'l':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
450 case 'L':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
451 sprintf(buffer, "<cparam '%c' (%ld)>",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
452 self->tag, self->value.l);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
453 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
454
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
455 #ifdef HAVE_LONG_LONG
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
456 case 'q':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
457 case 'Q':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
458 sprintf(buffer,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
459 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
460 "<cparam '%c' (%I64d)>",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
461 #else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
462 "<cparam '%c' (%qd)>",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
463 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
464 self->tag, self->value.q);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
465 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
466 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
467 case 'd':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
468 sprintf(buffer, "<cparam '%c' (%f)>",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
469 self->tag, self->value.d);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
470 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
471 case 'f':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
472 sprintf(buffer, "<cparam '%c' (%f)>",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
473 self->tag, self->value.f);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
474 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
475
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
476 case 'c':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
477 sprintf(buffer, "<cparam '%c' (%c)>",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
478 self->tag, self->value.c);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
479 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
480
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
481 /* Hm, are these 'z' and 'Z' codes useful at all?
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
482 Shouldn't they be replaced by the functionality of c_string
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
483 and c_wstring ?
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
484 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
485 case 'z':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
486 case 'Z':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
487 case 'P':
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
488 sprintf(buffer, "<cparam '%c' (%p)>",
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
489 self->tag, self->value.p);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
490 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
491
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
492 default:
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
493 sprintf(buffer, "<cparam '%c' at %p>",
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
494 self->tag, self);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
495 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
496 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
497 return PyString_FromString(buffer);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
498 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
499
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
500 static PyMemberDef PyCArgType_members[] = {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
501 { "_obj", T_OBJECT,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
502 offsetof(PyCArgObject, obj), READONLY,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
503 "the wrapped object" },
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
504 { NULL },
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 PyTypeObject PyCArg_Type = {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 42041
diff changeset
508 PyVarObject_HEAD_INIT(NULL, 0)
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
509 "CArgObject",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
510 sizeof(PyCArgObject),
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
511 0,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
512 (destructor)PyCArg_dealloc, /* tp_dealloc */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
513 0, /* tp_print */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
514 0, /* tp_getattr */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
515 0, /* tp_setattr */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
516 0, /* tp_compare */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
517 (reprfunc)PyCArg_repr, /* tp_repr */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
518 0, /* tp_as_number */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
519 0, /* tp_as_sequence */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
520 0, /* tp_as_mapping */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
521 0, /* tp_hash */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
522 0, /* tp_call */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
523 0, /* tp_str */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
524 0, /* tp_getattro */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
525 0, /* tp_setattro */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
526 0, /* tp_as_buffer */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
527 Py_TPFLAGS_DEFAULT, /* tp_flags */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
528 0, /* tp_doc */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
529 0, /* tp_traverse */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
530 0, /* tp_clear */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
531 0, /* tp_richcompare */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
532 0, /* tp_weaklistoffset */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
533 0, /* tp_iter */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
534 0, /* tp_iternext */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
535 0, /* tp_methods */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
536 PyCArgType_members, /* tp_members */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
537 };
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
538
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
539 /****************************************************************/
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
540 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
541 * Convert a PyObject * into a parameter suitable to pass to an
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
542 * C function call.
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 * 1. Python integers are converted to C int and passed by value.
56085
3c83a3cacd77 Issue #4606: Passing 'None' if ctypes argtype is set to POINTER(...)
Thomas Heller <theller@ctypes.org>
parents: 53410
diff changeset
545 * Py_None is converted to a C NULL pointer.
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
546 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
547 * 2. 3-tuples are expected to have a format character in the first
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
548 * item, which must be 'i', 'f', 'd', 'q', or 'P'.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
549 * The second item will have to be an integer, float, double, long long
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
550 * or integer (denoting an address void *), will be converted to the
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
551 * corresponding C data type and passed by value.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
552 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
553 * 3. Other Python objects are tested for an '_as_parameter_' attribute.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
554 * The value of this attribute must be an integer which will be passed
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
555 * by value, or a 2-tuple or 3-tuple which will be used according
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
556 * to point 2 above. The third item (if any), is ignored. It is normally
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
557 * used to keep the object alive where this parameter refers to.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
558 * XXX This convention is dangerous - you can construct arbitrary tuples
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
559 * in Python and pass them. Would it be safer to use a custom container
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
560 * datatype instead of a tuple?
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
561 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
562 * 4. Other Python objects cannot be passed as parameters - an exception is raised.
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 * 5. ConvParam will store the converted result in a struct containing format
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
565 * and value.
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 union result {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
569 char c;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
570 char b;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
571 short h;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
572 int i;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
573 long l;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
574 #ifdef HAVE_LONG_LONG
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
575 PY_LONG_LONG q;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
576 #endif
43278
28716dd14bc5 Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents: 42333
diff changeset
577 long double D;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
578 double d;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
579 float f;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
580 void *p;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
581 };
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
582
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
583 struct argument {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
584 ffi_type *ffi_type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
585 PyObject *keep;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
586 union result value;
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
589 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
590 * Convert a single Python object into a PyCArgObject and return it.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
591 */
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
592 static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
593 {
39488
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
594 StgDictObject *dict;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
595 pa->keep = NULL; /* so we cannot forget it later */
39488
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
596
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
597 dict = PyObject_stgdict(obj);
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
598 if (dict) {
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
599 PyCArgObject *carg;
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
600 assert(dict->paramfunc);
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
601 /* If it has an stgdict, it is a CDataObject */
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
602 carg = dict->paramfunc((CDataObject *)obj);
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
603 pa->ffi_type = carg->pffi_type;
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
604 memcpy(&pa->value, &carg->value, sizeof(pa->value));
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
605 pa->keep = (PyObject *)carg;
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
606 return 0;
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
607 }
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
608
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
609 if (PyCArg_CheckExact(obj)) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
610 PyCArgObject *carg = (PyCArgObject *)obj;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
611 pa->ffi_type = carg->pffi_type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
612 Py_INCREF(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
613 pa->keep = obj;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
614 memcpy(&pa->value, &carg->value, sizeof(pa->value));
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
615 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
616 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
617
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
618 /* check for None, integer, string or unicode and use directly if successful */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
619 if (obj == Py_None) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
620 pa->ffi_type = &ffi_type_pointer;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
621 pa->value.p = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
622 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
623 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
624
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
625 if (PyInt_Check(obj)) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
626 pa->ffi_type = &ffi_type_sint;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
627 pa->value.i = PyInt_AS_LONG(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
628 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
629 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
630
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
631 if (PyLong_Check(obj)) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
632 pa->ffi_type = &ffi_type_sint;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
633 pa->value.i = (long)PyLong_AsUnsignedLong(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
634 if (pa->value.i == -1 && PyErr_Occurred()) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
635 PyErr_Clear();
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
636 pa->value.i = PyLong_AsLong(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
637 if (pa->value.i == -1 && PyErr_Occurred()) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
638 PyErr_SetString(PyExc_OverflowError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
639 "long int too long to convert");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
640 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
641 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
642 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
643 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
644 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
645
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
646 if (PyString_Check(obj)) {
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
647 pa->ffi_type = &ffi_type_pointer;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
648 pa->value.p = PyString_AS_STRING(obj);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
649 Py_INCREF(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
650 pa->keep = obj;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
651 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
652 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
653
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
654 #ifdef CTYPES_UNICODE
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
655 if (PyUnicode_Check(obj)) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
656 #ifdef HAVE_USABLE_WCHAR_T
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
657 pa->ffi_type = &ffi_type_pointer;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
658 pa->value.p = PyUnicode_AS_UNICODE(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
659 Py_INCREF(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
660 pa->keep = obj;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
661 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
662 #else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
663 int size = PyUnicode_GET_SIZE(obj);
51525
d3e88f778cdc Merged revisions 69505 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 49930
diff changeset
664 pa->ffi_type = &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
665 size += 1; /* terminating NUL */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
666 size *= sizeof(wchar_t);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
667 pa->value.p = PyMem_Malloc(size);
41562
6a56aedbe280 Make sure to call PyErr_NoMemory() in several places where
Thomas Heller <theller@ctypes.org>
parents: 41525
diff changeset
668 if (!pa->value.p) {
6a56aedbe280 Make sure to call PyErr_NoMemory() in several places where
Thomas Heller <theller@ctypes.org>
parents: 41525
diff changeset
669 PyErr_NoMemory();
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
670 return -1;
41562
6a56aedbe280 Make sure to call PyErr_NoMemory() in several places where
Thomas Heller <theller@ctypes.org>
parents: 41525
diff changeset
671 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
672 memset(pa->value.p, 0, size);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
673 pa->keep = PyCObject_FromVoidPtr(pa->value.p, PyMem_Free);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
674 if (!pa->keep) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
675 PyMem_Free(pa->value.p);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
676 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
677 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
678 if (-1 == PyUnicode_AsWideChar((PyUnicodeObject *)obj,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
679 pa->value.p, PyUnicode_GET_SIZE(obj)))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
680 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
681 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
682 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
683 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
684 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
685
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
686 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
687 PyObject *arg;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
688 arg = PyObject_GetAttrString(obj, "_as_parameter_");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
689 /* Which types should we exactly allow here?
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
690 integers are required for using Python classes
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
691 as parameters (they have to expose the '_as_parameter_'
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
692 attribute)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
693 */
39488
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
694 if (arg) {
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
695 int result;
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
696 result = ConvParam(arg, index, pa);
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
697 Py_DECREF(arg);
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
698 return result;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
699 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
700 PyErr_Format(PyExc_TypeError,
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
701 "Don't know how to convert parameter %d",
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
702 Py_SAFE_DOWNCAST(index, Py_ssize_t, int));
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
703 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
704 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
705 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
706
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
707
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
708 ffi_type *_ctypes_get_ffi_type(PyObject *obj)
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
709 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
710 StgDictObject *dict;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
711 if (obj == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
712 return &ffi_type_sint;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
713 dict = PyType_stgdict(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
714 if (dict == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
715 return &ffi_type_sint;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
716 #if defined(MS_WIN32) && !defined(_WIN32_WCE)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
717 /* This little trick works correctly with MSVC.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
718 It returns small structures in registers
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
719 */
37849
41f13b56dc32 Rename remaining StgDictObject's ffi_type fields to ffi_type_pointer.
Thomas Heller <theller@ctypes.org>
parents: 37848
diff changeset
720 if (dict->ffi_type_pointer.type == FFI_TYPE_STRUCT) {
41f13b56dc32 Rename remaining StgDictObject's ffi_type fields to ffi_type_pointer.
Thomas Heller <theller@ctypes.org>
parents: 37848
diff changeset
721 if (dict->ffi_type_pointer.size <= 4)
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
722 return &ffi_type_sint32;
37849
41f13b56dc32 Rename remaining StgDictObject's ffi_type fields to ffi_type_pointer.
Thomas Heller <theller@ctypes.org>
parents: 37848
diff changeset
723 else if (dict->ffi_type_pointer.size <= 8)
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
724 return &ffi_type_sint64;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
725 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
726 #endif
37848
dd4156c36703 C++ compiler cleanup: the typical few casts, and ... C++ didn't like that
Skip Montanaro <skip@pobox.com>
parents: 37514
diff changeset
727 return &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
728 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
729
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
730
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
731 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
732 * libffi uses:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
733 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
734 * ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
735 * unsigned int nargs,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
736 * ffi_type *rtype,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
737 * ffi_type **atypes);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
738 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
739 * and then
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
740 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
741 * void ffi_call(ffi_cif *cif, void *fn, void *rvalue, void **avalues);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
742 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
743 static int _call_function_pointer(int flags,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
744 PPROC pProc,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
745 void **avalues,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
746 ffi_type **atypes,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
747 ffi_type *restype,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
748 void *resmem,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
749 int argcount)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
750 {
39074
892b7ac26d3b A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents: 39013
diff changeset
751 #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
752 PyThreadState *_save = NULL; /* For Py_BLOCK_THREADS and Py_UNBLOCK_THREADS */
38963
c6d04c9c3c4a Protect the thread api calls in the _ctypes extension module within
Thomas Heller <theller@ctypes.org>
parents: 38780
diff changeset
753 #endif
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
754 PyObject *error_object = NULL;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
755 int *space;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
756 ffi_cif cif;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
757 int cc;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
758 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
759 int delta;
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
760 #ifndef DONT_USE_SEH
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
761 DWORD dwExceptionCode = 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
762 EXCEPTION_RECORD record;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
763 #endif
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
764 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
765 /* XXX check before here */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
766 if (restype == NULL) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
767 PyErr_SetString(PyExc_RuntimeError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
768 "No ffi_type for result");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
769 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
770 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
771
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
772 cc = FFI_DEFAULT_ABI;
39679
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
773 #if defined(MS_WIN32) && !defined(MS_WIN64) && !defined(_WIN32_WCE)
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
774 if ((flags & FUNCFLAG_CDECL) == 0)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
775 cc = FFI_STDCALL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
776 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
777 if (FFI_OK != ffi_prep_cif(&cif,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
778 cc,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
779 argcount,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
780 restype,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
781 atypes)) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
782 PyErr_SetString(PyExc_RuntimeError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
783 "ffi_prep_cif failed");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
784 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
785 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
786
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
787 if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) {
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
788 error_object = _ctypes_get_errobj(&space);
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
789 if (error_object == NULL)
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
790 return -1;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
791 }
39074
892b7ac26d3b A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents: 39013
diff changeset
792 #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
793 if ((flags & FUNCFLAG_PYTHONAPI) == 0)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
794 Py_UNBLOCK_THREADS
38963
c6d04c9c3c4a Protect the thread api calls in the _ctypes extension module within
Thomas Heller <theller@ctypes.org>
parents: 38780
diff changeset
795 #endif
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
796 if (flags & FUNCFLAG_USE_ERRNO) {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
797 int temp = space[0];
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
798 space[0] = errno;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
799 errno = temp;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
800 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
801 #ifdef MS_WIN32
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
802 if (flags & FUNCFLAG_USE_LASTERROR) {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
803 int temp = space[1];
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
804 space[1] = GetLastError();
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
805 SetLastError(temp);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
806 }
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
807 #ifndef DONT_USE_SEH
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
808 __try {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
809 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
810 delta =
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
811 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
812 ffi_call(&cif, (void *)pProc, resmem, avalues);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
813 #ifdef MS_WIN32
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
814 #ifndef DONT_USE_SEH
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
815 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
816 __except (HandleException(GetExceptionInformation(),
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
817 &dwExceptionCode, &record)) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
818 ;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
819 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
820 #endif
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
821 if (flags & FUNCFLAG_USE_LASTERROR) {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
822 int temp = space[1];
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
823 space[1] = GetLastError();
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
824 SetLastError(temp);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
825 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
826 #endif
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
827 if (flags & FUNCFLAG_USE_ERRNO) {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
828 int temp = space[0];
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
829 space[0] = errno;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
830 errno = temp;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
831 }
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
832 Py_XDECREF(error_object);
39074
892b7ac26d3b A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents: 39013
diff changeset
833 #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
834 if ((flags & FUNCFLAG_PYTHONAPI) == 0)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
835 Py_BLOCK_THREADS
38963
c6d04c9c3c4a Protect the thread api calls in the _ctypes extension module within
Thomas Heller <theller@ctypes.org>
parents: 38780
diff changeset
836 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
837 #ifdef MS_WIN32
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
838 #ifndef DONT_USE_SEH
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
839 if (dwExceptionCode) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
840 SetException(dwExceptionCode, &record);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
841 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
842 }
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
843 #endif
39679
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
844 #ifdef MS_WIN64
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
845 if (delta != 0) {
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
846 PyErr_Format(PyExc_RuntimeError,
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
847 "ffi_call failed with code %d",
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
848 delta);
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
849 return -1;
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
850 }
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
851 #else
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
852 if (delta < 0) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
853 if (flags & FUNCFLAG_CDECL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
854 PyErr_Format(PyExc_ValueError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
855 "Procedure called with not enough "
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
856 "arguments (%d bytes missing) "
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
857 "or wrong calling convention",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
858 -delta);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
859 else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
860 PyErr_Format(PyExc_ValueError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
861 "Procedure probably called with not enough "
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
862 "arguments (%d bytes missing)",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
863 -delta);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
864 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
865 } else if (delta > 0) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
866 PyErr_Format(PyExc_ValueError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
867 "Procedure probably called with too many "
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
868 "arguments (%d bytes in excess)",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
869 delta);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
870 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
871 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
872 #endif
39679
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
873 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
874 if ((flags & FUNCFLAG_PYTHONAPI) && PyErr_Occurred())
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
875 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
876 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
877 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
878
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
879 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
880 * Convert the C value in result into a Python object, depending on restype.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
881 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
882 * - If restype is NULL, return a Python integer.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
883 * - If restype is None, return None.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
884 * - If restype is a simple ctypes type (c_int, c_void_p), call the type's getfunc,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
885 * pass the result to checker and return the result.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
886 * - If restype is another ctypes type, return an instance of that.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
887 * - Otherwise, call restype and return the result.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
888 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
889 static PyObject *GetResult(PyObject *restype, void *result, PyObject *checker)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
890 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
891 StgDictObject *dict;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
892 PyObject *retval, *v;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
893
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
894 if (restype == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
895 return PyInt_FromLong(*(int *)result);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
896
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
897 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
898 Py_INCREF(Py_None);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
899 return Py_None;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
900 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
901
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
902 dict = PyType_stgdict(restype);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
903 if (dict == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
904 return PyObject_CallFunction(restype, "i", *(int *)result);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
905
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
906 if (dict->getfunc && !_ctypes_simple_instance(restype)) {
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
907 retval = dict->getfunc(result, dict->size);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
908 /* If restype is py_object (detected by comparing getfunc with
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
909 O_get), we have to call Py_DECREF because O_get has already
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
910 called Py_INCREF.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
911 */
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
912 if (dict->getfunc == _ctypes_get_fielddesc("O")->getfunc) {
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
913 Py_DECREF(retval);
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
914 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
915 } else
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
916 retval = PyCData_FromBaseObj(restype, NULL, 0, result);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
917
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
918 if (!checker || !retval)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
919 return retval;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
920
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
921 v = PyObject_CallFunctionObjArgs(checker, retval, NULL);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
922 if (v == NULL)
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
923 _ctypes_add_traceback("GetResult", "_ctypes/callproc.c", __LINE__-2);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
924 Py_DECREF(retval);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
925 return v;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
926 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
927
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
928 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
929 * Raise a new exception 'exc_class', adding additional text to the original
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
930 * exception string.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
931 */
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
932 void _ctypes_extend_error(PyObject *exc_class, char *fmt, ...)
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
933 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
934 va_list vargs;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
935 PyObject *tp, *v, *tb, *s, *cls_str, *msg_str;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
936
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
937 va_start(vargs, fmt);
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
938 s = PyString_FromFormatV(fmt, vargs);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
939 va_end(vargs);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
940 if (!s)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
941 return;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
942
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
943 PyErr_Fetch(&tp, &v, &tb);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
944 PyErr_NormalizeException(&tp, &v, &tb);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
945 cls_str = PyObject_Str(tp);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
946 if (cls_str) {
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
947 PyString_ConcatAndDel(&s, cls_str);
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
948 PyString_ConcatAndDel(&s, PyString_FromString(": "));
37514
2b0a5eec028b Handle error conditions from PyString_ConcatAndDel().
Neal Norwitz <nnorwitz@gmail.com>
parents: 37147
diff changeset
949 if (s == NULL)
2b0a5eec028b Handle error conditions from PyString_ConcatAndDel().
Neal Norwitz <nnorwitz@gmail.com>
parents: 37147
diff changeset
950 goto error;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
951 } else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
952 PyErr_Clear();
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
953 msg_str = PyObject_Str(v);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
954 if (msg_str)
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
955 PyString_ConcatAndDel(&s, msg_str);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
956 else {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
957 PyErr_Clear();
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
958 PyString_ConcatAndDel(&s, PyString_FromString("???"));
37514
2b0a5eec028b Handle error conditions from PyString_ConcatAndDel().
Neal Norwitz <nnorwitz@gmail.com>
parents: 37147
diff changeset
959 if (s == NULL)
2b0a5eec028b Handle error conditions from PyString_ConcatAndDel().
Neal Norwitz <nnorwitz@gmail.com>
parents: 37147
diff changeset
960 goto error;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
961 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
962 PyErr_SetObject(exc_class, s);
37514
2b0a5eec028b Handle error conditions from PyString_ConcatAndDel().
Neal Norwitz <nnorwitz@gmail.com>
parents: 37147
diff changeset
963 error:
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
964 Py_XDECREF(tp);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
965 Py_XDECREF(v);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
966 Py_XDECREF(tb);
37514
2b0a5eec028b Handle error conditions from PyString_ConcatAndDel().
Neal Norwitz <nnorwitz@gmail.com>
parents: 37147
diff changeset
967 Py_XDECREF(s);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
968 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
969
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
970
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
971 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
972
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
973 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
974 GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
975 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
976 HRESULT hr;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
977 ISupportErrorInfo *psei = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
978 IErrorInfo *pei = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
979 BSTR descr=NULL, helpfile=NULL, source=NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
980 GUID guid;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
981 DWORD helpcontext=0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
982 LPOLESTR progid;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
983 PyObject *obj;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
984 TCHAR *text;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
985
38747
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
986 /* We absolutely have to release the GIL during COM method calls,
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
987 otherwise we may get a deadlock!
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
988 */
39119
c5759b5a57f0 Make sure the _ctypes extension can be compiled when WITH_THREAD is
Thomas Heller <theller@ctypes.org>
parents: 39074
diff changeset
989 #ifdef WITH_THREAD
38747
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
990 Py_BEGIN_ALLOW_THREADS
39119
c5759b5a57f0 Make sure the _ctypes extension can be compiled when WITH_THREAD is
Thomas Heller <theller@ctypes.org>
parents: 39074
diff changeset
991 #endif
38747
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
992
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
993 hr = pIunk->lpVtbl->QueryInterface(pIunk, &IID_ISupportErrorInfo, (void **)&psei);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
994 if (FAILED(hr))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
995 goto failed;
38747
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
996
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
997 hr = psei->lpVtbl->InterfaceSupportsErrorInfo(psei, riid);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
998 psei->lpVtbl->Release(psei);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
999 if (FAILED(hr))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1000 goto failed;
38747
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
1001
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1002 hr = GetErrorInfo(0, &pei);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1003 if (hr != S_OK)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1004 goto failed;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1005
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1006 pei->lpVtbl->GetDescription(pei, &descr);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1007 pei->lpVtbl->GetGUID(pei, &guid);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1008 pei->lpVtbl->GetHelpContext(pei, &helpcontext);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1009 pei->lpVtbl->GetHelpFile(pei, &helpfile);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1010 pei->lpVtbl->GetSource(pei, &source);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1011
38747
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
1012 pei->lpVtbl->Release(pei);
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
1013
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1014 failed:
39119
c5759b5a57f0 Make sure the _ctypes extension can be compiled when WITH_THREAD is
Thomas Heller <theller@ctypes.org>
parents: 39074
diff changeset
1015 #ifdef WITH_THREAD
38747
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
1016 Py_END_ALLOW_THREADS
39119
c5759b5a57f0 Make sure the _ctypes extension can be compiled when WITH_THREAD is
Thomas Heller <theller@ctypes.org>
parents: 39074
diff changeset
1017 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1018
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1019 progid = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1020 ProgIDFromCLSID(&guid, &progid);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1021
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1022 text = FormatError(errcode);
39252
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1023 obj = Py_BuildValue(
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1024 #ifdef _UNICODE
39252
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1025 "iu(uuuiu)",
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1026 #else
39252
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1027 "is(uuuiu)",
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1028 #endif
39252
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1029 errcode,
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1030 text,
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1031 descr, source, helpfile, helpcontext,
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1032 progid);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1033 if (obj) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1034 PyErr_SetObject(ComError, obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1035 Py_DECREF(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1036 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1037 LocalFree(text);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1038
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1039 if (descr)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1040 SysFreeString(descr);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1041 if (helpfile)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1042 SysFreeString(helpfile);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1043 if (source)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1044 SysFreeString(source);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1045
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1046 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1047 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1048 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1049
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1050 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1051 * Requirements, must be ensured by the caller:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1052 * - argtuple is tuple of arguments
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1053 * - argtypes is either NULL, or a tuple of the same size as argtuple
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1054 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1055 * - XXX various requirements for restype, not yet collected
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1056 */
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1057 PyObject *_ctypes_callproc(PPROC pProc,
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1058 PyObject *argtuple,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1059 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1060 IUnknown *pIunk,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1061 GUID *iid,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1062 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1063 int flags,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1064 PyObject *argtypes, /* misleading name: This is a tuple of
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1065 methods, not types: the .from_param
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1066 class methods of the types */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1067 PyObject *restype,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1068 PyObject *checker)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1069 {
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1070 Py_ssize_t i, n, argcount, argtype_count;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1071 void *resbuf;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1072 struct argument *args, *pa;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1073 ffi_type **atypes;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1074 ffi_type *rtype;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1075 void **avalues;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1076 PyObject *retval = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1077
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1078 n = argcount = PyTuple_GET_SIZE(argtuple);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1079 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1080 /* an optional COM object this pointer */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1081 if (pIunk)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1082 ++argcount;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1083 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1084
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1085 args = (struct argument *)alloca(sizeof(struct argument) * argcount);
39477
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1086 if (!args) {
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1087 PyErr_NoMemory();
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1088 return NULL;
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1089 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1090 memset(args, 0, sizeof(struct argument) * argcount);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1091 argtype_count = argtypes ? PyTuple_GET_SIZE(argtypes) : 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1092 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1093 if (pIunk) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1094 args[0].ffi_type = &ffi_type_pointer;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1095 args[0].value.p = pIunk;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1096 pa = &args[1];
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1097 } else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1098 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1099 pa = &args[0];
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1100
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1101 /* Convert the arguments */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1102 for (i = 0; i < n; ++i, ++pa) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1103 PyObject *converter;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1104 PyObject *arg;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1105 int err;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1106
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1107 arg = PyTuple_GET_ITEM(argtuple, i); /* borrowed ref */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1108 /* For cdecl functions, we allow more actual arguments
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1109 than the length of the argtypes tuple.
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1110 This is checked in _ctypes::PyCFuncPtr_Call
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1111 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1112 if (argtypes && argtype_count > i) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1113 PyObject *v;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1114 converter = PyTuple_GET_ITEM(argtypes, i);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1115 v = PyObject_CallFunctionObjArgs(converter,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1116 arg,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1117 NULL);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1118 if (v == NULL) {
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1119 _ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1120 goto cleanup;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1121 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1122
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1123 err = ConvParam(v, i+1, pa);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1124 Py_DECREF(v);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1125 if (-1 == err) {
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1126 _ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1127 goto cleanup;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1128 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1129 } else {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1130 err = ConvParam(arg, i+1, pa);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1131 if (-1 == err) {
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1132 _ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1133 goto cleanup; /* leaking ? */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1134 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1135 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1136 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1137
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1138 rtype = _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
1139 resbuf = alloca(max(rtype->size, sizeof(ffi_arg)));
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1140
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1141 avalues = (void **)alloca(sizeof(void *) * argcount);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1142 atypes = (ffi_type **)alloca(sizeof(ffi_type *) * argcount);
39477
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1143 if (!resbuf || !avalues || !atypes) {
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1144 PyErr_NoMemory();
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1145 goto cleanup;
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1146 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1147 for (i = 0; i < argcount; ++i) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1148 atypes[i] = args[i].ffi_type;
39679
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1149 if (atypes[i]->type == FFI_TYPE_STRUCT
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1150 #ifdef _WIN64
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1151 && atypes[i]->size <= sizeof(void *)
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1152 #endif
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1153 )
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1154 avalues[i] = (void *)args[i].value.p;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1155 else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1156 avalues[i] = (void *)&args[i].value;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1157 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1158
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1159 if (-1 == _call_function_pointer(flags, pProc, avalues, atypes,
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1160 rtype, resbuf,
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1161 Py_SAFE_DOWNCAST(argcount,
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1162 Py_ssize_t,
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1163 int)))
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1164 goto cleanup;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1165
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1166 #ifdef WORDS_BIGENDIAN
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1167 /* libffi returns the result in a buffer with sizeof(ffi_arg). This
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1168 causes problems on big endian machines, since the result buffer
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1169 address cannot simply be used as result pointer, instead we must
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1170 adjust the pointer value:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1171 */
38633
625c2d98a1f8 Add a hack so that foreign functions returning float now do work on 64-bit
Thomas Heller <theller@ctypes.org>
parents: 37849
diff changeset
1172 /*
625c2d98a1f8 Add a hack so that foreign functions returning float now do work on 64-bit
Thomas Heller <theller@ctypes.org>
parents: 37849
diff changeset
1173 XXX I should find out and clarify why this is needed at all,
625c2d98a1f8 Add a hack so that foreign functions returning float now do work on 64-bit
Thomas Heller <theller@ctypes.org>
parents: 37849
diff changeset
1174 especially why adjusting for ffi_type_float must be avoided on
625c2d98a1f8 Add a hack so that foreign functions returning float now do work on 64-bit
Thomas Heller <theller@ctypes.org>
parents: 37849
diff changeset
1175 64-bit platforms.
625c2d98a1f8 Add a hack so that foreign functions returning float now do work on 64-bit
Thomas Heller <theller@ctypes.org>
parents: 37849
diff changeset
1176 */
38652
fc3bcd4e44b9 Fix for foreign functions returning small structures on 64-bit big
Thomas Heller <theller@ctypes.org>
parents: 38633
diff changeset
1177 if (rtype->type != FFI_TYPE_FLOAT
fc3bcd4e44b9 Fix for foreign functions returning small structures on 64-bit big
Thomas Heller <theller@ctypes.org>
parents: 38633
diff changeset
1178 && rtype->type != FFI_TYPE_STRUCT
fc3bcd4e44b9 Fix for foreign functions returning small structures on 64-bit big
Thomas Heller <theller@ctypes.org>
parents: 38633
diff changeset
1179 && rtype->size < sizeof(ffi_arg))
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1180 resbuf = (char *)resbuf + sizeof(ffi_arg) - rtype->size;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1181 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1182
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1183 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1184 if (iid && pIunk) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1185 if (*(int *)resbuf & 0x80000000)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1186 retval = GetComError(*(HRESULT *)resbuf, iid, pIunk);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1187 else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1188 retval = PyInt_FromLong(*(int *)resbuf);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1189 } else if (flags & FUNCFLAG_HRESULT) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1190 if (*(int *)resbuf & 0x80000000)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1191 retval = PyErr_SetFromWindowsErr(*(int *)resbuf);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1192 else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1193 retval = PyInt_FromLong(*(int *)resbuf);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1194 } else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1195 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1196 retval = GetResult(restype, resbuf, checker);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1197 cleanup:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1198 for (i = 0; i < argcount; ++i)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1199 Py_XDECREF(args[i].keep);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1200 return retval;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1201 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1202
42041
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1203 static int
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1204 _parse_voidp(PyObject *obj, void **address)
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1205 {
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1206 *address = PyLong_AsVoidPtr(obj);
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1207 if (*address == NULL)
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1208 return 0;
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1209 return 1;
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1210 }
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1211
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1212 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1213
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1214 #ifdef _UNICODE
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1215 # define PYBUILD_TSTR "u"
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1216 #else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1217 # define PYBUILD_TSTR "s"
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1218 # ifndef _T
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1219 # define _T(text) text
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1220 # endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1221 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1222
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1223 static char format_error_doc[] =
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1224 "FormatError([integer]) -> string\n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1225 \n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1226 Convert a win32 error code into a string. If the error code is not\n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1227 given, the return value of a call to GetLastError() is used.\n";
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1228 static PyObject *format_error(PyObject *self, PyObject *args)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1229 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1230 PyObject *result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1231 TCHAR *lpMsgBuf;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1232 DWORD code = 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1233 if (!PyArg_ParseTuple(args, "|i:FormatError", &code))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1234 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1235 if (code == 0)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1236 code = GetLastError();
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1237 lpMsgBuf = FormatError(code);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1238 if (lpMsgBuf) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1239 result = Py_BuildValue(PYBUILD_TSTR, lpMsgBuf);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1240 LocalFree(lpMsgBuf);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1241 } else {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1242 result = Py_BuildValue("s", "<no description>");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1243 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1244 return result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1245 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1246
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1247 static char load_library_doc[] =
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1248 "LoadLibrary(name) -> handle\n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1249 \n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1250 Load an executable (usually a DLL), and return a handle to it.\n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1251 The handle may be used to locate exported functions in this\n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1252 module.\n";
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1253 static PyObject *load_library(PyObject *self, PyObject *args)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1254 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1255 TCHAR *name;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1256 PyObject *nameobj;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1257 PyObject *ignored;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1258 HMODULE hMod;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1259 if (!PyArg_ParseTuple(args, "O|O:LoadLibrary", &nameobj, &ignored))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1260 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1261 #ifdef _UNICODE
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
1262 name = alloca((PyString_Size(nameobj) + 1) * sizeof(WCHAR));
39477
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1263 if (!name) {
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1264 PyErr_NoMemory();
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1265 return NULL;
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1266 }
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1267
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1268 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1269 int r;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
1270 char *aname = PyString_AsString(nameobj);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1271 if(!aname)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1272 return NULL;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
1273 r = MultiByteToWideChar(CP_ACP, 0, aname, -1, name, PyString_Size(nameobj) + 1);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1274 name[r] = 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1275 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1276 #else
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
1277 name = PyString_AsString(nameobj);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1278 if(!name)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1279 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1280 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1281
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1282 hMod = LoadLibrary(name);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1283 if (!hMod)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1284 return PyErr_SetFromWindowsErr(GetLastError());
39679
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1285 #ifdef _WIN64
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1286 return PyLong_FromVoidPtr(hMod);
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1287 #else
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1288 return Py_BuildValue("i", hMod);
39679
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1289 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1290 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1291
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1292 static char free_library_doc[] =
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1293 "FreeLibrary(handle) -> void\n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1294 \n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1295 Free the handle of an executable previously loaded by LoadLibrary.\n";
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1296 static PyObject *free_library(PyObject *self, PyObject *args)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1297 {
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1298 void *hMod;
42041
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1299 if (!PyArg_ParseTuple(args, "O&:FreeLibrary", &_parse_voidp, &hMod))
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1300 return NULL;
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1301 if (!FreeLibrary((HMODULE)hMod))
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1302 return PyErr_SetFromWindowsErr(GetLastError());
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1303 Py_INCREF(Py_None);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1304 return Py_None;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1305 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1306
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1307 /* obsolete, should be removed */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1308 /* Only used by sample code (in samples\Windows\COM.py) */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1309 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1310 call_commethod(PyObject *self, PyObject *args)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1311 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1312 IUnknown *pIunk;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1313 int index;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1314 PyObject *arguments;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1315 PPROC *lpVtbl;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1316 PyObject *result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1317 CDataObject *pcom;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1318 PyObject *argtypes = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1319
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1320 if (!PyArg_ParseTuple(args,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1321 "OiO!|O!",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1322 &pcom, &index,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1323 &PyTuple_Type, &arguments,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1324 &PyTuple_Type, &argtypes))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1325 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1326
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1327 if (argtypes && (PyTuple_GET_SIZE(arguments) != PyTuple_GET_SIZE(argtypes))) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1328 PyErr_Format(PyExc_TypeError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1329 "Method takes %d arguments (%d given)",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1330 PyTuple_GET_SIZE(argtypes), PyTuple_GET_SIZE(arguments));
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1331 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1332 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1333
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1334 if (!CDataObject_Check(pcom) || (pcom->b_size != sizeof(void *))) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1335 PyErr_Format(PyExc_TypeError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1336 "COM Pointer expected instead of %s instance",
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43278
diff changeset
1337 Py_TYPE(pcom)->tp_name);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1338 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1339 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1340
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1341 if ((*(void **)(pcom->b_ptr)) == NULL) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1342 PyErr_SetString(PyExc_ValueError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1343 "The COM 'this' pointer is NULL");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1344 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1345 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1346
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1347 pIunk = (IUnknown *)(*(void **)(pcom->b_ptr));
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1348 lpVtbl = (PPROC *)(pIunk->lpVtbl);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1349
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1350 result = _ctypes_callproc(lpVtbl[index],
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1351 arguments,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1352 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1353 pIunk,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1354 NULL,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1355 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1356 FUNCFLAG_HRESULT, /* flags */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1357 argtypes, /* self->argtypes */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1358 NULL, /* self->restype */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1359 NULL); /* checker */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1360 return result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1361 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1362
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1363 static char copy_com_pointer_doc[] =
39340
d39aee6cdd32 Minimal useful docstring for CopyComPointer.
Thomas Heller <theller@ctypes.org>
parents: 39252
diff changeset
1364 "CopyComPointer(src, dst) -> HRESULT value\n";
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1365
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1366 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1367 copy_com_pointer(PyObject *self, PyObject *args)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1368 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1369 PyObject *p1, *p2, *r = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1370 struct argument a, b;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1371 IUnknown *src, **pdst;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1372 if (!PyArg_ParseTuple(args, "OO:CopyComPointer", &p1, &p2))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1373 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1374 a.keep = b.keep = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1375
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1376 if (-1 == ConvParam(p1, 0, &a) || -1 == ConvParam(p2, 1, &b))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1377 goto done;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1378 src = (IUnknown *)a.value.p;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1379 pdst = (IUnknown **)b.value.p;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1380
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1381 if (pdst == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1382 r = PyInt_FromLong(E_POINTER);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1383 else {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1384 if (src)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1385 src->lpVtbl->AddRef(src);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1386 *pdst = src;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1387 r = PyInt_FromLong(S_OK);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1388 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1389 done:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1390 Py_XDECREF(a.keep);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1391 Py_XDECREF(b.keep);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1392 return r;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1393 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1394 #else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1395
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1396 static PyObject *py_dl_open(PyObject *self, PyObject *args)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1397 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1398 char *name;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1399 void * handle;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1400 #ifdef RTLD_LOCAL
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1401 int mode = RTLD_NOW | RTLD_LOCAL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1402 #else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1403 /* cygwin doesn't define RTLD_LOCAL */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1404 int mode = RTLD_NOW;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1405 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1406 if (!PyArg_ParseTuple(args, "z|i:dlopen", &name, &mode))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1407 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1408 mode |= RTLD_NOW;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1409 handle = ctypes_dlopen(name, mode);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1410 if (!handle) {
47967
875beb4ad889 Issue #3313: Contrary to the man page, a failed dlopen() call does not
Thomas Heller <theller@ctypes.org>
parents: 47671
diff changeset
1411 char *errmsg = ctypes_dlerror();
875beb4ad889 Issue #3313: Contrary to the man page, a failed dlopen() call does not
Thomas Heller <theller@ctypes.org>
parents: 47671
diff changeset
1412 if (!errmsg)
875beb4ad889 Issue #3313: Contrary to the man page, a failed dlopen() call does not
Thomas Heller <theller@ctypes.org>
parents: 47671
diff changeset
1413 errmsg = "dlopen() error";
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1414 PyErr_SetString(PyExc_OSError,
47967
875beb4ad889 Issue #3313: Contrary to the man page, a failed dlopen() call does not
Thomas Heller <theller@ctypes.org>
parents: 47671
diff changeset
1415 errmsg);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1416 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1417 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1418 return PyLong_FromVoidPtr(handle);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1419 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1420
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1421 static PyObject *py_dl_close(PyObject *self, PyObject *args)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1422 {
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1423 void *handle;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1424
42041
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1425 if (!PyArg_ParseTuple(args, "O&:dlclose", &_parse_voidp, &handle))
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1426 return NULL;
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1427 if (dlclose(handle)) {
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1428 PyErr_SetString(PyExc_OSError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1429 ctypes_dlerror());
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1430 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1431 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1432 Py_INCREF(Py_None);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1433 return Py_None;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1434 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1435
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1436 static PyObject *py_dl_sym(PyObject *self, PyObject *args)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1437 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1438 char *name;
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1439 void *handle;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1440 void *ptr;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1441
42041
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1442 if (!PyArg_ParseTuple(args, "O&s:dlsym",
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1443 &_parse_voidp, &handle, &name))
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1444 return NULL;
40152
e2df1356349f Fix various minor errors in passing arguments to
Martin v. Löwis <martin@v.loewis.de>
parents: 39679
diff changeset
1445 ptr = ctypes_dlsym((void*)handle, name);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1446 if (!ptr) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1447 PyErr_SetString(PyExc_OSError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1448 ctypes_dlerror());
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1449 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1450 }
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1451 return PyLong_FromVoidPtr(ptr);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1452 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1453 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1454
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1455 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1456 * Only for debugging so far: So that we can call CFunction instances
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1457 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1458 * XXX Needs to accept more arguments: flags, argtypes, restype
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1459 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1460 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1461 call_function(PyObject *self, PyObject *args)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1462 {
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1463 void *func;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1464 PyObject *arguments;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1465 PyObject *result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1466
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1467 if (!PyArg_ParseTuple(args,
42041
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1468 "O&O!",
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1469 &_parse_voidp, &func,
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1470 &PyTuple_Type, &arguments))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1471 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1472
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1473 result = _ctypes_callproc((PPROC)func,
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1474 arguments,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1475 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1476 NULL,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1477 NULL,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1478 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1479 0, /* flags */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1480 NULL, /* self->argtypes */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1481 NULL, /* self->restype */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1482 NULL); /* checker */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1483 return result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1484 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1485
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1486 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1487 * Only for debugging so far: So that we can call CFunction instances
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1488 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1489 * XXX Needs to accept more arguments: flags, argtypes, restype
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1490 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1491 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1492 call_cdeclfunction(PyObject *self, PyObject *args)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1493 {
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1494 void *func;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1495 PyObject *arguments;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1496 PyObject *result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1497
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1498 if (!PyArg_ParseTuple(args,
42041
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1499 "O&O!",
3e64d0eac774 Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
Thomas Heller <theller@ctypes.org>
parents: 41998
diff changeset
1500 &_parse_voidp, &func,
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1501 &PyTuple_Type, &arguments))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1502 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1503
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1504 result = _ctypes_callproc((PPROC)func,
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1505 arguments,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1506 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1507 NULL,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1508 NULL,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1509 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1510 FUNCFLAG_CDECL, /* flags */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1511 NULL, /* self->argtypes */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1512 NULL, /* self->restype */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1513 NULL); /* checker */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1514 return result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1515 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1516
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1517 /*****************************************************************
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1518 * functions
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1519 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1520 static char sizeof_doc[] =
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1521 "sizeof(C type) -> integer\n"
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1522 "sizeof(C instance) -> integer\n"
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1523 "Return the size in bytes of a C instance";
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1524
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1525 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1526 sizeof_func(PyObject *self, PyObject *obj)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1527 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1528 StgDictObject *dict;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1529
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1530 dict = PyType_stgdict(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1531 if (dict)
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1532 return PyInt_FromSsize_t(dict->size);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1533
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1534 if (CDataObject_Check(obj))
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1535 return PyInt_FromSsize_t(((CDataObject *)obj)->b_size);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1536 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
1537 "this type has no size");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1538 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1539 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1540
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1541 static char alignment_doc[] =
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1542 "alignment(C type) -> integer\n"
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1543 "alignment(C instance) -> integer\n"
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1544 "Return the alignment requirements of a C instance";
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1545
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1546 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1547 align_func(PyObject *self, PyObject *obj)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1548 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1549 StgDictObject *dict;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1550
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1551 dict = PyType_stgdict(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1552 if (dict)
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1553 return PyInt_FromSsize_t(dict->align);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1554
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1555 dict = PyObject_stgdict(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1556 if (dict)
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1557 return PyInt_FromSsize_t(dict->align);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1558
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1559 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
1560 "no alignment info");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1561 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1562 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1563
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1564 static char byref_doc[] =
47547
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1565 "byref(C instance[, offset=0]) -> byref-object\n"
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1566 "Return a pointer lookalike to a C instance, only usable\n"
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1567 "as function argument";
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1568
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1569 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1570 * We must return something which can be converted to a parameter,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1571 * but still has a reference to self.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1572 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1573 static PyObject *
47547
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1574 byref(PyObject *self, PyObject *args)
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1575 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1576 PyCArgObject *parg;
47547
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1577 PyObject *obj;
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1578 PyObject *pyoffset = NULL;
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1579 Py_ssize_t offset = 0;
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1580
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1581 if (!PyArg_UnpackTuple(args, "byref", 1, 2,
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1582 &obj, &pyoffset))
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1583 return NULL;
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1584 if (pyoffset) {
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1585 offset = PyNumber_AsSsize_t(pyoffset, NULL);
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1586 if (offset == -1 && PyErr_Occurred())
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1587 return NULL;
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1588 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1589 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
1590 PyErr_Format(PyExc_TypeError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1591 "byref() argument must be a ctypes instance, not '%s'",
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43278
diff changeset
1592 Py_TYPE(obj)->tp_name);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1593 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1594 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1595
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1596 parg = PyCArgObject_new();
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1597 if (parg == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1598 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1599
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1600 parg->tag = 'P';
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1601 parg->pffi_type = &ffi_type_pointer;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1602 Py_INCREF(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1603 parg->obj = obj;
47547
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1604 parg->value.p = (char *)((CDataObject *)obj)->b_ptr + offset;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1605 return (PyObject *)parg;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1606 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1607
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1608 static char addressof_doc[] =
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1609 "addressof(C instance) -> integer\n"
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1610 "Return the address of the C instance internal buffer";
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1611
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1612 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1613 addressof(PyObject *self, PyObject *obj)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1614 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1615 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
1616 return PyLong_FromVoidPtr(((CDataObject *)obj)->b_ptr);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1617 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
1618 "invalid type");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1619 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1620 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1621
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1622 static int
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1623 converter(PyObject *obj, void **address)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1624 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1625 *address = PyLong_AsVoidPtr(obj);
37109
5a7750db0977 Fix another bug found by Coverty.
Thomas Heller <theller@ctypes.org>
parents: 37061
diff changeset
1626 return *address != NULL;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1627 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1628
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1629 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1630 My_PyObj_FromPtr(PyObject *self, PyObject *args)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1631 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1632 PyObject *ob;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1633 if (!PyArg_ParseTuple(args, "O&:PyObj_FromPtr", converter, &ob))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1634 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1635 Py_INCREF(ob);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1636 return ob;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1637 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1638
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1639 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1640 My_Py_INCREF(PyObject *self, PyObject *arg)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1641 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1642 Py_INCREF(arg); /* that's what this function is for */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1643 Py_INCREF(arg); /* that for returning it */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1644 return arg;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1645 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1646
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1647 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1648 My_Py_DECREF(PyObject *self, PyObject *arg)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1649 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1650 Py_DECREF(arg); /* that's what this function is for */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1651 Py_INCREF(arg); /* that's for returning it */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1652 return arg;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1653 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1654
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1655 #ifdef CTYPES_UNICODE
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1656
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1657 static char set_conversion_mode_doc[] =
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1658 "set_conversion_mode(encoding, errors) -> (previous-encoding, previous-errors)\n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1659 \n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1660 Set the encoding and error handling ctypes uses when converting\n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1661 between unicode and strings. Returns the previous values.\n";
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1662
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1663 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1664 set_conversion_mode(PyObject *self, PyObject *args)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1665 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1666 char *coding, *mode;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1667 PyObject *result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1668
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1669 if (!PyArg_ParseTuple(args, "zs:set_conversion_mode", &coding, &mode))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1670 return NULL;
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1671 result = Py_BuildValue("(zz)", _ctypes_conversion_encoding, _ctypes_conversion_errors);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1672 if (coding) {
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1673 PyMem_Free(_ctypes_conversion_encoding);
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1674 _ctypes_conversion_encoding = PyMem_Malloc(strlen(coding) + 1);
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1675 strcpy(_ctypes_conversion_encoding, coding);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1676 } else {
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1677 _ctypes_conversion_encoding = NULL;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1678 }
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1679 PyMem_Free(_ctypes_conversion_errors);
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1680 _ctypes_conversion_errors = PyMem_Malloc(strlen(mode) + 1);
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1681 strcpy(_ctypes_conversion_errors, mode);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1682 return result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1683 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1684 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1685
38720
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1686 static PyObject *
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1687 resize(PyObject *self, PyObject *args)
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1688 {
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1689 CDataObject *obj;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1690 StgDictObject *dict;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1691 Py_ssize_t size;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1692
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1693 if (!PyArg_ParseTuple(args,
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1694 #if (PY_VERSION_HEX < 0x02050000)
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1695 "Oi:resize",
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1696 #else
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1697 "On:resize",
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1698 #endif
40152
e2df1356349f Fix various minor errors in passing arguments to
Martin v. Löwis <martin@v.loewis.de>
parents: 39679
diff changeset
1699 &obj, &size))
38720
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1700 return NULL;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1701
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1702 dict = PyObject_stgdict((PyObject *)obj);
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1703 if (dict == NULL) {
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1704 PyErr_SetString(PyExc_TypeError,
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1705 "excepted ctypes instance");
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1706 return NULL;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1707 }
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1708 if (size < dict->size) {
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1709 PyErr_Format(PyExc_ValueError,
38970
272f195a284e Revert the use of PY_FORMAT_SIZE_T in PyErr_Format.
Thomas Heller <theller@ctypes.org>
parents: 38968
diff changeset
1710 #if PY_VERSION_HEX < 0x02050000
272f195a284e Revert the use of PY_FORMAT_SIZE_T in PyErr_Format.
Thomas Heller <theller@ctypes.org>
parents: 38968
diff changeset
1711 "minimum size is %d",
272f195a284e Revert the use of PY_FORMAT_SIZE_T in PyErr_Format.
Thomas Heller <theller@ctypes.org>
parents: 38968
diff changeset
1712 #else
272f195a284e Revert the use of PY_FORMAT_SIZE_T in PyErr_Format.
Thomas Heller <theller@ctypes.org>
parents: 38968
diff changeset
1713 "minimum size is %zd",
272f195a284e Revert the use of PY_FORMAT_SIZE_T in PyErr_Format.
Thomas Heller <theller@ctypes.org>
parents: 38968
diff changeset
1714 #endif
38968
d85708769ab1 Silence compiler warning
Neal Norwitz <nnorwitz@gmail.com>
parents: 38963
diff changeset
1715 dict->size);
38720
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1716 return NULL;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1717 }
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1718 if (obj->b_needsfree == 0) {
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1719 PyErr_Format(PyExc_ValueError,
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1720 "Memory cannot be resized because this object doesn't own it");
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1721 return NULL;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1722 }
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1723 if (size <= sizeof(obj->b_value)) {
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1724 /* internal default buffer is large enough */
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1725 obj->b_size = size;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1726 goto done;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1727 }
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1728 if (obj->b_size <= sizeof(obj->b_value)) {
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1729 /* We are currently using the objects default buffer, but it
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1730 isn't large enough any more. */
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1731 void *ptr = PyMem_Malloc(size);
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1732 if (ptr == NULL)
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1733 return PyErr_NoMemory();
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1734 memset(ptr, 0, size);
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1735 memmove(ptr, obj->b_ptr, obj->b_size);
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1736 obj->b_ptr = ptr;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1737 obj->b_size = size;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1738 } else {
38730
b8f22851c1ff Handle failure of PyMem_Realloc.
Thomas Heller <theller@ctypes.org>
parents: 38720
diff changeset
1739 void * ptr = PyMem_Realloc(obj->b_ptr, size);
b8f22851c1ff Handle failure of PyMem_Realloc.
Thomas Heller <theller@ctypes.org>
parents: 38720
diff changeset
1740 if (ptr == NULL)
b8f22851c1ff Handle failure of PyMem_Realloc.
Thomas Heller <theller@ctypes.org>
parents: 38720
diff changeset
1741 return PyErr_NoMemory();
b8f22851c1ff Handle failure of PyMem_Realloc.
Thomas Heller <theller@ctypes.org>
parents: 38720
diff changeset
1742 obj->b_ptr = ptr;
38720
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1743 obj->b_size = size;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1744 }
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1745 done:
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1746 Py_INCREF(Py_None);
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1747 return Py_None;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1748 }
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1749
45315
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1750 static PyObject *
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1751 unpickle(PyObject *self, PyObject *args)
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1752 {
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1753 PyObject *typ;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1754 PyObject *state;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1755 PyObject *result;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1756 PyObject *tmp;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1757
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1758 if (!PyArg_ParseTuple(args, "OO", &typ, &state))
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1759 return NULL;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1760 result = PyObject_CallMethod(typ, "__new__", "O", typ);
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1761 if (result == NULL)
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1762 return NULL;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1763 tmp = PyObject_CallMethod(result, "__setstate__", "O", state);
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1764 if (tmp == NULL) {
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1765 Py_DECREF(result);
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1766 return NULL;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1767 }
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1768 Py_DECREF(tmp);
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1769 return result;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1770 }
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1771
46442
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1772 static PyObject *
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1773 POINTER(PyObject *self, PyObject *cls)
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1774 {
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1775 PyObject *result;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1776 PyTypeObject *typ;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1777 PyObject *key;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1778 char *buf;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1779
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1780 result = PyDict_GetItem(_ctypes_ptrtype_cache, cls);
46442
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1781 if (result) {
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1782 Py_INCREF(result);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1783 return result;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1784 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
1785 if (PyString_CheckExact(cls)) {
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
1786 buf = alloca(strlen(PyString_AS_STRING(cls)) + 3 + 1);
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
1787 sprintf(buf, "LP_%s", PyString_AS_STRING(cls));
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1788 result = PyObject_CallFunction((PyObject *)Py_TYPE(&PyCPointer_Type),
46442
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1789 "s(O){}",
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1790 buf,
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1791 &PyCPointer_Type);
46442
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1792 if (result == NULL)
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1793 return result;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1794 key = PyLong_FromVoidPtr(result);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1795 } else if (PyType_Check(cls)) {
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1796 typ = (PyTypeObject *)cls;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1797 buf = alloca(strlen(typ->tp_name) + 3 + 1);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1798 sprintf(buf, "LP_%s", typ->tp_name);
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1799 result = PyObject_CallFunction((PyObject *)Py_TYPE(&PyCPointer_Type),
46442
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1800 "s(O){sO}",
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1801 buf,
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1802 &PyCPointer_Type,
46442
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1803 "_type_", cls);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1804 if (result == NULL)
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1805 return result;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1806 Py_INCREF(cls);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1807 key = cls;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1808 } else {
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1809 PyErr_SetString(PyExc_TypeError, "must be a ctypes type");
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1810 return NULL;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1811 }
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1812 if (-1 == PyDict_SetItem(_ctypes_ptrtype_cache, key, result)) {
46442
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1813 Py_DECREF(result);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1814 Py_DECREF(key);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1815 return NULL;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1816 }
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1817 Py_DECREF(key);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1818 return result;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1819 }
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1820
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1821 static PyObject *
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1822 pointer(PyObject *self, PyObject *arg)
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1823 {
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1824 PyObject *result;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1825 PyObject *typ;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1826
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1827 typ = PyDict_GetItem(_ctypes_ptrtype_cache, (PyObject *)Py_TYPE(arg));
46442
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1828 if (typ)
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1829 return PyObject_CallFunctionObjArgs(typ, arg, NULL);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1830 typ = POINTER(NULL, (PyObject *)Py_TYPE(arg));
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1831 if (typ == NULL)
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1832 return NULL;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1833 result = PyObject_CallFunctionObjArgs(typ, arg, NULL);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1834 Py_DECREF(typ);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1835 return result;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1836 }
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1837
47475
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1838 static PyObject *
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1839 buffer_info(PyObject *self, PyObject *arg)
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1840 {
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1841 StgDictObject *dict = PyType_stgdict(arg);
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1842 PyObject *shape;
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1843 Py_ssize_t i;
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1844
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1845 if (dict == NULL)
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1846 dict = PyObject_stgdict(arg);
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1847 if (dict == NULL) {
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1848 PyErr_SetString(PyExc_TypeError,
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1849 "not a ctypes type or object");
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1850 return NULL;
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1851 }
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1852 shape = PyTuple_New(dict->ndim);
47671
e30af3264a0f Check for memory alloc failure
Neal Norwitz <nnorwitz@gmail.com>
parents: 47547
diff changeset
1853 if (shape == NULL)
e30af3264a0f Check for memory alloc failure
Neal Norwitz <nnorwitz@gmail.com>
parents: 47547
diff changeset
1854 return NULL;
47475
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1855 for (i = 0; i < (int)dict->ndim; ++i)
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1856 PyTuple_SET_ITEM(shape, i, PyLong_FromSsize_t(dict->shape[i]));
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1857
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1858 if (PyErr_Occurred()) {
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1859 Py_DECREF(shape);
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1860 return NULL;
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1861 }
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1862 return Py_BuildValue("siN", dict->format, dict->ndim, shape);
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1863 }
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1864
53365
d51e4f62bc8c Issue #3102: All global symbols that the _ctypes extension defines are
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
1865 PyMethodDef _ctypes_module_methods[] = {
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
1866 {"get_errno", get_errno, METH_NOARGS},
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
1867 {"set_errno", set_errno, METH_VARARGS},
46442
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1868 {"POINTER", POINTER, METH_O },
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1869 {"pointer", pointer, METH_O },
45315
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1870 {"_unpickle", unpickle, METH_VARARGS },
47475
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1871 {"_buffer_info", buffer_info, METH_O,
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1872 "Return buffer interface information (for testing only)"},
38720
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1873 {"resize", resize, METH_VARARGS, "Resize the memory buffer of a ctypes instance"},
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1874 #ifdef CTYPES_UNICODE
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1875 {"set_conversion_mode", set_conversion_mode, METH_VARARGS, set_conversion_mode_doc},
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1876 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1877 #ifdef MS_WIN32
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
1878 {"get_last_error", get_last_error, METH_NOARGS},
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
1879 {"set_last_error", set_last_error, METH_VARARGS},
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1880 {"CopyComPointer", copy_com_pointer, METH_VARARGS, copy_com_pointer_doc},
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1881 {"FormatError", format_error, METH_VARARGS, format_error_doc},
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1882 {"LoadLibrary", load_library, METH_VARARGS, load_library_doc},
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1883 {"FreeLibrary", free_library, METH_VARARGS, free_library_doc},
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1884 {"call_commethod", call_commethod, METH_VARARGS },
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1885 {"_check_HRESULT", check_hresult, METH_VARARGS},
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1886 #else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1887 {"dlopen", py_dl_open, METH_VARARGS,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1888 "dlopen(name, flag={RTLD_GLOBAL|RTLD_LOCAL}) open a shared library"},
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1889 {"dlclose", py_dl_close, METH_VARARGS, "dlclose a library"},
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1890 {"dlsym", py_dl_sym, METH_VARARGS, "find symbol in shared library"},
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1891 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1892 {"alignment", align_func, METH_O, alignment_doc},
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1893 {"sizeof", sizeof_func, METH_O, sizeof_doc},
47547
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1894 {"byref", byref, METH_VARARGS, byref_doc},
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1895 {"addressof", addressof, METH_O, addressof_doc},
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1896 {"call_function", call_function, METH_VARARGS },
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1897 {"call_cdeclfunction", call_cdeclfunction, METH_VARARGS },
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1898 {"PyObj_FromPtr", My_PyObj_FromPtr, METH_VARARGS },
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1899 {"Py_INCREF", My_Py_INCREF, METH_O },
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1900 {"Py_DECREF", My_Py_DECREF, METH_O },
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1901 {NULL, NULL} /* Sentinel */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1902 };
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1903
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1904 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1905 Local Variables:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1906 compile-command: "cd .. && python setup.py -q build -g && python setup.py -q build install --home ~"
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1907 End:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1908 */