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