annotate Modules/_ctypes/callproc.c @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents b4ca59484914
children e38335d4df91
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
23 1. _ctypes.c::CFuncPtr_call receives an argument tuple 'inargs' and a
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
35 4. _CallProc is then called with the 'callargs' tuple. _CallProc first
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:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
55 - the inargs tuple (in CFuncPtr_call)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
56 - the callargs tuple (in CFuncPtr_call)
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 *
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
121 get_error_object(int **pspace)
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;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
161 PyObject *errobj = get_error_object(&space);
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;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
180 errobj = get_error_object(&space);
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
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
237 void SetException(DWORD code, EXCEPTION_RECORD *pr)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
238 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
239 TCHAR *lpMsgBuf;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
240 lpMsgBuf = FormatError(code);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
241 if(lpMsgBuf) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
242 PyErr_SetFromWindowsErr(code);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
243 LocalFree(lpMsgBuf);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
244 } else {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
245 switch (code) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
246 case EXCEPTION_ACCESS_VIOLATION:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
247 /* The thread attempted to read from or write
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
248 to a virtual address for which it does not
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
249 have the appropriate access. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
250 if (pr->ExceptionInformation[0] == 0)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
251 PyErr_Format(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
252 "exception: access violation reading %p",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
253 pr->ExceptionInformation[1]);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
254 else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
255 PyErr_Format(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
256 "exception: access violation writing %p",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
257 pr->ExceptionInformation[1]);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
258 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
259 case EXCEPTION_BREAKPOINT:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
260 /* A breakpoint was encountered. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
261 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
262 "exception: breakpoint encountered");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
263 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
264
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
265 case EXCEPTION_DATATYPE_MISALIGNMENT:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
266 /* The thread attempted to read or write data that is
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
267 misaligned on hardware that does not provide
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
268 alignment. For example, 16-bit values must be
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
269 aligned on 2-byte boundaries, 32-bit values on
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
270 4-byte boundaries, and so on. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
271 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
272 "exception: datatype misalignment");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
273 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
274
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
275 case EXCEPTION_SINGLE_STEP:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
276 /* A trace trap or other single-instruction mechanism
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
277 signaled that one instruction has been executed. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
278 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
279 "exception: single step");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
280 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
281
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
282 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
283 /* The thread attempted to access an array element
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
284 that is out of bounds, and the underlying hardware
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
285 supports bounds checking. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
286 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
287 "exception: array bounds exceeded");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
288 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
289
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
290 case EXCEPTION_FLT_DENORMAL_OPERAND:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
291 /* One of the operands in a floating-point operation
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
292 is denormal. A denormal value is one that is too
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
293 small to represent as a standard floating-point
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
294 value. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
295 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
296 "exception: floating-point operand denormal");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
297 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
298
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
299 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
300 /* The thread attempted to divide a floating-point
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
301 value by a floating-point divisor of zero. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
302 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
303 "exception: float divide by zero");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
304 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
305
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
306 case EXCEPTION_FLT_INEXACT_RESULT:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
307 /* The result of a floating-point operation cannot be
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
308 represented exactly as a decimal fraction. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
309 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
310 "exception: float inexact");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
311 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
312
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
313 case EXCEPTION_FLT_INVALID_OPERATION:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
314 /* This exception represents any floating-point
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
315 exception not included in this list. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
316 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
317 "exception: float invalid operation");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
318 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
319
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
320 case EXCEPTION_FLT_OVERFLOW:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
321 /* The exponent of a floating-point operation is
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
322 greater than the magnitude allowed by the
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
323 corresponding type. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
324 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
325 "exception: float overflow");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
326 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
327
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
328 case EXCEPTION_FLT_STACK_CHECK:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
329 /* The stack overflowed or underflowed as the result
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
330 of a floating-point operation. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
331 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
332 "exception: stack over/underflow");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
333 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
334
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
335 case EXCEPTION_STACK_OVERFLOW:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
336 /* The stack overflowed or underflowed as the result
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
337 of a floating-point operation. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
338 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
339 "exception: stack overflow");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
340 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
341
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
342 case EXCEPTION_FLT_UNDERFLOW:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
343 /* The exponent of a floating-point operation is less
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
344 than the magnitude allowed by the corresponding
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
345 type. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
346 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
347 "exception: float underflow");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
348 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
349
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
350 case EXCEPTION_INT_DIVIDE_BY_ZERO:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
351 /* The thread attempted to divide an integer value by
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
352 an integer divisor of zero. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
353 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
354 "exception: integer divide by zero");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
355 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
356
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
357 case EXCEPTION_INT_OVERFLOW:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
358 /* The result of an integer operation caused a carry
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
359 out of the most significant bit of the result. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
360 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
361 "exception: integer overflow");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
362 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
363
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
364 case EXCEPTION_PRIV_INSTRUCTION:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
365 /* The thread attempted to execute an instruction
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
366 whose operation is not allowed in the current
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
367 machine mode. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
368 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
369 "exception: priviledged instruction");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
370 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
371
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
372 case EXCEPTION_NONCONTINUABLE_EXCEPTION:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
373 /* The thread attempted to continue execution after a
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
374 noncontinuable exception occurred. */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
375 PyErr_SetString(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
376 "exception: nocontinuable");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
377 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
378 default:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
379 printf("error %d\n", code);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
380 PyErr_Format(PyExc_WindowsError,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
381 "exception code 0x%08x",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
382 code);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
383 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
384 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
385 }
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
388 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
389 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
390 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
391 *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
392 *record = *ptrs->ExceptionRecord;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
393 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
394 }
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
395 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
396
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
397 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
398 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
399 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
400 HRESULT hr;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
401 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
402 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
403 if (FAILED(hr))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
404 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
405 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
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 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
409
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
410 /**************************************************************/
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
411
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
412 PyCArgObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
413 new_CArgObject(void)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
414 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
415 PyCArgObject *p;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
416 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
417 if (p == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
418 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
419 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
420 p->tag = '\0';
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
421 p->obj = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
422 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
423 return p;
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
426 static void
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
427 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
428 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
429 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
430 PyObject_Del(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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
433 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
434 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
435 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
436 char buffer[256];
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
437 switch(self->tag) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
438 case 'b':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
439 case 'B':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
440 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
441 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
442 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
443 case 'h':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
444 case 'H':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
445 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
446 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
447 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
448 case 'i':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
449 case 'I':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
450 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
451 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
452 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
453 case 'l':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
454 case 'L':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
455 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
456 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
457 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
458
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
459 #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
460 case 'q':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
461 case 'Q':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
462 sprintf(buffer,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
463 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
464 "<cparam '%c' (%I64d)>",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
465 #else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
466 "<cparam '%c' (%qd)>",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
467 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
468 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
469 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
470 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
471 case 'd':
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.d);
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 case 'f':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
476 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
477 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
478 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
479
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
480 case 'c':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
481 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
482 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
483 break;
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 /* 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
486 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
487 and c_wstring ?
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
488 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
489 case 'z':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
490 case 'Z':
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
491 case 'P':
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
492 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
493 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
494 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
495
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
496 default:
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
497 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
498 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
499 break;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
500 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
501 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
502 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
503
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
504 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
505 { "_obj", T_OBJECT,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
506 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
507 "the wrapped object" },
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
508 { NULL },
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
509 };
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
510
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
511 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
512 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
513 "CArgObject",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
514 sizeof(PyCArgObject),
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
515 0,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
516 (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
517 0, /* tp_print */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
518 0, /* tp_getattr */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
519 0, /* tp_setattr */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
520 0, /* tp_compare */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
521 (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
522 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
523 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
524 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
525 0, /* tp_hash */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
526 0, /* tp_call */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
527 0, /* tp_str */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
528 0, /* tp_getattro */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
529 0, /* tp_setattro */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
530 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
531 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
532 0, /* tp_doc */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
533 0, /* tp_traverse */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
534 0, /* tp_clear */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
535 0, /* tp_richcompare */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
536 0, /* tp_weaklistoffset */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
537 0, /* tp_iter */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
538 0, /* tp_iternext */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
539 0, /* tp_methods */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
540 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
541 };
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
542
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 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
545 * 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
546 * C function call.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
547 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
548 * 1. Python integers are converted to C int and passed by value.
56088
b4ca59484914 Merged revisions 74921 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 51525
diff changeset
549 * 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
550 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
551 * 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
552 * 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
553 * 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
554 * 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
555 * 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
556 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
557 * 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
558 * 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
559 * 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
560 * 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
561 * 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
562 * 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
563 * 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
564 * 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
565 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
566 * 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
567 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
568 * 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
569 * and value.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
570 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
571
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
572 union result {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
573 char c;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
574 char b;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
575 short h;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
576 int i;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
577 long l;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
578 #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
579 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
580 #endif
43278
28716dd14bc5 Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents: 42333
diff changeset
581 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
582 double d;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
583 float f;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
584 void *p;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
585 };
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
586
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
587 struct argument {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
588 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
589 PyObject *keep;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
590 union result value;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
591 };
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
592
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
593 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
594 * 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
595 */
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
596 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
597 {
39488
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
598 StgDictObject *dict;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
599 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
600
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
601 dict = PyObject_stgdict(obj);
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
602 if (dict) {
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
603 PyCArgObject *carg;
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
604 assert(dict->paramfunc);
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
605 /* 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
606 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
607 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
608 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
609 pa->keep = (PyObject *)carg;
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
610 return 0;
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
611 }
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
612
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
613 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
614 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
615 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
616 Py_INCREF(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
617 pa->keep = obj;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
618 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
619 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
620 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
621
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
622 /* 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
623 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
624 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
625 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
626 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
627 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
628
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
629 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
630 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
631 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
632 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
633 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
634
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
635 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
636 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
637 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
638 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
639 PyErr_Clear();
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
640 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
641 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
642 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
643 "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
644 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
645 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
646 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
647 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
648 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
649
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
650 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
651 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
652 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
653 Py_INCREF(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
654 pa->keep = obj;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
655 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
656 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
657
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
658 #ifdef CTYPES_UNICODE
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
659 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
660 #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
661 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
662 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
663 Py_INCREF(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
664 pa->keep = obj;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
665 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
666 #else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
667 int size = PyUnicode_GET_SIZE(obj);
51525
d3e88f778cdc Merged revisions 69505 via svnmerge from
Thomas Heller <theller@ctypes.org>
parents: 49930
diff changeset
668 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
669 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
670 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
671 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
672 if (!pa->value.p) {
6a56aedbe280 Make sure to call PyErr_NoMemory() in several places where
Thomas Heller <theller@ctypes.org>
parents: 41525
diff changeset
673 PyErr_NoMemory();
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
674 return -1;
41562
6a56aedbe280 Make sure to call PyErr_NoMemory() in several places where
Thomas Heller <theller@ctypes.org>
parents: 41525
diff changeset
675 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
676 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
677 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
678 if (!pa->keep) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
679 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
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 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
682 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
683 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
684 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
685 return 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
686 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
687 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
688 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
689
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
690 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
691 PyObject *arg;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
692 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
693 /* 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
694 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
695 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
696 attribute)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
697 */
39488
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
698 if (arg) {
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
699 int result;
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
700 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
701 Py_DECREF(arg);
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39477
diff changeset
702 return result;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
703 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
704 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
705 "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
706 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
707 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
708 }
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
711
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
712 ffi_type *GetType(PyObject *obj)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
713 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
714 StgDictObject *dict;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
715 if (obj == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
716 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
717 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
718 if (dict == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
719 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
720 #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
721 /* 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
722 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
723 */
37849
41f13b56dc32 Rename remaining StgDictObject's ffi_type fields to ffi_type_pointer.
Thomas Heller <theller@ctypes.org>
parents: 37848
diff changeset
724 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
725 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
726 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
727 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
728 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
729 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
730 #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
731 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
732 }
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
735 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
736 * libffi uses:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
737 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
738 * 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
739 * unsigned int nargs,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
740 * ffi_type *rtype,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
741 * ffi_type **atypes);
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 * and then
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
744 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
745 * 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
746 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
747 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
748 PPROC pProc,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
749 void **avalues,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
750 ffi_type **atypes,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
751 ffi_type *restype,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
752 void *resmem,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
753 int argcount)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
754 {
39074
892b7ac26d3b A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents: 39013
diff changeset
755 #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
756 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
757 #endif
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
758 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
759 int *space;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
760 ffi_cif cif;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
761 int cc;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
762 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
763 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
764 #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
765 DWORD dwExceptionCode = 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
766 EXCEPTION_RECORD record;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
767 #endif
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
768 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
769 /* 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
770 if (restype == NULL) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
771 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
772 "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
773 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
774 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
775
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
776 cc = FFI_DEFAULT_ABI;
39679
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
777 #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
778 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
779 cc = FFI_STDCALL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
780 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
781 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
782 cc,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
783 argcount,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
784 restype,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
785 atypes)) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
786 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
787 "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
788 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
789 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
790
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
791 if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) {
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
792 error_object = get_error_object(&space);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
793 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
794 return -1;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
795 }
39074
892b7ac26d3b A misspelled preprocessor symbol caused ctypes to be always compiled
Thomas Heller <theller@ctypes.org>
parents: 39013
diff changeset
796 #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
797 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
798 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
799 #endif
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
800 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
801 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
802 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
803 errno = temp;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
804 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
805 #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
806 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
807 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
808 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
809 SetLastError(temp);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
810 }
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
811 #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
812 __try {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
813 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
814 delta =
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
815 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
816 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
817 #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
818 #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
819 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
820 __except (HandleException(GetExceptionInformation(),
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
821 &dwExceptionCode, &record)) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
822 ;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
823 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
824 #endif
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
825 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
826 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
827 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
828 SetLastError(temp);
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
829 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
830 #endif
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
831 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
832 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
833 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
834 errno = temp;
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
835 }
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
836 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
837 #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
838 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
839 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
840 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
841 #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
842 #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
843 if (dwExceptionCode) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
844 SetException(dwExceptionCode, &record);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
845 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
846 }
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37109
diff changeset
847 #endif
39679
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
848 #ifdef MS_WIN64
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
849 if (delta != 0) {
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
850 PyErr_Format(PyExc_RuntimeError,
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
851 "ffi_call failed with code %d",
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
852 delta);
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
853 return -1;
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
854 }
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
855 #else
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
856 if (delta < 0) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
857 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
858 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
859 "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
860 "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
861 "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
862 -delta);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
863 else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
864 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
865 "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
866 "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
867 -delta);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
868 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
869 } 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
870 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
871 "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
872 "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
873 delta);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
874 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
875 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
876 #endif
39679
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
877 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
878 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
879 return -1;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
880 return 0;
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
883 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
884 * 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
885 *
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 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
887 * - 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
888 * - 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
889 * 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
890 * - 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
891 * - 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
892 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
893 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
894 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
895 StgDictObject *dict;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
896 PyObject *retval, *v;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
898 if (restype == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
899 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
900
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
901 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
902 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
903 return Py_None;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
904 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
905
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
906 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
907 if (dict == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
908 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
909
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
910 if (dict->getfunc && !IsSimpleSubType(restype)) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
911 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
912 /* 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
913 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
914 called Py_INCREF.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
915 */
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
916 if (dict->getfunc == getentry("O")->getfunc) {
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
917 Py_DECREF(retval);
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
918 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
919 } else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
920 retval = CData_FromBaseObj(restype, NULL, 0, result);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
921
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
922 if (!checker || !retval)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
923 return retval;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
924
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
925 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
926 if (v == NULL)
44597
5fb9b2f6bacb Use relative instead of absolute filenames in the C-level tracebacks.
Thomas Heller <theller@ctypes.org>
parents: 44350
diff changeset
927 _AddTraceback("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
928 Py_DECREF(retval);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
929 return v;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
930 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
931
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
932 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
933 * 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
934 * exception string.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
935 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
936 void Extend_Error_Info(PyObject *exc_class, char *fmt, ...)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
937 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
938 va_list vargs;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
939 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
940
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
941 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
942 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
943 va_end(vargs);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
944 if (!s)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
945 return;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
946
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
947 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
948 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
949 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
950 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
951 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
952 PyString_ConcatAndDel(&s, PyString_FromString(": "));
37514
2b0a5eec028b Handle error conditions from PyString_ConcatAndDel().
Neal Norwitz <nnorwitz@gmail.com>
parents: 37147
diff changeset
953 if (s == NULL)
2b0a5eec028b Handle error conditions from PyString_ConcatAndDel().
Neal Norwitz <nnorwitz@gmail.com>
parents: 37147
diff changeset
954 goto error;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
955 } else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
956 PyErr_Clear();
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
957 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
958 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
959 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
960 else {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
961 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
962 PyString_ConcatAndDel(&s, PyString_FromString("???"));
37514
2b0a5eec028b Handle error conditions from PyString_ConcatAndDel().
Neal Norwitz <nnorwitz@gmail.com>
parents: 37147
diff changeset
963 if (s == NULL)
2b0a5eec028b Handle error conditions from PyString_ConcatAndDel().
Neal Norwitz <nnorwitz@gmail.com>
parents: 37147
diff changeset
964 goto error;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
965 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
966 PyErr_SetObject(exc_class, s);
37514
2b0a5eec028b Handle error conditions from PyString_ConcatAndDel().
Neal Norwitz <nnorwitz@gmail.com>
parents: 37147
diff changeset
967 error:
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
968 Py_XDECREF(tp);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
969 Py_XDECREF(v);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
970 Py_XDECREF(tb);
37514
2b0a5eec028b Handle error conditions from PyString_ConcatAndDel().
Neal Norwitz <nnorwitz@gmail.com>
parents: 37147
diff changeset
971 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
972 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
973
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
974
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
975 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
976
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
977 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
978 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
979 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
980 HRESULT hr;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
981 ISupportErrorInfo *psei = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
982 IErrorInfo *pei = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
983 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
984 GUID guid;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
985 DWORD helpcontext=0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
986 LPOLESTR progid;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
987 PyObject *obj;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
988 TCHAR *text;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
989
38747
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
990 /* 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
991 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
992 */
39119
c5759b5a57f0 Make sure the _ctypes extension can be compiled when WITH_THREAD is
Thomas Heller <theller@ctypes.org>
parents: 39074
diff changeset
993 #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
994 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
995 #endif
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 = 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
998 if (FAILED(hr))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
999 goto failed;
38747
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
1000
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1001 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
1002 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
1003 if (FAILED(hr))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1004 goto failed;
38747
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
1005
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1006 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
1007 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
1008 goto failed;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1009
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1010 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
1011 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
1012 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
1013 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
1014 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
1015
38747
a789390d8ea7 Release the GIL during COM method calls, to avoid deadlocks in
Thomas Heller <theller@ctypes.org>
parents: 38730
diff changeset
1016 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
1017
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1018 failed:
39119
c5759b5a57f0 Make sure the _ctypes extension can be compiled when WITH_THREAD is
Thomas Heller <theller@ctypes.org>
parents: 39074
diff changeset
1019 #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
1020 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
1021 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1022
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1023 progid = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1024 ProgIDFromCLSID(&guid, &progid);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1025
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1026 text = FormatError(errcode);
39252
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1027 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
1028 #ifdef _UNICODE
39252
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1029 "iu(uuuiu)",
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1030 #else
39252
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1031 "is(uuuiu)",
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1032 #endif
39252
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1033 errcode,
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1034 text,
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1035 descr, source, helpfile, helpcontext,
6b96d8c923be Remove a useless XXX comment.
Thomas Heller <theller@ctypes.org>
parents: 39119
diff changeset
1036 progid);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1037 if (obj) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1038 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
1039 Py_DECREF(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1040 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1041 LocalFree(text);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1042
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1043 if (descr)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1044 SysFreeString(descr);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1045 if (helpfile)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1046 SysFreeString(helpfile);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1047 if (source)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1048 SysFreeString(source);
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 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1051 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1052 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1053
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 * 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
1056 * - 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
1057 * - 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
1058 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1059 * - 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
1060 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1061 PyObject *_CallProc(PPROC pProc,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1062 PyObject *argtuple,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1063 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1064 IUnknown *pIunk,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1065 GUID *iid,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1066 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1067 int flags,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1068 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
1069 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
1070 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
1071 PyObject *restype,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1072 PyObject *checker)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1073 {
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1074 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
1075 void *resbuf;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1076 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
1077 ffi_type **atypes;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1078 ffi_type *rtype;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1079 void **avalues;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1080 PyObject *retval = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1081
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1082 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
1083 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1084 /* 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
1085 if (pIunk)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1086 ++argcount;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1087 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1088
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1089 args = (struct argument *)alloca(sizeof(struct argument) * argcount);
39477
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1090 if (!args) {
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1091 PyErr_NoMemory();
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1092 return NULL;
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1093 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1094 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
1095 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
1096 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1097 if (pIunk) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1098 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
1099 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
1100 pa = &args[1];
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1101 } else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1102 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1103 pa = &args[0];
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1104
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1105 /* Convert the arguments */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1106 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
1107 PyObject *converter;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1108 PyObject *arg;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1109 int err;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1110
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1111 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
1112 /* 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
1113 than the length of the argtypes tuple.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1114 This is checked in _ctypes::CFuncPtr_Call
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1115 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1116 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
1117 PyObject *v;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1118 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
1119 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
1120 arg,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1121 NULL);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1122 if (v == NULL) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1123 Extend_Error_Info(PyExc_ArgError, "argument %d: ", i+1);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1124 goto cleanup;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1125 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1126
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1127 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
1128 Py_DECREF(v);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1129 if (-1 == err) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1130 Extend_Error_Info(PyExc_ArgError, "argument %d: ", i+1);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1131 goto cleanup;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1132 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1133 } else {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1134 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
1135 if (-1 == err) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1136 Extend_Error_Info(PyExc_ArgError, "argument %d: ", i+1);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1137 goto cleanup; /* leaking ? */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1138 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1139 }
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1142 rtype = GetType(restype);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1143 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
1144
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1145 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
1146 atypes = (ffi_type **)alloca(sizeof(ffi_type *) * argcount);
39477
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1147 if (!resbuf || !avalues || !atypes) {
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1148 PyErr_NoMemory();
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1149 goto cleanup;
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1150 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1151 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
1152 atypes[i] = args[i].ffi_type;
39679
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1153 if (atypes[i]->type == FFI_TYPE_STRUCT
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1154 #ifdef _WIN64
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1155 && atypes[i]->size <= sizeof(void *)
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1156 #endif
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1157 )
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1158 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
1159 else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1160 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
1161 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1162
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1163 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
1164 rtype, resbuf,
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1165 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
1166 Py_ssize_t,
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1167 int)))
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1168 goto cleanup;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1169
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1170 #ifdef WORDS_BIGENDIAN
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1171 /* 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
1172 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
1173 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
1174 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
1175 */
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
1176 /*
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
1177 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
1178 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
1179 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
1180 */
38652
fc3bcd4e44b9 Fix for foreign functions returning small structures on 64-bit big
Thomas Heller <theller@ctypes.org>
parents: 38633
diff changeset
1181 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
1182 && 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
1183 && 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
1184 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
1185 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1186
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1187 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1188 if (iid && pIunk) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1189 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
1190 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
1191 else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1192 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
1193 } 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
1194 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
1195 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
1196 else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1197 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
1198 } else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1199 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1200 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
1201 cleanup:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1202 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
1203 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
1204 return retval;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1205 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1206
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
1207 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
1208 _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
1209 {
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 *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
1211 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
1212 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
1213 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
1214 }
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
1215
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1216 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1217
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1218 #ifdef _UNICODE
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1219 # 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
1220 #else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1221 # 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
1222 # ifndef _T
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1223 # 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
1224 # endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1225 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1226
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1227 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
1228 "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
1229 \n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1230 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
1231 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
1232 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
1233 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1234 PyObject *result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1235 TCHAR *lpMsgBuf;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1236 DWORD code = 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1237 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
1238 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1239 if (code == 0)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1240 code = GetLastError();
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1241 lpMsgBuf = FormatError(code);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1242 if (lpMsgBuf) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1243 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
1244 LocalFree(lpMsgBuf);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1245 } else {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1246 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
1247 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1248 return result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1249 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1250
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1251 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
1252 "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
1253 \n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1254 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
1255 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
1256 module.\n";
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1257 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
1258 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1259 TCHAR *name;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1260 PyObject *nameobj;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1261 PyObject *ignored;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1262 HMODULE hMod;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1263 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
1264 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1265 #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
1266 name = alloca((PyString_Size(nameobj) + 1) * sizeof(WCHAR));
39477
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1267 if (!name) {
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1268 PyErr_NoMemory();
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1269 return NULL;
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1270 }
0356dd9cc274 Handle alloca failures.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39340
diff changeset
1271
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1272 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1273 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
1274 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
1275 if(!aname)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1276 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
1277 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
1278 name[r] = 0;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1279 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1280 #else
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
1281 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
1282 if(!name)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1283 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1284 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1285
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1286 hMod = LoadLibrary(name);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1287 if (!hMod)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1288 return PyErr_SetFromWindowsErr(GetLastError());
39679
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1289 #ifdef _WIN64
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1290 return PyLong_FromVoidPtr(hMod);
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1291 #else
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1292 return Py_BuildValue("i", hMod);
39679
3bfc8bb4e726 Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents: 39488
diff changeset
1293 #endif
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1294 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1295
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1296 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
1297 "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
1298 \n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1299 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
1300 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
1301 {
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1302 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
1303 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
1304 return NULL;
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1305 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
1306 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
1307 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
1308 return Py_None;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1309 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1310
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1311 /* 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
1312 /* 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
1313 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1314 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
1315 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1316 IUnknown *pIunk;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1317 int index;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1318 PyObject *arguments;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1319 PPROC *lpVtbl;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1320 PyObject *result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1321 CDataObject *pcom;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1322 PyObject *argtypes = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1323
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1324 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
1325 "OiO!|O!",
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1326 &pcom, &index,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1327 &PyTuple_Type, &arguments,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1328 &PyTuple_Type, &argtypes))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1329 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1330
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1331 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
1332 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
1333 "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
1334 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
1335 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1336 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1337
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1338 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
1339 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
1340 "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
1341 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
1342 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1343 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1344
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1345 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
1346 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
1347 "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
1348 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1349 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1350
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1351 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
1352 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
1353
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1354 result = _CallProc(lpVtbl[index],
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1355 arguments,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1356 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1357 pIunk,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1358 NULL,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1359 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1360 FUNCFLAG_HRESULT, /* flags */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1361 argtypes, /* self->argtypes */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1362 NULL, /* self->restype */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1363 NULL); /* checker */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1364 return result;
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1367 static char copy_com_pointer_doc[] =
39340
d39aee6cdd32 Minimal useful docstring for CopyComPointer.
Thomas Heller <theller@ctypes.org>
parents: 39252
diff changeset
1368 "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
1369
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1370 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1371 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
1372 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1373 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
1374 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
1375 IUnknown *src, **pdst;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1376 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
1377 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1378 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
1379
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1380 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
1381 goto done;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1382 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
1383 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
1384
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1385 if (pdst == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1386 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
1387 else {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1388 if (src)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1389 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
1390 *pdst = src;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1391 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
1392 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1393 done:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1394 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
1395 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
1396 return r;
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 #else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1399
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1400 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
1401 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1402 char *name;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1403 void * handle;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1404 #ifdef RTLD_LOCAL
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1405 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
1406 #else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1407 /* 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
1408 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
1409 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1410 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
1411 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1412 mode |= RTLD_NOW;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1413 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
1414 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
1415 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
1416 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
1417 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
1418 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
1419 errmsg);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1420 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1421 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1422 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
1423 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1424
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1425 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
1426 {
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1427 void *handle;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1428
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
1429 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
1430 return NULL;
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1431 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
1432 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
1433 ctypes_dlerror());
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1434 return NULL;
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 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
1437 return Py_None;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1438 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1439
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1440 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
1441 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1442 char *name;
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1443 void *handle;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1444 void *ptr;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1445
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
1446 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
1447 &_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
1448 return NULL;
40152
e2df1356349f Fix various minor errors in passing arguments to
Martin v. Löwis <martin@v.loewis.de>
parents: 39679
diff changeset
1449 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
1450 if (!ptr) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1451 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
1452 ctypes_dlerror());
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1453 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1454 }
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1455 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
1456 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1457 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1458
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 * 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
1461 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1462 * 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
1463 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1464 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1465 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
1466 {
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1467 void *func;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1468 PyObject *arguments;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1469 PyObject *result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1470
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1471 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
1472 "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
1473 &_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
1474 &PyTuple_Type, &arguments))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1475 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1476
40152
e2df1356349f Fix various minor errors in passing arguments to
Martin v. Löwis <martin@v.loewis.de>
parents: 39679
diff changeset
1477 result = _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
1478 arguments,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1479 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1480 NULL,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1481 NULL,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1482 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1483 0, /* flags */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1484 NULL, /* self->argtypes */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1485 NULL, /* self->restype */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1486 NULL); /* checker */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1487 return result;
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
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 * 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
1492 *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1493 * 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
1494 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1495 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1496 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
1497 {
41612
2131e03721ef Do not truncate 64-bit pointers to 32-bit integers.
Thomas Heller <theller@ctypes.org>
parents: 41562
diff changeset
1498 void *func;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1499 PyObject *arguments;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1500 PyObject *result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1501
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1502 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
1503 "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
1504 &_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
1505 &PyTuple_Type, &arguments))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1506 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1507
40152
e2df1356349f Fix various minor errors in passing arguments to
Martin v. Löwis <martin@v.loewis.de>
parents: 39679
diff changeset
1508 result = _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
1509 arguments,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1510 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1511 NULL,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1512 NULL,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1513 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1514 FUNCFLAG_CDECL, /* flags */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1515 NULL, /* self->argtypes */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1516 NULL, /* self->restype */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1517 NULL); /* checker */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1518 return result;
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1521 /*****************************************************************
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1522 * functions
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1523 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1524 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
1525 "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
1526 "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
1527 "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
1528
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1529 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1530 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
1531 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1532 StgDictObject *dict;
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 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
1535 if (dict)
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1536 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
1537
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1538 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
1539 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
1540 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
1541 "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
1542 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1543 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1544
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1545 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
1546 "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
1547 "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
1548 "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
1549
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1550 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1551 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
1552 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1553 StgDictObject *dict;
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 = PyType_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 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
1560 if (dict)
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
1561 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
1562
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1563 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
1564 "no alignment info");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1565 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1566 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1567
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1568 static char byref_doc[] =
47547
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1569 "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
1570 "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
1571 "as function argument";
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 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1574 * 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
1575 * 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
1576 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1577 static PyObject *
47547
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1578 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
1579 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1580 PyCArgObject *parg;
47547
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1581 PyObject *obj;
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1582 PyObject *pyoffset = NULL;
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1583 Py_ssize_t offset = 0;
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1584
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1585 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
1586 &obj, &pyoffset))
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 if (pyoffset) {
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1589 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
1590 if (offset == -1 && PyErr_Occurred())
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1591 return NULL;
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1592 }
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1593 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
1594 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
1595 "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
1596 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
1597 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1598 }
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 = new_CArgObject();
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1601 if (parg == NULL)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1602 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1603
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1604 parg->tag = 'P';
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1605 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
1606 Py_INCREF(obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1607 parg->obj = obj;
47547
813b87b16dc5 Add an optional 'offset' parameter to byref, defaultingto zero.
Thomas Heller <theller@ctypes.org>
parents: 47527
diff changeset
1608 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
1609 return (PyObject *)parg;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1610 }
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 char addressof_doc[] =
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1613 "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
1614 "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
1615
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1616 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1617 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
1618 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1619 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
1620 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
1621 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
1622 "invalid type");
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1623 return NULL;
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1626 static int
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1627 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
1628 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1629 *address = PyLong_AsVoidPtr(obj);
37109
5a7750db0977 Fix another bug found by Coverty.
Thomas Heller <theller@ctypes.org>
parents: 37061
diff changeset
1630 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
1631 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1632
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1633 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1634 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
1635 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1636 PyObject *ob;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1637 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
1638 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1639 Py_INCREF(ob);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1640 return ob;
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1643 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1644 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
1645 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1646 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
1647 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
1648 return 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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1651 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1652 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
1653 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1654 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
1655 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
1656 return arg;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1657 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1658
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1659 #ifdef CTYPES_UNICODE
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1660
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1661 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
1662 "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
1663 \n\
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1664 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
1665 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
1666
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1667 static PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1668 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
1669 {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1670 char *coding, *mode;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1671 PyObject *result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1672
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1673 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
1674 return NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1675 result = Py_BuildValue("(zz)", conversion_mode_encoding, conversion_mode_errors);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1676 if (coding) {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1677 PyMem_Free(conversion_mode_encoding);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1678 conversion_mode_encoding = PyMem_Malloc(strlen(coding) + 1);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1679 strcpy(conversion_mode_encoding, coding);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1680 } else {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1681 conversion_mode_encoding = NULL;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1682 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1683 PyMem_Free(conversion_mode_errors);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1684 conversion_mode_errors = PyMem_Malloc(strlen(mode) + 1);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1685 strcpy(conversion_mode_errors, mode);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1686 return result;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1687 }
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1688 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1689
38720
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1690 static PyObject *
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1691 resize(PyObject *self, PyObject *args)
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 CDataObject *obj;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1694 StgDictObject *dict;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1695 Py_ssize_t size;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1696
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1697 if (!PyArg_ParseTuple(args,
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1698 #if (PY_VERSION_HEX < 0x02050000)
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1699 "Oi:resize",
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1700 #else
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1701 "On:resize",
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1702 #endif
40152
e2df1356349f Fix various minor errors in passing arguments to
Martin v. Löwis <martin@v.loewis.de>
parents: 39679
diff changeset
1703 &obj, &size))
38720
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1704 return NULL;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1705
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1706 dict = PyObject_stgdict((PyObject *)obj);
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1707 if (dict == NULL) {
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1708 PyErr_SetString(PyExc_TypeError,
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1709 "excepted ctypes instance");
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1710 return NULL;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1711 }
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1712 if (size < dict->size) {
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1713 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
1714 #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
1715 "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
1716 #else
272f195a284e Revert the use of PY_FORMAT_SIZE_T in PyErr_Format.
Thomas Heller <theller@ctypes.org>
parents: 38968
diff changeset
1717 "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
1718 #endif
38968
d85708769ab1 Silence compiler warning
Neal Norwitz <nnorwitz@gmail.com>
parents: 38963
diff changeset
1719 dict->size);
38720
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1720 return NULL;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1721 }
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1722 if (obj->b_needsfree == 0) {
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1723 PyErr_Format(PyExc_ValueError,
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1724 "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
1725 return NULL;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1726 }
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1727 if (size <= sizeof(obj->b_value)) {
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1728 /* internal default buffer is large enough */
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1729 obj->b_size = size;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1730 goto done;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1731 }
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1732 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
1733 /* 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
1734 isn't large enough any more. */
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1735 void *ptr = PyMem_Malloc(size);
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1736 if (ptr == NULL)
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1737 return PyErr_NoMemory();
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1738 memset(ptr, 0, size);
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1739 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
1740 obj->b_ptr = ptr;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1741 obj->b_size = size;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1742 } else {
38730
b8f22851c1ff Handle failure of PyMem_Realloc.
Thomas Heller <theller@ctypes.org>
parents: 38720
diff changeset
1743 void * ptr = PyMem_Realloc(obj->b_ptr, size);
b8f22851c1ff Handle failure of PyMem_Realloc.
Thomas Heller <theller@ctypes.org>
parents: 38720
diff changeset
1744 if (ptr == NULL)
b8f22851c1ff Handle failure of PyMem_Realloc.
Thomas Heller <theller@ctypes.org>
parents: 38720
diff changeset
1745 return PyErr_NoMemory();
b8f22851c1ff Handle failure of PyMem_Realloc.
Thomas Heller <theller@ctypes.org>
parents: 38720
diff changeset
1746 obj->b_ptr = ptr;
38720
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1747 obj->b_size = size;
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 done:
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1750 Py_INCREF(Py_None);
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1751 return Py_None;
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1752 }
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 38652
diff changeset
1753
45315
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1754 static PyObject *
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1755 unpickle(PyObject *self, PyObject *args)
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1756 {
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1757 PyObject *typ;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1758 PyObject *state;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1759 PyObject *result;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1760 PyObject *tmp;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1761
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1762 if (!PyArg_ParseTuple(args, "OO", &typ, &state))
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1763 return NULL;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1764 result = PyObject_CallMethod(typ, "__new__", "O", typ);
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1765 if (result == NULL)
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 tmp = PyObject_CallMethod(result, "__setstate__", "O", state);
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1768 if (tmp == NULL) {
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1769 Py_DECREF(result);
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1770 return NULL;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1771 }
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1772 Py_DECREF(tmp);
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1773 return result;
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1774 }
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1775
46442
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1776 static PyObject *
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1777 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
1778 {
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1779 PyObject *result;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1780 PyTypeObject *typ;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1781 PyObject *key;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1782 char *buf;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1783
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1784 result = PyDict_GetItem(_pointer_type_cache, cls);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1785 if (result) {
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1786 Py_INCREF(result);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1787 return result;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1788 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47497
diff changeset
1789 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
1790 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
1791 sprintf(buf, "LP_%s", PyString_AS_STRING(cls));
46442
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1792 result = PyObject_CallFunction((PyObject *)Py_TYPE(&Pointer_Type),
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1793 "s(O){}",
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1794 buf,
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1795 &Pointer_Type);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1796 if (result == NULL)
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1797 return result;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1798 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
1799 } 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
1800 typ = (PyTypeObject *)cls;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1801 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
1802 sprintf(buf, "LP_%s", typ->tp_name);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1803 result = PyObject_CallFunction((PyObject *)Py_TYPE(&Pointer_Type),
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1804 "s(O){sO}",
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1805 buf,
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1806 &Pointer_Type,
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1807 "_type_", cls);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1808 if (result == NULL)
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1809 return result;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1810 Py_INCREF(cls);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1811 key = cls;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1812 } else {
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1813 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
1814 return NULL;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1815 }
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1816 if (-1 == PyDict_SetItem(_pointer_type_cache, key, result)) {
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1817 Py_DECREF(result);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1818 Py_DECREF(key);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1819 return NULL;
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 Py_DECREF(key);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1822 return result;
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
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1825 static PyObject *
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1826 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
1827 {
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1828 PyObject *result;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1829 PyObject *typ;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1830
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1831 typ = PyDict_GetItem(_pointer_type_cache, (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
1832 if (typ)
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1833 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
1834 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
1835 if (typ == NULL)
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1836 return NULL;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1837 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
1838 Py_DECREF(typ);
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1839 return result;
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1840 }
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
1841
47475
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1842 static PyObject *
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1843 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
1844 {
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1845 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
1846 PyObject *shape;
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1847 Py_ssize_t i;
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1848
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1849 if (dict == NULL)
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1850 dict = PyObject_stgdict(arg);
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1851 if (dict == NULL) {
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1852 PyErr_SetString(PyExc_TypeError,
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1853 "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
1854 return NULL;
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1855 }
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1856 shape = PyTuple_New(dict->ndim);
47671
e30af3264a0f Check for memory alloc failure
Neal Norwitz <nnorwitz@gmail.com>
parents: 47547
diff changeset
1857 if (shape == NULL)
e30af3264a0f Check for memory alloc failure
Neal Norwitz <nnorwitz@gmail.com>
parents: 47547
diff changeset
1858 return NULL;
47475
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1859 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
1860 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
1861
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1862 if (PyErr_Occurred()) {
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1863 Py_DECREF(shape);
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1864 return NULL;
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1865 }
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1866 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
1867 }
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
1868
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1869 PyMethodDef 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
1870 {"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
1871 {"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
1872 {"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
1873 {"pointer", pointer, METH_O },
45315
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 44597
diff changeset
1874 {"_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
1875 {"_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
1876 "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
1877 {"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
1878 #ifdef CTYPES_UNICODE
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1879 {"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
1880 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1881 #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
1882 {"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
1883 {"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
1884 {"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
1885 {"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
1886 {"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
1887 {"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
1888 {"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
1889 {"_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
1890 #else
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1891 {"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
1892 "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
1893 {"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
1894 {"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
1895 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1896 {"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
1897 {"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
1898 {"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
1899 {"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
1900 {"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
1901 {"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
1902 {"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
1903 {"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
1904 {"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
1905 {NULL, NULL} /* Sentinel */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1906 };
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1907
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1908 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1909 Local Variables:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1910 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
1911 End:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
1912 */