annotate Modules/_ctypes/ctypes.h @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 92f7a460ff82
children 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: 38720
diff changeset
1 /*****************************************************************
381a72ab5fb8 Add pep-291 compatibility markers.
Thomas Heller <theller@ctypes.org>
parents: 38720
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: 38720
diff changeset
3 *****************************************************************/
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
4
45851
96601f8f3391 Include <alloca.h> on Solaris, see issue #1506.
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
5 #if defined (__SVR4) && defined (__sun)
96601f8f3391 Include <alloca.h> on Solaris, see issue #1506.
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
6 # include <alloca.h>
96601f8f3391 Include <alloca.h> on Solaris, see issue #1506.
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
7 #endif
96601f8f3391 Include <alloca.h> on Solaris, see issue #1506.
Thomas Heller <theller@ctypes.org>
parents: 45315
diff changeset
8
48067
290078e9b6a2 Make ctypes compatible with Python 2.3, 2.4, and 2.5 again.
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
9 #if (PY_VERSION_HEX < 0x02040000)
290078e9b6a2 Make ctypes compatible with Python 2.3, 2.4, and 2.5 again.
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
10 #define PyDict_CheckExact(ob) (Py_TYPE(ob) == &PyDict_Type)
290078e9b6a2 Make ctypes compatible with Python 2.3, 2.4, and 2.5 again.
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
11 #endif
290078e9b6a2 Make ctypes compatible with Python 2.3, 2.4, and 2.5 again.
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
12
37004
3bf23061d86c Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents: 36981
diff changeset
13 #if (PY_VERSION_HEX < 0x02050000)
3bf23061d86c Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents: 36981
diff changeset
14 typedef int Py_ssize_t;
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
15 #define PyInt_FromSsize_t PyInt_FromLong
46286
d818f6d29384 Issue #2543: Make ctypes compatible (again) with Python 2.3, 2.4, and 2.5.
Thomas Heller <theller@ctypes.org>
parents: 45851
diff changeset
16 #define PyNumber_AsSsize_t(ob, exc) PyInt_AsLong(ob)
46402
bc33770ca114 Move backwards compatibility macro to the correct place;
Thomas Heller <theller@ctypes.org>
parents: 46286
diff changeset
17 #define PyIndex_Check(ob) PyInt_Check(ob)
48067
290078e9b6a2 Make ctypes compatible with Python 2.3, 2.4, and 2.5 again.
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
18 typedef Py_ssize_t (*readbufferproc)(PyObject *, Py_ssize_t, void **);
290078e9b6a2 Make ctypes compatible with Python 2.3, 2.4, and 2.5 again.
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
19 typedef Py_ssize_t (*writebufferproc)(PyObject *, Py_ssize_t, void **);
290078e9b6a2 Make ctypes compatible with Python 2.3, 2.4, and 2.5 again.
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
20 typedef Py_ssize_t (*segcountproc)(PyObject *, Py_ssize_t *);
290078e9b6a2 Make ctypes compatible with Python 2.3, 2.4, and 2.5 again.
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
21 typedef Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, char **);
37004
3bf23061d86c Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents: 36981
diff changeset
22 #endif
3bf23061d86c Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents: 36981
diff changeset
23
46286
d818f6d29384 Issue #2543: Make ctypes compatible (again) with Python 2.3, 2.4, and 2.5.
Thomas Heller <theller@ctypes.org>
parents: 45851
diff changeset
24 #if (PY_VERSION_HEX < 0x02060000)
d818f6d29384 Issue #2543: Make ctypes compatible (again) with Python 2.3, 2.4, and 2.5.
Thomas Heller <theller@ctypes.org>
parents: 45851
diff changeset
25 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
d818f6d29384 Issue #2543: Make ctypes compatible (again) with Python 2.3, 2.4, and 2.5.
Thomas Heller <theller@ctypes.org>
parents: 45851
diff changeset
26 #define PyVarObject_HEAD_INIT(type, size) \
d818f6d29384 Issue #2543: Make ctypes compatible (again) with Python 2.3, 2.4, and 2.5.
Thomas Heller <theller@ctypes.org>
parents: 45851
diff changeset
27 PyObject_HEAD_INIT(type) size,
d818f6d29384 Issue #2543: Make ctypes compatible (again) with Python 2.3, 2.4, and 2.5.
Thomas Heller <theller@ctypes.org>
parents: 45851
diff changeset
28 #define PyImport_ImportModuleNoBlock PyImport_ImportModule
48067
290078e9b6a2 Make ctypes compatible with Python 2.3, 2.4, and 2.5 again.
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
29 #define PyLong_FromSsize_t PyInt_FromLong
290078e9b6a2 Make ctypes compatible with Python 2.3, 2.4, and 2.5 again.
Thomas Heller <theller@ctypes.org>
parents: 47488
diff changeset
30 #define Py_TPFLAGS_HAVE_NEWBUFFER 0
46286
d818f6d29384 Issue #2543: Make ctypes compatible (again) with Python 2.3, 2.4, and 2.5.
Thomas Heller <theller@ctypes.org>
parents: 45851
diff changeset
31 #endif
d818f6d29384 Issue #2543: Make ctypes compatible (again) with Python 2.3, 2.4, and 2.5.
Thomas Heller <theller@ctypes.org>
parents: 45851
diff changeset
32
d818f6d29384 Issue #2543: Make ctypes compatible (again) with Python 2.3, 2.4, and 2.5.
Thomas Heller <theller@ctypes.org>
parents: 45851
diff changeset
33
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
34 #ifndef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
35 #define max(a, b) ((a) > (b) ? (a) : (b))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
36 #define min(a, b) ((a) < (b) ? (a) : (b))
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
37
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
38 #define PARAMFLAG_FIN 0x1
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
39 #define PARAMFLAG_FOUT 0x2
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
40 #define PARAMFLAG_FLCID 0x4
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
41 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
42
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 Backwards compatibility:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
45 Python2.2 used LONG_LONG instead of PY_LONG_LONG
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 #if defined(HAVE_LONG_LONG) && !defined(PY_LONG_LONG)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
48 #define PY_LONG_LONG LONG_LONG
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
49 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
50
39488
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39085
diff changeset
51 typedef struct tagPyCArgObject PyCArgObject;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
52 typedef struct tagCDataObject CDataObject;
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
53 typedef PyObject *(* GETFUNC)(void *, Py_ssize_t size);
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
54 typedef PyObject *(* SETFUNC)(void *, PyObject *value, Py_ssize_t size);
39488
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39085
diff changeset
55 typedef PyCArgObject *(* PARAMFUNC)(CDataObject *obj);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
56
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
57 /* A default buffer in CDataObject, which can be used for small C types. If
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
58 this buffer is too small, PyMem_Malloc will be called to create a larger one,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
59 and this one is not used.
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 Making CDataObject a variable size object would be a better solution, but more
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
62 difficult in the presence of CFuncPtrObject. Maybe later.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
63 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
64 union value {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
65 char c[16];
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
66 short s;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
67 int i;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
68 long l;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
69 float f;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
70 double d;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
71 #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
72 PY_LONG_LONG ll;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
73 #endif
43278
28716dd14bc5 Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents: 42266
diff changeset
74 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
75 };
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
76
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
77 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
78 Hm. Are there CDataObject's which do not need the b_objects member? In
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
79 this case we probably should introduce b_flags to mark it as present... If
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
80 b_objects is not present/unused b_length is unneeded as well.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
81 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
82
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
83 struct tagCDataObject {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
84 PyObject_HEAD
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
85 char *b_ptr; /* pointer to memory block */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
86 int b_needsfree; /* need _we_ free the memory? */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
87 CDataObject *b_base; /* pointer to base object or NULL */
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
88 Py_ssize_t b_size; /* size of memory block in bytes */
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
89 Py_ssize_t b_length; /* number of references we need */
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
90 Py_ssize_t b_index; /* index of this object into base's
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
91 b_object list */
38720
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 37848
diff changeset
92 PyObject *b_objects; /* dictionary of references we need to keep, or Py_None */
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
93 union value b_value;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
94 };
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
95
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
96 typedef struct {
46546
4ff8dfaec3fc Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents: 46442
diff changeset
97 PyObject_VAR_HEAD
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37114
diff changeset
98 ffi_closure *pcl; /* the C callable */
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37114
diff changeset
99 ffi_cif cif;
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
100 int flags;
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37114
diff changeset
101 PyObject *converters;
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37114
diff changeset
102 PyObject *callable;
46546
4ff8dfaec3fc Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents: 46442
diff changeset
103 PyObject *restype;
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37114
diff changeset
104 SETFUNC setfunc;
46546
4ff8dfaec3fc Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents: 46442
diff changeset
105 ffi_type *ffi_restype;
42266
f8c75e849956 Fix for SF# 1649098: avoid zero-sized array declaration in structure.
Thomas Heller <theller@ctypes.org>
parents: 42041
diff changeset
106 ffi_type *atypes[1];
46546
4ff8dfaec3fc Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents: 46442
diff changeset
107 } CThunkObject;
4ff8dfaec3fc Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents: 46442
diff changeset
108 extern PyTypeObject CThunk_Type;
4ff8dfaec3fc Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents: 46442
diff changeset
109 #define CThunk_CheckExact(v) ((v)->ob_type == &CThunk_Type)
37147
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37114
diff changeset
110
0057862a3bdb Include <malloc.h> on windows, to avoid warnings when compiling with mingw.
Thomas Heller <theller@ctypes.org>
parents: 37114
diff changeset
111 typedef struct {
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
112 /* First part identical to tagCDataObject */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
113 PyObject_HEAD
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
114 char *b_ptr; /* pointer to memory block */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
115 int b_needsfree; /* need _we_ free the memory? */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
116 CDataObject *b_base; /* pointer to base object or NULL */
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
117 Py_ssize_t b_size; /* size of memory block in bytes */
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
118 Py_ssize_t b_length; /* number of references we need */
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
119 Py_ssize_t b_index; /* index of this object into base's
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
120 b_object list */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
121 PyObject *b_objects; /* list of references we need to keep */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
122 union value b_value;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
123 /* end of tagCDataObject, additional fields follow */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
124
46546
4ff8dfaec3fc Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents: 46442
diff changeset
125 CThunkObject *thunk;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
126 PyObject *callable;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
127
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
128 /* These two fields will override the ones in the type's stgdict if
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
129 they are set */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
130 PyObject *converters;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
131 PyObject *argtypes;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
132 PyObject *restype;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
133 PyObject *checker;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
134 PyObject *errcheck;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
135 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
136 int index;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
137 GUID *iid;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
138 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
139 PyObject *paramflags;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
140 } CFuncPtrObject;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
141
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
142 extern PyTypeObject StgDict_Type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
143 #define StgDict_CheckExact(v) ((v)->ob_type == &StgDict_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
144 #define StgDict_Check(v) PyObject_TypeCheck(v, &StgDict_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
145
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
146 extern int StructUnionType_update_stgdict(PyObject *fields, PyObject *type, int isStruct);
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
147 extern int PyType_stginfo(PyTypeObject *self, Py_ssize_t *psize, Py_ssize_t *palign, Py_ssize_t *plength);
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
148 extern int PyObject_stginfo(PyObject *self, Py_ssize_t *psize, Py_ssize_t *palign, Py_ssize_t *plength);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
149
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
150
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
151
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
152 extern PyTypeObject CData_Type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
153 #define CDataObject_CheckExact(v) ((v)->ob_type == &CData_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
154 #define CDataObject_Check(v) PyObject_TypeCheck(v, &CData_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
155
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
156 extern PyTypeObject SimpleType_Type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
157 #define SimpleTypeObject_CheckExact(v) ((v)->ob_type == &SimpleType_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
158 #define SimpleTypeObject_Check(v) PyObject_TypeCheck(v, &SimpleType_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
159
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
160 extern PyTypeObject CField_Type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
161 extern struct fielddesc *getentry(char *fmt);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
162
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
163
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
164 extern PyObject *
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
165 CField_FromDesc(PyObject *desc, Py_ssize_t index,
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
166 Py_ssize_t *pfield_size, int bitsize, int *pbitofs,
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
167 Py_ssize_t *psize, Py_ssize_t *poffset, Py_ssize_t *palign,
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
168 int pack, int is_big_endian);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
169
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
170 extern PyObject *CData_AtAddress(PyObject *type, void *buf);
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
171 extern PyObject *CData_FromBytes(PyObject *type, char *data, Py_ssize_t length);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
172
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
173 extern PyTypeObject ArrayType_Type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
174 extern PyTypeObject Array_Type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
175 extern PyTypeObject PointerType_Type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
176 extern PyTypeObject Pointer_Type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
177 extern PyTypeObject CFuncPtr_Type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
178 extern PyTypeObject CFuncPtrType_Type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
179 extern PyTypeObject StructType_Type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
180
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
181 #define ArrayTypeObject_Check(v) PyObject_TypeCheck(v, &ArrayType_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
182 #define ArrayObject_Check(v) PyObject_TypeCheck(v, &Array_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
183 #define PointerObject_Check(v) PyObject_TypeCheck(v, &Pointer_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
184 #define PointerTypeObject_Check(v) PyObject_TypeCheck(v, &PointerType_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
185 #define CFuncPtrObject_Check(v) PyObject_TypeCheck(v, &CFuncPtr_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
186 #define CFuncPtrTypeObject_Check(v) PyObject_TypeCheck(v, &CFuncPtrType_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
187 #define StructTypeObject_Check(v) PyObject_TypeCheck(v, &StructType_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
188
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
189 extern PyObject *
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
190 CreateArrayType(PyObject *itemtype, Py_ssize_t length);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
191
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
192 extern PyMethodDef module_methods[];
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
193
46546
4ff8dfaec3fc Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents: 46442
diff changeset
194 extern CThunkObject *AllocFunctionCallback(PyObject *callable,
4ff8dfaec3fc Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents: 46442
diff changeset
195 PyObject *converters,
4ff8dfaec3fc Remove cyclic reference in CFuncPtr instances; see issue #2682.
Thomas Heller <theller@ctypes.org>
parents: 46442
diff changeset
196 PyObject *restype,
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
197 int flags);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
198 /* a table entry describing a predefined ctypes type */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
199 struct fielddesc {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
200 char code;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
201 SETFUNC setfunc;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
202 GETFUNC getfunc;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
203 ffi_type *pffi_type; /* always statically allocated */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
204 SETFUNC setfunc_swapped;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
205 GETFUNC getfunc_swapped;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
206 };
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
207
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
208 typedef struct {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
209 PyObject_HEAD
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
210 Py_ssize_t offset;
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
211 Py_ssize_t size;
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
212 Py_ssize_t index; /* Index into CDataObject's
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
213 object array */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
214 PyObject *proto; /* a type or NULL */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
215 GETFUNC getfunc; /* getter function if proto is NULL */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
216 SETFUNC setfunc; /* setter function if proto is NULL */
38720
aa5a1bca28dd Upgrade to ctypes version 0.9.9.7.
Thomas Heller <theller@ctypes.org>
parents: 37848
diff changeset
217 int anonymous;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
218 } CFieldObject;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
219
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
220 /* A subclass of PyDictObject, used as the instance dictionary of ctypes
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
221 metatypes */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
222 typedef struct {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
223 PyDictObject dict; /* first part identical to PyDictObject */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
224 /* The size and align fields are unneeded, they are in ffi_type as well. As
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
225 an experiment shows, it's trivial to get rid of them, the only thing to
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
226 remember is that in ArrayType_new the ffi_type fields must be filled in -
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
227 so far it was unneeded because libffi doesn't support arrays at all
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
228 (because they are passed as pointers to function calls anyway). But it's
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
229 too much risk to change that now, and there are other fields which doen't
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
230 belong into this structure anyway. Maybe in ctypes 2.0... (ctypes 2000?)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
231 */
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
232 Py_ssize_t size; /* number of bytes */
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
233 Py_ssize_t align; /* alignment requirements */
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
234 Py_ssize_t length; /* number of fields */
37848
dd4156c36703 C++ compiler cleanup: the typical few casts, and ... C++ didn't like that
Skip Montanaro <skip@pobox.com>
parents: 37147
diff changeset
235 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
236 PyObject *proto; /* Only for Pointer/ArrayObject */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
237 SETFUNC setfunc; /* Only for simple objects */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
238 GETFUNC getfunc; /* Only for simple objects */
39488
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39085
diff changeset
239 PARAMFUNC paramfunc;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
240
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
241 /* Following fields only used by CFuncPtrType_Type instances */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
242 PyObject *argtypes; /* tuple of CDataObjects */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
243 PyObject *converters; /* tuple([t.from_param for t in argtypes]) */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
244 PyObject *restype; /* CDataObject or NULL */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
245 PyObject *checker;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
246 int flags; /* calling convention and such */
47475
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
247
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
248 /* pep3118 fields, pointers neeed PyMem_Free */
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
249 char *format;
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
250 int ndim;
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
251 Py_ssize_t *shape;
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
252 /* Py_ssize_t *strides; */ /* unused in ctypes */
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
253 /* Py_ssize_t *suboffsets; */ /* unused in ctypes */
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
254
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
255 } StgDictObject;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
256
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
257 /****************************************************************
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
258 StgDictObject fields
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
259
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
260 setfunc and getfunc is only set for simple data types, it is copied from the
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
261 corresponding fielddesc entry. These are functions to set and get the value
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
262 in a memory block.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
263 They should probably by used by other types as well.
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 proto is only used for Pointer and Array types - it points to the item type
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
266 object.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
267
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
268 Probably all the magic ctypes methods (like from_param) should have C
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
269 callable wrappers in the StgDictObject. For simple data type, for example,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
270 the fielddesc table could have entries for C codec from_param functions or
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
271 other methods as well, if a subtype overrides this method in Python at
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
272 construction time, or assigns to it later, tp_setattro should update the
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
273 StgDictObject function to a generic one.
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 Currently, CFuncPtr types have 'converters' and 'checker' entries in their
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
276 type dict. They are only used to cache attributes from other entries, whihc
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
277 is wrong.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
278
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
279 One use case is the .value attribute that all simple types have. But some
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
280 complex structures, like VARIANT, represent a single value also, and should
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
281 have this attribute.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
282
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
283 Another use case is a _check_retval_ function, which is called when a ctypes
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
284 type is used as return type of a function to validate and compute the return
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
285 value.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
286
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
287 Common ctypes protocol:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
288
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
289 - setfunc: store a python value in a memory block
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
290 - getfunc: convert data from a memory block into a python value
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
291
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
292 - checkfunc: validate and convert a return value from a function call
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
293 - toparamfunc: convert a python value into a function argument
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
294
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
295 *****************************************************************/
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
296
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
297 /* May return NULL, but does not set an exception! */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
298 extern StgDictObject *PyType_stgdict(PyObject *obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
299
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
300 /* May return NULL, but does not set an exception! */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
301 extern StgDictObject *PyObject_stgdict(PyObject *self);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
302
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
303 extern int StgDict_clone(StgDictObject *src, StgDictObject *dst);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
304
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
305 typedef int(* PPROC)(void);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
306
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
307 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
308 PyObject *arguments,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
309 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
310 IUnknown *pIUnk,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
311 GUID *iid,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
312 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
313 int flags,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
314 PyObject *argtypes,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
315 PyObject *restype,
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
316 PyObject *checker);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
317
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
318
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
319 #define FUNCFLAG_STDCALL 0x0
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
320 #define FUNCFLAG_CDECL 0x1
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
321 #define FUNCFLAG_HRESULT 0x2
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
322 #define FUNCFLAG_PYTHONAPI 0x4
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
323 #define FUNCFLAG_USE_ERRNO 0x8
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
324 #define FUNCFLAG_USE_LASTERROR 0x10
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
325
45315
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 43278
diff changeset
326 #define TYPEFLAG_ISPOINTER 0x100
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 43278
diff changeset
327 #define TYPEFLAG_HASPOINTER 0x200
beea35b0ed50 Add pickle support to ctypes types.
Thomas Heller <theller@ctypes.org>
parents: 43278
diff changeset
328
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
329 #define DICTFLAG_FINAL 0x1000
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
330
39488
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39085
diff changeset
331 struct tagPyCArgObject {
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
332 PyObject_HEAD
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
333 ffi_type *pffi_type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
334 char tag;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
335 union {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
336 char c;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
337 char b;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
338 short h;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
339 int i;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
340 long l;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
341 #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
342 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
343 #endif
43278
28716dd14bc5 Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents: 42266
diff changeset
344 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
345 double d;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
346 float f;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
347 void *p;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
348 } value;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
349 PyObject *obj;
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
350 Py_ssize_t size; /* for the 'V' tag */
39488
a55369e23f06 Apply the patch #1532975 plus ideas from the patch #1533481.
Thomas Heller <theller@ctypes.org>
parents: 39085
diff changeset
351 };
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
352
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
353 extern PyTypeObject PyCArg_Type;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
354 #define PyCArg_CheckExact(v) ((v)->ob_type == &PyCArg_Type)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
355 extern PyCArgObject *new_CArgObject(void);
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 extern PyObject *
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
358 CData_get(PyObject *type, GETFUNC getfunc, PyObject *src,
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
359 Py_ssize_t index, Py_ssize_t size, char *ptr);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
360
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
361 extern int
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
362 CData_set(PyObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
363 Py_ssize_t index, Py_ssize_t size, char *ptr);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
364
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
365 extern 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
366
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
367 struct basespec {
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
368 CDataObject *base;
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
369 Py_ssize_t index;
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
370 char *adr;
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
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
373 extern char basespec_string[];
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
374
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
375 extern 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
376
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
377 /* exception classes */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
378 extern PyObject *PyExc_ArgError;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
379
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
380 extern char *conversion_mode_encoding;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
381 extern char *conversion_mode_errors;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
382
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
383 /* Python 2.4 macros, which are not available in Python 2.3 */
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 #ifndef Py_CLEAR
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
386 #define Py_CLEAR(op) \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
387 do { \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
388 if (op) { \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
389 PyObject *tmp = (PyObject *)(op); \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
390 (op) = NULL; \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
391 Py_DECREF(tmp); \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
392 } \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
393 } while (0)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
394 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
395
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
396 #ifndef Py_VISIT
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
397 /* Utility macro to help write tp_traverse functions.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
398 * To use this macro, the tp_traverse function must name its arguments
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
399 * "visit" and "arg". This is intended to keep tp_traverse functions
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
400 * looking as much alike as possible.
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
401 */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
402 #define Py_VISIT(op) \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
403 do { \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
404 if (op) { \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
405 int vret = visit((op), arg); \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
406 if (vret) \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
407 return vret; \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
408 } \
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
409 } while (0)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
410 #endif
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 /* Python's PyUnicode_*WideChar functions are broken ... */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
413 #if defined(Py_USING_UNICODE) && defined(HAVE_WCHAR_H)
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
414 # define CTYPES_UNICODE
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
415 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
416
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
417
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
418 #ifdef CTYPES_UNICODE
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
419 # undef PyUnicode_FromWideChar
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
420 # define PyUnicode_FromWideChar My_PyUnicode_FromWideChar
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
421
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
422 # undef PyUnicode_AsWideChar
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
423 # define PyUnicode_AsWideChar My_PyUnicode_AsWideChar
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
424
39085
85ffc0bfcc98 Make the prototypes of our private PyUnicode_FromWideChar and
Thomas Heller <theller@ctypes.org>
parents: 38780
diff changeset
425 extern PyObject *My_PyUnicode_FromWideChar(const wchar_t *, Py_ssize_t);
41998
7b84e8919b00 [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents: 41612
diff changeset
426 extern Py_ssize_t My_PyUnicode_AsWideChar(PyUnicodeObject *, wchar_t *, Py_ssize_t);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
427
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
428 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
429
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
430 extern void FreeClosure(void *);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
431 extern void *MallocClosure(void);
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 extern void _AddTraceback(char *, char *, int);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
434
36981
ff3024259d91 Integrate patch from Neal Norwitz. He writes:
Thomas Heller <theller@ctypes.org>
parents: 36897
diff changeset
435 extern PyObject *CData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr);
47475
bbce18d00d87 Backport from py3k: Implement the new buffer interface from pep3118
Thomas Heller <theller@ctypes.org>
parents: 47469
diff changeset
436 extern char *alloc_format_string(const char *prefix, const char *suffix);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
437
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
438 /* XXX better name needed! */
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
439 extern int IsSimpleSubType(PyObject *obj);
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
440
46442
b3dca8f5535e Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
Thomas Heller <theller@ctypes.org>
parents: 46402
diff changeset
441 extern PyObject *_pointer_type_cache;
47488
4f5e6aaf5a6a Issue #1798: Add ctypes calling convention that allows safe access of errno.
Thomas Heller <theller@ctypes.org>
parents: 47475
diff changeset
442 PyObject *get_error_object(int **pspace);
36897
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
443
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
444 #ifdef MS_WIN32
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
445 extern PyObject *ComError;
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
446 #endif
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
447
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
448 /*
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
449 Local Variables:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
450 compile-command: "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
451 End:
6f2eda495d9d Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff changeset
452 */