File indexing completed on 2025-01-18 10:06:49
0001 #ifndef Py_OBJECT_H
0002 #define Py_OBJECT_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 #include "pystats.h"
0055
0056
0057 #if defined(Py_DEBUG) && !defined(Py_REF_DEBUG)
0058 # define Py_REF_DEBUG
0059 #endif
0060
0061 #if defined(Py_LIMITED_API) && defined(Py_TRACE_REFS)
0062 # error Py_LIMITED_API is incompatible with Py_TRACE_REFS
0063 #endif
0064
0065 #ifdef Py_TRACE_REFS
0066
0067 #define _PyObject_HEAD_EXTRA \
0068 PyObject *_ob_next; \
0069 PyObject *_ob_prev;
0070
0071 #define _PyObject_EXTRA_INIT _Py_NULL, _Py_NULL,
0072
0073 #else
0074 # define _PyObject_HEAD_EXTRA
0075 # define _PyObject_EXTRA_INIT
0076 #endif
0077
0078
0079 #define PyObject_HEAD PyObject ob_base;
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095 #if SIZEOF_VOID_P > 4
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110 #define _Py_IMMORTAL_REFCNT UINT_MAX
0111
0112 #else
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 #define _Py_IMMORTAL_REFCNT (UINT_MAX >> 2)
0126 #endif
0127
0128
0129
0130 #ifdef Py_BUILD_CORE
0131 #define PyObject_HEAD_INIT(type) \
0132 { \
0133 _PyObject_EXTRA_INIT \
0134 { _Py_IMMORTAL_REFCNT }, \
0135 (type) \
0136 },
0137 #else
0138 #define PyObject_HEAD_INIT(type) \
0139 { \
0140 _PyObject_EXTRA_INIT \
0141 { 1 }, \
0142 (type) \
0143 },
0144 #endif
0145
0146 #define PyVarObject_HEAD_INIT(type, size) \
0147 { \
0148 PyObject_HEAD_INIT(type) \
0149 (size) \
0150 },
0151
0152
0153
0154
0155
0156
0157
0158 #define PyObject_VAR_HEAD PyVarObject ob_base;
0159 #define Py_INVALID_SIZE (Py_ssize_t)-1
0160
0161
0162
0163
0164
0165
0166 struct _object {
0167 _PyObject_HEAD_EXTRA
0168
0169 #if (defined(__GNUC__) || defined(__clang__)) \
0170 && !(defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L)
0171
0172 __extension__
0173 #endif
0174 #ifdef _MSC_VER
0175
0176
0177 __pragma(warning(push))
0178 __pragma(warning(disable: 4201))
0179 #endif
0180 union {
0181 Py_ssize_t ob_refcnt;
0182 #if SIZEOF_VOID_P > 4
0183 PY_UINT32_T ob_refcnt_split[2];
0184 #endif
0185 };
0186 #ifdef _MSC_VER
0187 __pragma(warning(pop))
0188 #endif
0189
0190 PyTypeObject *ob_type;
0191 };
0192
0193
0194 #define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
0195
0196 typedef struct {
0197 PyObject ob_base;
0198 Py_ssize_t ob_size;
0199 } PyVarObject;
0200
0201
0202 #define _PyVarObject_CAST(op) _Py_CAST(PyVarObject*, (op))
0203
0204
0205
0206 PyAPI_FUNC(int) Py_Is(PyObject *x, PyObject *y);
0207 #define Py_Is(x, y) ((x) == (y))
0208
0209
0210 static inline Py_ssize_t Py_REFCNT(PyObject *ob) {
0211 return ob->ob_refcnt;
0212 }
0213 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0214 # define Py_REFCNT(ob) Py_REFCNT(_PyObject_CAST(ob))
0215 #endif
0216
0217
0218
0219 static inline PyTypeObject* Py_TYPE(PyObject *ob) {
0220 return ob->ob_type;
0221 }
0222 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0223 # define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
0224 #endif
0225
0226 PyAPI_DATA(PyTypeObject) PyLong_Type;
0227 PyAPI_DATA(PyTypeObject) PyBool_Type;
0228
0229
0230 static inline Py_ssize_t Py_SIZE(PyObject *ob) {
0231 assert(ob->ob_type != &PyLong_Type);
0232 assert(ob->ob_type != &PyBool_Type);
0233 return _PyVarObject_CAST(ob)->ob_size;
0234 }
0235 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0236 # define Py_SIZE(ob) Py_SIZE(_PyObject_CAST(ob))
0237 #endif
0238
0239 static inline Py_ALWAYS_INLINE int _Py_IsImmortal(PyObject *op)
0240 {
0241 #if SIZEOF_VOID_P > 4
0242 return _Py_CAST(PY_INT32_T, op->ob_refcnt) < 0;
0243 #else
0244 return op->ob_refcnt == _Py_IMMORTAL_REFCNT;
0245 #endif
0246 }
0247 #define _Py_IsImmortal(op) _Py_IsImmortal(_PyObject_CAST(op))
0248
0249 static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
0250 return Py_TYPE(ob) == type;
0251 }
0252 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0253 # define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
0254 #endif
0255
0256
0257 static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
0258
0259
0260
0261
0262 if (_Py_IsImmortal(ob)) {
0263 return;
0264 }
0265 ob->ob_refcnt = refcnt;
0266 }
0267 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0268 # define Py_SET_REFCNT(ob, refcnt) Py_SET_REFCNT(_PyObject_CAST(ob), (refcnt))
0269 #endif
0270
0271
0272 static inline void Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {
0273 ob->ob_type = type;
0274 }
0275 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0276 # define Py_SET_TYPE(ob, type) Py_SET_TYPE(_PyObject_CAST(ob), type)
0277 #endif
0278
0279 static inline void Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) {
0280 assert(ob->ob_base.ob_type != &PyLong_Type);
0281 assert(ob->ob_base.ob_type != &PyBool_Type);
0282 ob->ob_size = size;
0283 }
0284 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0285 # define Py_SET_SIZE(ob, size) Py_SET_SIZE(_PyVarObject_CAST(ob), (size))
0286 #endif
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304 typedef PyObject * (*unaryfunc)(PyObject *);
0305 typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
0306 typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
0307 typedef int (*inquiry)(PyObject *);
0308 typedef Py_ssize_t (*lenfunc)(PyObject *);
0309 typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
0310 typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
0311 typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
0312 typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
0313 typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
0314
0315 typedef int (*objobjproc)(PyObject *, PyObject *);
0316 typedef int (*visitproc)(PyObject *, void *);
0317 typedef int (*traverseproc)(PyObject *, visitproc, void *);
0318
0319
0320 typedef void (*freefunc)(void *);
0321 typedef void (*destructor)(PyObject *);
0322 typedef PyObject *(*getattrfunc)(PyObject *, char *);
0323 typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
0324 typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
0325 typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
0326 typedef PyObject *(*reprfunc)(PyObject *);
0327 typedef Py_hash_t (*hashfunc)(PyObject *);
0328 typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
0329 typedef PyObject *(*getiterfunc) (PyObject *);
0330 typedef PyObject *(*iternextfunc) (PyObject *);
0331 typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *);
0332 typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *);
0333 typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
0334 typedef PyObject *(*newfunc)(PyTypeObject *, PyObject *, PyObject *);
0335 typedef PyObject *(*allocfunc)(PyTypeObject *, Py_ssize_t);
0336
0337 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030c0000
0338 typedef PyObject *(*vectorcallfunc)(PyObject *callable, PyObject *const *args,
0339 size_t nargsf, PyObject *kwnames);
0340 #endif
0341
0342 typedef struct{
0343 int slot;
0344 void *pfunc;
0345 } PyType_Slot;
0346
0347 typedef struct{
0348 const char* name;
0349 int basicsize;
0350 int itemsize;
0351 unsigned int flags;
0352 PyType_Slot *slots;
0353 } PyType_Spec;
0354
0355 PyAPI_FUNC(PyObject*) PyType_FromSpec(PyType_Spec*);
0356 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
0357 PyAPI_FUNC(PyObject*) PyType_FromSpecWithBases(PyType_Spec*, PyObject*);
0358 #endif
0359 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000
0360 PyAPI_FUNC(void*) PyType_GetSlot(PyTypeObject*, int);
0361 #endif
0362 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
0363 PyAPI_FUNC(PyObject*) PyType_FromModuleAndSpec(PyObject *, PyType_Spec *, PyObject *);
0364 PyAPI_FUNC(PyObject *) PyType_GetModule(PyTypeObject *);
0365 PyAPI_FUNC(void *) PyType_GetModuleState(PyTypeObject *);
0366 #endif
0367 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030B0000
0368 PyAPI_FUNC(PyObject *) PyType_GetName(PyTypeObject *);
0369 PyAPI_FUNC(PyObject *) PyType_GetQualName(PyTypeObject *);
0370 #endif
0371 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030C0000
0372 PyAPI_FUNC(PyObject *) PyType_FromMetaclass(PyTypeObject*, PyObject*, PyType_Spec*, PyObject*);
0373 PyAPI_FUNC(void *) PyObject_GetTypeData(PyObject *obj, PyTypeObject *cls);
0374 PyAPI_FUNC(Py_ssize_t) PyType_GetTypeDataSize(PyTypeObject *cls);
0375 #endif
0376
0377
0378 PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
0379
0380 static inline int PyObject_TypeCheck(PyObject *ob, PyTypeObject *type) {
0381 return Py_IS_TYPE(ob, type) || PyType_IsSubtype(Py_TYPE(ob), type);
0382 }
0383 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0384 # define PyObject_TypeCheck(ob, type) PyObject_TypeCheck(_PyObject_CAST(ob), (type))
0385 #endif
0386
0387 PyAPI_DATA(PyTypeObject) PyType_Type;
0388 PyAPI_DATA(PyTypeObject) PyBaseObject_Type;
0389 PyAPI_DATA(PyTypeObject) PySuper_Type;
0390
0391 PyAPI_FUNC(unsigned long) PyType_GetFlags(PyTypeObject*);
0392
0393 PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
0394 PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
0395 PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
0396 PyObject *, PyObject *);
0397 PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
0398 PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
0399
0400
0401 PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *);
0402 PyAPI_FUNC(PyObject *) PyObject_Str(PyObject *);
0403 PyAPI_FUNC(PyObject *) PyObject_ASCII(PyObject *);
0404 PyAPI_FUNC(PyObject *) PyObject_Bytes(PyObject *);
0405 PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
0406 PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
0407 PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *);
0408 PyAPI_FUNC(int) PyObject_SetAttrString(PyObject *, const char *, PyObject *);
0409 PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *);
0410 PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
0411 PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
0412 PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
0413 PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
0414 PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
0415 PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *, PyObject *, PyObject *);
0416 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
0417 PyAPI_FUNC(int) PyObject_GenericSetDict(PyObject *, PyObject *, void *);
0418 #endif
0419 PyAPI_FUNC(Py_hash_t) PyObject_Hash(PyObject *);
0420 PyAPI_FUNC(Py_hash_t) PyObject_HashNotImplemented(PyObject *);
0421 PyAPI_FUNC(int) PyObject_IsTrue(PyObject *);
0422 PyAPI_FUNC(int) PyObject_Not(PyObject *);
0423 PyAPI_FUNC(int) PyCallable_Check(PyObject *);
0424 PyAPI_FUNC(void) PyObject_ClearWeakRefs(PyObject *);
0425
0426
0427
0428
0429
0430
0431 PyAPI_FUNC(PyObject *) PyObject_Dir(PyObject *);
0432
0433
0434 #ifndef Py_LIMITED_API
0435 PyAPI_FUNC(PyObject *) _PyObject_GetState(PyObject *);
0436 #endif
0437
0438
0439
0440 PyAPI_FUNC(int) Py_ReprEnter(PyObject *);
0441 PyAPI_FUNC(void) Py_ReprLeave(PyObject *);
0442
0443
0444 #define Py_PRINT_RAW 1
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466 #ifndef Py_LIMITED_API
0467
0468
0469 #define _Py_TPFLAGS_STATIC_BUILTIN (1 << 1)
0470
0471
0472
0473
0474 #define Py_TPFLAGS_MANAGED_WEAKREF (1 << 3)
0475
0476
0477
0478
0479 #define Py_TPFLAGS_MANAGED_DICT (1 << 4)
0480
0481 #define Py_TPFLAGS_PREHEADER (Py_TPFLAGS_MANAGED_WEAKREF | Py_TPFLAGS_MANAGED_DICT)
0482
0483
0484 #define Py_TPFLAGS_SEQUENCE (1 << 5)
0485
0486 #define Py_TPFLAGS_MAPPING (1 << 6)
0487 #endif
0488
0489
0490
0491 #define Py_TPFLAGS_DISALLOW_INSTANTIATION (1UL << 7)
0492
0493
0494 #define Py_TPFLAGS_IMMUTABLETYPE (1UL << 8)
0495
0496
0497 #define Py_TPFLAGS_HEAPTYPE (1UL << 9)
0498
0499
0500 #define Py_TPFLAGS_BASETYPE (1UL << 10)
0501
0502
0503 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030C0000
0504 #define Py_TPFLAGS_HAVE_VECTORCALL (1UL << 11)
0505 #ifndef Py_LIMITED_API
0506
0507 #define _Py_TPFLAGS_HAVE_VECTORCALL Py_TPFLAGS_HAVE_VECTORCALL
0508 #endif
0509 #endif
0510
0511
0512 #define Py_TPFLAGS_READY (1UL << 12)
0513
0514
0515 #define Py_TPFLAGS_READYING (1UL << 13)
0516
0517
0518 #define Py_TPFLAGS_HAVE_GC (1UL << 14)
0519
0520
0521 #ifdef STACKLESS
0522 #define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION (3UL << 15)
0523 #else
0524 #define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
0525 #endif
0526
0527
0528 #define Py_TPFLAGS_METHOD_DESCRIPTOR (1UL << 17)
0529
0530
0531 #define Py_TPFLAGS_VALID_VERSION_TAG (1UL << 19)
0532
0533
0534 #define Py_TPFLAGS_IS_ABSTRACT (1UL << 20)
0535
0536
0537
0538
0539 #define _Py_TPFLAGS_MATCH_SELF (1UL << 22)
0540
0541
0542 #define Py_TPFLAGS_ITEMS_AT_END (1UL << 23)
0543
0544
0545 #define Py_TPFLAGS_LONG_SUBCLASS (1UL << 24)
0546 #define Py_TPFLAGS_LIST_SUBCLASS (1UL << 25)
0547 #define Py_TPFLAGS_TUPLE_SUBCLASS (1UL << 26)
0548 #define Py_TPFLAGS_BYTES_SUBCLASS (1UL << 27)
0549 #define Py_TPFLAGS_UNICODE_SUBCLASS (1UL << 28)
0550 #define Py_TPFLAGS_DICT_SUBCLASS (1UL << 29)
0551 #define Py_TPFLAGS_BASE_EXC_SUBCLASS (1UL << 30)
0552 #define Py_TPFLAGS_TYPE_SUBCLASS (1UL << 31)
0553
0554 #define Py_TPFLAGS_DEFAULT ( \
0555 Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
0556 0)
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571 #define Py_TPFLAGS_HAVE_FINALIZE (1UL << 0)
0572 #define Py_TPFLAGS_HAVE_VERSION_TAG (1UL << 18)
0573
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601
0602
0603 #if defined(Py_REF_DEBUG) && !defined(Py_LIMITED_API)
0604 PyAPI_FUNC(void) _Py_NegativeRefcount(const char *filename, int lineno,
0605 PyObject *op);
0606 PyAPI_FUNC(void) _Py_INCREF_IncRefTotal(void);
0607 PyAPI_FUNC(void) _Py_DECREF_DecRefTotal(void);
0608 #endif
0609
0610 PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
0611
0612
0613
0614
0615
0616 PyAPI_FUNC(void) Py_IncRef(PyObject *);
0617 PyAPI_FUNC(void) Py_DecRef(PyObject *);
0618
0619
0620
0621 PyAPI_FUNC(void) _Py_IncRef(PyObject *);
0622 PyAPI_FUNC(void) _Py_DecRef(PyObject *);
0623
0624 static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
0625 {
0626 #if defined(Py_LIMITED_API) && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
0627
0628
0629
0630
0631 # if Py_LIMITED_API+0 >= 0x030a00A7
0632 _Py_IncRef(op);
0633 # else
0634 Py_IncRef(op);
0635 # endif
0636 #else
0637
0638
0639 #if SIZEOF_VOID_P > 4
0640
0641 PY_UINT32_T cur_refcnt = op->ob_refcnt_split[PY_BIG_ENDIAN];
0642 PY_UINT32_T new_refcnt = cur_refcnt + 1;
0643 if (new_refcnt == 0) {
0644 return;
0645 }
0646 op->ob_refcnt_split[PY_BIG_ENDIAN] = new_refcnt;
0647 #else
0648
0649 if (_Py_IsImmortal(op)) {
0650 return;
0651 }
0652 op->ob_refcnt++;
0653 #endif
0654 _Py_INCREF_STAT_INC();
0655 #ifdef Py_REF_DEBUG
0656 _Py_INCREF_IncRefTotal();
0657 #endif
0658 #endif
0659 }
0660 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0661 # define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
0662 #endif
0663
0664 #if defined(Py_LIMITED_API) && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
0665
0666
0667
0668
0669 static inline void Py_DECREF(PyObject *op) {
0670 # if Py_LIMITED_API+0 >= 0x030a00A7
0671 _Py_DecRef(op);
0672 # else
0673 Py_DecRef(op);
0674 # endif
0675 }
0676 #define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
0677
0678 #elif defined(Py_REF_DEBUG)
0679 static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
0680 {
0681 if (op->ob_refcnt <= 0) {
0682 _Py_NegativeRefcount(filename, lineno, op);
0683 }
0684 if (_Py_IsImmortal(op)) {
0685 return;
0686 }
0687 _Py_DECREF_STAT_INC();
0688 _Py_DECREF_DecRefTotal();
0689 if (--op->ob_refcnt == 0) {
0690 _Py_Dealloc(op);
0691 }
0692 }
0693 #define Py_DECREF(op) Py_DECREF(__FILE__, __LINE__, _PyObject_CAST(op))
0694
0695 #else
0696 static inline Py_ALWAYS_INLINE void Py_DECREF(PyObject *op)
0697 {
0698
0699
0700 if (_Py_IsImmortal(op)) {
0701 return;
0702 }
0703 _Py_DECREF_STAT_INC();
0704 if (--op->ob_refcnt == 0) {
0705 _Py_Dealloc(op);
0706 }
0707 }
0708 #define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
0709 #endif
0710
0711
0712
0713
0714
0715
0716
0717
0718
0719
0720
0721
0722
0723
0724
0725
0726
0727
0728
0729
0730
0731
0732
0733
0734
0735
0736
0737
0738
0739
0740
0741
0742
0743
0744
0745
0746
0747
0748
0749
0750
0751
0752
0753
0754
0755
0756
0757
0758
0759
0760 #ifdef _Py_TYPEOF
0761 #define Py_CLEAR(op) \
0762 do { \
0763 _Py_TYPEOF(op)* _tmp_op_ptr = &(op); \
0764 _Py_TYPEOF(op) _tmp_old_op = (*_tmp_op_ptr); \
0765 if (_tmp_old_op != NULL) { \
0766 *_tmp_op_ptr = _Py_NULL; \
0767 Py_DECREF(_tmp_old_op); \
0768 } \
0769 } while (0)
0770 #else
0771 #define Py_CLEAR(op) \
0772 do { \
0773 PyObject **_tmp_op_ptr = _Py_CAST(PyObject**, &(op)); \
0774 PyObject *_tmp_old_op = (*_tmp_op_ptr); \
0775 if (_tmp_old_op != NULL) { \
0776 PyObject *_null_ptr = _Py_NULL; \
0777 memcpy(_tmp_op_ptr, &_null_ptr, sizeof(PyObject*)); \
0778 Py_DECREF(_tmp_old_op); \
0779 } \
0780 } while (0)
0781 #endif
0782
0783
0784
0785 static inline void Py_XINCREF(PyObject *op)
0786 {
0787 if (op != _Py_NULL) {
0788 Py_INCREF(op);
0789 }
0790 }
0791 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0792 # define Py_XINCREF(op) Py_XINCREF(_PyObject_CAST(op))
0793 #endif
0794
0795 static inline void Py_XDECREF(PyObject *op)
0796 {
0797 if (op != _Py_NULL) {
0798 Py_DECREF(op);
0799 }
0800 }
0801 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0802 # define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
0803 #endif
0804
0805
0806
0807 PyAPI_FUNC(PyObject*) Py_NewRef(PyObject *obj);
0808
0809
0810 PyAPI_FUNC(PyObject*) Py_XNewRef(PyObject *obj);
0811
0812 static inline PyObject* _Py_NewRef(PyObject *obj)
0813 {
0814 Py_INCREF(obj);
0815 return obj;
0816 }
0817
0818 static inline PyObject* _Py_XNewRef(PyObject *obj)
0819 {
0820 Py_XINCREF(obj);
0821 return obj;
0822 }
0823
0824
0825
0826
0827 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0828 # define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
0829 # define Py_XNewRef(obj) _Py_XNewRef(_PyObject_CAST(obj))
0830 #else
0831 # define Py_NewRef(obj) _Py_NewRef(obj)
0832 # define Py_XNewRef(obj) _Py_XNewRef(obj)
0833 #endif
0834
0835
0836
0837
0838
0839
0840
0841
0842 PyAPI_DATA(PyObject) _Py_NoneStruct;
0843 #define Py_None (&_Py_NoneStruct)
0844
0845
0846 PyAPI_FUNC(int) Py_IsNone(PyObject *x);
0847 #define Py_IsNone(x) Py_Is((x), Py_None)
0848
0849
0850 #define Py_RETURN_NONE return Py_None
0851
0852
0853
0854
0855
0856 PyAPI_DATA(PyObject) _Py_NotImplementedStruct;
0857 #define Py_NotImplemented (&_Py_NotImplementedStruct)
0858
0859
0860 #define Py_RETURN_NOTIMPLEMENTED return Py_NotImplemented
0861
0862
0863 #define Py_LT 0
0864 #define Py_LE 1
0865 #define Py_EQ 2
0866 #define Py_NE 3
0867 #define Py_GT 4
0868 #define Py_GE 5
0869
0870 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
0871
0872 typedef enum {
0873 PYGEN_RETURN = 0,
0874 PYGEN_ERROR = -1,
0875 PYGEN_NEXT = 1,
0876 } PySendResult;
0877 #endif
0878
0879
0880
0881
0882
0883
0884 #define Py_RETURN_RICHCOMPARE(val1, val2, op) \
0885 do { \
0886 switch (op) { \
0887 case Py_EQ: if ((val1) == (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
0888 case Py_NE: if ((val1) != (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
0889 case Py_LT: if ((val1) < (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
0890 case Py_GT: if ((val1) > (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
0891 case Py_LE: if ((val1) <= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
0892 case Py_GE: if ((val1) >= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
0893 default: \
0894 Py_UNREACHABLE(); \
0895 } \
0896 } while (0)
0897
0898
0899
0900
0901
0902
0903
0904
0905
0906
0907
0908
0909
0910
0911
0912
0913
0914
0915
0916
0917
0918
0919
0920
0921
0922
0923
0924
0925
0926
0927
0928
0929
0930
0931
0932
0933
0934
0935
0936
0937
0938
0939
0940
0941
0942
0943
0944
0945
0946
0947
0948
0949
0950
0951 #ifndef Py_LIMITED_API
0952 # define Py_CPYTHON_OBJECT_H
0953 # include "cpython/object.h"
0954 # undef Py_CPYTHON_OBJECT_H
0955 #endif
0956
0957
0958 static inline int
0959 PyType_HasFeature(PyTypeObject *type, unsigned long feature)
0960 {
0961 unsigned long flags;
0962 #ifdef Py_LIMITED_API
0963
0964 flags = PyType_GetFlags(type);
0965 #else
0966 flags = type->tp_flags;
0967 #endif
0968 return ((flags & feature) != 0);
0969 }
0970
0971 #define PyType_FastSubclass(type, flag) PyType_HasFeature((type), (flag))
0972
0973 static inline int PyType_Check(PyObject *op) {
0974 return PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS);
0975 }
0976 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0977 # define PyType_Check(op) PyType_Check(_PyObject_CAST(op))
0978 #endif
0979
0980 #define _PyType_CAST(op) \
0981 (assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
0982
0983 static inline int PyType_CheckExact(PyObject *op) {
0984 return Py_IS_TYPE(op, &PyType_Type);
0985 }
0986 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0987 # define PyType_CheckExact(op) PyType_CheckExact(_PyObject_CAST(op))
0988 #endif
0989
0990 #ifdef __cplusplus
0991 }
0992 #endif
0993 #endif