Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Delta Between Two Patch Sets: Modules/_ctypes/ctypes.h

Issue 10744: ctypes arrays have incorrect buffer information (PEP-3118)
Left Patch Set: Created 5 years, 9 months ago
Right Patch Set: Created 5 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Modules/_ctypes/_ctypes.c ('k') | Modules/_ctypes/stgdict.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /*****************************************************************
2 This file should be kept compatible with Python 2.3, see PEP 291.
3 *****************************************************************/
4
5 #if defined (__SVR4) && defined (__sun) 1 #if defined (__SVR4) && defined (__sun)
6 # include <alloca.h> 2 # include <alloca.h>
7 #endif 3 #endif
8
9 #if (PY_VERSION_HEX < 0x02040000)
10 #define PyDict_CheckExact(ob) (Py_TYPE(ob) == &PyDict_Type)
11 #endif
12
13 #if (PY_VERSION_HEX < 0x02050000)
14 typedef int Py_ssize_t;
15 #define PyInt_FromSsize_t PyInt_FromLong
16 #define PyNumber_AsSsize_t(ob, exc) PyInt_AsLong(ob)
17 #define PyIndex_Check(ob) PyInt_Check(ob)
18 typedef Py_ssize_t (*readbufferproc)(PyObject *, Py_ssize_t, void **);
19 typedef Py_ssize_t (*writebufferproc)(PyObject *, Py_ssize_t, void **);
20 typedef Py_ssize_t (*segcountproc)(PyObject *, Py_ssize_t *);
21 typedef Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, char **);
22 #endif
23
24 #if (PY_VERSION_HEX < 0x02060000)
25 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
26 #define PyVarObject_HEAD_INIT(type, size) \
27 PyObject_HEAD_INIT(type) size,
28 #define PyImport_ImportModuleNoBlock PyImport_ImportModule
29 #define PyLong_FromSsize_t PyInt_FromLong
30 #define Py_TPFLAGS_HAVE_NEWBUFFER 0
31 #endif
32
33 4
34 #ifndef MS_WIN32 5 #ifndef MS_WIN32
35 #define max(a, b) ((a) > (b) ? (a) : (b)) 6 #define max(a, b) ((a) > (b) ? (a) : (b))
36 #define min(a, b) ((a) < (b) ? (a) : (b)) 7 #define min(a, b) ((a) < (b) ? (a) : (b))
37 8
38 #define PARAMFLAG_FIN 0x1 9 #define PARAMFLAG_FIN 0x1
39 #define PARAMFLAG_FOUT 0x2 10 #define PARAMFLAG_FOUT 0x2
40 #define PARAMFLAG_FLCID 0x4 11 #define PARAMFLAG_FLCID 0x4
41 #endif
42
43 /*
44 Backwards compatibility:
45 Python2.2 used LONG_LONG instead of PY_LONG_LONG
46 */
47 #if defined(HAVE_LONG_LONG) && !defined(PY_LONG_LONG)
48 #define PY_LONG_LONG LONG_LONG
49 #endif 12 #endif
50 13
51 typedef struct tagPyCArgObject PyCArgObject; 14 typedef struct tagPyCArgObject PyCArgObject;
52 typedef struct tagCDataObject CDataObject; 15 typedef struct tagCDataObject CDataObject;
53 typedef PyObject *(* GETFUNC)(void *, Py_ssize_t size); 16 typedef PyObject *(* GETFUNC)(void *, Py_ssize_t size);
54 typedef PyObject *(* SETFUNC)(void *, PyObject *value, Py_ssize_t size); 17 typedef PyObject *(* SETFUNC)(void *, PyObject *value, Py_ssize_t size);
55 typedef PyCArgObject *(* PARAMFUNC)(CDataObject *obj); 18 typedef PyCArgObject *(* PARAMFUNC)(CDataObject *obj);
56 19
57 /* A default buffer in CDataObject, which can be used for small C types. If 20 /* A default buffer in CDataObject, which can be used for small C types. If
58 this buffer is too small, PyMem_Malloc will be called to create a larger one, 21 this buffer is too small, PyMem_Malloc will be called to create a larger one,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 extern PyTypeObject PyCData_Type; 116 extern PyTypeObject PyCData_Type;
154 #define CDataObject_CheckExact(v) ((v)->ob_type == &PyCData_Type) 117 #define CDataObject_CheckExact(v) ((v)->ob_type == &PyCData_Type)
155 #define CDataObject_Check(v) PyObject_TypeCheck(v, &PyCData_Type) 118 #define CDataObject_Check(v) PyObject_TypeCheck(v, &PyCData_Type)
156 #define _CDataObject_HasExternalBuffer(v) ((v)->b_ptr != (char *)&(v)->b_value) 119 #define _CDataObject_HasExternalBuffer(v) ((v)->b_ptr != (char *)&(v)->b_value)
157 120
158 extern PyTypeObject PyCSimpleType_Type; 121 extern PyTypeObject PyCSimpleType_Type;
159 #define PyCSimpleTypeObject_CheckExact(v) ((v)->ob_type == &PyCSimpleType_ Type) 122 #define PyCSimpleTypeObject_CheckExact(v) ((v)->ob_type == &PyCSimpleType_ Type)
160 #define PyCSimpleTypeObject_Check(v) PyObject_TypeCheck(v, &PyCSimpleType_Typ e) 123 #define PyCSimpleTypeObject_Check(v) PyObject_TypeCheck(v, &PyCSimpleType_Typ e)
161 124
162 extern PyTypeObject PyCField_Type; 125 extern PyTypeObject PyCField_Type;
163 extern struct fielddesc *_ctypes_get_fielddesc(char *fmt); 126 extern struct fielddesc *_ctypes_get_fielddesc(const char *fmt);
164 127
165 128
166 extern PyObject * 129 extern PyObject *
167 PyCField_FromDesc(PyObject *desc, Py_ssize_t index, 130 PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
168 Py_ssize_t *pfield_size, int bitsize, int *pbitofs, 131 Py_ssize_t *pfield_size, int bitsize, int *pbitofs,
169 Py_ssize_t *psize, Py_ssize_t *poffset, Py_ssize_t *palign, 132 Py_ssize_t *psize, Py_ssize_t *poffset, Py_ssize_t *palign,
170 int pack, int is_big_endian); 133 int pack, int is_big_endian);
171 134
172 extern PyObject *PyCData_AtAddress(PyObject *type, void *buf); 135 extern PyObject *PyCData_AtAddress(PyObject *type, void *buf);
173 extern PyObject *PyCData_FromBytes(PyObject *type, char *data, Py_ssize_t length ); 136 extern PyObject *PyCData_FromBytes(PyObject *type, char *data, Py_ssize_t length );
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 extern char basespec_string[]; 338 extern char basespec_string[];
376 339
377 extern ffi_type *_ctypes_get_ffi_type(PyObject *obj); 340 extern ffi_type *_ctypes_get_ffi_type(PyObject *obj);
378 341
379 /* exception classes */ 342 /* exception classes */
380 extern PyObject *PyExc_ArgError; 343 extern PyObject *PyExc_ArgError;
381 344
382 extern char *_ctypes_conversion_encoding; 345 extern char *_ctypes_conversion_encoding;
383 extern char *_ctypes_conversion_errors; 346 extern char *_ctypes_conversion_errors;
384 347
385 /* Python 2.4 macros, which are not available in Python 2.3 */ 348 #if defined(HAVE_WCHAR_H)
386
387 #ifndef Py_CLEAR
388 #define Py_CLEAR(op) \
389 do { \
390 if (op) { \
391 PyObject *tmp = (PyObject *)(op); \
392 (op) = NULL; \
393 Py_DECREF(tmp); \
394 } \
395 } while (0)
396 #endif
397
398 #ifndef Py_VISIT
399 /* Utility macro to help write tp_traverse functions.
400 * To use this macro, the tp_traverse function must name its arguments
401 * "visit" and "arg". This is intended to keep tp_traverse functions
402 * looking as much alike as possible.
403 */
404 #define Py_VISIT(op) \
405 do { \
406 if (op) { \
407 int vret = visit((op), arg); \
408 if (vret) \
409 return vret; \
410 } \
411 } while (0)
412 #endif
413
414 /* Python's PyUnicode_*WideChar functions are broken ... */
415 #if defined(Py_USING_UNICODE) && defined(HAVE_WCHAR_H)
416 # define CTYPES_UNICODE 349 # define CTYPES_UNICODE
417 #endif 350 #endif
418 351
419 352
420 #if (PY_VERSION_HEX < 0x02040000) 353 extern void _ctypes_free_closure(void *);
421 #ifdef CTYPES_UNICODE 354 extern void *_ctypes_alloc_closure(void);
422 # undef PyUnicode_FromWideChar
423 # define PyUnicode_FromWideChar PyUnicode_FromWideChar_fixed
424
425 # undef PyUnicode_AsWideChar
426 # define PyUnicode_AsWideChar PyUnicode_AsWideChar_fixed
427
428 extern PyObject *PyUnicode_FromWideChar_fixed(const wchar_t *, Py_ssize_t);
429 extern Py_ssize_t PyUnicode_AsWideChar_fixed(PyUnicodeObject *, wchar_t *, Py_ss ize_t);
430 #endif
431 #endif
432 355
433 extern void _ctypes_add_traceback(char *, char *, int); 356 extern void _ctypes_add_traceback(char *, char *, int);
434 357
435 extern PyObject *PyCData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr); 358 extern PyObject *PyCData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr);
436 extern char *_ctypes_alloc_format_string(const char *prefix, const char *suffix) ; 359 extern char *_ctypes_alloc_format_string(const char *prefix, const char *suffix) ;
437 extern char *_ctypes_alloc_format_string_with_shape(int ndim, 360 extern char *_ctypes_alloc_format_string_with_shape(int ndim,
438 const Py_ssize_t *shape, 361 const Py_ssize_t *shape,
439 const char *prefix, const char * suffix); 362 const char *prefix, const char * suffix);
440 363
441 extern int _ctypes_simple_instance(PyObject *obj); 364 extern int _ctypes_simple_instance(PyObject *obj);
442 365
443 extern PyObject *_ctypes_ptrtype_cache; 366 extern PyObject *_ctypes_ptrtype_cache;
444 PyObject *_ctypes_get_errobj(int **pspace); 367 PyObject *_ctypes_get_errobj(int **pspace);
445 368
446 #ifdef MS_WIN32 369 #ifdef MS_WIN32
447 extern PyObject *ComError; 370 extern PyObject *ComError;
448 #endif 371 #endif
449 372
450 #if PY_VERSION_HEX >= 0x020700A4
451 /* Use PyCapsule for 2.7 */
452
453 #define CTYPES_USING_CAPSULE
454
455 #define CTYPES_CAPSULE_INSTANTIATE_DESTRUCTOR(name) \
456 static void capsule_destructor_ ## name(PyObject *ptr) \
457 { \
458 void *p = PyCapsule_GetPointer(ptr, name); \
459 if (p) { \
460 PyMem_Free(p); \
461 } \
462 } \
463
464 #define CAPSULE_NEW(pointer, name) \
465 (PyCapsule_New(pointer, name, capsule_destructor_ ## name))
466
467 #define CAPSULE_DEREFERENCE(capsule, name) \
468 (PyCapsule_GetPointer(capsule, name))
469
470 #else /* PY_VERSION_HEX >= 0x020700A4 */
471 /* Use CObject for 2.6 and before */
472
473 #define CTYPES_CAPSULE_INSTANTIATE_DESTRUCTOR(name)
474
475 #define CAPSULE_NEW(pointer, name) \
476 (PyCObject_FromVoidPtr(pointer, PyMem_Free))
477
478 #define CAPSULE_DEREFERENCE(capsule, name) \
479 (PyCObject_AsVoidPtr(capsule))
480
481 #endif /* PY_VERSION_HEX >= 0x020700A4 */
482
483
484 /* 373 /*
485 Local Variables: 374 Local Variables:
486 compile-command: "python setup.py -q build install --home ~" 375 compile-command: "python setup.py -q build install --home ~"
487 End: 376 End:
488 */ 377 */
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+