Changeset 391 for python/trunk/Include/object.h
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Include/object.h
r2 r391 64 64 #ifdef Py_TRACE_REFS 65 65 /* Define pointers to support a doubly-linked list of all live heap objects. */ 66 #define _PyObject_HEAD_EXTRA 67 struct _object *_ob_next;\68 66 #define _PyObject_HEAD_EXTRA \ 67 struct _object *_ob_next; \ 68 struct _object *_ob_prev; 69 69 70 70 #define _PyObject_EXTRA_INIT 0, 0, … … 76 76 77 77 /* PyObject_HEAD defines the initial segment of every PyObject. */ 78 #define PyObject_HEAD 79 _PyObject_HEAD_EXTRA\80 Py_ssize_t ob_refcnt;\81 82 83 #define PyObject_HEAD_INIT(type) 84 _PyObject_EXTRA_INIT\85 86 87 #define PyVarObject_HEAD_INIT(type, size) 88 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, 89 89 90 90 /* PyObject_VAR_HEAD defines the initial segment of all variable-size … … 94 94 * not necessarily a byte count. 95 95 */ 96 #define PyObject_VAR_HEAD 97 PyObject_HEAD\98 96 #define PyObject_VAR_HEAD \ 97 PyObject_HEAD \ 98 Py_ssize_t ob_size; /* Number of items in variable part */ 99 99 #define Py_INVALID_SIZE (Py_ssize_t)-1 100 100 … … 105 105 */ 106 106 typedef struct _object { 107 107 PyObject_HEAD 108 108 } PyObject; 109 109 110 110 typedef struct { 111 111 PyObject_VAR_HEAD 112 112 } PyVarObject; 113 113 114 #define Py_REFCNT(ob) 115 #define Py_TYPE(ob) 116 #define Py_SIZE(ob) 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) 117 117 118 118 /* … … 160 160 typedef Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, char **); 161 161 162 162 163 /* Py3k buffer interface */ 163 164 164 typedef 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; 177 179 } Py_buffer; 178 180 … … 180 182 typedef void (*releasebufferproc)(PyObject *, Py_buffer *); 181 183 182 184 /* Flags for getting buffers */ 183 185 #define PyBUF_SIMPLE 0 184 186 #define PyBUF_WRITABLE 0x0001 … … 216 218 217 219 typedef struct { 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 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; 271 273 } PyNumberMethods; 272 274 273 275 typedef struct { 274 275 276 277 278 279 280 281 282 283 284 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; 285 287 } PySequenceMethods; 286 288 287 289 typedef struct { 288 289 290 290 lenfunc mp_length; 291 binaryfunc mp_subscript; 292 objobjargproc mp_ass_subscript; 291 293 } PyMappingMethods; 292 294 293 295 typedef struct { 294 295 296 297 298 299 296 readbufferproc bf_getreadbuffer; 297 writebufferproc bf_getwritebuffer; 298 segcountproc bf_getsegcount; 299 charbufferproc bf_getcharbuffer; 300 getbufferproc bf_getbuffer; 301 releasebufferproc bf_releasebuffer; 300 302 } PyBufferProcs; 301 303 … … 321 323 322 324 typedef struct _typeobject { 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 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; 400 402 401 403 #ifdef COUNT_ALLOCS 402 403 404 405 406 407 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; 408 410 #endif 409 411 } PyTypeObject; … … 412 414 /* The *real* layout of a type object when allocated on the heap */ 413 415 typedef struct _heaptypeobject { 414 415 416 417 418 419 420 421 422 423 424 425 426 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. */ 427 429 } PyHeapTypeObject; 428 430 … … 435 437 PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *); 436 438 #define PyObject_TypeCheck(ob, tp) \ 437 439 (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp))) 438 440 439 441 PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */ … … 442 444 443 445 #define PyType_Check(op) \ 444 446 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS) 445 447 #define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type) 446 448 … … 448 450 PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t); 449 451 PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *, 450 452 PyObject *, PyObject *); 451 453 PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *); 454 PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, char *, PyObject **); 452 455 PyAPI_FUNC(unsigned int) PyType_ClearCache(void); 453 456 PyAPI_FUNC(void) PyType_Modified(PyTypeObject *); … … 474 477 PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *); 475 478 PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *); 479 PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *); 476 480 PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *); 477 481 PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *, 478 482 PyObject *, PyObject *); 479 483 PyAPI_FUNC(long) PyObject_Hash(PyObject *); 480 484 PyAPI_FUNC(long) PyObject_HashNotImplemented(PyObject *); … … 489 493 /* A slot function whose address we need to compare */ 490 494 extern int _PyObject_SlotCompare(PyObject *, PyObject *); 495 /* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes 496 dict as the last parameter. */ 497 PyAPI_FUNC(PyObject *) 498 _PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *); 499 PyAPI_FUNC(int) 500 _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *, 501 PyObject *, PyObject *); 491 502 492 503 … … 507 518 PyAPI_FUNC(long) _Py_HashPointer(void*); 508 519 520 typedef struct { 521 long prefix; 522 long suffix; 523 } _Py_HashSecret_t; 524 PyAPI_DATA(_Py_HashSecret_t) _Py_HashSecret; 525 526 #ifdef Py_DEBUG 527 PyAPI_DATA(int) _Py_HashSecret_Initialized; 528 #endif 529 509 530 /* Helper for passing objects to printf and the like */ 510 531 #define PyObject_REPR(obj) PyString_AS_STRING(PyObject_Repr(obj)) 511 532 512 533 /* Flag bits for printing: */ 513 #define Py_PRINT_RAW 1/* No string quotes etc. */534 #define Py_PRINT_RAW 1 /* No string quotes etc. */ 514 535 515 536 /* … … 604 625 605 626 /* These flags are used to determine if a type is a subclass. */ 606 #define Py_TPFLAGS_INT_SUBCLASS 607 #define Py_TPFLAGS_LONG_SUBCLASS 608 #define Py_TPFLAGS_LIST_SUBCLASS 609 #define Py_TPFLAGS_TUPLE_SUBCLASS 610 #define Py_TPFLAGS_STRING_SUBCLASS 611 #define Py_TPFLAGS_UNICODE_SUBCLASS 612 #define Py_TPFLAGS_DICT_SUBCLASS 613 #define Py_TPFLAGS_BASE_EXC_SUBCLASS 614 #define Py_TPFLAGS_TYPE_SUBCLASS 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) 615 636 616 637 #define Py_TPFLAGS_DEFAULT_EXTERNAL ( \ 617 618 619 620 621 622 623 624 625 626 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) 627 648 #define Py_TPFLAGS_DEFAULT_CORE (Py_TPFLAGS_DEFAULT_EXTERNAL | \ 628 649 Py_TPFLAGS_HAVE_VERSION_TAG) 629 650 630 651 #ifdef Py_BUILD_CORE … … 684 705 PyAPI_DATA(Py_ssize_t) _Py_RefTotal; 685 706 PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname, 686 707 int lineno, PyObject *op); 687 708 PyAPI_FUNC(PyObject *) _PyDict_Dummy(void); 688 709 PyAPI_FUNC(PyObject *) _PySet_Dummy(void); 689 710 PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void); 690 #define _Py_INC_REFTOTAL 691 #define _Py_DEC_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)); \ 697 718 } 698 719 #else … … 700 721 #define _Py_DEC_REFTOTAL 701 722 #define _Py_REF_DEBUG_COMMA 702 #define _Py_CHECK_REFCNT(OP) 723 #define _Py_CHECK_REFCNT(OP) /* a semicolon */; 703 724 #endif /* Py_REF_DEBUG */ 704 725 … … 706 727 PyAPI_FUNC(void) inc_count(PyTypeObject *); 707 728 PyAPI_FUNC(void) dec_count(PyTypeObject *); 708 #define _Py_INC_TPALLOCS(OP) 709 #define _Py_INC_TPFREES(OP) 710 #define _Py_DEC_TPFREES(OP) 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 , 712 733 #else 713 734 #define _Py_INC_TPALLOCS(OP) … … 730 751 * inline. 731 752 */ 732 #define _Py_NewReference(op) ( 733 _Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA\734 _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA\735 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) 736 757 737 758 #define _Py_ForgetReference(op) _Py_INC_TPFREES(op) 738 759 739 #define _Py_Dealloc(op) ( 740 _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA\741 760 #define _Py_Dealloc(op) ( \ 761 _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \ 762 (*Py_TYPE(op)->tp_dealloc)((PyObject *)(op))) 742 763 #endif /* !Py_TRACE_REFS */ 743 764 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) 754 777 755 778 /* Safely decref `op` and set `op` to NULL, especially useful in tp_clear … … 787 810 * to use Py_CLEAR() even if you can't think of a reason for why you need to. 788 811 */ 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 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) 797 820 798 821 /* 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) 801 824 802 825 /* … … 921 944 mytype_dealloc(mytype *p) 922 945 { 923 924 925 PyObject_GC_UnTrack(p);// must untrack first926 927 928 929 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) 930 953 } 931 954 … … 949 972 */ 950 973 974 /* This is the old private API, invoked by the macros before 2.7.4. 975 Kept for binary compatibility of extensions. */ 951 976 PyAPI_FUNC(void) _PyTrash_deposit_object(PyObject*); 952 977 PyAPI_FUNC(void) _PyTrash_destroy_chain(void); … … 954 979 PyAPI_DATA(PyObject *) _PyTrash_delete_later; 955 980 981 /* The new thread-safe private API, invoked by the macros below. */ 982 PyAPI_FUNC(void) _PyTrash_thread_deposit_object(PyObject*); 983 PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(void); 984 956 985 #define PyTrash_UNWIND_LEVEL 50 957 986 987 /* Note the workaround for when the thread state is NULL (issue #17703) */ 958 988 #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. */ 962 996 #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); 969 1007 970 1008 #ifdef __cplusplus
Note:
See TracChangeset
for help on using the changeset viewer.