Mercurial > cpython-lru_cache-weakref
annotate Modules/_ctypes/cfield.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 | 6d64cd69f384 |
| children | e38335d4df91 |
| rev | line source |
|---|---|
|
38780
381a72ab5fb8
Add pep-291 compatibility markers.
Thomas Heller <theller@ctypes.org>
parents:
38626
diff
changeset
|
1 /***************************************************************** |
|
381a72ab5fb8
Add pep-291 compatibility markers.
Thomas Heller <theller@ctypes.org>
parents:
38626
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:
38626
diff
changeset
|
3 *****************************************************************/ |
|
381a72ab5fb8
Add pep-291 compatibility markers.
Thomas Heller <theller@ctypes.org>
parents:
38626
diff
changeset
|
4 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
5 #include "Python.h" |
|
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 #include <ffi.h> |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
8 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
9 #include <windows.h> |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
10 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
11 #include "ctypes.h" |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
12 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
13 /******************************************************************/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
14 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
15 CField_Type |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
16 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
17 static PyObject * |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
18 CField_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
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 CFieldObject *obj; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
21 obj = (CFieldObject *)type->tp_alloc(type, 0); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
22 return (PyObject *)obj; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
23 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
24 |
|
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 * Expects the size, index and offset for the current field in *psize and |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
27 * *poffset, stores the total size so far in *psize, the offset for the next |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
28 * field in *poffset, the alignment requirements for the current field in |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
29 * *palign, and returns a field desriptor for this field. |
|
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 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
32 * bitfields extension: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
33 * bitsize != 0: this is a bit field. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
34 * pbitofs points to the current bit offset, this will be updated. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
35 * prev_desc points to the type of the previous bitfield, if any. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
36 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
37 PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
38 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:
41564
diff
changeset
|
39 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:
41564
diff
changeset
|
40 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
|
41 int pack, int big_endian) |
|
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 CFieldObject *self; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
44 PyObject *proto; |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
45 Py_ssize_t size, align, length; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
46 SETFUNC setfunc = NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
47 GETFUNC getfunc = NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
48 StgDictObject *dict; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
49 int fieldtype; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
50 #define NO_BITFIELD 0 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
51 #define NEW_BITFIELD 1 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
52 #define CONT_BITFIELD 2 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
53 #define EXPAND_BITFIELD 3 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
54 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
55 self = (CFieldObject *)PyObject_CallObject((PyObject *)&CField_Type, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
56 NULL); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
57 if (self == NULL) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
58 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
59 dict = PyType_stgdict(desc); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
60 if (!dict) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
61 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
|
62 "has no _stginfo_"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
63 Py_DECREF(self); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
64 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
65 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
66 if (bitsize /* this is a bitfield request */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
67 && *pfield_size /* we have a bitfield open */ |
|
49341
5b3529485421
Fix issue #3547 for MingW, update comments.
Thomas Heller <theller@ctypes.org>
parents:
49288
diff
changeset
|
68 #ifdef MS_WIN32 |
|
5b3529485421
Fix issue #3547 for MingW, update comments.
Thomas Heller <theller@ctypes.org>
parents:
49288
diff
changeset
|
69 /* MSVC, GCC with -mms-bitfields */ |
|
5b3529485421
Fix issue #3547 for MingW, update comments.
Thomas Heller <theller@ctypes.org>
parents:
49288
diff
changeset
|
70 && dict->size * 8 == *pfield_size |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
71 #else |
|
49341
5b3529485421
Fix issue #3547 for MingW, update comments.
Thomas Heller <theller@ctypes.org>
parents:
49288
diff
changeset
|
72 /* GCC */ |
|
5b3529485421
Fix issue #3547 for MingW, update comments.
Thomas Heller <theller@ctypes.org>
parents:
49288
diff
changeset
|
73 && dict->size * 8 <= *pfield_size |
|
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 && (*pbitofs + bitsize) <= *pfield_size) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
76 /* continue bit field */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
77 fieldtype = CONT_BITFIELD; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
78 #ifndef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
79 } else if (bitsize /* this is a bitfield request */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
80 && *pfield_size /* we have a bitfield open */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
81 && dict->size * 8 >= *pfield_size |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
82 && (*pbitofs + bitsize) <= dict->size * 8) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
83 /* expand bit field */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
84 fieldtype = EXPAND_BITFIELD; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
85 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
86 } else if (bitsize) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
87 /* start new bitfield */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
88 fieldtype = NEW_BITFIELD; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
89 *pbitofs = 0; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
90 *pfield_size = dict->size * 8; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
91 } else { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
92 /* not a bit field */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
93 fieldtype = NO_BITFIELD; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
94 *pbitofs = 0; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
95 *pfield_size = 0; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
96 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
97 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
98 size = dict->size; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
99 length = dict->length; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
100 proto = desc; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
101 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
102 /* Field descriptors for 'c_char * n' are be scpecial cased to |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
103 return a Python string instead of an Array object instance... |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
104 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
105 if (ArrayTypeObject_Check(proto)) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
106 StgDictObject *adict = PyType_stgdict(proto); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
107 StgDictObject *idict; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
108 if (adict && adict->proto) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
109 idict = PyType_stgdict(adict->proto); |
|
39454
9a1288d8200f
Check returned pointer is valid.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39097
diff
changeset
|
110 if (!idict) { |
|
9a1288d8200f
Check returned pointer is valid.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39097
diff
changeset
|
111 PyErr_SetString(PyExc_TypeError, |
|
9a1288d8200f
Check returned pointer is valid.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39097
diff
changeset
|
112 "has no _stginfo_"); |
|
9a1288d8200f
Check returned pointer is valid.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39097
diff
changeset
|
113 Py_DECREF(self); |
|
9a1288d8200f
Check returned pointer is valid.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39097
diff
changeset
|
114 return NULL; |
|
9a1288d8200f
Check returned pointer is valid.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39097
diff
changeset
|
115 } |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
116 if (idict->getfunc == getentry("c")->getfunc) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
117 struct fielddesc *fd = getentry("s"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
118 getfunc = fd->getfunc; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
119 setfunc = fd->setfunc; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
120 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
121 #ifdef CTYPES_UNICODE |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
122 if (idict->getfunc == getentry("u")->getfunc) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
123 struct fielddesc *fd = getentry("U"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
124 getfunc = fd->getfunc; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
125 setfunc = fd->setfunc; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
126 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
127 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
128 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
129 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
130 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
131 self->setfunc = setfunc; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
132 self->getfunc = getfunc; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
133 self->index = index; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
134 |
|
39097
aedb85ee4fec
proto was dereffed above and is known to be good. No need for X.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39049
diff
changeset
|
135 Py_INCREF(proto); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
136 self->proto = proto; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
137 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
138 switch (fieldtype) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
139 case NEW_BITFIELD: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
140 if (big_endian) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
141 self->size = (bitsize << 16) + *pfield_size - *pbitofs - bitsize; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
142 else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
143 self->size = (bitsize << 16) + *pbitofs; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
144 *pbitofs = bitsize; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
145 /* fall through */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
146 case NO_BITFIELD: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
147 if (pack) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
148 align = min(pack, dict->align); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
149 else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
150 align = dict->align; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
151 if (align && *poffset % align) { |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
152 Py_ssize_t delta = align - (*poffset % align); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
153 *psize += delta; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
154 *poffset += delta; |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
157 if (bitsize == 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
158 self->size = size; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
159 *psize += size; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
160 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
161 self->offset = *poffset; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
162 *poffset += size; |
|
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 *palign = align; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
165 break; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
166 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
167 case EXPAND_BITFIELD: |
|
49288
606ab25ddef1
Fix issue #3547: ctypes is confused by bitfields of varying integer types
Thomas Heller <theller@ctypes.org>
parents:
47527
diff
changeset
|
168 *poffset += dict->size - *pfield_size/8; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
169 *psize += dict->size - *pfield_size/8; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
170 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
171 *pfield_size = dict->size * 8; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
172 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
173 if (big_endian) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
174 self->size = (bitsize << 16) + *pfield_size - *pbitofs - bitsize; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
175 else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
176 self->size = (bitsize << 16) + *pbitofs; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
177 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
178 self->offset = *poffset - size; /* poffset is already updated for the NEXT field */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
179 *pbitofs += bitsize; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
180 break; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
181 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
182 case CONT_BITFIELD: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
183 if (big_endian) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
184 self->size = (bitsize << 16) + *pfield_size - *pbitofs - bitsize; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
185 else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
186 self->size = (bitsize << 16) + *pbitofs; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
187 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
188 self->offset = *poffset - size; /* poffset is already updated for the NEXT field */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
189 *pbitofs += bitsize; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
190 break; |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
193 return (PyObject *)self; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
194 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
195 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
196 static int |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
197 CField_set(CFieldObject *self, PyObject *inst, PyObject *value) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
198 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
199 CDataObject *dst; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
200 char *ptr; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
201 assert(CDataObject_Check(inst)); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
202 dst = (CDataObject *)inst; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
203 ptr = dst->b_ptr + self->offset; |
|
44335
b5b3080b360f
Issue #1642: Fix segfault in ctypes when trying to delete attributes.
Thomas Heller <theller@ctypes.org>
parents:
43678
diff
changeset
|
204 if (value == NULL) { |
|
b5b3080b360f
Issue #1642: Fix segfault in ctypes when trying to delete attributes.
Thomas Heller <theller@ctypes.org>
parents:
43678
diff
changeset
|
205 PyErr_SetString(PyExc_TypeError, |
|
b5b3080b360f
Issue #1642: Fix segfault in ctypes when trying to delete attributes.
Thomas Heller <theller@ctypes.org>
parents:
43678
diff
changeset
|
206 "can't delete attribute"); |
|
b5b3080b360f
Issue #1642: Fix segfault in ctypes when trying to delete attributes.
Thomas Heller <theller@ctypes.org>
parents:
43678
diff
changeset
|
207 return -1; |
|
b5b3080b360f
Issue #1642: Fix segfault in ctypes when trying to delete attributes.
Thomas Heller <theller@ctypes.org>
parents:
43678
diff
changeset
|
208 } |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
209 return CData_set(inst, self->proto, self->setfunc, value, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
210 self->index, self->size, ptr); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
211 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
212 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
213 static PyObject * |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
214 CField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
215 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
216 CDataObject *src; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
217 if (inst == NULL) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
218 Py_INCREF(self); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
219 return (PyObject *)self; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
220 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
221 assert(CDataObject_Check(inst)); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
222 src = (CDataObject *)inst; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
223 return CData_get(self->proto, self->getfunc, inst, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
224 self->index, self->size, src->b_ptr + self->offset); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
225 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
226 |
|
38625
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
227 static PyObject * |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
228 CField_get_offset(PyObject *self, void *data) |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
229 { |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
230 return PyInt_FromSsize_t(((CFieldObject *)self)->offset); |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
231 } |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
232 |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
233 static PyObject * |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
234 CField_get_size(PyObject *self, void *data) |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
235 { |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
236 return PyInt_FromSsize_t(((CFieldObject *)self)->size); |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
237 } |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
238 |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
239 static PyGetSetDef CField_getset[] = { |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
240 { "offset", CField_get_offset, NULL, "offset in bytes of this field" }, |
|
38626
0dcb62d6d99a
Damn - the sentinel was missing. And fix another silly mistake.
Thomas Heller <theller@ctypes.org>
parents:
38625
diff
changeset
|
241 { "size", CField_get_size, NULL, "size in bytes of this field" }, |
|
0dcb62d6d99a
Damn - the sentinel was missing. And fix another silly mistake.
Thomas Heller <theller@ctypes.org>
parents:
38625
diff
changeset
|
242 { NULL, NULL, NULL, NULL }, |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
243 }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
244 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
245 static int |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
246 CField_traverse(CFieldObject *self, visitproc visit, void *arg) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
247 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
248 Py_VISIT(self->proto); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
249 return 0; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
250 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
251 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
252 static int |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
253 CField_clear(CFieldObject *self) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
254 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
255 Py_CLEAR(self->proto); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
256 return 0; |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
259 static void |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
260 CField_dealloc(PyObject *self) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
261 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
262 CField_clear((CFieldObject *)self); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
263 self->ob_type->tp_free((PyObject *)self); |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
266 static PyObject * |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
267 CField_repr(CFieldObject *self) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
268 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
269 PyObject *result; |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
270 Py_ssize_t bits = self->size >> 16; |
|
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
271 Py_ssize_t size = self->size & 0xFFFF; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
272 const char *name; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
273 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
274 name = ((PyTypeObject *)self->proto)->tp_name; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
275 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
276 if (bits) |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
277 result = PyString_FromFormat( |
|
37004
3bf23061d86c
Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents:
36994
diff
changeset
|
278 #if (PY_VERSION_HEX < 0x02050000) |
|
3bf23061d86c
Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents:
36994
diff
changeset
|
279 "<Field type=%s, ofs=%d:%d, bits=%d>", |
|
3bf23061d86c
Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents:
36994
diff
changeset
|
280 #else |
|
41999
b4f4ee84c30d
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
Thomas Heller <theller@ctypes.org>
parents:
41998
diff
changeset
|
281 "<Field type=%s, ofs=%zd:%zd, bits=%zd>", |
|
37004
3bf23061d86c
Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents:
36994
diff
changeset
|
282 #endif |
|
3bf23061d86c
Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents:
36994
diff
changeset
|
283 name, self->offset, size, bits); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
284 else |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
285 result = PyString_FromFormat( |
|
37004
3bf23061d86c
Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents:
36994
diff
changeset
|
286 #if (PY_VERSION_HEX < 0x02050000) |
|
3bf23061d86c
Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents:
36994
diff
changeset
|
287 "<Field type=%s, ofs=%d, size=%d>", |
|
3bf23061d86c
Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents:
36994
diff
changeset
|
288 #else |
|
41999
b4f4ee84c30d
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
Thomas Heller <theller@ctypes.org>
parents:
41998
diff
changeset
|
289 "<Field type=%s, ofs=%zd, size=%zd>", |
|
37004
3bf23061d86c
Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents:
36994
diff
changeset
|
290 #endif |
|
3bf23061d86c
Backport from upstream version: compatibility with older Python
Thomas Heller <theller@ctypes.org>
parents:
36994
diff
changeset
|
291 name, self->offset, size); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
292 return result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
293 } |
|
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 PyTypeObject CField_Type = { |
|
42333
6620a510e9a9
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents:
41999
diff
changeset
|
296 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
|
297 "_ctypes.CField", /* tp_name */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
298 sizeof(CFieldObject), /* tp_basicsize */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
299 0, /* tp_itemsize */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
300 CField_dealloc, /* tp_dealloc */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
301 0, /* tp_print */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
302 0, /* tp_getattr */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
303 0, /* tp_setattr */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
304 0, /* tp_compare */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
305 (reprfunc)CField_repr, /* tp_repr */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 0, /* tp_hash */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
310 0, /* tp_call */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
311 0, /* tp_str */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
312 0, /* tp_getattro */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
313 0, /* tp_setattro */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
314 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
|
315 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
316 "Structure/Union member", /* tp_doc */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
317 (traverseproc)CField_traverse, /* tp_traverse */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
318 (inquiry)CField_clear, /* tp_clear */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
319 0, /* tp_richcompare */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
320 0, /* tp_weaklistoffset */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
321 0, /* tp_iter */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
322 0, /* tp_iternext */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
323 0, /* tp_methods */ |
|
38625
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
324 0, /* tp_members */ |
|
5fbefb5c8a23
Convert CFieldObject tp_members to tp_getset, since there is no
Thomas Heller <theller@ctypes.org>
parents:
37498
diff
changeset
|
325 CField_getset, /* tp_getset */ |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
326 0, /* tp_base */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
327 0, /* tp_dict */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
328 (descrgetfunc)CField_get, /* tp_descr_get */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
329 (descrsetfunc)CField_set, /* tp_descr_set */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
330 0, /* tp_dictoffset */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
331 0, /* tp_init */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
332 0, /* tp_alloc */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
333 CField_new, /* tp_new */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
334 0, /* tp_free */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
335 }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
336 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
337 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
338 /******************************************************************/ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
339 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
340 Accessor functions |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
343 /* Derived from Modules/structmodule.c: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
344 Helper routine to get a Python integer and raise the appropriate error |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
345 if it isn't one */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
346 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
347 static int |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
348 get_long(PyObject *v, long *p) |
|
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 long x; |
|
44924
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
351 if (PyFloat_Check(v)) { |
|
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
352 PyErr_SetString(PyExc_TypeError, |
|
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
353 "int expected instead of float"); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
354 return -1; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
355 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
356 x = PyInt_AsUnsignedLongMask(v); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
357 if (x == -1 && PyErr_Occurred()) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
358 return -1; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
359 *p = x; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
360 return 0; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
361 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
362 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
363 /* Same, but handling unsigned long */ |
|
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 static int |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
366 get_ulong(PyObject *v, unsigned long *p) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
367 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
368 unsigned long x; |
|
44924
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
369 if (PyFloat_Check(v)) { |
|
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
370 PyErr_SetString(PyExc_TypeError, |
|
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
371 "int expected instead of float"); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
372 return -1; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
373 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
374 x = PyInt_AsUnsignedLongMask(v); |
|
53799
6d64cd69f384
Merged revisions 72344 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50788
diff
changeset
|
375 if (x == (unsigned long)-1 && PyErr_Occurred()) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
376 return -1; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
377 *p = x; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
378 return 0; |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
381 #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
|
382 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
383 /* Same, but handling native long long. */ |
|
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 static int |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
386 get_longlong(PyObject *v, PY_LONG_LONG *p) |
|
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 PY_LONG_LONG x; |
|
44924
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
389 if (PyFloat_Check(v)) { |
|
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
390 PyErr_SetString(PyExc_TypeError, |
|
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
391 "int expected instead of float"); |
|
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
392 return -1; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
393 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
394 x = PyInt_AsUnsignedLongLongMask(v); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
395 if (x == -1 && PyErr_Occurred()) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
396 return -1; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
397 *p = x; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
398 return 0; |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
401 /* Same, but handling native unsigned long long. */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
402 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
403 static int |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
404 get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
405 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
406 unsigned PY_LONG_LONG x; |
|
44924
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
407 if (PyFloat_Check(v)) { |
|
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
408 PyErr_SetString(PyExc_TypeError, |
|
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
409 "int expected instead of float"); |
|
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
410 return -1; |
|
a8c74125376d
Invert the checks in get_[u]long and get_[u]longlong. The intent was
Thomas Heller <theller@ctypes.org>
parents:
44712
diff
changeset
|
411 } |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
412 x = PyInt_AsUnsignedLongLongMask(v); |
|
53799
6d64cd69f384
Merged revisions 72344 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50788
diff
changeset
|
413 if (x == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred()) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
414 return -1; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
415 *p = x; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
416 return 0; |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
419 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
420 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
421 /***************************************************************** |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
422 * Integer fields, with bitfield support |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
423 */ |
|
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 /* how to decode the size field, for integer get/set functions */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
426 #define LOW_BIT(x) ((x) & 0xFFFF) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
427 #define NUM_BITS(x) ((x) >> 16) |
|
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 /* This seems nore a compiler issue than a Windows/non-Windows one */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
430 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
431 # define BIT_MASK(size) ((1 << NUM_BITS(size))-1) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
432 #else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
433 # define BIT_MASK(size) ((1LL << NUM_BITS(size))-1) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
434 #endif |
|
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 /* This macro CHANGES the first parameter IN PLACE. For proper sign handling, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
437 we must first shift left, then right. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
438 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
439 #define GET_BITFIELD(v, size) \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
440 if (NUM_BITS(size)) { \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
441 v <<= (sizeof(v)*8 - LOW_BIT(size) - NUM_BITS(size)); \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
442 v >>= (sizeof(v)*8 - NUM_BITS(size)); \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
443 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
444 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
445 /* This macro RETURNS the first parameter with the bit field CHANGED. */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
446 #define SET(x, v, size) \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
447 (NUM_BITS(size) ? \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
448 ( ( x & ~(BIT_MASK(size) << LOW_BIT(size)) ) | ( (v & BIT_MASK(size)) << LOW_BIT(size) ) ) \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
449 : v) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
450 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
451 /* byte swapping macros */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
452 #define SWAP_2(v) \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
453 ( ( (v >> 8) & 0x00FF) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
454 ( (v << 8) & 0xFF00) ) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
455 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
456 #define SWAP_4(v) \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
457 ( ( (v & 0x000000FF) << 24 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
458 ( (v & 0x0000FF00) << 8 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
459 ( (v & 0x00FF0000) >> 8 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
460 ( ((v >> 24) & 0xFF)) ) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
461 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
462 #ifdef _MSC_VER |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
463 #define SWAP_8(v) \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
464 ( ( (v & 0x00000000000000FFL) << 56 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
465 ( (v & 0x000000000000FF00L) << 40 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
466 ( (v & 0x0000000000FF0000L) << 24 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
467 ( (v & 0x00000000FF000000L) << 8 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
468 ( (v & 0x000000FF00000000L) >> 8 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
469 ( (v & 0x0000FF0000000000L) >> 24 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
470 ( (v & 0x00FF000000000000L) >> 40 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
471 ( ((v >> 56) & 0xFF)) ) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
472 #else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
473 #define SWAP_8(v) \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
474 ( ( (v & 0x00000000000000FFLL) << 56 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
475 ( (v & 0x000000000000FF00LL) << 40 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
476 ( (v & 0x0000000000FF0000LL) << 24 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
477 ( (v & 0x00000000FF000000LL) << 8 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
478 ( (v & 0x000000FF00000000LL) >> 8 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
479 ( (v & 0x0000FF0000000000LL) >> 24 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
480 ( (v & 0x00FF000000000000LL) >> 40 ) | \ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
481 ( ((v >> 56) & 0xFF)) ) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
482 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
483 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
484 #define SWAP_INT SWAP_4 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
485 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
486 #if SIZEOF_LONG == 4 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
487 # define SWAP_LONG SWAP_4 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
488 #elif SIZEOF_LONG == 8 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
489 # define SWAP_LONG SWAP_8 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
490 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
491 /***************************************************************** |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
492 * The setter methods return an object which must be kept alive, to keep the |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
493 * data valid which has been stored in the memory block. The ctypes object |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
494 * instance inserts this object into its 'b_objects' list. |
|
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 * For simple Python types like integers or characters, there is nothing that |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
497 * has to been kept alive, so Py_None is returned in these cases. But this |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
498 * makes inspecting the 'b_objects' list, which is accessible from Python for |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
499 * debugging, less useful. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
500 * |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
501 * So, defining the _CTYPES_DEBUG_KEEP symbol returns the original value |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
502 * instead of Py_None. |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
505 #ifdef _CTYPES_DEBUG_KEEP |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
506 #define _RET(x) Py_INCREF(x); return x |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
507 #else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
508 #define _RET(X) Py_INCREF(Py_None); return Py_None |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
509 #endif |
|
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 /***************************************************************** |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
512 * integer accessor methods, supporting bit fields |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
513 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
514 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
515 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
516 b_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
517 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
518 long val; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
519 if (get_long(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
520 return NULL; |
|
37498
48d12def32b3
Explicitely use 'signed char', to avoid problems on platforms with unsigned char type.
Thomas Heller <theller@ctypes.org>
parents:
37106
diff
changeset
|
521 *(signed char *)ptr = (signed char)SET(*(signed char *)ptr, (signed char)val, size); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
522 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
523 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
524 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
525 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
526 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
527 b_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
528 { |
|
37498
48d12def32b3
Explicitely use 'signed char', to avoid problems on platforms with unsigned char type.
Thomas Heller <theller@ctypes.org>
parents:
37106
diff
changeset
|
529 signed char val = *(signed char *)ptr; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
530 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
531 return PyInt_FromLong(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
532 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
533 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
534 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
535 B_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
536 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
537 unsigned long val; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
538 if (get_ulong(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
539 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
540 *(unsigned char *)ptr = (unsigned char)SET(*(unsigned char*)ptr, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
541 (unsigned short)val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
542 _RET(value); |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
546 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
547 B_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
548 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
549 unsigned char val = *(unsigned char *)ptr; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
550 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
551 return PyInt_FromLong(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
552 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
553 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
554 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
555 h_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
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 long val; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
558 short x; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
559 if (get_long(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
560 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
561 memcpy(&x, ptr, sizeof(x)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
562 x = SET(x, (short)val, size); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
563 memcpy(ptr, &x, sizeof(x)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
564 _RET(value); |
|
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 |
|
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 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
569 h_set_sw(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
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 long val; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
572 short field; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
573 if (get_long(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
574 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
575 memcpy(&field, ptr, sizeof(field)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
576 field = SWAP_2(field); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
577 field = SET(field, (short)val, size); |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
578 field = SWAP_2(field); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
579 memcpy(ptr, &field, sizeof(field)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
580 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
581 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
582 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
583 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
584 h_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
585 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
586 short val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
587 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
588 GET_BITFIELD(val, size); |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
589 return PyInt_FromLong((long)val); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
590 } |
|
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 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
593 h_get_sw(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
594 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
595 short val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
596 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
597 val = SWAP_2(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
598 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
599 return PyInt_FromLong(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
600 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
601 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
602 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
603 H_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
604 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
605 unsigned long val; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
606 unsigned short x; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
607 if (get_ulong(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
608 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
609 memcpy(&x, ptr, sizeof(x)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
610 x = SET(x, (unsigned short)val, size); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
611 memcpy(ptr, &x, sizeof(x)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
612 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
613 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
614 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
615 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
616 H_set_sw(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
617 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
618 unsigned long val; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
619 unsigned short field; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
620 if (get_ulong(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
621 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
622 memcpy(&field, ptr, sizeof(field)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
623 field = SWAP_2(field); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
624 field = SET(field, (unsigned short)val, size); |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
625 field = SWAP_2(field); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
626 memcpy(ptr, &field, sizeof(field)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
627 _RET(value); |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
630 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
631 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
632 H_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
633 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
634 unsigned short val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
635 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
636 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
637 return PyInt_FromLong(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
638 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
639 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
640 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
641 H_get_sw(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
642 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
643 unsigned short val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
644 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
645 val = SWAP_2(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
646 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
647 return PyInt_FromLong(val); |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
650 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
651 i_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
652 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
653 long val; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
654 int x; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
655 if (get_long(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
656 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
657 memcpy(&x, ptr, sizeof(x)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
658 x = SET(x, (int)val, size); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
659 memcpy(ptr, &x, sizeof(x)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
660 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
661 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
662 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
663 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
664 i_set_sw(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
665 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
666 long val; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
667 int field; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
668 if (get_long(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
669 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
670 memcpy(&field, ptr, sizeof(field)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
671 field = SWAP_INT(field); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
672 field = SET(field, (int)val, size); |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
673 field = SWAP_INT(field); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
674 memcpy(ptr, &field, sizeof(field)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
675 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
676 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
677 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
678 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
679 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
680 i_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
681 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
682 int val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
683 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
684 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
685 return PyInt_FromLong(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
686 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
687 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
688 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
689 i_get_sw(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
690 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
691 int val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
692 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
693 val = SWAP_INT(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
694 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
695 return PyInt_FromLong(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
696 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
697 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
698 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
699 /* short BOOL - VARIANT_BOOL */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
700 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
701 vBOOL_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
702 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
703 switch (PyObject_IsTrue(value)) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
704 case -1: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
705 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
706 case 0: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
707 *(short int *)ptr = VARIANT_FALSE; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
708 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
709 default: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
710 *(short int *)ptr = VARIANT_TRUE; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
711 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
712 } |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
715 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
716 vBOOL_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
717 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
718 return PyBool_FromLong((long)*(short int *)ptr); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
719 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
720 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
721 |
|
41167
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
722 #ifdef HAVE_C99_BOOL |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
723 #define BOOL_TYPE _Bool |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
724 #else |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
725 #define BOOL_TYPE char |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
726 #undef SIZEOF__BOOL |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
727 #define SIZEOF__BOOL 1 |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
728 #endif |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
729 |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
730 static PyObject * |
|
45672
d41a4206405c
Issue 1872: Changed the struct module typecode from 't' to '?', for
Thomas Heller <theller@ctypes.org>
parents:
44924
diff
changeset
|
731 bool_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
41167
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
732 { |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
733 switch (PyObject_IsTrue(value)) { |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
734 case -1: |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
735 return NULL; |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
736 case 0: |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
737 *(BOOL_TYPE *)ptr = 0; |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
738 _RET(value); |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
739 default: |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
740 *(BOOL_TYPE *)ptr = 1; |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
741 _RET(value); |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
742 } |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
743 } |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
744 |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
745 static PyObject * |
|
45672
d41a4206405c
Issue 1872: Changed the struct module typecode from 't' to '?', for
Thomas Heller <theller@ctypes.org>
parents:
44924
diff
changeset
|
746 bool_get(void *ptr, Py_ssize_t size) |
|
41167
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
747 { |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
748 return PyBool_FromLong((long)*(BOOL_TYPE *)ptr); |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
749 } |
|
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
750 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
751 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
752 I_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
753 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
754 unsigned long val; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
755 unsigned int x; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
756 if (get_ulong(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
757 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
758 memcpy(&x, ptr, sizeof(x)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
759 x = SET(x, (unsigned int)val, size); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
760 memcpy(ptr, &x, sizeof(x)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
761 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
762 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
763 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
764 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
765 I_set_sw(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
766 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
767 unsigned long val; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
768 unsigned int field; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
769 if (get_ulong(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
770 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
771 memcpy(&field, ptr, sizeof(field)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
772 field = (unsigned int)SET(field, (unsigned int)val, size); |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
773 field = SWAP_INT(field); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
774 memcpy(ptr, &field, sizeof(field)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
775 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
776 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
777 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
778 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
779 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
780 I_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
781 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
782 unsigned int val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
783 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
784 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
785 return PyLong_FromUnsignedLong(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
786 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
787 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
788 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
789 I_get_sw(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
790 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
791 unsigned int val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
792 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
793 val = SWAP_INT(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
794 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
795 return PyLong_FromUnsignedLong(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
796 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
797 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
798 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
799 l_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
800 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
801 long val; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
802 long x; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
803 if (get_long(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
804 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
805 memcpy(&x, ptr, sizeof(x)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
806 x = SET(x, val, size); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
807 memcpy(ptr, &x, sizeof(x)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
808 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
809 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
810 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
811 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
812 l_set_sw(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
813 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
814 long val; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
815 long field; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
816 if (get_long(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
817 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
818 memcpy(&field, ptr, sizeof(field)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
819 field = SWAP_LONG(field); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
820 field = (long)SET(field, val, size); |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
821 field = SWAP_LONG(field); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
822 memcpy(ptr, &field, sizeof(field)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
823 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
824 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
825 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
826 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
827 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
828 l_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
829 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
830 long val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
831 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
832 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
833 return PyInt_FromLong(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
834 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
835 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
836 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
837 l_get_sw(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
838 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
839 long val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
840 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
841 val = SWAP_LONG(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
842 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
843 return PyInt_FromLong(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
844 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
845 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
846 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
847 L_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
848 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
849 unsigned long val; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
850 unsigned long x; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
851 if (get_ulong(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
852 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
853 memcpy(&x, ptr, sizeof(x)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
854 x = SET(x, val, size); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
855 memcpy(ptr, &x, sizeof(x)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
856 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
857 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
858 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
859 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
860 L_set_sw(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
861 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
862 unsigned long val; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
863 unsigned long field; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
864 if (get_ulong(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
865 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
866 memcpy(&field, ptr, sizeof(field)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
867 field = SWAP_LONG(field); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
868 field = (unsigned long)SET(field, val, size); |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
869 field = SWAP_LONG(field); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
870 memcpy(ptr, &field, sizeof(field)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
871 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
872 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
873 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
874 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
875 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
876 L_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
877 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
878 unsigned long val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
879 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
880 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
881 return PyLong_FromUnsignedLong(val); |
|
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 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
885 L_get_sw(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
886 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
887 unsigned long val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
888 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
889 val = SWAP_LONG(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
890 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
891 return PyLong_FromUnsignedLong(val); |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
894 #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
|
895 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
896 q_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
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 PY_LONG_LONG val; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
899 PY_LONG_LONG x; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
900 if (get_longlong(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
901 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
902 memcpy(&x, ptr, sizeof(x)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
903 x = SET(x, val, size); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
904 memcpy(ptr, &x, sizeof(x)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
905 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
906 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
907 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
908 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
909 q_set_sw(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
910 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
911 PY_LONG_LONG val; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
912 PY_LONG_LONG field; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
913 if (get_longlong(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
914 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
915 memcpy(&field, ptr, sizeof(field)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
916 field = SWAP_8(field); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
917 field = (PY_LONG_LONG)SET(field, val, size); |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
918 field = SWAP_8(field); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
919 memcpy(ptr, &field, sizeof(field)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
920 _RET(value); |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
923 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
924 q_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
925 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
926 PY_LONG_LONG val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
927 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
928 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
929 return PyLong_FromLongLong(val); |
|
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 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
933 q_get_sw(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
934 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
935 PY_LONG_LONG val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
936 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
937 val = SWAP_8(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
938 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
939 return PyLong_FromLongLong(val); |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
942 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
943 Q_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
944 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
945 unsigned PY_LONG_LONG val; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
946 unsigned PY_LONG_LONG x; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
947 if (get_ulonglong(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
948 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
949 memcpy(&x, ptr, sizeof(x)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
950 x = SET(x, val, size); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
951 memcpy(ptr, &x, sizeof(x)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
952 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
953 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
954 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
955 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
956 Q_set_sw(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
957 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
958 unsigned PY_LONG_LONG val; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
959 unsigned PY_LONG_LONG field; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
960 if (get_ulonglong(value, &val) < 0) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
961 return NULL; |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
962 memcpy(&field, ptr, sizeof(field)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
963 field = SWAP_8(field); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
964 field = (unsigned PY_LONG_LONG)SET(field, val, size); |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
965 field = SWAP_8(field); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
966 memcpy(ptr, &field, sizeof(field)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
967 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
968 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
969 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
970 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
971 Q_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
972 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
973 unsigned PY_LONG_LONG val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
974 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
975 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
976 return PyLong_FromUnsignedLongLong(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
977 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
978 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
979 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
980 Q_get_sw(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
981 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
982 unsigned PY_LONG_LONG val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
983 memcpy(&val, ptr, sizeof(val)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
984 val = SWAP_8(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
985 GET_BITFIELD(val, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
986 return PyLong_FromUnsignedLongLong(val); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
987 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
988 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
989 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
990 /***************************************************************** |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
991 * non-integer accessor methods, not supporting bit fields |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
992 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
993 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
994 |
|
43278
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
995 static PyObject * |
|
44712
2c9bc61d4f73
Use 'g' instead of 'D' as the ctypes typecode for c_longdouble, for
Thomas Heller <theller@ctypes.org>
parents:
44335
diff
changeset
|
996 g_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
43278
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
997 { |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
998 long double x; |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
999 |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1000 x = PyFloat_AsDouble(value); |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1001 if (x == -1 && PyErr_Occurred()) { |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1002 PyErr_Format(PyExc_TypeError, |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1003 " float expected instead of %s instance", |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1004 value->ob_type->tp_name); |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1005 return NULL; |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1006 } |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1007 memcpy(ptr, &x, sizeof(long double)); |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1008 _RET(value); |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1009 } |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1010 |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1011 static PyObject * |
|
44712
2c9bc61d4f73
Use 'g' instead of 'D' as the ctypes typecode for c_longdouble, for
Thomas Heller <theller@ctypes.org>
parents:
44335
diff
changeset
|
1012 g_get(void *ptr, Py_ssize_t size) |
|
43278
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1013 { |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1014 long double val; |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1015 memcpy(&val, ptr, sizeof(long double)); |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1016 return PyFloat_FromDouble(val); |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1019 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1020 d_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1021 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1022 double x; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1023 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1024 x = PyFloat_AsDouble(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1025 if (x == -1 && PyErr_Occurred()) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1026 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
|
1027 " float expected instead of %s instance", |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1028 value->ob_type->tp_name); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1029 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1030 } |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
1031 memcpy(ptr, &x, sizeof(double)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1032 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1033 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1034 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1035 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1036 d_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1037 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
1038 double val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
1039 memcpy(&val, ptr, sizeof(val)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
1040 return PyFloat_FromDouble(val); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1041 } |
|
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 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1044 d_set_sw(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1045 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1046 double x; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1047 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1048 x = PyFloat_AsDouble(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1049 if (x == -1 && PyErr_Occurred()) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1050 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
|
1051 " float expected instead of %s instance", |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1052 value->ob_type->tp_name); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1053 return NULL; |
|
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 #ifdef WORDS_BIGENDIAN |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1056 if (_PyFloat_Pack8(x, (unsigned char *)ptr, 1)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1057 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1058 #else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1059 if (_PyFloat_Pack8(x, (unsigned char *)ptr, 0)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1060 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1061 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1062 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1063 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1064 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1065 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1066 d_get_sw(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1067 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1068 #ifdef WORDS_BIGENDIAN |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1069 return PyFloat_FromDouble(_PyFloat_Unpack8(ptr, 1)); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1070 #else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1071 return PyFloat_FromDouble(_PyFloat_Unpack8(ptr, 0)); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1072 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1073 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1074 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1075 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1076 f_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1077 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1078 float x; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1079 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1080 x = (float)PyFloat_AsDouble(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1081 if (x == -1 && PyErr_Occurred()) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1082 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
|
1083 " float expected instead of %s instance", |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1084 value->ob_type->tp_name); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1085 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1086 } |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
1087 memcpy(ptr, &x, sizeof(x)); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1088 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1089 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1090 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1091 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1092 f_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1093 { |
|
37106
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
1094 float val; |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
1095 memcpy(&val, ptr, sizeof(val)); |
|
d860311f8a97
Accessing unaligned structure fields works now on all architectures.
Thomas Heller <theller@ctypes.org>
parents:
37034
diff
changeset
|
1096 return PyFloat_FromDouble(val); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1097 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1098 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1099 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1100 f_set_sw(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1101 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1102 float x; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1103 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1104 x = (float)PyFloat_AsDouble(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1105 if (x == -1 && PyErr_Occurred()) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1106 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
|
1107 " float expected instead of %s instance", |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1108 value->ob_type->tp_name); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1109 return NULL; |
|
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 #ifdef WORDS_BIGENDIAN |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1112 if (_PyFloat_Pack4(x, (unsigned char *)ptr, 1)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1113 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1114 #else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1115 if (_PyFloat_Pack4(x, (unsigned char *)ptr, 0)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1116 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1117 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1118 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1119 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1120 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1121 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1122 f_get_sw(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1123 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1124 #ifdef WORDS_BIGENDIAN |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1125 return PyFloat_FromDouble(_PyFloat_Unpack4(ptr, 1)); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1126 #else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1127 return PyFloat_FromDouble(_PyFloat_Unpack4(ptr, 0)); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1128 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1129 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1130 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1131 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1132 py_object refcounts: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1133 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1134 1. If we have a py_object instance, O_get must Py_INCREF the returned |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1135 object, of course. If O_get is called from a function result, no py_object |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1136 instance is created - so callproc.c::GetResult has to call Py_DECREF. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1137 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1138 2. The memory block in py_object owns a refcount. So, py_object must call |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1139 Py_DECREF on destruction. Maybe only when b_needsfree is non-zero. |
|
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 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1142 O_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1143 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1144 PyObject *ob = *(PyObject **)ptr; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1145 if (ob == NULL) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1146 if (!PyErr_Occurred()) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1147 /* Set an error if not yet set */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1148 PyErr_SetString(PyExc_ValueError, |
|
39523
d23b667f04da
The __repr__ method of a NULL py_object does no longer raise an
Thomas Heller <theller@ctypes.org>
parents:
39454
diff
changeset
|
1149 "PyObject is NULL"); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1150 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1151 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1152 Py_INCREF(ob); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1153 return ob; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1154 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1155 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1156 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1157 O_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1158 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1159 /* Hm, does the memory block need it's own refcount or not? */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1160 *(PyObject **)ptr = value; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1161 Py_INCREF(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1162 return value; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1163 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1164 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1165 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1166 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1167 c_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1168 { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1169 if (!PyString_Check(value) || (1 != PyString_Size(value))) { |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1170 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
|
1171 "one character string expected"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1172 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1173 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1174 *(char *)ptr = PyString_AS_STRING(value)[0]; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1175 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1176 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1177 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1178 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1179 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1180 c_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1181 { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1182 return PyString_FromStringAndSize((char *)ptr, 1); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1183 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1184 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1185 #ifdef CTYPES_UNICODE |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1186 /* u - a single wchar_t character */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1187 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1188 u_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1189 { |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1190 Py_ssize_t len; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1191 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1192 if (PyString_Check(value)) { |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1193 value = PyUnicode_FromEncodedObject(value, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1194 conversion_mode_encoding, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1195 conversion_mode_errors); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1196 if (!value) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1197 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1198 } else if (!PyUnicode_Check(value)) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1199 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
|
1200 "unicode string expected instead of %s instance", |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1201 value->ob_type->tp_name); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1202 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1203 } else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1204 Py_INCREF(value); |
|
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 len = PyUnicode_GET_SIZE(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1207 if (len != 1) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1208 Py_DECREF(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1209 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
|
1210 "one character unicode string expected"); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1211 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1212 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1213 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1214 *(wchar_t *)ptr = PyUnicode_AS_UNICODE(value)[0]; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1215 Py_DECREF(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1216 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1217 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1218 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1219 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1220 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1221 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1222 u_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1223 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1224 return PyUnicode_FromWideChar((wchar_t *)ptr, 1); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1225 } |
|
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 /* U - a unicode string */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1228 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1229 U_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1230 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1231 PyObject *result; |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1232 Py_ssize_t len; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1233 Py_UNICODE *p; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1234 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1235 size /= sizeof(wchar_t); /* we count character units here, not bytes */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1236 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1237 result = PyUnicode_FromWideChar((wchar_t *)ptr, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1238 if (!result) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1239 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1240 /* We need 'result' to be able to count the characters with wcslen, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1241 since ptr may not be NUL terminated. If the length is smaller (if |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1242 it was actually NUL terminated, we construct a new one and throw |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1243 away the result. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1244 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1245 /* chop off at the first NUL character, if any. */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1246 p = PyUnicode_AS_UNICODE(result); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1247 for (len = 0; len < size; ++len) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1248 if (!p[len]) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1249 break; |
|
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 if (len < size) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1252 PyObject *ob = PyUnicode_FromWideChar((wchar_t *)ptr, len); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1253 Py_DECREF(result); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1254 return ob; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1255 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1256 return result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1257 } |
|
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 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1260 U_set(void *ptr, PyObject *value, 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
|
1261 { |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1262 Py_ssize_t size; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1263 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1264 /* It's easier to calculate in characters than in bytes */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1265 length /= sizeof(wchar_t); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1266 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1267 if (PyString_Check(value)) { |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1268 value = PyUnicode_FromEncodedObject(value, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1269 conversion_mode_encoding, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1270 conversion_mode_errors); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1271 if (!value) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1272 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1273 } else if (!PyUnicode_Check(value)) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1274 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
|
1275 "unicode string expected instead of %s instance", |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1276 value->ob_type->tp_name); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1277 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1278 } else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1279 Py_INCREF(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1280 size = PyUnicode_GET_SIZE(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1281 if (size > length) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1282 PyErr_Format(PyExc_ValueError, |
|
41999
b4f4ee84c30d
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
Thomas Heller <theller@ctypes.org>
parents:
41998
diff
changeset
|
1283 #if (PY_VERSION_HEX < 0x02050000) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1284 "string too long (%d, maximum length %d)", |
|
41999
b4f4ee84c30d
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
Thomas Heller <theller@ctypes.org>
parents:
41998
diff
changeset
|
1285 #else |
|
b4f4ee84c30d
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
Thomas Heller <theller@ctypes.org>
parents:
41998
diff
changeset
|
1286 "string too long (%zd, maximum length %zd)", |
|
b4f4ee84c30d
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
Thomas Heller <theller@ctypes.org>
parents:
41998
diff
changeset
|
1287 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1288 size, length); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1289 Py_DECREF(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1290 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1291 } else if (size < length-1) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1292 /* copy terminating NUL character if there is space */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1293 size += 1; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1294 PyUnicode_AsWideChar((PyUnicodeObject *)value, (wchar_t *)ptr, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1295 return value; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1296 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1297 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1298 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1299 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1300 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1301 s_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1302 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1303 PyObject *result; |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1304 size_t slen; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1305 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1306 result = PyString_FromString((char *)ptr); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1307 if (!result) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1308 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1309 /* chop off at the first NUL character, if any. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1310 * On error, result will be deallocated and set to NULL. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1311 */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1312 slen = strlen(PyString_AS_STRING(result)); |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1313 size = min(size, (Py_ssize_t)slen); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1314 if (result->ob_refcnt == 1) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1315 /* shorten the result */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1316 _PyString_Resize(&result, size); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1317 return result; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1318 } else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1319 /* cannot shorten the result */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1320 return PyString_FromStringAndSize(ptr, size); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1321 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1322 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1323 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1324 s_set(void *ptr, PyObject *value, 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
|
1325 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1326 char *data; |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1327 Py_ssize_t size; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1328 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1329 data = PyString_AsString(value); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1330 if (!data) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1331 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1332 size = strlen(data); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1333 if (size < length) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1334 /* This will copy the leading NUL character |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1335 * if there is space for it. |
|
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 ++size; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1338 } else if (size > length) { |
|
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_ValueError, |
|
41999
b4f4ee84c30d
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
Thomas Heller <theller@ctypes.org>
parents:
41998
diff
changeset
|
1340 #if (PY_VERSION_HEX < 0x02050000) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1341 "string too long (%d, maximum length %d)", |
|
41999
b4f4ee84c30d
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
Thomas Heller <theller@ctypes.org>
parents:
41998
diff
changeset
|
1342 #else |
|
b4f4ee84c30d
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
Thomas Heller <theller@ctypes.org>
parents:
41998
diff
changeset
|
1343 "string too long (%zd, maximum length %zd)", |
|
b4f4ee84c30d
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
Thomas Heller <theller@ctypes.org>
parents:
41998
diff
changeset
|
1344 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1345 size, length); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1346 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1347 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1348 /* Also copy the terminating NUL character if there is space */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1349 memcpy((char *)ptr, data, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1350 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1351 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1352 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1353 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1354 z_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1355 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1356 if (value == Py_None) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1357 *(char **)ptr = NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1358 Py_INCREF(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1359 return value; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1360 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1361 if (PyString_Check(value)) { |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1362 *(char **)ptr = PyString_AS_STRING(value); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1363 Py_INCREF(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1364 return value; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1365 } else if (PyUnicode_Check(value)) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1366 PyObject *str = PyUnicode_AsEncodedString(value, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1367 conversion_mode_encoding, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1368 conversion_mode_errors); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1369 if (str == NULL) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1370 return NULL; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1371 *(char **)ptr = PyString_AS_STRING(str); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1372 return str; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1373 } else if (PyInt_Check(value) || PyLong_Check(value)) { |
|
39679
3bfc8bb4e726
Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents:
39523
diff
changeset
|
1374 #if SIZEOF_VOID_P == SIZEOF_LONG_LONG |
|
3bfc8bb4e726
Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents:
39523
diff
changeset
|
1375 *(char **)ptr = (char *)PyInt_AsUnsignedLongLongMask(value); |
|
3bfc8bb4e726
Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents:
39523
diff
changeset
|
1376 #else |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1377 *(char **)ptr = (char *)PyInt_AsUnsignedLongMask(value); |
|
39679
3bfc8bb4e726
Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents:
39523
diff
changeset
|
1378 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1379 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1380 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1381 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
|
1382 "string or integer address expected instead of %s instance", |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1383 value->ob_type->tp_name); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1384 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1385 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1386 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1387 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1388 z_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1389 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1390 /* XXX What about invalid pointers ??? */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1391 if (*(void **)ptr) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1392 #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
|
1393 if (IsBadStringPtrA(*(char **)ptr, -1)) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1394 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
|
1395 "invalid string pointer %p", |
|
41564
82e79983cb0c
When accessing the .value attribute of a c_wchar_p instance, and the
Thomas Heller <theller@ctypes.org>
parents:
41562
diff
changeset
|
1396 *(char **)ptr); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1397 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1398 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1399 #endif |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1400 return PyString_FromString(*(char **)ptr); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1401 } else { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1402 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
|
1403 return Py_None; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1404 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1405 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1406 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1407 #ifdef CTYPES_UNICODE |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1408 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1409 Z_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1410 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1411 if (value == Py_None) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1412 *(wchar_t **)ptr = NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1413 Py_INCREF(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1414 return value; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1415 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1416 if (PyString_Check(value)) { |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1417 value = PyUnicode_FromEncodedObject(value, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1418 conversion_mode_encoding, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1419 conversion_mode_errors); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1420 if (!value) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1421 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1422 } else if (PyInt_Check(value) || PyLong_Check(value)) { |
|
39679
3bfc8bb4e726
Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents:
39523
diff
changeset
|
1423 #if SIZEOF_VOID_P == SIZEOF_LONG_LONG |
|
3bfc8bb4e726
Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents:
39523
diff
changeset
|
1424 *(wchar_t **)ptr = (wchar_t *)PyInt_AsUnsignedLongLongMask(value); |
|
3bfc8bb4e726
Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents:
39523
diff
changeset
|
1425 #else |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1426 *(wchar_t **)ptr = (wchar_t *)PyInt_AsUnsignedLongMask(value); |
|
39679
3bfc8bb4e726
Port _ctypes.pyd to win64 on AMD64.
Thomas Heller <theller@ctypes.org>
parents:
39523
diff
changeset
|
1427 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1428 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
|
1429 return Py_None; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1430 } else if (!PyUnicode_Check(value)) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1431 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
|
1432 "unicode string or integer address expected instead of %s instance", |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1433 value->ob_type->tp_name); |
|
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 } else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1436 Py_INCREF(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1437 #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
|
1438 /* HAVE_USABLE_WCHAR_T means that Py_UNICODE and wchar_t is the same |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1439 type. So we can copy directly. Hm, are unicode objects always NUL |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1440 terminated in Python, internally? |
|
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 *(wchar_t **)ptr = PyUnicode_AS_UNICODE(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1443 return value; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1444 #else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1445 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1446 /* We must create a wchar_t* buffer from the unicode object, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1447 and keep it alive */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1448 PyObject *keep; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1449 wchar_t *buffer; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1450 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1451 int size = PyUnicode_GET_SIZE(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1452 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
|
1453 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
|
1454 buffer = (wchar_t *)PyMem_Malloc(size); |
|
50788
e11c99e1e6e7
Merged revisions 68521,68527,68534-68536,68540,68547,68552,68563,68570,68572,68575,68579-68580,68584 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49341
diff
changeset
|
1455 if (!buffer) { |
|
e11c99e1e6e7
Merged revisions 68521,68527,68534-68536,68540,68547,68552,68563,68570,68572,68575,68579-68580,68584 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49341
diff
changeset
|
1456 Py_DECREF(value); |
|
41562
6a56aedbe280
Make sure to call PyErr_NoMemory() in several places where
Thomas Heller <theller@ctypes.org>
parents:
41278
diff
changeset
|
1457 return PyErr_NoMemory(); |
|
50788
e11c99e1e6e7
Merged revisions 68521,68527,68534-68536,68540,68547,68552,68563,68570,68572,68575,68579-68580,68584 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49341
diff
changeset
|
1458 } |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1459 memset(buffer, 0, size); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1460 keep = PyCObject_FromVoidPtr(buffer, PyMem_Free); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1461 if (!keep) { |
|
50788
e11c99e1e6e7
Merged revisions 68521,68527,68534-68536,68540,68547,68552,68563,68570,68572,68575,68579-68580,68584 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49341
diff
changeset
|
1462 Py_DECREF(value); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1463 PyMem_Free(buffer); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1464 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1465 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1466 *(wchar_t **)ptr = (wchar_t *)buffer; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1467 if (-1 == PyUnicode_AsWideChar((PyUnicodeObject *)value, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1468 buffer, PyUnicode_GET_SIZE(value))) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1469 Py_DECREF(value); |
|
37034
fff4eecdef45
Fix a leak that would happen under error conditions (found by Coverty).
Thomas Heller <theller@ctypes.org>
parents:
37004
diff
changeset
|
1470 Py_DECREF(keep); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1471 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1472 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1473 Py_DECREF(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1474 return keep; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1475 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1476 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1477 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1478 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1479 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1480 Z_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1481 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1482 wchar_t *p; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1483 p = *(wchar_t **)ptr; |
|
41564
82e79983cb0c
When accessing the .value attribute of a c_wchar_p instance, and the
Thomas Heller <theller@ctypes.org>
parents:
41562
diff
changeset
|
1484 if (p) { |
|
82e79983cb0c
When accessing the .value attribute of a c_wchar_p instance, and the
Thomas Heller <theller@ctypes.org>
parents:
41562
diff
changeset
|
1485 #if defined(MS_WIN32) && !defined(_WIN32_WCE) |
|
82e79983cb0c
When accessing the .value attribute of a c_wchar_p instance, and the
Thomas Heller <theller@ctypes.org>
parents:
41562
diff
changeset
|
1486 if (IsBadStringPtrW(*(wchar_t **)ptr, -1)) { |
|
82e79983cb0c
When accessing the .value attribute of a c_wchar_p instance, and the
Thomas Heller <theller@ctypes.org>
parents:
41562
diff
changeset
|
1487 PyErr_Format(PyExc_ValueError, |
|
82e79983cb0c
When accessing the .value attribute of a c_wchar_p instance, and the
Thomas Heller <theller@ctypes.org>
parents:
41562
diff
changeset
|
1488 "invalid string pointer %p", |
|
82e79983cb0c
When accessing the .value attribute of a c_wchar_p instance, and the
Thomas Heller <theller@ctypes.org>
parents:
41562
diff
changeset
|
1489 *(wchar_t **)ptr); |
|
82e79983cb0c
When accessing the .value attribute of a c_wchar_p instance, and the
Thomas Heller <theller@ctypes.org>
parents:
41562
diff
changeset
|
1490 return NULL; |
|
82e79983cb0c
When accessing the .value attribute of a c_wchar_p instance, and the
Thomas Heller <theller@ctypes.org>
parents:
41562
diff
changeset
|
1491 } |
|
82e79983cb0c
When accessing the .value attribute of a c_wchar_p instance, and the
Thomas Heller <theller@ctypes.org>
parents:
41562
diff
changeset
|
1492 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1493 return PyUnicode_FromWideChar(p, wcslen(p)); |
|
41564
82e79983cb0c
When accessing the .value attribute of a c_wchar_p instance, and the
Thomas Heller <theller@ctypes.org>
parents:
41562
diff
changeset
|
1494 } else { |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1495 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
|
1496 return Py_None; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1497 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1498 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1499 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1500 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1501 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1502 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1503 BSTR_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1504 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1505 BSTR bstr; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1506 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1507 /* convert value into a PyUnicodeObject or NULL */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1508 if (Py_None == value) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1509 value = NULL; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47473
diff
changeset
|
1510 } else if (PyString_Check(value)) { |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1511 value = PyUnicode_FromEncodedObject(value, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1512 conversion_mode_encoding, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1513 conversion_mode_errors); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1514 if (!value) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1515 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1516 } else if (PyUnicode_Check(value)) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1517 Py_INCREF(value); /* for the descref below */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1518 } else { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1519 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
|
1520 "unicode string expected instead of %s instance", |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1521 value->ob_type->tp_name); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1522 return NULL; |
|
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 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1525 /* create a BSTR from value */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1526 if (value) { |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1527 Py_ssize_t size = PyUnicode_GET_SIZE(value); |
|
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1528 if ((unsigned) size != size) { |
|
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1529 PyErr_SetString(PyExc_ValueError, "String too long for BSTR"); |
|
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1530 return NULL; |
|
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1531 } |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1532 bstr = SysAllocStringLen(PyUnicode_AS_UNICODE(value), |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1533 (unsigned)size); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1534 Py_DECREF(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1535 } else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1536 bstr = NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1537 |
|
41278
afb1c6cb2c88
Back out "Patch #1643874: memory leak in ctypes fixed."
Thomas Heller <theller@ctypes.org>
parents:
41167
diff
changeset
|
1538 /* free the previous contents, if any */ |
|
afb1c6cb2c88
Back out "Patch #1643874: memory leak in ctypes fixed."
Thomas Heller <theller@ctypes.org>
parents:
41167
diff
changeset
|
1539 if (*(BSTR *)ptr) |
|
afb1c6cb2c88
Back out "Patch #1643874: memory leak in ctypes fixed."
Thomas Heller <theller@ctypes.org>
parents:
41167
diff
changeset
|
1540 SysFreeString(*(BSTR *)ptr); |
|
afb1c6cb2c88
Back out "Patch #1643874: memory leak in ctypes fixed."
Thomas Heller <theller@ctypes.org>
parents:
41167
diff
changeset
|
1541 |
|
afb1c6cb2c88
Back out "Patch #1643874: memory leak in ctypes fixed."
Thomas Heller <theller@ctypes.org>
parents:
41167
diff
changeset
|
1542 /* and store it */ |
|
afb1c6cb2c88
Back out "Patch #1643874: memory leak in ctypes fixed."
Thomas Heller <theller@ctypes.org>
parents:
41167
diff
changeset
|
1543 *(BSTR *)ptr = bstr; |
|
40711
a5b269ce079d
Fix for #1643874: When calling SysAllocString, create a PyCObject
Thomas Heller <theller@ctypes.org>
parents:
39679
diff
changeset
|
1544 |
|
41278
afb1c6cb2c88
Back out "Patch #1643874: memory leak in ctypes fixed."
Thomas Heller <theller@ctypes.org>
parents:
41167
diff
changeset
|
1545 /* We don't need to keep any other object */ |
|
afb1c6cb2c88
Back out "Patch #1643874: memory leak in ctypes fixed."
Thomas Heller <theller@ctypes.org>
parents:
41167
diff
changeset
|
1546 _RET(value); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1547 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1548 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1549 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1550 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1551 BSTR_get(void *ptr, Py_ssize_t size) |
|
36897
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 BSTR p; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1554 p = *(BSTR *)ptr; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1555 if (p) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1556 return PyUnicode_FromWideChar(p, SysStringLen(p)); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1557 else { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1558 /* Hm, it seems NULL pointer and zero length string are the |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1559 same in BSTR, see Don Box, p 81 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1560 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1561 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
|
1562 return Py_None; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1563 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1564 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1565 #endif |
|
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 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1568 P_set(void *ptr, PyObject *value, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1569 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1570 void *v; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1571 if (value == Py_None) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1572 *(void **)ptr = NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1573 _RET(value); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1574 } |
|
39049
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1575 |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1576 if (!PyInt_Check(value) && !PyLong_Check(value)) { |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1577 PyErr_SetString(PyExc_TypeError, |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1578 "cannot be converted to pointer"); |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1579 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1580 } |
|
39049
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1581 |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1582 #if SIZEOF_VOID_P <= SIZEOF_LONG |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1583 v = (void *)PyInt_AsUnsignedLongMask(value); |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1584 #else |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1585 #ifndef HAVE_LONG_LONG |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1586 # error "PyLong_AsVoidPtr: sizeof(void*) > sizeof(long), but no long long" |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1587 #elif SIZEOF_LONG_LONG < SIZEOF_VOID_P |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1588 # error "PyLong_AsVoidPtr: sizeof(PY_LONG_LONG) < sizeof(void*)" |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1589 #endif |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1590 v = (void *)PyInt_AsUnsignedLongLongMask(value); |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1591 #endif |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1592 |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1593 if (PyErr_Occurred()) |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1594 return NULL; |
|
35c4fda47dfb
Fix bug #1518190: accept any integer or long value in the
Thomas Heller <theller@ctypes.org>
parents:
39002
diff
changeset
|
1595 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1596 *(void **)ptr = v; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1597 _RET(value); |
|
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 static PyObject * |
|
41998
7b84e8919b00
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
Thomas Heller <theller@ctypes.org>
parents:
41564
diff
changeset
|
1601 P_get(void *ptr, Py_ssize_t size) |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1602 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1603 if (*(void **)ptr == NULL) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1604 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
|
1605 return Py_None; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1606 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1607 return PyLong_FromVoidPtr(*(void **)ptr); |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1608 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1609 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1610 static struct fielddesc formattable[] = { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1611 { 's', s_set, s_get, &ffi_type_pointer}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1612 { 'b', b_set, b_get, &ffi_type_schar}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1613 { 'B', B_set, B_get, &ffi_type_uchar}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1614 { 'c', c_set, c_get, &ffi_type_schar}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1615 { 'd', d_set, d_get, &ffi_type_double, d_set_sw, d_get_sw}, |
|
44712
2c9bc61d4f73
Use 'g' instead of 'D' as the ctypes typecode for c_longdouble, for
Thomas Heller <theller@ctypes.org>
parents:
44335
diff
changeset
|
1616 { 'g', g_set, g_get, &ffi_type_longdouble}, |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1617 { 'f', f_set, f_get, &ffi_type_float, f_set_sw, f_get_sw}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1618 { 'h', h_set, h_get, &ffi_type_sshort, h_set_sw, h_get_sw}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1619 { 'H', H_set, H_get, &ffi_type_ushort, H_set_sw, H_get_sw}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1620 { 'i', i_set, i_get, &ffi_type_sint, i_set_sw, i_get_sw}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1621 { 'I', I_set, I_get, &ffi_type_uint, I_set_sw, I_get_sw}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1622 /* XXX Hm, sizeof(int) == sizeof(long) doesn't hold on every platform */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1623 /* As soon as we can get rid of the type codes, this is no longer a problem */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1624 #if SIZEOF_LONG == 4 |
|
43601
8a0167416223
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
Thomas Heller <theller@ctypes.org>
parents:
43279
diff
changeset
|
1625 { 'l', l_set, l_get, &ffi_type_sint32, l_set_sw, l_get_sw}, |
|
8a0167416223
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
Thomas Heller <theller@ctypes.org>
parents:
43279
diff
changeset
|
1626 { 'L', L_set, L_get, &ffi_type_uint32, L_set_sw, L_get_sw}, |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1627 #elif SIZEOF_LONG == 8 |
|
43601
8a0167416223
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
Thomas Heller <theller@ctypes.org>
parents:
43279
diff
changeset
|
1628 { 'l', l_set, l_get, &ffi_type_sint64, l_set_sw, l_get_sw}, |
|
8a0167416223
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
Thomas Heller <theller@ctypes.org>
parents:
43279
diff
changeset
|
1629 { 'L', L_set, L_get, &ffi_type_uint64, L_set_sw, L_get_sw}, |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1630 #else |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1631 # error |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1632 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1633 #ifdef HAVE_LONG_LONG |
|
43601
8a0167416223
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
Thomas Heller <theller@ctypes.org>
parents:
43279
diff
changeset
|
1634 #if SIZEOF_LONG_LONG == 8 |
|
8a0167416223
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
Thomas Heller <theller@ctypes.org>
parents:
43279
diff
changeset
|
1635 { 'q', q_set, q_get, &ffi_type_sint64, q_set_sw, q_get_sw}, |
|
8a0167416223
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
Thomas Heller <theller@ctypes.org>
parents:
43279
diff
changeset
|
1636 { 'Q', Q_set, Q_get, &ffi_type_uint64, Q_set_sw, Q_get_sw}, |
|
8a0167416223
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
Thomas Heller <theller@ctypes.org>
parents:
43279
diff
changeset
|
1637 #else |
|
8a0167416223
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
Thomas Heller <theller@ctypes.org>
parents:
43279
diff
changeset
|
1638 # error |
|
8a0167416223
Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
Thomas Heller <theller@ctypes.org>
parents:
43279
diff
changeset
|
1639 #endif |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1640 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1641 { 'P', P_set, P_get, &ffi_type_pointer}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1642 { 'z', z_set, z_get, &ffi_type_pointer}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1643 #ifdef CTYPES_UNICODE |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1644 { 'u', u_set, u_get, NULL}, /* ffi_type set later */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1645 { 'U', U_set, U_get, &ffi_type_pointer}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1646 { 'Z', Z_set, Z_get, &ffi_type_pointer}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1647 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1648 #ifdef MS_WIN32 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1649 { 'X', BSTR_set, BSTR_get, &ffi_type_pointer}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1650 { 'v', vBOOL_set, vBOOL_get, &ffi_type_sshort}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1651 #endif |
|
41167
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
1652 #if SIZEOF__BOOL == 1 |
|
45672
d41a4206405c
Issue 1872: Changed the struct module typecode from 't' to '?', for
Thomas Heller <theller@ctypes.org>
parents:
44924
diff
changeset
|
1653 { '?', bool_set, bool_get, &ffi_type_uchar}, /* Also fallback for no native _Bool support */ |
|
41167
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
1654 #elif SIZEOF__BOOL == SIZEOF_SHORT |
|
45672
d41a4206405c
Issue 1872: Changed the struct module typecode from 't' to '?', for
Thomas Heller <theller@ctypes.org>
parents:
44924
diff
changeset
|
1655 { '?', bool_set, bool_get, &ffi_type_ushort}, |
|
41167
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
1656 #elif SIZEOF__BOOL == SIZEOF_INT |
|
45672
d41a4206405c
Issue 1872: Changed the struct module typecode from 't' to '?', for
Thomas Heller <theller@ctypes.org>
parents:
44924
diff
changeset
|
1657 { '?', bool_set, bool_get, &ffi_type_uint, I_set_sw, I_get_sw}, |
|
41167
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
1658 #elif SIZEOF__BOOL == SIZEOF_LONG |
|
45672
d41a4206405c
Issue 1872: Changed the struct module typecode from 't' to '?', for
Thomas Heller <theller@ctypes.org>
parents:
44924
diff
changeset
|
1659 { '?', bool_set, bool_get, &ffi_type_ulong, L_set_sw, L_get_sw}, |
|
41167
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
1660 #elif SIZEOF__BOOL == SIZEOF_LONG_LONG |
|
45672
d41a4206405c
Issue 1872: Changed the struct module typecode from 't' to '?', for
Thomas Heller <theller@ctypes.org>
parents:
44924
diff
changeset
|
1661 { '?', bool_set, bool_get, &ffi_type_ulong, Q_set_sw, Q_get_sw}, |
|
41167
493cae705f91
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
Thomas Heller <theller@ctypes.org>
parents:
40711
diff
changeset
|
1662 #endif /* SIZEOF__BOOL */ |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1663 { 'O', O_set, O_get, &ffi_type_pointer}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1664 { 0, NULL, NULL, NULL}, |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1665 }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1666 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1667 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1668 Ideas: Implement VARIANT in this table, using 'V' code. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1669 Use '?' as code for BOOL. |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1670 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1671 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1672 struct fielddesc * |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1673 getentry(char *fmt) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1674 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1675 static int initialized = 0; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1676 struct fielddesc *table = formattable; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1677 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1678 if (!initialized) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1679 initialized = 1; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1680 #ifdef CTYPES_UNICODE |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1681 if (sizeof(wchar_t) == sizeof(short)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1682 getentry("u")->pffi_type = &ffi_type_sshort; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1683 else if (sizeof(wchar_t) == sizeof(int)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1684 getentry("u")->pffi_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
|
1685 else if (sizeof(wchar_t) == sizeof(long)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1686 getentry("u")->pffi_type = &ffi_type_slong; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1687 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1688 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1689 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1690 for (; table->code; ++table) { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1691 if (table->code == fmt[0]) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1692 return table; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1693 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1694 return NULL; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1695 } |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1696 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1697 typedef struct { char c; char x; } s_char; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1698 typedef struct { char c; short x; } s_short; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1699 typedef struct { char c; int x; } s_int; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1700 typedef struct { char c; long x; } s_long; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1701 typedef struct { char c; float x; } s_float; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1702 typedef struct { char c; double x; } s_double; |
|
43278
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1703 typedef struct { char c; long double x; } s_long_double; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1704 typedef struct { char c; char *x; } s_char_p; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1705 typedef struct { char c; void *x; } s_void_p; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1706 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1707 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1708 #define CHAR_ALIGN (sizeof(s_char) - sizeof(char)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1709 #define SHORT_ALIGN (sizeof(s_short) - sizeof(short)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1710 #define INT_ALIGN (sizeof(s_int) - sizeof(int)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1711 #define LONG_ALIGN (sizeof(s_long) - sizeof(long)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1712 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1713 #define FLOAT_ALIGN (sizeof(s_float) - sizeof(float)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1714 #define DOUBLE_ALIGN (sizeof(s_double) - sizeof(double)) |
|
43278
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1715 #define LONGDOUBLE_ALIGN (sizeof(s_long_double) - sizeof(long double)) |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1716 |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1717 /* #define CHAR_P_ALIGN (sizeof(s_char_p) - sizeof(char*)) */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1718 #define VOID_P_ALIGN (sizeof(s_void_p) - sizeof(void*)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1719 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1720 /* |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1721 #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
|
1722 typedef struct { char c; wchar_t x; } s_wchar; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1723 typedef struct { char c; wchar_t *x; } s_wchar_p; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1724 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1725 #define WCHAR_ALIGN (sizeof(s_wchar) - sizeof(wchar_t)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1726 #define WCHAR_P_ALIGN (sizeof(s_wchar_p) - sizeof(wchar_t*)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1727 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1728 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1729 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1730 #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
|
1731 typedef struct { char c; PY_LONG_LONG x; } s_long_long; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1732 #define LONG_LONG_ALIGN (sizeof(s_long_long) - sizeof(PY_LONG_LONG)) |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1733 #endif |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1734 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1735 /* from ffi.h: |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1736 typedef struct _ffi_type |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1737 { |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1738 size_t size; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1739 unsigned short alignment; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1740 unsigned short type; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1741 struct _ffi_type **elements; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1742 } ffi_type; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1743 */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1744 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1745 /* align and size are bogus for void, but they must not be zero */ |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1746 ffi_type ffi_type_void = { 1, 1, FFI_TYPE_VOID }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1747 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1748 ffi_type ffi_type_uint8 = { 1, 1, FFI_TYPE_UINT8 }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1749 ffi_type ffi_type_sint8 = { 1, 1, FFI_TYPE_SINT8 }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1750 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1751 ffi_type ffi_type_uint16 = { 2, 2, FFI_TYPE_UINT16 }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1752 ffi_type ffi_type_sint16 = { 2, 2, FFI_TYPE_SINT16 }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1753 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1754 ffi_type ffi_type_uint32 = { 4, 4, FFI_TYPE_UINT32 }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1755 ffi_type ffi_type_sint32 = { 4, 4, FFI_TYPE_SINT32 }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1756 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1757 ffi_type ffi_type_uint64 = { 8, LONG_LONG_ALIGN, FFI_TYPE_UINT64 }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1758 ffi_type ffi_type_sint64 = { 8, LONG_LONG_ALIGN, FFI_TYPE_SINT64 }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1759 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1760 ffi_type ffi_type_float = { sizeof(float), FLOAT_ALIGN, FFI_TYPE_FLOAT }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1761 ffi_type ffi_type_double = { sizeof(double), DOUBLE_ALIGN, FFI_TYPE_DOUBLE }; |
|
43678
530573cd4f7a
ffi_type_longdouble may be already #defined.
Thomas Heller <theller@ctypes.org>
parents:
43601
diff
changeset
|
1762 |
|
530573cd4f7a
ffi_type_longdouble may be already #defined.
Thomas Heller <theller@ctypes.org>
parents:
43601
diff
changeset
|
1763 #ifdef ffi_type_longdouble |
|
530573cd4f7a
ffi_type_longdouble may be already #defined.
Thomas Heller <theller@ctypes.org>
parents:
43601
diff
changeset
|
1764 #undef ffi_type_longdouble |
|
530573cd4f7a
ffi_type_longdouble may be already #defined.
Thomas Heller <theller@ctypes.org>
parents:
43601
diff
changeset
|
1765 #endif |
|
47473
c34e34057714
MacOS X: Enable 4-way universal builds
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47294
diff
changeset
|
1766 /* This is already defined on OSX */ |
|
43278
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1767 ffi_type ffi_type_longdouble = { sizeof(long double), LONGDOUBLE_ALIGN, |
|
28716dd14bc5
Add a 'c_longdouble' type to the ctypes module.
Thomas Heller <theller@ctypes.org>
parents:
42333
diff
changeset
|
1768 FFI_TYPE_LONGDOUBLE }; |
|
36897
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1769 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1770 ffi_type ffi_type_pointer = { sizeof(void *), VOID_P_ALIGN, FFI_TYPE_POINTER }; |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1771 |
|
6f2eda495d9d
Copy ctypes-0.9.9.4 sources from external into the trunk.
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1772 /*---------------- EOF ----------------*/ |
