Georg Brandl | ca9400f | 2010-07-31 09:37:03 +0000 | [diff] [blame] | 1 | #if defined (__SVR4) && defined (__sun) |
| 2 | # include <alloca.h> |
| 3 | #endif |
| 4 | |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 5 | #ifndef MS_WIN32 |
| 6 | #define max(a, b) ((a) > (b) ? (a) : (b)) |
| 7 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
| 8 | |
| 9 | #define PARAMFLAG_FIN 0x1 |
| 10 | #define PARAMFLAG_FOUT 0x2 |
| 11 | #define PARAMFLAG_FLCID 0x4 |
| 12 | #endif |
| 13 | |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 14 | typedef struct tagPyCArgObject PyCArgObject; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 15 | typedef struct tagCDataObject CDataObject; |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 16 | typedef PyObject *(* GETFUNC)(void *, Py_ssize_t size); |
| 17 | typedef PyObject *(* SETFUNC)(void *, PyObject *value, Py_ssize_t size); |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 18 | typedef PyCArgObject *(* PARAMFUNC)(CDataObject *obj); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 19 | |
| 20 | /* A default buffer in CDataObject, which can be used for small C types. If |
| 21 | this buffer is too small, PyMem_Malloc will be called to create a larger one, |
| 22 | and this one is not used. |
| 23 | |
| 24 | Making CDataObject a variable size object would be a better solution, but more |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 25 | difficult in the presence of PyCFuncPtrObject. Maybe later. |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 26 | */ |
| 27 | union value { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 28 | char c[16]; |
| 29 | short s; |
| 30 | int i; |
| 31 | long l; |
| 32 | float f; |
| 33 | double d; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 34 | #ifdef HAVE_LONG_LONG |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 35 | PY_LONG_LONG ll; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 36 | #endif |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 37 | long double D; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | /* |
| 41 | Hm. Are there CDataObject's which do not need the b_objects member? In |
| 42 | this case we probably should introduce b_flags to mark it as present... If |
| 43 | b_objects is not present/unused b_length is unneeded as well. |
| 44 | */ |
| 45 | |
| 46 | struct tagCDataObject { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 47 | PyObject_HEAD |
| 48 | char *b_ptr; /* pointer to memory block */ |
| 49 | int b_needsfree; /* need _we_ free the memory? */ |
| 50 | CDataObject *b_base; /* pointer to base object or NULL */ |
| 51 | Py_ssize_t b_size; /* size of memory block in bytes */ |
| 52 | Py_ssize_t b_length; /* number of references we need */ |
| 53 | Py_ssize_t b_index; /* index of this object into base's |
| 54 | b_object list */ |
| 55 | PyObject *b_objects; /* dictionary of references we need to keep, or Py_None */ |
| 56 | union value b_value; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | typedef struct { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 60 | PyObject_VAR_HEAD |
Thomas Heller | 864cc67 | 2010-08-08 17:58:53 +0000 | [diff] [blame] | 61 | ffi_closure *pcl_write; /* the C callable, writeable */ |
| 62 | void *pcl_exec; /* the C callable, executable */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 63 | ffi_cif cif; |
| 64 | int flags; |
| 65 | PyObject *converters; |
| 66 | PyObject *callable; |
| 67 | PyObject *restype; |
| 68 | SETFUNC setfunc; |
| 69 | ffi_type *ffi_restype; |
| 70 | ffi_type *atypes[1]; |
Thomas Heller | e106dc3 | 2008-04-24 18:39:36 +0000 | [diff] [blame] | 71 | } CThunkObject; |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 72 | extern PyTypeObject PyCThunk_Type; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 73 | #define CThunk_CheckExact(v) ((v)->ob_type == &PyCThunk_Type) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 74 | |
| 75 | typedef struct { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 76 | /* First part identical to tagCDataObject */ |
| 77 | PyObject_HEAD |
| 78 | char *b_ptr; /* pointer to memory block */ |
| 79 | int b_needsfree; /* need _we_ free the memory? */ |
| 80 | CDataObject *b_base; /* pointer to base object or NULL */ |
| 81 | Py_ssize_t b_size; /* size of memory block in bytes */ |
| 82 | Py_ssize_t b_length; /* number of references we need */ |
| 83 | Py_ssize_t b_index; /* index of this object into base's |
| 84 | b_object list */ |
| 85 | PyObject *b_objects; /* list of references we need to keep */ |
| 86 | union value b_value; |
| 87 | /* end of tagCDataObject, additional fields follow */ |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 88 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 89 | CThunkObject *thunk; |
| 90 | PyObject *callable; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 91 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 92 | /* These two fields will override the ones in the type's stgdict if |
| 93 | they are set */ |
| 94 | PyObject *converters; |
| 95 | PyObject *argtypes; |
| 96 | PyObject *restype; |
| 97 | PyObject *checker; |
| 98 | PyObject *errcheck; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 99 | #ifdef MS_WIN32 |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 100 | int index; |
| 101 | GUID *iid; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 102 | #endif |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 103 | PyObject *paramflags; |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 104 | } PyCFuncPtrObject; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 105 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 106 | extern PyTypeObject PyCStgDict_Type; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 107 | #define PyCStgDict_CheckExact(v) ((v)->ob_type == &PyCStgDict_Type) |
| 108 | #define PyCStgDict_Check(v) PyObject_TypeCheck(v, &PyCStgDict_Type) |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 109 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 110 | extern int PyCStructUnionType_update_stgdict(PyObject *fields, PyObject *type, int isStruct); |
Thomas Heller | fe8f862 | 2006-03-14 19:53:09 +0000 | [diff] [blame] | 111 | extern int PyType_stginfo(PyTypeObject *self, Py_ssize_t *psize, Py_ssize_t *palign, Py_ssize_t *plength); |
| 112 | extern int PyObject_stginfo(PyObject *self, Py_ssize_t *psize, Py_ssize_t *palign, Py_ssize_t *plength); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 113 | |
| 114 | |
| 115 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 116 | extern PyTypeObject PyCData_Type; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 117 | #define CDataObject_CheckExact(v) ((v)->ob_type == &PyCData_Type) |
| 118 | #define CDataObject_Check(v) PyObject_TypeCheck(v, &PyCData_Type) |
Antoine Pitrou | 305e1a7 | 2012-12-08 11:05:50 +0100 | [diff] [blame] | 119 | #define _CDataObject_HasExternalBuffer(v) ((v)->b_ptr != (char *)&(v)->b_value) |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 120 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 121 | extern PyTypeObject PyCSimpleType_Type; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 122 | #define PyCSimpleTypeObject_CheckExact(v) ((v)->ob_type == &PyCSimpleType_Type) |
| 123 | #define PyCSimpleTypeObject_Check(v) PyObject_TypeCheck(v, &PyCSimpleType_Type) |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 124 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 125 | extern PyTypeObject PyCField_Type; |
| 126 | extern struct fielddesc *_ctypes_get_fielddesc(const char *fmt); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 127 | |
| 128 | |
| 129 | extern PyObject * |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 130 | PyCField_FromDesc(PyObject *desc, Py_ssize_t index, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 131 | Py_ssize_t *pfield_size, int bitsize, int *pbitofs, |
| 132 | Py_ssize_t *psize, Py_ssize_t *poffset, Py_ssize_t *palign, |
| 133 | int pack, int is_big_endian); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 134 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 135 | extern PyObject *PyCData_AtAddress(PyObject *type, void *buf); |
| 136 | extern PyObject *PyCData_FromBytes(PyObject *type, char *data, Py_ssize_t length); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 137 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 138 | extern PyTypeObject PyCArrayType_Type; |
| 139 | extern PyTypeObject PyCArray_Type; |
| 140 | extern PyTypeObject PyCPointerType_Type; |
| 141 | extern PyTypeObject PyCPointer_Type; |
| 142 | extern PyTypeObject PyCFuncPtr_Type; |
| 143 | extern PyTypeObject PyCFuncPtrType_Type; |
| 144 | extern PyTypeObject PyCStructType_Type; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 145 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 146 | #define PyCArrayTypeObject_Check(v) PyObject_TypeCheck(v, &PyCArrayType_Type) |
| 147 | #define ArrayObject_Check(v) PyObject_TypeCheck(v, &PyCArray_Type) |
| 148 | #define PointerObject_Check(v) PyObject_TypeCheck(v, &PyCPointer_Type) |
| 149 | #define PyCPointerTypeObject_Check(v) PyObject_TypeCheck(v, &PyCPointerType_Type) |
| 150 | #define PyCFuncPtrObject_Check(v) PyObject_TypeCheck(v, &PyCFuncPtr_Type) |
| 151 | #define PyCFuncPtrTypeObject_Check(v) PyObject_TypeCheck(v, &PyCFuncPtrType_Type) |
| 152 | #define PyCStructTypeObject_Check(v) PyObject_TypeCheck(v, &PyCStructType_Type) |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 153 | |
| 154 | extern PyObject * |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 155 | PyCArrayType_from_ctype(PyObject *itemtype, Py_ssize_t length); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 156 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 157 | extern PyMethodDef _ctypes_module_methods[]; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 158 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 159 | extern CThunkObject *_ctypes_alloc_callback(PyObject *callable, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 160 | PyObject *converters, |
| 161 | PyObject *restype, |
| 162 | int flags); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 163 | /* a table entry describing a predefined ctypes type */ |
| 164 | struct fielddesc { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 165 | char code; |
| 166 | SETFUNC setfunc; |
| 167 | GETFUNC getfunc; |
| 168 | ffi_type *pffi_type; /* always statically allocated */ |
| 169 | SETFUNC setfunc_swapped; |
| 170 | GETFUNC getfunc_swapped; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | typedef struct { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 174 | PyObject_HEAD |
| 175 | Py_ssize_t offset; |
| 176 | Py_ssize_t size; |
| 177 | Py_ssize_t index; /* Index into CDataObject's |
| 178 | object array */ |
| 179 | PyObject *proto; /* a type or NULL */ |
| 180 | GETFUNC getfunc; /* getter function if proto is NULL */ |
| 181 | SETFUNC setfunc; /* setter function if proto is NULL */ |
| 182 | int anonymous; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 183 | } CFieldObject; |
| 184 | |
| 185 | /* A subclass of PyDictObject, used as the instance dictionary of ctypes |
| 186 | metatypes */ |
| 187 | typedef struct { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 188 | PyDictObject dict; /* first part identical to PyDictObject */ |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 189 | /* The size and align fields are unneeded, they are in ffi_type as well. As |
| 190 | an experiment shows, it's trivial to get rid of them, the only thing to |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 191 | remember is that in PyCArrayType_new the ffi_type fields must be filled in - |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 192 | so far it was unneeded because libffi doesn't support arrays at all |
| 193 | (because they are passed as pointers to function calls anyway). But it's |
Berker Peksag | 4882cac | 2015-04-14 09:30:01 +0300 | [diff] [blame] | 194 | too much risk to change that now, and there are other fields which doesn't |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 195 | belong into this structure anyway. Maybe in ctypes 2.0... (ctypes 2000?) |
| 196 | */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 197 | Py_ssize_t size; /* number of bytes */ |
| 198 | Py_ssize_t align; /* alignment requirements */ |
| 199 | Py_ssize_t length; /* number of fields */ |
| 200 | ffi_type ffi_type_pointer; |
| 201 | PyObject *proto; /* Only for Pointer/ArrayObject */ |
| 202 | SETFUNC setfunc; /* Only for simple objects */ |
| 203 | GETFUNC getfunc; /* Only for simple objects */ |
| 204 | PARAMFUNC paramfunc; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 205 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 206 | /* Following fields only used by PyCFuncPtrType_Type instances */ |
| 207 | PyObject *argtypes; /* tuple of CDataObjects */ |
| 208 | PyObject *converters; /* tuple([t.from_param for t in argtypes]) */ |
| 209 | PyObject *restype; /* CDataObject or NULL */ |
| 210 | PyObject *checker; |
| 211 | int flags; /* calling convention and such */ |
Thomas Heller | b041fda | 2008-04-30 17:11:46 +0000 | [diff] [blame] | 212 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 213 | /* pep3118 fields, pointers neeed PyMem_Free */ |
| 214 | char *format; |
| 215 | int ndim; |
| 216 | Py_ssize_t *shape; |
| 217 | /* Py_ssize_t *strides; */ /* unused in ctypes */ |
| 218 | /* Py_ssize_t *suboffsets; */ /* unused in ctypes */ |
Thomas Heller | b041fda | 2008-04-30 17:11:46 +0000 | [diff] [blame] | 219 | |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 220 | } StgDictObject; |
| 221 | |
| 222 | /**************************************************************** |
| 223 | StgDictObject fields |
| 224 | |
| 225 | setfunc and getfunc is only set for simple data types, it is copied from the |
| 226 | corresponding fielddesc entry. These are functions to set and get the value |
| 227 | in a memory block. |
| 228 | They should probably by used by other types as well. |
| 229 | |
| 230 | proto is only used for Pointer and Array types - it points to the item type |
| 231 | object. |
| 232 | |
| 233 | Probably all the magic ctypes methods (like from_param) should have C |
| 234 | callable wrappers in the StgDictObject. For simple data type, for example, |
| 235 | the fielddesc table could have entries for C codec from_param functions or |
| 236 | other methods as well, if a subtype overrides this method in Python at |
| 237 | construction time, or assigns to it later, tp_setattro should update the |
| 238 | StgDictObject function to a generic one. |
| 239 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 240 | Currently, PyCFuncPtr types have 'converters' and 'checker' entries in their |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 241 | type dict. They are only used to cache attributes from other entries, whihc |
| 242 | is wrong. |
| 243 | |
| 244 | One use case is the .value attribute that all simple types have. But some |
| 245 | complex structures, like VARIANT, represent a single value also, and should |
| 246 | have this attribute. |
| 247 | |
| 248 | Another use case is a _check_retval_ function, which is called when a ctypes |
| 249 | type is used as return type of a function to validate and compute the return |
| 250 | value. |
| 251 | |
| 252 | Common ctypes protocol: |
| 253 | |
| 254 | - setfunc: store a python value in a memory block |
| 255 | - getfunc: convert data from a memory block into a python value |
| 256 | |
| 257 | - checkfunc: validate and convert a return value from a function call |
| 258 | - toparamfunc: convert a python value into a function argument |
| 259 | |
| 260 | *****************************************************************/ |
| 261 | |
| 262 | /* May return NULL, but does not set an exception! */ |
| 263 | extern StgDictObject *PyType_stgdict(PyObject *obj); |
| 264 | |
| 265 | /* May return NULL, but does not set an exception! */ |
| 266 | extern StgDictObject *PyObject_stgdict(PyObject *self); |
| 267 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 268 | extern int PyCStgDict_clone(StgDictObject *src, StgDictObject *dst); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 269 | |
| 270 | typedef int(* PPROC)(void); |
| 271 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 272 | PyObject *_ctypes_callproc(PPROC pProc, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 273 | PyObject *arguments, |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 274 | #ifdef MS_WIN32 |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 275 | IUnknown *pIUnk, |
| 276 | GUID *iid, |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 277 | #endif |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 278 | int flags, |
| 279 | PyObject *argtypes, |
| 280 | PyObject *restype, |
| 281 | PyObject *checker); |
| 282 | |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 283 | |
| 284 | #define FUNCFLAG_STDCALL 0x0 |
| 285 | #define FUNCFLAG_CDECL 0x1 |
| 286 | #define FUNCFLAG_HRESULT 0x2 |
| 287 | #define FUNCFLAG_PYTHONAPI 0x4 |
Thomas Heller | 9cac7b6 | 2008-06-06 09:31:40 +0000 | [diff] [blame] | 288 | #define FUNCFLAG_USE_ERRNO 0x8 |
| 289 | #define FUNCFLAG_USE_LASTERROR 0x10 |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 290 | |
Thomas Heller | 13394e9 | 2008-02-13 20:40:44 +0000 | [diff] [blame] | 291 | #define TYPEFLAG_ISPOINTER 0x100 |
| 292 | #define TYPEFLAG_HASPOINTER 0x200 |
| 293 | |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 294 | #define DICTFLAG_FINAL 0x1000 |
| 295 | |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 296 | struct tagPyCArgObject { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 297 | PyObject_HEAD |
| 298 | ffi_type *pffi_type; |
| 299 | char tag; |
| 300 | union { |
| 301 | char c; |
| 302 | char b; |
| 303 | short h; |
| 304 | int i; |
| 305 | long l; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 306 | #ifdef HAVE_LONG_LONG |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 307 | PY_LONG_LONG q; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 308 | #endif |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 309 | long double D; |
| 310 | double d; |
| 311 | float f; |
| 312 | void *p; |
| 313 | } value; |
| 314 | PyObject *obj; |
| 315 | Py_ssize_t size; /* for the 'V' tag */ |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 316 | }; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 317 | |
| 318 | extern PyTypeObject PyCArg_Type; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 319 | #define PyCArg_CheckExact(v) ((v)->ob_type == &PyCArg_Type) |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 320 | extern PyCArgObject *PyCArgObject_new(void); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 321 | |
| 322 | extern PyObject * |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 323 | PyCData_get(PyObject *type, GETFUNC getfunc, PyObject *src, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 324 | Py_ssize_t index, Py_ssize_t size, char *ptr); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 325 | |
| 326 | extern int |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 327 | PyCData_set(PyObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 328 | Py_ssize_t index, Py_ssize_t size, char *ptr); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 329 | |
Serhiy Storchaka | ef1585e | 2015-12-25 20:01:53 +0200 | [diff] [blame] | 330 | extern void _ctypes_extend_error(PyObject *exc_class, const char *fmt, ...); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 331 | |
| 332 | struct basespec { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 333 | CDataObject *base; |
| 334 | Py_ssize_t index; |
| 335 | char *adr; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 336 | }; |
| 337 | |
| 338 | extern char basespec_string[]; |
| 339 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 340 | extern ffi_type *_ctypes_get_ffi_type(PyObject *obj); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 341 | |
| 342 | /* exception classes */ |
| 343 | extern PyObject *PyExc_ArgError; |
| 344 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 345 | extern char *_ctypes_conversion_encoding; |
| 346 | extern char *_ctypes_conversion_errors; |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 347 | |
Thomas Heller | 5fa3f05 | 2007-07-12 11:00:22 +0000 | [diff] [blame] | 348 | #if defined(HAVE_WCHAR_H) |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 349 | # define CTYPES_UNICODE |
| 350 | #endif |
| 351 | |
| 352 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 353 | extern void _ctypes_free_closure(void *); |
| 354 | extern void *_ctypes_alloc_closure(void); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 355 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 356 | extern PyObject *PyCData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr); |
| 357 | extern char *_ctypes_alloc_format_string(const char *prefix, const char *suffix); |
Benjamin Peterson | 5eb6b39 | 2014-05-17 14:59:12 -0700 | [diff] [blame] | 358 | extern char *_ctypes_alloc_format_string_with_shape(int ndim, |
| 359 | const Py_ssize_t *shape, |
| 360 | const char *prefix, const char *suffix); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 361 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 362 | extern int _ctypes_simple_instance(PyObject *obj); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 363 | |
Thomas Heller | 34596a9 | 2009-04-24 20:50:00 +0000 | [diff] [blame] | 364 | extern PyObject *_ctypes_ptrtype_cache; |
| 365 | PyObject *_ctypes_get_errobj(int **pspace); |
Thomas Heller | d4c9320 | 2006-03-08 19:35:11 +0000 | [diff] [blame] | 366 | |
| 367 | #ifdef MS_WIN32 |
| 368 | extern PyObject *ComError; |
| 369 | #endif |
| 370 | |
| 371 | /* |
| 372 | Local Variables: |
| 373 | compile-command: "python setup.py -q build install --home ~" |
| 374 | End: |
| 375 | */ |