Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Include/object.h

    r2 r391  
    6464#ifdef Py_TRACE_REFS
    6565/* Define pointers to support a doubly-linked list of all live heap objects. */
    66 #define _PyObject_HEAD_EXTRA            \
    67         struct _object *_ob_next;       \
    68         struct _object *_ob_prev;
     66#define _PyObject_HEAD_EXTRA            \
     67    struct _object *_ob_next;           \
     68    struct _object *_ob_prev;
    6969
    7070#define _PyObject_EXTRA_INIT 0, 0,
     
    7676
    7777/* PyObject_HEAD defines the initial segment of every PyObject. */
    78 #define PyObject_HEAD                   \
    79         _PyObject_HEAD_EXTRA            \
    80         Py_ssize_t ob_refcnt;           \
    81         struct _typeobject *ob_type;
    82 
    83 #define PyObject_HEAD_INIT(type)        \
    84         _PyObject_EXTRA_INIT            \
    85         1, type,
    86 
    87 #define PyVarObject_HEAD_INIT(type, size)       \
    88         PyObject_HEAD_INIT(type) size,
     78#define PyObject_HEAD                   \
     79    _PyObject_HEAD_EXTRA                \
     80    Py_ssize_t ob_refcnt;               \
     81    struct _typeobject *ob_type;
     82
     83#define PyObject_HEAD_INIT(type)        \
     84    _PyObject_EXTRA_INIT                \
     85    1, type,
     86
     87#define PyVarObject_HEAD_INIT(type, size)       \
     88    PyObject_HEAD_INIT(type) size,
    8989
    9090/* PyObject_VAR_HEAD defines the initial segment of all variable-size
     
    9494 * not necessarily a byte count.
    9595 */
    96 #define PyObject_VAR_HEAD               \
    97         PyObject_HEAD                   \
    98         Py_ssize_t ob_size; /* Number of items in variable part */
     96#define PyObject_VAR_HEAD               \
     97    PyObject_HEAD                       \
     98    Py_ssize_t ob_size; /* Number of items in variable part */
    9999#define Py_INVALID_SIZE (Py_ssize_t)-1
    100100
     
    105105 */
    106106typedef struct _object {
    107         PyObject_HEAD
     107    PyObject_HEAD
    108108} PyObject;
    109109
    110110typedef struct {
    111         PyObject_VAR_HEAD
     111    PyObject_VAR_HEAD
    112112} PyVarObject;
    113113
    114 #define Py_REFCNT(ob)           (((PyObject*)(ob))->ob_refcnt)
    115 #define Py_TYPE(ob)             (((PyObject*)(ob))->ob_type)
    116 #define Py_SIZE(ob)             (((PyVarObject*)(ob))->ob_size)
     114#define Py_REFCNT(ob)           (((PyObject*)(ob))->ob_refcnt)
     115#define Py_TYPE(ob)             (((PyObject*)(ob))->ob_type)
     116#define Py_SIZE(ob)             (((PyVarObject*)(ob))->ob_size)
    117117
    118118/*
     
    160160typedef Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, char **);
    161161
     162
    162163/* Py3k buffer interface */
    163 
    164164typedef struct bufferinfo {
    165         void *buf;
    166         PyObject *obj;        /* borrowed reference */
    167         Py_ssize_t len;
    168         Py_ssize_t itemsize;  /* This is Py_ssize_t so it can be
    169                                  pointed to by strides in simple case.*/
    170         int readonly;
    171         int ndim;
    172         char *format;
    173         Py_ssize_t *shape;
    174         Py_ssize_t *strides;
    175         Py_ssize_t *suboffsets;
    176         void *internal;
     165    void *buf;
     166    PyObject *obj;        /* owned reference */
     167    Py_ssize_t len;
     168    Py_ssize_t itemsize;  /* This is Py_ssize_t so it can be
     169                             pointed to by strides in simple case.*/
     170    int readonly;
     171    int ndim;
     172    char *format;
     173    Py_ssize_t *shape;
     174    Py_ssize_t *strides;
     175    Py_ssize_t *suboffsets;
     176    Py_ssize_t smalltable[2];  /* static store for shape and strides of
     177                                  mono-dimensional buffers. */
     178    void *internal;
    177179} Py_buffer;
    178180
     
    180182typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
    181183
    182         /* Flags for getting buffers */
     184    /* Flags for getting buffers */
    183185#define PyBUF_SIMPLE 0
    184186#define PyBUF_WRITABLE 0x0001
     
    216218
    217219typedef struct {
    218         /* For numbers without flag bit Py_TPFLAGS_CHECKTYPES set, all
    219            arguments are guaranteed to be of the object's type (modulo
    220            coercion hacks -- i.e. if the type's coercion function
    221            returns other types, then these are allowed as well).  Numbers that
    222            have the Py_TPFLAGS_CHECKTYPES flag bit set should check *both*
    223            arguments for proper type and implement the necessary conversions
    224            in the slot functions themselves. */
    225 
    226         binaryfunc nb_add;
    227         binaryfunc nb_subtract;
    228         binaryfunc nb_multiply;
    229         binaryfunc nb_divide;
    230         binaryfunc nb_remainder;
    231         binaryfunc nb_divmod;
    232         ternaryfunc nb_power;
    233         unaryfunc nb_negative;
    234         unaryfunc nb_positive;
    235         unaryfunc nb_absolute;
    236         inquiry nb_nonzero;
    237         unaryfunc nb_invert;
    238         binaryfunc nb_lshift;
    239         binaryfunc nb_rshift;
    240         binaryfunc nb_and;
    241         binaryfunc nb_xor;
    242         binaryfunc nb_or;
    243         coercion nb_coerce;
    244         unaryfunc nb_int;
    245         unaryfunc nb_long;
    246         unaryfunc nb_float;
    247         unaryfunc nb_oct;
    248         unaryfunc nb_hex;
    249         /* Added in release 2.0 */
    250         binaryfunc nb_inplace_add;
    251         binaryfunc nb_inplace_subtract;
    252         binaryfunc nb_inplace_multiply;
    253         binaryfunc nb_inplace_divide;
    254         binaryfunc nb_inplace_remainder;
    255         ternaryfunc nb_inplace_power;
    256         binaryfunc nb_inplace_lshift;
    257         binaryfunc nb_inplace_rshift;
    258         binaryfunc nb_inplace_and;
    259         binaryfunc nb_inplace_xor;
    260         binaryfunc nb_inplace_or;
    261 
    262         /* Added in release 2.2 */
    263         /* The following require the Py_TPFLAGS_HAVE_CLASS flag */
    264         binaryfunc nb_floor_divide;
    265         binaryfunc nb_true_divide;
    266         binaryfunc nb_inplace_floor_divide;
    267         binaryfunc nb_inplace_true_divide;
    268 
    269         /* Added in release 2.5 */
    270         unaryfunc nb_index;
     220    /* For numbers without flag bit Py_TPFLAGS_CHECKTYPES set, all
     221       arguments are guaranteed to be of the object's type (modulo
     222       coercion hacks -- i.e. if the type's coercion function
     223       returns other types, then these are allowed as well).  Numbers that
     224       have the Py_TPFLAGS_CHECKTYPES flag bit set should check *both*
     225       arguments for proper type and implement the necessary conversions
     226       in the slot functions themselves. */
     227
     228    binaryfunc nb_add;
     229    binaryfunc nb_subtract;
     230    binaryfunc nb_multiply;
     231    binaryfunc nb_divide;
     232    binaryfunc nb_remainder;
     233    binaryfunc nb_divmod;
     234    ternaryfunc nb_power;
     235    unaryfunc nb_negative;
     236    unaryfunc nb_positive;
     237    unaryfunc nb_absolute;
     238    inquiry nb_nonzero;
     239    unaryfunc nb_invert;
     240    binaryfunc nb_lshift;
     241    binaryfunc nb_rshift;
     242    binaryfunc nb_and;
     243    binaryfunc nb_xor;
     244    binaryfunc nb_or;
     245    coercion nb_coerce;
     246    unaryfunc nb_int;
     247    unaryfunc nb_long;
     248    unaryfunc nb_float;
     249    unaryfunc nb_oct;
     250    unaryfunc nb_hex;
     251    /* Added in release 2.0 */
     252    binaryfunc nb_inplace_add;
     253    binaryfunc nb_inplace_subtract;
     254    binaryfunc nb_inplace_multiply;
     255    binaryfunc nb_inplace_divide;
     256    binaryfunc nb_inplace_remainder;
     257    ternaryfunc nb_inplace_power;
     258    binaryfunc nb_inplace_lshift;
     259    binaryfunc nb_inplace_rshift;
     260    binaryfunc nb_inplace_and;
     261    binaryfunc nb_inplace_xor;
     262    binaryfunc nb_inplace_or;
     263
     264    /* Added in release 2.2 */
     265    /* The following require the Py_TPFLAGS_HAVE_CLASS flag */
     266    binaryfunc nb_floor_divide;
     267    binaryfunc nb_true_divide;
     268    binaryfunc nb_inplace_floor_divide;
     269    binaryfunc nb_inplace_true_divide;
     270
     271    /* Added in release 2.5 */
     272    unaryfunc nb_index;
    271273} PyNumberMethods;
    272274
    273275typedef struct {
    274         lenfunc sq_length;
    275         binaryfunc sq_concat;
    276         ssizeargfunc sq_repeat;
    277         ssizeargfunc sq_item;
    278         ssizessizeargfunc sq_slice;
    279         ssizeobjargproc sq_ass_item;
    280         ssizessizeobjargproc sq_ass_slice;
    281         objobjproc sq_contains;
    282         /* Added in release 2.0 */
    283         binaryfunc sq_inplace_concat;
    284         ssizeargfunc sq_inplace_repeat;
     276    lenfunc sq_length;
     277    binaryfunc sq_concat;
     278    ssizeargfunc sq_repeat;
     279    ssizeargfunc sq_item;
     280    ssizessizeargfunc sq_slice;
     281    ssizeobjargproc sq_ass_item;
     282    ssizessizeobjargproc sq_ass_slice;
     283    objobjproc sq_contains;
     284    /* Added in release 2.0 */
     285    binaryfunc sq_inplace_concat;
     286    ssizeargfunc sq_inplace_repeat;
    285287} PySequenceMethods;
    286288
    287289typedef struct {
    288         lenfunc mp_length;
    289         binaryfunc mp_subscript;
    290         objobjargproc mp_ass_subscript;
     290    lenfunc mp_length;
     291    binaryfunc mp_subscript;
     292    objobjargproc mp_ass_subscript;
    291293} PyMappingMethods;
    292294
    293295typedef struct {
    294         readbufferproc bf_getreadbuffer;
    295         writebufferproc bf_getwritebuffer;
    296         segcountproc bf_getsegcount;
    297         charbufferproc bf_getcharbuffer;
    298         getbufferproc bf_getbuffer;
    299         releasebufferproc bf_releasebuffer;
     296    readbufferproc bf_getreadbuffer;
     297    writebufferproc bf_getwritebuffer;
     298    segcountproc bf_getsegcount;
     299    charbufferproc bf_getcharbuffer;
     300    getbufferproc bf_getbuffer;
     301    releasebufferproc bf_releasebuffer;
    300302} PyBufferProcs;
    301303
     
    321323
    322324typedef struct _typeobject {
    323         PyObject_VAR_HEAD
    324         const char *tp_name; /* For printing, in format "<module>.<name>" */
    325         Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
    326 
    327         /* Methods to implement standard operations */
    328 
    329         destructor tp_dealloc;
    330         printfunc tp_print;
    331         getattrfunc tp_getattr;
    332         setattrfunc tp_setattr;
    333         cmpfunc tp_compare;
    334         reprfunc tp_repr;
    335 
    336         /* Method suites for standard classes */
    337 
    338         PyNumberMethods *tp_as_number;
    339         PySequenceMethods *tp_as_sequence;
    340         PyMappingMethods *tp_as_mapping;
    341 
    342         /* More standard operations (here for binary compatibility) */
    343 
    344         hashfunc tp_hash;
    345         ternaryfunc tp_call;
    346         reprfunc tp_str;
    347         getattrofunc tp_getattro;
    348         setattrofunc tp_setattro;
    349 
    350         /* Functions to access object as input/output buffer */
    351         PyBufferProcs *tp_as_buffer;
    352 
    353         /* Flags to define presence of optional/expanded features */
    354         long tp_flags;
    355 
    356         const char *tp_doc; /* Documentation string */
    357 
    358         /* Assigned meaning in release 2.0 */
    359         /* call function for all accessible objects */
    360         traverseproc tp_traverse;
    361 
    362         /* delete references to contained objects */
    363         inquiry tp_clear;
    364 
    365         /* Assigned meaning in release 2.1 */
    366         /* rich comparisons */
    367         richcmpfunc tp_richcompare;
    368 
    369         /* weak reference enabler */
    370         Py_ssize_t tp_weaklistoffset;
    371 
    372         /* Added in release 2.2 */
    373         /* Iterators */
    374         getiterfunc tp_iter;
    375         iternextfunc tp_iternext;
    376 
    377         /* Attribute descriptor and subclassing stuff */
    378         struct PyMethodDef *tp_methods;
    379         struct PyMemberDef *tp_members;
    380         struct PyGetSetDef *tp_getset;
    381         struct _typeobject *tp_base;
    382         PyObject *tp_dict;
    383         descrgetfunc tp_descr_get;
    384         descrsetfunc tp_descr_set;
    385         Py_ssize_t tp_dictoffset;
    386         initproc tp_init;
    387         allocfunc tp_alloc;
    388         newfunc tp_new;
    389         freefunc tp_free; /* Low-level free-memory routine */
    390         inquiry tp_is_gc; /* For PyObject_IS_GC */
    391         PyObject *tp_bases;
    392         PyObject *tp_mro; /* method resolution order */
    393         PyObject *tp_cache;
    394         PyObject *tp_subclasses;
    395         PyObject *tp_weaklist;
    396         destructor tp_del;
    397 
    398         /* Type attribute cache version tag. Added in version 2.6 */
    399         unsigned int tp_version_tag;
     325    PyObject_VAR_HEAD
     326    const char *tp_name; /* For printing, in format "<module>.<name>" */
     327    Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
     328
     329    /* Methods to implement standard operations */
     330
     331    destructor tp_dealloc;
     332    printfunc tp_print;
     333    getattrfunc tp_getattr;
     334    setattrfunc tp_setattr;
     335    cmpfunc tp_compare;
     336    reprfunc tp_repr;
     337
     338    /* Method suites for standard classes */
     339
     340    PyNumberMethods *tp_as_number;
     341    PySequenceMethods *tp_as_sequence;
     342    PyMappingMethods *tp_as_mapping;
     343
     344    /* More standard operations (here for binary compatibility) */
     345
     346    hashfunc tp_hash;
     347    ternaryfunc tp_call;
     348    reprfunc tp_str;
     349    getattrofunc tp_getattro;
     350    setattrofunc tp_setattro;
     351
     352    /* Functions to access object as input/output buffer */
     353    PyBufferProcs *tp_as_buffer;
     354
     355    /* Flags to define presence of optional/expanded features */
     356    long tp_flags;
     357
     358    const char *tp_doc; /* Documentation string */
     359
     360    /* Assigned meaning in release 2.0 */
     361    /* call function for all accessible objects */
     362    traverseproc tp_traverse;
     363
     364    /* delete references to contained objects */
     365    inquiry tp_clear;
     366
     367    /* Assigned meaning in release 2.1 */
     368    /* rich comparisons */
     369    richcmpfunc tp_richcompare;
     370
     371    /* weak reference enabler */
     372    Py_ssize_t tp_weaklistoffset;
     373
     374    /* Added in release 2.2 */
     375    /* Iterators */
     376    getiterfunc tp_iter;
     377    iternextfunc tp_iternext;
     378
     379    /* Attribute descriptor and subclassing stuff */
     380    struct PyMethodDef *tp_methods;
     381    struct PyMemberDef *tp_members;
     382    struct PyGetSetDef *tp_getset;
     383    struct _typeobject *tp_base;
     384    PyObject *tp_dict;
     385    descrgetfunc tp_descr_get;
     386    descrsetfunc tp_descr_set;
     387    Py_ssize_t tp_dictoffset;
     388    initproc tp_init;
     389    allocfunc tp_alloc;
     390    newfunc tp_new;
     391    freefunc tp_free; /* Low-level free-memory routine */
     392    inquiry tp_is_gc; /* For PyObject_IS_GC */
     393    PyObject *tp_bases;
     394    PyObject *tp_mro; /* method resolution order */
     395    PyObject *tp_cache;
     396    PyObject *tp_subclasses;
     397    PyObject *tp_weaklist;
     398    destructor tp_del;
     399
     400    /* Type attribute cache version tag. Added in version 2.6 */
     401    unsigned int tp_version_tag;
    400402
    401403#ifdef COUNT_ALLOCS
    402         /* these must be last and never explicitly initialized */
    403         Py_ssize_t tp_allocs;
    404         Py_ssize_t tp_frees;
    405         Py_ssize_t tp_maxalloc;
    406         struct _typeobject *tp_prev;
    407         struct _typeobject *tp_next;
     404    /* these must be last and never explicitly initialized */
     405    Py_ssize_t tp_allocs;
     406    Py_ssize_t tp_frees;
     407    Py_ssize_t tp_maxalloc;
     408    struct _typeobject *tp_prev;
     409    struct _typeobject *tp_next;
    408410#endif
    409411} PyTypeObject;
     
    412414/* The *real* layout of a type object when allocated on the heap */
    413415typedef struct _heaptypeobject {
    414         /* Note: there's a dependency on the order of these members
    415            in slotptr() in typeobject.c . */
    416         PyTypeObject ht_type;
    417         PyNumberMethods as_number;
    418         PyMappingMethods as_mapping;
    419         PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
    420                                           so that the mapping wins when both
    421                                           the mapping and the sequence define
    422                                           a given operator (e.g. __getitem__).
    423                                           see add_operators() in typeobject.c . */
    424         PyBufferProcs as_buffer;
    425         PyObject *ht_name, *ht_slots;
    426         /* here are optional user slots, followed by the members. */
     416    /* Note: there's a dependency on the order of these members
     417       in slotptr() in typeobject.c . */
     418    PyTypeObject ht_type;
     419    PyNumberMethods as_number;
     420    PyMappingMethods as_mapping;
     421    PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
     422                                      so that the mapping wins when both
     423                                      the mapping and the sequence define
     424                                      a given operator (e.g. __getitem__).
     425                                      see add_operators() in typeobject.c . */
     426    PyBufferProcs as_buffer;
     427    PyObject *ht_name, *ht_slots;
     428    /* here are optional user slots, followed by the members. */
    427429} PyHeapTypeObject;
    428430
     
    435437PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
    436438#define PyObject_TypeCheck(ob, tp) \
    437         (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
     439    (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
    438440
    439441PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
     
    442444
    443445#define PyType_Check(op) \
    444         PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
     446    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
    445447#define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type)
    446448
     
    448450PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
    449451PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
    450                                                PyObject *, PyObject *);
     452                                               PyObject *, PyObject *);
    451453PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
     454PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, char *, PyObject **);
    452455PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
    453456PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
     
    474477PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
    475478PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
     479PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *);
    476480PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
    477481PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *,
    478                                               PyObject *, PyObject *);
     482                                              PyObject *, PyObject *);
    479483PyAPI_FUNC(long) PyObject_Hash(PyObject *);
    480484PyAPI_FUNC(long) PyObject_HashNotImplemented(PyObject *);
     
    489493/* A slot function whose address we need to compare */
    490494extern int _PyObject_SlotCompare(PyObject *, PyObject *);
     495/* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes
     496   dict as the last parameter. */
     497PyAPI_FUNC(PyObject *)
     498_PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *);
     499PyAPI_FUNC(int)
     500_PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
     501                                 PyObject *, PyObject *);
    491502
    492503
     
    507518PyAPI_FUNC(long) _Py_HashPointer(void*);
    508519
     520typedef struct {
     521    long prefix;
     522    long suffix;
     523} _Py_HashSecret_t;
     524PyAPI_DATA(_Py_HashSecret_t) _Py_HashSecret;
     525
     526#ifdef Py_DEBUG
     527PyAPI_DATA(int) _Py_HashSecret_Initialized;
     528#endif
     529
    509530/* Helper for passing objects to printf and the like */
    510531#define PyObject_REPR(obj) PyString_AS_STRING(PyObject_Repr(obj))
    511532
    512533/* Flag bits for printing: */
    513 #define Py_PRINT_RAW    1       /* No string quotes etc. */
     534#define Py_PRINT_RAW    1       /* No string quotes etc. */
    514535
    515536/*
     
    604625
    605626/* These flags are used to determine if a type is a subclass. */
    606 #define Py_TPFLAGS_INT_SUBCLASS         (1L<<23)
    607 #define Py_TPFLAGS_LONG_SUBCLASS        (1L<<24)
    608 #define Py_TPFLAGS_LIST_SUBCLASS        (1L<<25)
    609 #define Py_TPFLAGS_TUPLE_SUBCLASS       (1L<<26)
    610 #define Py_TPFLAGS_STRING_SUBCLASS      (1L<<27)
    611 #define Py_TPFLAGS_UNICODE_SUBCLASS     (1L<<28)
    612 #define Py_TPFLAGS_DICT_SUBCLASS        (1L<<29)
    613 #define Py_TPFLAGS_BASE_EXC_SUBCLASS    (1L<<30)
    614 #define Py_TPFLAGS_TYPE_SUBCLASS        (1L<<31)
     627#define Py_TPFLAGS_INT_SUBCLASS         (1L<<23)
     628#define Py_TPFLAGS_LONG_SUBCLASS        (1L<<24)
     629#define Py_TPFLAGS_LIST_SUBCLASS        (1L<<25)
     630#define Py_TPFLAGS_TUPLE_SUBCLASS       (1L<<26)
     631#define Py_TPFLAGS_STRING_SUBCLASS      (1L<<27)
     632#define Py_TPFLAGS_UNICODE_SUBCLASS     (1L<<28)
     633#define Py_TPFLAGS_DICT_SUBCLASS        (1L<<29)
     634#define Py_TPFLAGS_BASE_EXC_SUBCLASS    (1L<<30)
     635#define Py_TPFLAGS_TYPE_SUBCLASS        (1L<<31)
    615636
    616637#define Py_TPFLAGS_DEFAULT_EXTERNAL ( \
    617                              Py_TPFLAGS_HAVE_GETCHARBUFFER | \
    618                              Py_TPFLAGS_HAVE_SEQUENCE_IN | \
    619                              Py_TPFLAGS_HAVE_INPLACEOPS | \
    620                              Py_TPFLAGS_HAVE_RICHCOMPARE | \
    621                              Py_TPFLAGS_HAVE_WEAKREFS | \
    622                              Py_TPFLAGS_HAVE_ITER | \
    623                              Py_TPFLAGS_HAVE_CLASS | \
    624                              Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
    625                              Py_TPFLAGS_HAVE_INDEX | \
    626                              0)
     638                 Py_TPFLAGS_HAVE_GETCHARBUFFER | \
     639                 Py_TPFLAGS_HAVE_SEQUENCE_IN | \
     640                 Py_TPFLAGS_HAVE_INPLACEOPS | \
     641                 Py_TPFLAGS_HAVE_RICHCOMPARE | \
     642                 Py_TPFLAGS_HAVE_WEAKREFS | \
     643                 Py_TPFLAGS_HAVE_ITER | \
     644                 Py_TPFLAGS_HAVE_CLASS | \
     645                 Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
     646                 Py_TPFLAGS_HAVE_INDEX | \
     647                 0)
    627648#define Py_TPFLAGS_DEFAULT_CORE (Py_TPFLAGS_DEFAULT_EXTERNAL | \
    628                                  Py_TPFLAGS_HAVE_VERSION_TAG)
     649                 Py_TPFLAGS_HAVE_VERSION_TAG)
    629650
    630651#ifdef Py_BUILD_CORE
     
    684705PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
    685706PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname,
    686                                             int lineno, PyObject *op);
     707                                            int lineno, PyObject *op);
    687708PyAPI_FUNC(PyObject *) _PyDict_Dummy(void);
    688709PyAPI_FUNC(PyObject *) _PySet_Dummy(void);
    689710PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
    690 #define _Py_INC_REFTOTAL        _Py_RefTotal++
    691 #define _Py_DEC_REFTOTAL        _Py_RefTotal--
    692 #define _Py_REF_DEBUG_COMMA     ,
    693 #define _Py_CHECK_REFCNT(OP)                                    \
    694 {       if (((PyObject*)OP)->ob_refcnt < 0)                             \
    695                 _Py_NegativeRefcount(__FILE__, __LINE__,        \
    696                                      (PyObject *)(OP));         \
     711#define _Py_INC_REFTOTAL        _Py_RefTotal++
     712#define _Py_DEC_REFTOTAL        _Py_RefTotal--
     713#define _Py_REF_DEBUG_COMMA     ,
     714#define _Py_CHECK_REFCNT(OP)                                    \
     715{       if (((PyObject*)OP)->ob_refcnt < 0)                             \
     716                _Py_NegativeRefcount(__FILE__, __LINE__,        \
     717                                     (PyObject *)(OP));         \
    697718}
    698719#else
     
    700721#define _Py_DEC_REFTOTAL
    701722#define _Py_REF_DEBUG_COMMA
    702 #define _Py_CHECK_REFCNT(OP)    /* a semicolon */;
     723#define _Py_CHECK_REFCNT(OP)    /* a semicolon */;
    703724#endif /* Py_REF_DEBUG */
    704725
     
    706727PyAPI_FUNC(void) inc_count(PyTypeObject *);
    707728PyAPI_FUNC(void) dec_count(PyTypeObject *);
    708 #define _Py_INC_TPALLOCS(OP)    inc_count(Py_TYPE(OP))
    709 #define _Py_INC_TPFREES(OP)     dec_count(Py_TYPE(OP))
    710 #define _Py_DEC_TPFREES(OP)     Py_TYPE(OP)->tp_frees--
    711 #define _Py_COUNT_ALLOCS_COMMA  ,
     729#define _Py_INC_TPALLOCS(OP)    inc_count(Py_TYPE(OP))
     730#define _Py_INC_TPFREES(OP)     dec_count(Py_TYPE(OP))
     731#define _Py_DEC_TPFREES(OP)     Py_TYPE(OP)->tp_frees--
     732#define _Py_COUNT_ALLOCS_COMMA  ,
    712733#else
    713734#define _Py_INC_TPALLOCS(OP)
     
    730751 * inline.
    731752 */
    732 #define _Py_NewReference(op) (                          \
    733         _Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA     \
    734         _Py_INC_REFTOTAL  _Py_REF_DEBUG_COMMA           \
    735         Py_REFCNT(op) = 1)
     753#define _Py_NewReference(op) (                          \
     754    _Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA         \
     755    _Py_INC_REFTOTAL  _Py_REF_DEBUG_COMMA               \
     756    Py_REFCNT(op) = 1)
    736757
    737758#define _Py_ForgetReference(op) _Py_INC_TPFREES(op)
    738759
    739 #define _Py_Dealloc(op) (                               \
    740         _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA      \
    741         (*Py_TYPE(op)->tp_dealloc)((PyObject *)(op)))
     760#define _Py_Dealloc(op) (                               \
     761    _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA          \
     762    (*Py_TYPE(op)->tp_dealloc)((PyObject *)(op)))
    742763#endif /* !Py_TRACE_REFS */
    743764
    744 #define Py_INCREF(op) (                         \
    745         _Py_INC_REFTOTAL  _Py_REF_DEBUG_COMMA   \
    746         ((PyObject*)(op))->ob_refcnt++)
    747 
    748 #define Py_DECREF(op)                                   \
    749         if (_Py_DEC_REFTOTAL  _Py_REF_DEBUG_COMMA       \
    750             --((PyObject*)(op))->ob_refcnt != 0)                \
    751                 _Py_CHECK_REFCNT(op)                    \
    752         else                                            \
    753                 _Py_Dealloc((PyObject *)(op))
     765#define Py_INCREF(op) (                         \
     766    _Py_INC_REFTOTAL  _Py_REF_DEBUG_COMMA       \
     767    ((PyObject*)(op))->ob_refcnt++)
     768
     769#define Py_DECREF(op)                                   \
     770    do {                                                \
     771        if (_Py_DEC_REFTOTAL  _Py_REF_DEBUG_COMMA       \
     772        --((PyObject*)(op))->ob_refcnt != 0)            \
     773            _Py_CHECK_REFCNT(op)                        \
     774        else                                            \
     775        _Py_Dealloc((PyObject *)(op));                  \
     776    } while (0)
    754777
    755778/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
     
    787810 * to use Py_CLEAR() even if you can't think of a reason for why you need to.
    788811 */
    789 #define Py_CLEAR(op)                            \
    790         do {                                    \
    791                 if (op) {                       \
    792                         PyObject *_py_tmp = (PyObject *)(op);   \
    793                         (op) = NULL;            \
    794                         Py_DECREF(_py_tmp);     \
    795                 }                               \
    796         } while (0)
     812#define Py_CLEAR(op)                            \
     813    do {                                        \
     814        if (op) {                               \
     815            PyObject *_py_tmp = (PyObject *)(op);               \
     816            (op) = NULL;                        \
     817            Py_DECREF(_py_tmp);                 \
     818        }                                       \
     819    } while (0)
    797820
    798821/* Macros to use in case the object pointer may be NULL: */
    799 #define Py_XINCREF(op) if ((op) == NULL) ; else Py_INCREF(op)
    800 #define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op)
     822#define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0)
     823#define Py_XDECREF(op) do { if ((op) == NULL) ; else Py_DECREF(op); } while (0)
    801824
    802825/*
     
    921944mytype_dealloc(mytype *p)
    922945{
    923         ... declarations go here ...
    924 
    925         PyObject_GC_UnTrack(p);    // must untrack first
    926         Py_TRASHCAN_SAFE_BEGIN(p)
    927         ... The body of the deallocator goes here, including all calls ...
    928         ... to Py_DECREF on contained objects.                         ...
    929         Py_TRASHCAN_SAFE_END(p)
     946    ... declarations go here ...
     947
     948    PyObject_GC_UnTrack(p);        // must untrack first
     949    Py_TRASHCAN_SAFE_BEGIN(p)
     950    ... The body of the deallocator goes here, including all calls ...
     951    ... to Py_DECREF on contained objects.                         ...
     952    Py_TRASHCAN_SAFE_END(p)
    930953}
    931954
     
    949972*/
    950973
     974/* This is the old private API, invoked by the macros before 2.7.4.
     975   Kept for binary compatibility of extensions. */
    951976PyAPI_FUNC(void) _PyTrash_deposit_object(PyObject*);
    952977PyAPI_FUNC(void) _PyTrash_destroy_chain(void);
     
    954979PyAPI_DATA(PyObject *) _PyTrash_delete_later;
    955980
     981/* The new thread-safe private API, invoked by the macros below. */
     982PyAPI_FUNC(void) _PyTrash_thread_deposit_object(PyObject*);
     983PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(void);
     984
    956985#define PyTrash_UNWIND_LEVEL 50
    957986
     987/* Note the workaround for when the thread state is NULL (issue #17703) */
    958988#define Py_TRASHCAN_SAFE_BEGIN(op) \
    959         if (_PyTrash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
    960                 ++_PyTrash_delete_nesting;
    961                 /* The body of the deallocator is here. */
     989    do { \
     990        PyThreadState *_tstate = PyThreadState_GET(); \
     991        if (!_tstate || \
     992            _tstate->trash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
     993            if (_tstate) \
     994                ++_tstate->trash_delete_nesting;
     995            /* The body of the deallocator is here. */
    962996#define Py_TRASHCAN_SAFE_END(op) \
    963                 --_PyTrash_delete_nesting; \
    964                 if (_PyTrash_delete_later && _PyTrash_delete_nesting <= 0) \
    965                         _PyTrash_destroy_chain(); \
    966         } \
    967         else \
    968                 _PyTrash_deposit_object((PyObject*)op);
     997            if (_tstate) { \
     998                --_tstate->trash_delete_nesting; \
     999                if (_tstate->trash_delete_later \
     1000                    && _tstate->trash_delete_nesting <= 0) \
     1001                    _PyTrash_thread_destroy_chain(); \
     1002            } \
     1003        } \
     1004        else \
     1005            _PyTrash_thread_deposit_object((PyObject*)op); \
     1006    } while (0);
    9691007
    9701008#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.