You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2037 lines
56 KiB

36 years ago
36 years ago
36 years ago
36 years ago
23 years ago
36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
Merged revisions 53451-53537 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r53454 | brett.cannon | 2007-01-15 20:12:08 +0100 (Mon, 15 Jan 2007) | 3 lines Add a note for strptime that just because strftime supports some extra directive that is not documented that strptime will as well. ........ r53458 | vinay.sajip | 2007-01-16 10:50:07 +0100 (Tue, 16 Jan 2007) | 1 line Updated rotating file handlers to use _open(). ........ r53459 | marc-andre.lemburg | 2007-01-16 14:03:06 +0100 (Tue, 16 Jan 2007) | 2 lines Add news items for the recent pybench and platform changes. ........ r53460 | sjoerd.mullender | 2007-01-16 17:42:38 +0100 (Tue, 16 Jan 2007) | 4 lines Fixed ntpath.expandvars to not replace references to non-existing variables with nothing. Also added tests. This fixes bug #494589. ........ r53464 | neal.norwitz | 2007-01-17 07:23:51 +0100 (Wed, 17 Jan 2007) | 1 line Give Calvin Spealman access for python-dev summaries. ........ r53465 | neal.norwitz | 2007-01-17 09:37:26 +0100 (Wed, 17 Jan 2007) | 1 line Remove Calvin since he only has access to the website currently. ........ r53466 | thomas.heller | 2007-01-17 10:40:34 +0100 (Wed, 17 Jan 2007) | 2 lines Replace C++ comments with C comments. ........ r53472 | andrew.kuchling | 2007-01-17 20:55:06 +0100 (Wed, 17 Jan 2007) | 1 line [Part of bug #1599254] Add suggestion to Mailbox docs to use Maildir, and warn user to lock/unlock mailboxes when modifying them ........ r53475 | georg.brandl | 2007-01-17 22:09:04 +0100 (Wed, 17 Jan 2007) | 2 lines Bug #1637967: missing //= operator in list. ........ r53477 | georg.brandl | 2007-01-17 22:19:58 +0100 (Wed, 17 Jan 2007) | 2 lines Bug #1629125: fix wrong data type (int -> Py_ssize_t) in PyDict_Next docs. ........ r53481 | neal.norwitz | 2007-01-18 06:40:58 +0100 (Thu, 18 Jan 2007) | 1 line Try reverting part of r53145 that seems to cause the Windows buildbots to fail in test_uu.UUFileTest.test_encode ........ r53482 | fred.drake | 2007-01-18 06:42:30 +0100 (Thu, 18 Jan 2007) | 1 line add missing version entry ........ r53483 | neal.norwitz | 2007-01-18 07:20:55 +0100 (Thu, 18 Jan 2007) | 7 lines This test doesn't pass on Windows. The cause seems to be that chmod doesn't support the same funcationality as on Unix. I'm not sure if this fix is the best (or if it will even work)--it's a test to see if the buildbots start passing again. It might be better to not even run this test if it's windows (or non-posix). ........ r53488 | neal.norwitz | 2007-01-19 06:53:33 +0100 (Fri, 19 Jan 2007) | 1 line SF #1635217, Fix unbalanced paren ........ r53489 | martin.v.loewis | 2007-01-19 07:42:22 +0100 (Fri, 19 Jan 2007) | 3 lines Prefix AST symbols with _Py_. Fixes #1637022. Will backport. ........ r53497 | martin.v.loewis | 2007-01-19 19:01:38 +0100 (Fri, 19 Jan 2007) | 2 lines Add UUIDs for 2.5.1 and 2.5.2 ........ r53499 | raymond.hettinger | 2007-01-19 19:07:18 +0100 (Fri, 19 Jan 2007) | 1 line SF# 1635892: Fix docs for betavariate's input parameters . ........ r53503 | martin.v.loewis | 2007-01-20 15:05:39 +0100 (Sat, 20 Jan 2007) | 2 lines Merge 53501 and 53502 from 25 branch: Add /GS- for AMD64 and Itanium builds where missing. ........ r53504 | walter.doerwald | 2007-01-20 18:28:31 +0100 (Sat, 20 Jan 2007) | 2 lines Port test_resource.py to unittest. ........ r53505 | walter.doerwald | 2007-01-20 19:19:33 +0100 (Sat, 20 Jan 2007) | 2 lines Add argument tests an calls of resource.getrusage(). ........ r53506 | walter.doerwald | 2007-01-20 20:03:17 +0100 (Sat, 20 Jan 2007) | 2 lines resource.RUSAGE_BOTH might not exist. ........ r53507 | walter.doerwald | 2007-01-21 00:07:28 +0100 (Sun, 21 Jan 2007) | 2 lines Port test_new.py to unittest. ........ r53508 | martin.v.loewis | 2007-01-21 10:33:07 +0100 (Sun, 21 Jan 2007) | 2 lines Patch #1610575: Add support for _Bool to struct. ........ r53509 | georg.brandl | 2007-01-21 11:28:43 +0100 (Sun, 21 Jan 2007) | 3 lines Bug #1486663: don't reject keyword arguments for subclasses of builtin types. ........ r53511 | georg.brandl | 2007-01-21 11:35:10 +0100 (Sun, 21 Jan 2007) | 2 lines Patch #1627441: close sockets properly in urllib2. ........ r53517 | georg.brandl | 2007-01-22 20:40:21 +0100 (Mon, 22 Jan 2007) | 3 lines Use new email module names (#1637162, #1637159, #1637157). ........ r53518 | andrew.kuchling | 2007-01-22 21:26:40 +0100 (Mon, 22 Jan 2007) | 1 line Improve pattern used for mbox 'From' lines; add a simple test ........ r53519 | andrew.kuchling | 2007-01-22 21:27:50 +0100 (Mon, 22 Jan 2007) | 1 line Make comment match the code ........ r53522 | georg.brandl | 2007-01-22 22:10:33 +0100 (Mon, 22 Jan 2007) | 2 lines Bug #1249573: fix rfc822.parsedate not accepting a certain date format ........ r53524 | georg.brandl | 2007-01-22 22:23:41 +0100 (Mon, 22 Jan 2007) | 2 lines Bug #1627316: handle error in condition/ignore pdb commands more gracefully. ........ r53526 | lars.gustaebel | 2007-01-23 12:17:33 +0100 (Tue, 23 Jan 2007) | 4 lines Patch #1507247: tarfile.py: use current umask for intermediate directories. ........ r53527 | thomas.wouters | 2007-01-23 14:42:00 +0100 (Tue, 23 Jan 2007) | 13 lines SF patch #1630975: Fix crash when replacing sys.stdout in sitecustomize When running the interpreter in an environment that would cause it to set stdout/stderr/stdin's encoding, having a sitecustomize that would replace them with something other than PyFile objects would crash the interpreter. Fix it by simply ignoring the encoding-setting for non-files. This could do with a test, but I can think of no maintainable and portable way to test this bug, short of adding a sitecustomize.py to the buildsystem and have it always run with it (hmmm....) ........ r53528 | thomas.wouters | 2007-01-23 14:50:49 +0100 (Tue, 23 Jan 2007) | 4 lines Add news entry about last checkin (oops.) ........ r53531 | martin.v.loewis | 2007-01-23 22:11:47 +0100 (Tue, 23 Jan 2007) | 4 lines Make PyTraceBack_Here use the current thread, not the frame's thread state. Fixes #1579370. Will backport. ........ r53535 | brett.cannon | 2007-01-24 00:21:22 +0100 (Wed, 24 Jan 2007) | 5 lines Fix crasher for when an object's __del__ creates a new weakref to itself. Patch only fixes new-style classes; classic classes still buggy. Closes bug #1377858. Already backported. ........ r53536 | walter.doerwald | 2007-01-24 01:42:19 +0100 (Wed, 24 Jan 2007) | 2 lines Port test_popen.py to unittest. ........
19 years ago
36 years ago
Changes to recursive-object comparisons, having to do with a test case I found where rich comparison of unequal recursive objects gave unintuituve results. In a discussion with Tim, where we discovered that our intuition on when a<=b should be true was failing, we decided to outlaw ordering comparisons on recursive objects. (Once we have fixed our intuition and designed a matching algorithm that's practical and reasonable to implement, we can allow such orderings again.) - Refactored the recursive-object comparison framework; more is now done in the support routines so less needs to be done in the calling routines (even at the expense of slowing it down a bit -- this should normally never be invoked, it's mostly just there to avoid blowing up the interpreter). - Changed the framework so that the comparison operator used is also stored. (The dictionary now stores triples (v, w, op) instead of pairs (v, w).) - Changed the nesting limit to a more reasonable small 20; this only slows down comparisons of very deeply nested objects (unlikely to occur in practice), while speeding up comparisons of recursive objects (previously, this would first waste time and space on 500 nested comparisons before it would start detecting recursion). - Changed rich comparisons for recursive objects to raise a ValueError exception when recursion is detected for ordering oprators (<, <=, >, >=). Unrelated change: - Moved PyObject_Unicode() to just under PyObject_Str(), where it belongs. MAL's patch must've inserted in a random spot between two functions in the file -- between two helpers for rich comparison...
25 years ago
16 years ago
16 years ago
Restructure comparison dramatically. There is no longer a default *ordering* between objects; there is only a default equality test (defined by an object being equal to itself only). Read the comment in object.c. The current implementation never uses a three-way comparison to compute a rich comparison, but it does use a rich comparison to compute a three-way comparison. I'm not quite done ripping out all the calls to PyObject_Compare/Cmp, or replacing tp_compare implementations with tp_richcompare implementations; but much of that has happened (to make most unit tests pass). The following tests still fail, because I need help deciding or understanding: test_codeop -- depends on comparing code objects test_datetime -- need Tim Peters' opinion test_marshal -- depends on comparing code objects test_mutants -- need help understanding it The problem with test_codeop and test_marshal is this: these tests compare two different code objects and expect them to be equal. Is that still a feature we'd like to support? I've temporarily removed the comparison and hash code from code objects, so they use the default (equality by pointer only) comparison. For the other two tests, run them to see for yourself. (There may be more failing test with "-u all".) A general problem with getting lots of these tests to pass is the reality that for object types that have a natural total ordering, implementing __cmp__ is much more convenient than implementing __eq__, __ne__, __lt__, and so on. Should we go back to allowing __cmp__ to provide a total ordering? Should we provide some other way to implement rich comparison with a single method override? Alex proposed a __key__() method; I've considered a __richcmp__() method. Or perhaps __cmp__() just shouldn't be killed off...
20 years ago
Restructure comparison dramatically. There is no longer a default *ordering* between objects; there is only a default equality test (defined by an object being equal to itself only). Read the comment in object.c. The current implementation never uses a three-way comparison to compute a rich comparison, but it does use a rich comparison to compute a three-way comparison. I'm not quite done ripping out all the calls to PyObject_Compare/Cmp, or replacing tp_compare implementations with tp_richcompare implementations; but much of that has happened (to make most unit tests pass). The following tests still fail, because I need help deciding or understanding: test_codeop -- depends on comparing code objects test_datetime -- need Tim Peters' opinion test_marshal -- depends on comparing code objects test_mutants -- need help understanding it The problem with test_codeop and test_marshal is this: these tests compare two different code objects and expect them to be equal. Is that still a feature we'd like to support? I've temporarily removed the comparison and hash code from code objects, so they use the default (equality by pointer only) comparison. For the other two tests, run them to see for yourself. (There may be more failing test with "-u all".) A general problem with getting lots of these tests to pass is the reality that for object types that have a natural total ordering, implementing __cmp__ is much more convenient than implementing __eq__, __ne__, __lt__, and so on. Should we go back to allowing __cmp__ to provide a total ordering? Should we provide some other way to implement rich comparison with a single method override? Alex proposed a __key__() method; I've considered a __richcmp__() method. Or perhaps __cmp__() just shouldn't be killed off...
20 years ago
Restructure comparison dramatically. There is no longer a default *ordering* between objects; there is only a default equality test (defined by an object being equal to itself only). Read the comment in object.c. The current implementation never uses a three-way comparison to compute a rich comparison, but it does use a rich comparison to compute a three-way comparison. I'm not quite done ripping out all the calls to PyObject_Compare/Cmp, or replacing tp_compare implementations with tp_richcompare implementations; but much of that has happened (to make most unit tests pass). The following tests still fail, because I need help deciding or understanding: test_codeop -- depends on comparing code objects test_datetime -- need Tim Peters' opinion test_marshal -- depends on comparing code objects test_mutants -- need help understanding it The problem with test_codeop and test_marshal is this: these tests compare two different code objects and expect them to be equal. Is that still a feature we'd like to support? I've temporarily removed the comparison and hash code from code objects, so they use the default (equality by pointer only) comparison. For the other two tests, run them to see for yourself. (There may be more failing test with "-u all".) A general problem with getting lots of these tests to pass is the reality that for object types that have a natural total ordering, implementing __cmp__ is much more convenient than implementing __eq__, __ne__, __lt__, and so on. Should we go back to allowing __cmp__ to provide a total ordering? Should we provide some other way to implement rich comparison with a single method override? Alex proposed a __key__() method; I've considered a __richcmp__() method. Or perhaps __cmp__() just shouldn't be killed off...
20 years ago
Restructure comparison dramatically. There is no longer a default *ordering* between objects; there is only a default equality test (defined by an object being equal to itself only). Read the comment in object.c. The current implementation never uses a three-way comparison to compute a rich comparison, but it does use a rich comparison to compute a three-way comparison. I'm not quite done ripping out all the calls to PyObject_Compare/Cmp, or replacing tp_compare implementations with tp_richcompare implementations; but much of that has happened (to make most unit tests pass). The following tests still fail, because I need help deciding or understanding: test_codeop -- depends on comparing code objects test_datetime -- need Tim Peters' opinion test_marshal -- depends on comparing code objects test_mutants -- need help understanding it The problem with test_codeop and test_marshal is this: these tests compare two different code objects and expect them to be equal. Is that still a feature we'd like to support? I've temporarily removed the comparison and hash code from code objects, so they use the default (equality by pointer only) comparison. For the other two tests, run them to see for yourself. (There may be more failing test with "-u all".) A general problem with getting lots of these tests to pass is the reality that for object types that have a natural total ordering, implementing __cmp__ is much more convenient than implementing __eq__, __ne__, __lt__, and so on. Should we go back to allowing __cmp__ to provide a total ordering? Should we provide some other way to implement rich comparison with a single method override? Alex proposed a __key__() method; I've considered a __richcmp__() method. Or perhaps __cmp__() just shouldn't be killed off...
20 years ago
Restructure comparison dramatically. There is no longer a default *ordering* between objects; there is only a default equality test (defined by an object being equal to itself only). Read the comment in object.c. The current implementation never uses a three-way comparison to compute a rich comparison, but it does use a rich comparison to compute a three-way comparison. I'm not quite done ripping out all the calls to PyObject_Compare/Cmp, or replacing tp_compare implementations with tp_richcompare implementations; but much of that has happened (to make most unit tests pass). The following tests still fail, because I need help deciding or understanding: test_codeop -- depends on comparing code objects test_datetime -- need Tim Peters' opinion test_marshal -- depends on comparing code objects test_mutants -- need help understanding it The problem with test_codeop and test_marshal is this: these tests compare two different code objects and expect them to be equal. Is that still a feature we'd like to support? I've temporarily removed the comparison and hash code from code objects, so they use the default (equality by pointer only) comparison. For the other two tests, run them to see for yourself. (There may be more failing test with "-u all".) A general problem with getting lots of these tests to pass is the reality that for object types that have a natural total ordering, implementing __cmp__ is much more convenient than implementing __eq__, __ne__, __lt__, and so on. Should we go back to allowing __cmp__ to provide a total ordering? Should we provide some other way to implement rich comparison with a single method override? Alex proposed a __key__() method; I've considered a __richcmp__() method. Or perhaps __cmp__() just shouldn't be killed off...
20 years ago
Restructure comparison dramatically. There is no longer a default *ordering* between objects; there is only a default equality test (defined by an object being equal to itself only). Read the comment in object.c. The current implementation never uses a three-way comparison to compute a rich comparison, but it does use a rich comparison to compute a three-way comparison. I'm not quite done ripping out all the calls to PyObject_Compare/Cmp, or replacing tp_compare implementations with tp_richcompare implementations; but much of that has happened (to make most unit tests pass). The following tests still fail, because I need help deciding or understanding: test_codeop -- depends on comparing code objects test_datetime -- need Tim Peters' opinion test_marshal -- depends on comparing code objects test_mutants -- need help understanding it The problem with test_codeop and test_marshal is this: these tests compare two different code objects and expect them to be equal. Is that still a feature we'd like to support? I've temporarily removed the comparison and hash code from code objects, so they use the default (equality by pointer only) comparison. For the other two tests, run them to see for yourself. (There may be more failing test with "-u all".) A general problem with getting lots of these tests to pass is the reality that for object types that have a natural total ordering, implementing __cmp__ is much more convenient than implementing __eq__, __ne__, __lt__, and so on. Should we go back to allowing __cmp__ to provide a total ordering? Should we provide some other way to implement rich comparison with a single method override? Alex proposed a __key__() method; I've considered a __richcmp__() method. Or perhaps __cmp__() just shouldn't be killed off...
20 years ago
Restructure comparison dramatically. There is no longer a default *ordering* between objects; there is only a default equality test (defined by an object being equal to itself only). Read the comment in object.c. The current implementation never uses a three-way comparison to compute a rich comparison, but it does use a rich comparison to compute a three-way comparison. I'm not quite done ripping out all the calls to PyObject_Compare/Cmp, or replacing tp_compare implementations with tp_richcompare implementations; but much of that has happened (to make most unit tests pass). The following tests still fail, because I need help deciding or understanding: test_codeop -- depends on comparing code objects test_datetime -- need Tim Peters' opinion test_marshal -- depends on comparing code objects test_mutants -- need help understanding it The problem with test_codeop and test_marshal is this: these tests compare two different code objects and expect them to be equal. Is that still a feature we'd like to support? I've temporarily removed the comparison and hash code from code objects, so they use the default (equality by pointer only) comparison. For the other two tests, run them to see for yourself. (There may be more failing test with "-u all".) A general problem with getting lots of these tests to pass is the reality that for object types that have a natural total ordering, implementing __cmp__ is much more convenient than implementing __eq__, __ne__, __lt__, and so on. Should we go back to allowing __cmp__ to provide a total ordering? Should we provide some other way to implement rich comparison with a single method override? Alex proposed a __key__() method; I've considered a __richcmp__() method. Or perhaps __cmp__() just shouldn't be killed off...
20 years ago
36 years ago
Restructure comparison dramatically. There is no longer a default *ordering* between objects; there is only a default equality test (defined by an object being equal to itself only). Read the comment in object.c. The current implementation never uses a three-way comparison to compute a rich comparison, but it does use a rich comparison to compute a three-way comparison. I'm not quite done ripping out all the calls to PyObject_Compare/Cmp, or replacing tp_compare implementations with tp_richcompare implementations; but much of that has happened (to make most unit tests pass). The following tests still fail, because I need help deciding or understanding: test_codeop -- depends on comparing code objects test_datetime -- need Tim Peters' opinion test_marshal -- depends on comparing code objects test_mutants -- need help understanding it The problem with test_codeop and test_marshal is this: these tests compare two different code objects and expect them to be equal. Is that still a feature we'd like to support? I've temporarily removed the comparison and hash code from code objects, so they use the default (equality by pointer only) comparison. For the other two tests, run them to see for yourself. (There may be more failing test with "-u all".) A general problem with getting lots of these tests to pass is the reality that for object types that have a natural total ordering, implementing __cmp__ is much more convenient than implementing __eq__, __ne__, __lt__, and so on. Should we go back to allowing __cmp__ to provide a total ordering? Should we provide some other way to implement rich comparison with a single method override? Alex proposed a __key__() method; I've considered a __richcmp__() method. Or perhaps __cmp__() just shouldn't be killed off...
20 years ago
Restructure comparison dramatically. There is no longer a default *ordering* between objects; there is only a default equality test (defined by an object being equal to itself only). Read the comment in object.c. The current implementation never uses a three-way comparison to compute a rich comparison, but it does use a rich comparison to compute a three-way comparison. I'm not quite done ripping out all the calls to PyObject_Compare/Cmp, or replacing tp_compare implementations with tp_richcompare implementations; but much of that has happened (to make most unit tests pass). The following tests still fail, because I need help deciding or understanding: test_codeop -- depends on comparing code objects test_datetime -- need Tim Peters' opinion test_marshal -- depends on comparing code objects test_mutants -- need help understanding it The problem with test_codeop and test_marshal is this: these tests compare two different code objects and expect them to be equal. Is that still a feature we'd like to support? I've temporarily removed the comparison and hash code from code objects, so they use the default (equality by pointer only) comparison. For the other two tests, run them to see for yourself. (There may be more failing test with "-u all".) A general problem with getting lots of these tests to pass is the reality that for object types that have a natural total ordering, implementing __cmp__ is much more convenient than implementing __eq__, __ne__, __lt__, and so on. Should we go back to allowing __cmp__ to provide a total ordering? Should we provide some other way to implement rich comparison with a single method override? Alex proposed a __key__() method; I've considered a __richcmp__() method. Or perhaps __cmp__() just shouldn't be killed off...
20 years ago
Restructure comparison dramatically. There is no longer a default *ordering* between objects; there is only a default equality test (defined by an object being equal to itself only). Read the comment in object.c. The current implementation never uses a three-way comparison to compute a rich comparison, but it does use a rich comparison to compute a three-way comparison. I'm not quite done ripping out all the calls to PyObject_Compare/Cmp, or replacing tp_compare implementations with tp_richcompare implementations; but much of that has happened (to make most unit tests pass). The following tests still fail, because I need help deciding or understanding: test_codeop -- depends on comparing code objects test_datetime -- need Tim Peters' opinion test_marshal -- depends on comparing code objects test_mutants -- need help understanding it The problem with test_codeop and test_marshal is this: these tests compare two different code objects and expect them to be equal. Is that still a feature we'd like to support? I've temporarily removed the comparison and hash code from code objects, so they use the default (equality by pointer only) comparison. For the other two tests, run them to see for yourself. (There may be more failing test with "-u all".) A general problem with getting lots of these tests to pass is the reality that for object types that have a natural total ordering, implementing __cmp__ is much more convenient than implementing __eq__, __ne__, __lt__, and so on. Should we go back to allowing __cmp__ to provide a total ordering? Should we provide some other way to implement rich comparison with a single method override? Alex proposed a __key__() method; I've considered a __richcmp__() method. Or perhaps __cmp__() just shouldn't be killed off...
20 years ago
Restructure comparison dramatically. There is no longer a default *ordering* between objects; there is only a default equality test (defined by an object being equal to itself only). Read the comment in object.c. The current implementation never uses a three-way comparison to compute a rich comparison, but it does use a rich comparison to compute a three-way comparison. I'm not quite done ripping out all the calls to PyObject_Compare/Cmp, or replacing tp_compare implementations with tp_richcompare implementations; but much of that has happened (to make most unit tests pass). The following tests still fail, because I need help deciding or understanding: test_codeop -- depends on comparing code objects test_datetime -- need Tim Peters' opinion test_marshal -- depends on comparing code objects test_mutants -- need help understanding it The problem with test_codeop and test_marshal is this: these tests compare two different code objects and expect them to be equal. Is that still a feature we'd like to support? I've temporarily removed the comparison and hash code from code objects, so they use the default (equality by pointer only) comparison. For the other two tests, run them to see for yourself. (There may be more failing test with "-u all".) A general problem with getting lots of these tests to pass is the reality that for object types that have a natural total ordering, implementing __cmp__ is much more convenient than implementing __eq__, __ne__, __lt__, and so on. Should we go back to allowing __cmp__ to provide a total ordering? Should we provide some other way to implement rich comparison with a single method override? Alex proposed a __key__() method; I've considered a __richcmp__() method. Or perhaps __cmp__() just shouldn't be killed off...
20 years ago
36 years ago
36 years ago
36 years ago
34 years ago
36 years ago
36 years ago
36 years ago
Restructure comparison dramatically. There is no longer a default *ordering* between objects; there is only a default equality test (defined by an object being equal to itself only). Read the comment in object.c. The current implementation never uses a three-way comparison to compute a rich comparison, but it does use a rich comparison to compute a three-way comparison. I'm not quite done ripping out all the calls to PyObject_Compare/Cmp, or replacing tp_compare implementations with tp_richcompare implementations; but much of that has happened (to make most unit tests pass). The following tests still fail, because I need help deciding or understanding: test_codeop -- depends on comparing code objects test_datetime -- need Tim Peters' opinion test_marshal -- depends on comparing code objects test_mutants -- need help understanding it The problem with test_codeop and test_marshal is this: these tests compare two different code objects and expect them to be equal. Is that still a feature we'd like to support? I've temporarily removed the comparison and hash code from code objects, so they use the default (equality by pointer only) comparison. For the other two tests, run them to see for yourself. (There may be more failing test with "-u all".) A general problem with getting lots of these tests to pass is the reality that for object types that have a natural total ordering, implementing __cmp__ is much more convenient than implementing __eq__, __ne__, __lt__, and so on. Should we go back to allowing __cmp__ to provide a total ordering? Should we provide some other way to implement rich comparison with a single method override? Alex proposed a __key__() method; I've considered a __richcmp__() method. Or perhaps __cmp__() just shouldn't be killed off...
20 years ago
36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
  1. /* Generic object operations; and implementation of None */
  2. #include "Python.h"
  3. #include "frameobject.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. _Py_IDENTIFIER(Py_Repr);
  8. _Py_IDENTIFIER(__bytes__);
  9. _Py_IDENTIFIER(__dir__);
  10. _Py_IDENTIFIER(__isabstractmethod__);
  11. _Py_IDENTIFIER(builtins);
  12. #ifdef Py_REF_DEBUG
  13. Py_ssize_t _Py_RefTotal;
  14. Py_ssize_t
  15. _Py_GetRefTotal(void)
  16. {
  17. PyObject *o;
  18. Py_ssize_t total = _Py_RefTotal;
  19. /* ignore the references to the dummy object of the dicts and sets
  20. because they are not reliable and not useful (now that the
  21. hash table code is well-tested) */
  22. o = _PyDict_Dummy();
  23. if (o != NULL)
  24. total -= o->ob_refcnt;
  25. o = _PySet_Dummy;
  26. if (o != NULL)
  27. total -= o->ob_refcnt;
  28. return total;
  29. }
  30. void
  31. _PyDebug_PrintTotalRefs(void) {
  32. PyObject *xoptions, *value;
  33. _Py_IDENTIFIER(showrefcount);
  34. xoptions = PySys_GetXOptions();
  35. if (xoptions == NULL)
  36. return;
  37. value = _PyDict_GetItemId(xoptions, &PyId_showrefcount);
  38. if (value == Py_True)
  39. fprintf(stderr,
  40. "[%" PY_FORMAT_SIZE_T "d refs, "
  41. "%" PY_FORMAT_SIZE_T "d blocks]\n",
  42. _Py_GetRefTotal(), _Py_GetAllocatedBlocks());
  43. }
  44. #endif /* Py_REF_DEBUG */
  45. /* Object allocation routines used by NEWOBJ and NEWVAROBJ macros.
  46. These are used by the individual routines for object creation.
  47. Do not call them otherwise, they do not initialize the object! */
  48. #ifdef Py_TRACE_REFS
  49. /* Head of circular doubly-linked list of all objects. These are linked
  50. * together via the _ob_prev and _ob_next members of a PyObject, which
  51. * exist only in a Py_TRACE_REFS build.
  52. */
  53. static PyObject refchain = {&refchain, &refchain};
  54. /* Insert op at the front of the list of all objects. If force is true,
  55. * op is added even if _ob_prev and _ob_next are non-NULL already. If
  56. * force is false amd _ob_prev or _ob_next are non-NULL, do nothing.
  57. * force should be true if and only if op points to freshly allocated,
  58. * uninitialized memory, or you've unlinked op from the list and are
  59. * relinking it into the front.
  60. * Note that objects are normally added to the list via _Py_NewReference,
  61. * which is called by PyObject_Init. Not all objects are initialized that
  62. * way, though; exceptions include statically allocated type objects, and
  63. * statically allocated singletons (like Py_True and Py_None).
  64. */
  65. void
  66. _Py_AddToAllObjects(PyObject *op, int force)
  67. {
  68. #ifdef Py_DEBUG
  69. if (!force) {
  70. /* If it's initialized memory, op must be in or out of
  71. * the list unambiguously.
  72. */
  73. assert((op->_ob_prev == NULL) == (op->_ob_next == NULL));
  74. }
  75. #endif
  76. if (force || op->_ob_prev == NULL) {
  77. op->_ob_next = refchain._ob_next;
  78. op->_ob_prev = &refchain;
  79. refchain._ob_next->_ob_prev = op;
  80. refchain._ob_next = op;
  81. }
  82. }
  83. #endif /* Py_TRACE_REFS */
  84. #ifdef COUNT_ALLOCS
  85. static PyTypeObject *type_list;
  86. /* All types are added to type_list, at least when
  87. they get one object created. That makes them
  88. immortal, which unfortunately contributes to
  89. garbage itself. If unlist_types_without_objects
  90. is set, they will be removed from the type_list
  91. once the last object is deallocated. */
  92. static int unlist_types_without_objects;
  93. extern Py_ssize_t tuple_zero_allocs, fast_tuple_allocs;
  94. extern Py_ssize_t quick_int_allocs, quick_neg_int_allocs;
  95. extern Py_ssize_t null_strings, one_strings;
  96. void
  97. dump_counts(FILE* f)
  98. {
  99. PyTypeObject *tp;
  100. for (tp = type_list; tp; tp = tp->tp_next)
  101. fprintf(f, "%s alloc'd: %" PY_FORMAT_SIZE_T "d, "
  102. "freed: %" PY_FORMAT_SIZE_T "d, "
  103. "max in use: %" PY_FORMAT_SIZE_T "d\n",
  104. tp->tp_name, tp->tp_allocs, tp->tp_frees,
  105. tp->tp_maxalloc);
  106. fprintf(f, "fast tuple allocs: %" PY_FORMAT_SIZE_T "d, "
  107. "empty: %" PY_FORMAT_SIZE_T "d\n",
  108. fast_tuple_allocs, tuple_zero_allocs);
  109. fprintf(f, "fast int allocs: pos: %" PY_FORMAT_SIZE_T "d, "
  110. "neg: %" PY_FORMAT_SIZE_T "d\n",
  111. quick_int_allocs, quick_neg_int_allocs);
  112. fprintf(f, "null strings: %" PY_FORMAT_SIZE_T "d, "
  113. "1-strings: %" PY_FORMAT_SIZE_T "d\n",
  114. null_strings, one_strings);
  115. }
  116. PyObject *
  117. get_counts(void)
  118. {
  119. PyTypeObject *tp;
  120. PyObject *result;
  121. PyObject *v;
  122. result = PyList_New(0);
  123. if (result == NULL)
  124. return NULL;
  125. for (tp = type_list; tp; tp = tp->tp_next) {
  126. v = Py_BuildValue("(snnn)", tp->tp_name, tp->tp_allocs,
  127. tp->tp_frees, tp->tp_maxalloc);
  128. if (v == NULL) {
  129. Py_DECREF(result);
  130. return NULL;
  131. }
  132. if (PyList_Append(result, v) < 0) {
  133. Py_DECREF(v);
  134. Py_DECREF(result);
  135. return NULL;
  136. }
  137. Py_DECREF(v);
  138. }
  139. return result;
  140. }
  141. void
  142. inc_count(PyTypeObject *tp)
  143. {
  144. if (tp->tp_next == NULL && tp->tp_prev == NULL) {
  145. /* first time; insert in linked list */
  146. if (tp->tp_next != NULL) /* sanity check */
  147. Py_FatalError("XXX inc_count sanity check");
  148. if (type_list)
  149. type_list->tp_prev = tp;
  150. tp->tp_next = type_list;
  151. /* Note that as of Python 2.2, heap-allocated type objects
  152. * can go away, but this code requires that they stay alive
  153. * until program exit. That's why we're careful with
  154. * refcounts here. type_list gets a new reference to tp,
  155. * while ownership of the reference type_list used to hold
  156. * (if any) was transferred to tp->tp_next in the line above.
  157. * tp is thus effectively immortal after this.
  158. */
  159. Py_INCREF(tp);
  160. type_list = tp;
  161. #ifdef Py_TRACE_REFS
  162. /* Also insert in the doubly-linked list of all objects,
  163. * if not already there.
  164. */
  165. _Py_AddToAllObjects((PyObject *)tp, 0);
  166. #endif
  167. }
  168. tp->tp_allocs++;
  169. if (tp->tp_allocs - tp->tp_frees > tp->tp_maxalloc)
  170. tp->tp_maxalloc = tp->tp_allocs - tp->tp_frees;
  171. }
  172. void dec_count(PyTypeObject *tp)
  173. {
  174. tp->tp_frees++;
  175. if (unlist_types_without_objects &&
  176. tp->tp_allocs == tp->tp_frees) {
  177. /* unlink the type from type_list */
  178. if (tp->tp_prev)
  179. tp->tp_prev->tp_next = tp->tp_next;
  180. else
  181. type_list = tp->tp_next;
  182. if (tp->tp_next)
  183. tp->tp_next->tp_prev = tp->tp_prev;
  184. tp->tp_next = tp->tp_prev = NULL;
  185. Py_DECREF(tp);
  186. }
  187. }
  188. #endif
  189. #ifdef Py_REF_DEBUG
  190. /* Log a fatal error; doesn't return. */
  191. void
  192. _Py_NegativeRefcount(const char *fname, int lineno, PyObject *op)
  193. {
  194. char buf[300];
  195. PyOS_snprintf(buf, sizeof(buf),
  196. "%s:%i object at %p has negative ref count "
  197. "%" PY_FORMAT_SIZE_T "d",
  198. fname, lineno, op, op->ob_refcnt);
  199. Py_FatalError(buf);
  200. }
  201. #endif /* Py_REF_DEBUG */
  202. void
  203. Py_IncRef(PyObject *o)
  204. {
  205. Py_XINCREF(o);
  206. }
  207. void
  208. Py_DecRef(PyObject *o)
  209. {
  210. Py_XDECREF(o);
  211. }
  212. PyObject *
  213. PyObject_Init(PyObject *op, PyTypeObject *tp)
  214. {
  215. if (op == NULL)
  216. return PyErr_NoMemory();
  217. /* Any changes should be reflected in PyObject_INIT (objimpl.h) */
  218. Py_TYPE(op) = tp;
  219. _Py_NewReference(op);
  220. return op;
  221. }
  222. PyVarObject *
  223. PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, Py_ssize_t size)
  224. {
  225. if (op == NULL)
  226. return (PyVarObject *) PyErr_NoMemory();
  227. /* Any changes should be reflected in PyObject_INIT_VAR */
  228. op->ob_size = size;
  229. Py_TYPE(op) = tp;
  230. _Py_NewReference((PyObject *)op);
  231. return op;
  232. }
  233. PyObject *
  234. _PyObject_New(PyTypeObject *tp)
  235. {
  236. PyObject *op;
  237. op = (PyObject *) PyObject_MALLOC(_PyObject_SIZE(tp));
  238. if (op == NULL)
  239. return PyErr_NoMemory();
  240. return PyObject_INIT(op, tp);
  241. }
  242. PyVarObject *
  243. _PyObject_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
  244. {
  245. PyVarObject *op;
  246. const size_t size = _PyObject_VAR_SIZE(tp, nitems);
  247. op = (PyVarObject *) PyObject_MALLOC(size);
  248. if (op == NULL)
  249. return (PyVarObject *)PyErr_NoMemory();
  250. return PyObject_INIT_VAR(op, tp, nitems);
  251. }
  252. void
  253. PyObject_CallFinalizer(PyObject *self)
  254. {
  255. PyTypeObject *tp = Py_TYPE(self);
  256. /* The former could happen on heaptypes created from the C API, e.g.
  257. PyType_FromSpec(). */
  258. if (!PyType_HasFeature(tp, Py_TPFLAGS_HAVE_FINALIZE) ||
  259. tp->tp_finalize == NULL)
  260. return;
  261. /* tp_finalize should only be called once. */
  262. if (PyType_IS_GC(tp) && _PyGC_FINALIZED(self))
  263. return;
  264. tp->tp_finalize(self);
  265. if (PyType_IS_GC(tp))
  266. _PyGC_SET_FINALIZED(self, 1);
  267. }
  268. int
  269. PyObject_CallFinalizerFromDealloc(PyObject *self)
  270. {
  271. Py_ssize_t refcnt;
  272. /* Temporarily resurrect the object. */
  273. if (self->ob_refcnt != 0) {
  274. Py_FatalError("PyObject_CallFinalizerFromDealloc called on "
  275. "object with a non-zero refcount");
  276. }
  277. self->ob_refcnt = 1;
  278. PyObject_CallFinalizer(self);
  279. /* Undo the temporary resurrection; can't use DECREF here, it would
  280. * cause a recursive call.
  281. */
  282. assert(self->ob_refcnt > 0);
  283. if (--self->ob_refcnt == 0)
  284. return 0; /* this is the normal path out */
  285. /* tp_finalize resurrected it! Make it look like the original Py_DECREF
  286. * never happened.
  287. */
  288. refcnt = self->ob_refcnt;
  289. _Py_NewReference(self);
  290. self->ob_refcnt = refcnt;
  291. if (PyType_IS_GC(Py_TYPE(self))) {
  292. assert(_PyGC_REFS(self) != _PyGC_REFS_UNTRACKED);
  293. }
  294. /* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
  295. * we need to undo that. */
  296. _Py_DEC_REFTOTAL;
  297. /* If Py_TRACE_REFS, _Py_NewReference re-added self to the object
  298. * chain, so no more to do there.
  299. * If COUNT_ALLOCS, the original decref bumped tp_frees, and
  300. * _Py_NewReference bumped tp_allocs: both of those need to be
  301. * undone.
  302. */
  303. #ifdef COUNT_ALLOCS
  304. --Py_TYPE(self)->tp_frees;
  305. --Py_TYPE(self)->tp_allocs;
  306. #endif
  307. return -1;
  308. }
  309. int
  310. PyObject_Print(PyObject *op, FILE *fp, int flags)
  311. {
  312. int ret = 0;
  313. if (PyErr_CheckSignals())
  314. return -1;
  315. #ifdef USE_STACKCHECK
  316. if (PyOS_CheckStack()) {
  317. PyErr_SetString(PyExc_MemoryError, "stack overflow");
  318. return -1;
  319. }
  320. #endif
  321. clearerr(fp); /* Clear any previous error condition */
  322. if (op == NULL) {
  323. Py_BEGIN_ALLOW_THREADS
  324. fprintf(fp, "<nil>");
  325. Py_END_ALLOW_THREADS
  326. }
  327. else {
  328. if (op->ob_refcnt <= 0)
  329. /* XXX(twouters) cast refcount to long until %zd is
  330. universally available */
  331. Py_BEGIN_ALLOW_THREADS
  332. fprintf(fp, "<refcnt %ld at %p>",
  333. (long)op->ob_refcnt, op);
  334. Py_END_ALLOW_THREADS
  335. else {
  336. PyObject *s;
  337. if (flags & Py_PRINT_RAW)
  338. s = PyObject_Str(op);
  339. else
  340. s = PyObject_Repr(op);
  341. if (s == NULL)
  342. ret = -1;
  343. else if (PyBytes_Check(s)) {
  344. fwrite(PyBytes_AS_STRING(s), 1,
  345. PyBytes_GET_SIZE(s), fp);
  346. }
  347. else if (PyUnicode_Check(s)) {
  348. PyObject *t;
  349. t = PyUnicode_AsEncodedString(s, "utf-8", "backslashreplace");
  350. if (t == NULL)
  351. ret = 0;
  352. else {
  353. fwrite(PyBytes_AS_STRING(t), 1,
  354. PyBytes_GET_SIZE(t), fp);
  355. Py_DECREF(t);
  356. }
  357. }
  358. else {
  359. PyErr_Format(PyExc_TypeError,
  360. "str() or repr() returned '%.100s'",
  361. s->ob_type->tp_name);
  362. ret = -1;
  363. }
  364. Py_XDECREF(s);
  365. }
  366. }
  367. if (ret == 0) {
  368. if (ferror(fp)) {
  369. PyErr_SetFromErrno(PyExc_IOError);
  370. clearerr(fp);
  371. ret = -1;
  372. }
  373. }
  374. return ret;
  375. }
  376. /* For debugging convenience. Set a breakpoint here and call it from your DLL */
  377. void
  378. _Py_BreakPoint(void)
  379. {
  380. }
  381. /* For debugging convenience. See Misc/gdbinit for some useful gdb hooks */
  382. void
  383. _PyObject_Dump(PyObject* op)
  384. {
  385. if (op == NULL)
  386. fprintf(stderr, "NULL\n");
  387. else {
  388. #ifdef WITH_THREAD
  389. PyGILState_STATE gil;
  390. #endif
  391. PyObject *error_type, *error_value, *error_traceback;
  392. fprintf(stderr, "object : ");
  393. #ifdef WITH_THREAD
  394. gil = PyGILState_Ensure();
  395. #endif
  396. PyErr_Fetch(&error_type, &error_value, &error_traceback);
  397. (void)PyObject_Print(op, stderr, 0);
  398. PyErr_Restore(error_type, error_value, error_traceback);
  399. #ifdef WITH_THREAD
  400. PyGILState_Release(gil);
  401. #endif
  402. /* XXX(twouters) cast refcount to long until %zd is
  403. universally available */
  404. fprintf(stderr, "\n"
  405. "type : %s\n"
  406. "refcount: %ld\n"
  407. "address : %p\n",
  408. Py_TYPE(op)==NULL ? "NULL" : Py_TYPE(op)->tp_name,
  409. (long)op->ob_refcnt,
  410. op);
  411. }
  412. }
  413. PyObject *
  414. PyObject_Repr(PyObject *v)
  415. {
  416. PyObject *res;
  417. if (PyErr_CheckSignals())
  418. return NULL;
  419. #ifdef USE_STACKCHECK
  420. if (PyOS_CheckStack()) {
  421. PyErr_SetString(PyExc_MemoryError, "stack overflow");
  422. return NULL;
  423. }
  424. #endif
  425. if (v == NULL)
  426. return PyUnicode_FromString("<NULL>");
  427. if (Py_TYPE(v)->tp_repr == NULL)
  428. return PyUnicode_FromFormat("<%s object at %p>",
  429. v->ob_type->tp_name, v);
  430. #ifdef Py_DEBUG
  431. /* PyObject_Repr() must not be called with an exception set,
  432. because it may clear it (directly or indirectly) and so the
  433. caller looses its exception */
  434. assert(!PyErr_Occurred());
  435. #endif
  436. res = (*v->ob_type->tp_repr)(v);
  437. if (res == NULL)
  438. return NULL;
  439. if (!PyUnicode_Check(res)) {
  440. PyErr_Format(PyExc_TypeError,
  441. "__repr__ returned non-string (type %.200s)",
  442. res->ob_type->tp_name);
  443. Py_DECREF(res);
  444. return NULL;
  445. }
  446. #ifndef Py_DEBUG
  447. if (PyUnicode_READY(res) < 0)
  448. return NULL;
  449. #endif
  450. return res;
  451. }
  452. PyObject *
  453. PyObject_Str(PyObject *v)
  454. {
  455. PyObject *res;
  456. if (PyErr_CheckSignals())
  457. return NULL;
  458. #ifdef USE_STACKCHECK
  459. if (PyOS_CheckStack()) {
  460. PyErr_SetString(PyExc_MemoryError, "stack overflow");
  461. return NULL;
  462. }
  463. #endif
  464. if (v == NULL)
  465. return PyUnicode_FromString("<NULL>");
  466. if (PyUnicode_CheckExact(v)) {
  467. #ifndef Py_DEBUG
  468. if (PyUnicode_READY(v) < 0)
  469. return NULL;
  470. #endif
  471. Py_INCREF(v);
  472. return v;
  473. }
  474. if (Py_TYPE(v)->tp_str == NULL)
  475. return PyObject_Repr(v);
  476. #ifdef Py_DEBUG
  477. /* PyObject_Str() must not be called with an exception set,
  478. because it may clear it (directly or indirectly) and so the
  479. caller loses its exception */
  480. assert(!PyErr_Occurred());
  481. #endif
  482. /* It is possible for a type to have a tp_str representation that loops
  483. infinitely. */
  484. if (Py_EnterRecursiveCall(" while getting the str of an object"))
  485. return NULL;
  486. res = (*Py_TYPE(v)->tp_str)(v);
  487. Py_LeaveRecursiveCall();
  488. if (res == NULL)
  489. return NULL;
  490. if (!PyUnicode_Check(res)) {
  491. PyErr_Format(PyExc_TypeError,
  492. "__str__ returned non-string (type %.200s)",
  493. Py_TYPE(res)->tp_name);
  494. Py_DECREF(res);
  495. return NULL;
  496. }
  497. #ifndef Py_DEBUG
  498. if (PyUnicode_READY(res) < 0)
  499. return NULL;
  500. #endif
  501. assert(_PyUnicode_CheckConsistency(res, 1));
  502. return res;
  503. }
  504. PyObject *
  505. PyObject_ASCII(PyObject *v)
  506. {
  507. PyObject *repr, *ascii, *res;
  508. repr = PyObject_Repr(v);
  509. if (repr == NULL)
  510. return NULL;
  511. if (PyUnicode_IS_ASCII(repr))
  512. return repr;
  513. /* repr is guaranteed to be a PyUnicode object by PyObject_Repr */
  514. ascii = _PyUnicode_AsASCIIString(repr, "backslashreplace");
  515. Py_DECREF(repr);
  516. if (ascii == NULL)
  517. return NULL;
  518. res = PyUnicode_DecodeASCII(
  519. PyBytes_AS_STRING(ascii),
  520. PyBytes_GET_SIZE(ascii),
  521. NULL);
  522. Py_DECREF(ascii);
  523. return res;
  524. }
  525. PyObject *
  526. PyObject_Bytes(PyObject *v)
  527. {
  528. PyObject *result, *func;
  529. if (v == NULL)
  530. return PyBytes_FromString("<NULL>");
  531. if (PyBytes_CheckExact(v)) {
  532. Py_INCREF(v);
  533. return v;
  534. }
  535. func = _PyObject_LookupSpecial(v, &PyId___bytes__);
  536. if (func != NULL) {
  537. result = PyObject_CallFunctionObjArgs(func, NULL);
  538. Py_DECREF(func);
  539. if (result == NULL)
  540. return NULL;
  541. if (!PyBytes_Check(result)) {
  542. PyErr_Format(PyExc_TypeError,
  543. "__bytes__ returned non-bytes (type %.200s)",
  544. Py_TYPE(result)->tp_name);
  545. Py_DECREF(result);
  546. return NULL;
  547. }
  548. return result;
  549. }
  550. else if (PyErr_Occurred())
  551. return NULL;
  552. return PyBytes_FromObject(v);
  553. }
  554. /* For Python 3.0.1 and later, the old three-way comparison has been
  555. completely removed in favour of rich comparisons. PyObject_Compare() and
  556. PyObject_Cmp() are gone, and the builtin cmp function no longer exists.
  557. The old tp_compare slot has been renamed to tp_reserved, and should no
  558. longer be used. Use tp_richcompare instead.
  559. See (*) below for practical amendments.
  560. tp_richcompare gets called with a first argument of the appropriate type
  561. and a second object of an arbitrary type. We never do any kind of
  562. coercion.
  563. The tp_richcompare slot should return an object, as follows:
  564. NULL if an exception occurred
  565. NotImplemented if the requested comparison is not implemented
  566. any other false value if the requested comparison is false
  567. any other true value if the requested comparison is true
  568. The PyObject_RichCompare[Bool]() wrappers raise TypeError when they get
  569. NotImplemented.
  570. (*) Practical amendments:
  571. - If rich comparison returns NotImplemented, == and != are decided by
  572. comparing the object pointer (i.e. falling back to the base object
  573. implementation).
  574. */
  575. /* Map rich comparison operators to their swapped version, e.g. LT <--> GT */
  576. int _Py_SwappedOp[] = {Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE};
  577. static char *opstrings[] = {"<", "<=", "==", "!=", ">", ">="};
  578. /* Perform a rich comparison, raising TypeError when the requested comparison
  579. operator is not supported. */
  580. static PyObject *
  581. do_richcompare(PyObject *v, PyObject *w, int op)
  582. {
  583. richcmpfunc f;
  584. PyObject *res;
  585. int checked_reverse_op = 0;
  586. if (v->ob_type != w->ob_type &&
  587. PyType_IsSubtype(w->ob_type, v->ob_type) &&
  588. (f = w->ob_type->tp_richcompare) != NULL) {
  589. checked_reverse_op = 1;
  590. res = (*f)(w, v, _Py_SwappedOp[op]);
  591. if (res != Py_NotImplemented)
  592. return res;
  593. Py_DECREF(res);
  594. }
  595. if ((f = v->ob_type->tp_richcompare) != NULL) {
  596. res = (*f)(v, w, op);
  597. if (res != Py_NotImplemented)
  598. return res;
  599. Py_DECREF(res);
  600. }
  601. if (!checked_reverse_op && (f = w->ob_type->tp_richcompare) != NULL) {
  602. res = (*f)(w, v, _Py_SwappedOp[op]);
  603. if (res != Py_NotImplemented)
  604. return res;
  605. Py_DECREF(res);
  606. }
  607. /* If neither object implements it, provide a sensible default
  608. for == and !=, but raise an exception for ordering. */
  609. switch (op) {
  610. case Py_EQ:
  611. res = (v == w) ? Py_True : Py_False;
  612. break;
  613. case Py_NE:
  614. res = (v != w) ? Py_True : Py_False;
  615. break;
  616. default:
  617. /* XXX Special-case None so it doesn't show as NoneType() */
  618. PyErr_Format(PyExc_TypeError,
  619. "unorderable types: %.100s() %s %.100s()",
  620. v->ob_type->tp_name,
  621. opstrings[op],
  622. w->ob_type->tp_name);
  623. return NULL;
  624. }
  625. Py_INCREF(res);
  626. return res;
  627. }
  628. /* Perform a rich comparison with object result. This wraps do_richcompare()
  629. with a check for NULL arguments and a recursion check. */
  630. PyObject *
  631. PyObject_RichCompare(PyObject *v, PyObject *w, int op)
  632. {
  633. PyObject *res;
  634. assert(Py_LT <= op && op <= Py_GE);
  635. if (v == NULL || w == NULL) {
  636. if (!PyErr_Occurred())
  637. PyErr_BadInternalCall();
  638. return NULL;
  639. }
  640. if (Py_EnterRecursiveCall(" in comparison"))
  641. return NULL;
  642. res = do_richcompare(v, w, op);
  643. Py_LeaveRecursiveCall();
  644. return res;
  645. }
  646. /* Perform a rich comparison with integer result. This wraps
  647. PyObject_RichCompare(), returning -1 for error, 0 for false, 1 for true. */
  648. int
  649. PyObject_RichCompareBool(PyObject *v, PyObject *w, int op)
  650. {
  651. PyObject *res;
  652. int ok;
  653. /* Quick result when objects are the same.
  654. Guarantees that identity implies equality. */
  655. if (v == w) {
  656. if (op == Py_EQ)
  657. return 1;
  658. else if (op == Py_NE)
  659. return 0;
  660. }
  661. res = PyObject_RichCompare(v, w, op);
  662. if (res == NULL)
  663. return -1;
  664. if (PyBool_Check(res))
  665. ok = (res == Py_True);
  666. else
  667. ok = PyObject_IsTrue(res);
  668. Py_DECREF(res);
  669. return ok;
  670. }
  671. Py_hash_t
  672. PyObject_HashNotImplemented(PyObject *v)
  673. {
  674. PyErr_Format(PyExc_TypeError, "unhashable type: '%.200s'",
  675. Py_TYPE(v)->tp_name);
  676. return -1;
  677. }
  678. Py_hash_t
  679. PyObject_Hash(PyObject *v)
  680. {
  681. PyTypeObject *tp = Py_TYPE(v);
  682. if (tp->tp_hash != NULL)
  683. return (*tp->tp_hash)(v);
  684. /* To keep to the general practice that inheriting
  685. * solely from object in C code should work without
  686. * an explicit call to PyType_Ready, we implicitly call
  687. * PyType_Ready here and then check the tp_hash slot again
  688. */
  689. if (tp->tp_dict == NULL) {
  690. if (PyType_Ready(tp) < 0)
  691. return -1;
  692. if (tp->tp_hash != NULL)
  693. return (*tp->tp_hash)(v);
  694. }
  695. /* Otherwise, the object can't be hashed */
  696. return PyObject_HashNotImplemented(v);
  697. }
  698. PyObject *
  699. PyObject_GetAttrString(PyObject *v, const char *name)
  700. {
  701. PyObject *w, *res;
  702. if (Py_TYPE(v)->tp_getattr != NULL)
  703. return (*Py_TYPE(v)->tp_getattr)(v, (char*)name);
  704. w = PyUnicode_InternFromString(name);
  705. if (w == NULL)
  706. return NULL;
  707. res = PyObject_GetAttr(v, w);
  708. Py_DECREF(w);
  709. return res;
  710. }
  711. int
  712. PyObject_HasAttrString(PyObject *v, const char *name)
  713. {
  714. PyObject *res = PyObject_GetAttrString(v, name);
  715. if (res != NULL) {
  716. Py_DECREF(res);
  717. return 1;
  718. }
  719. PyErr_Clear();
  720. return 0;
  721. }
  722. int
  723. PyObject_SetAttrString(PyObject *v, const char *name, PyObject *w)
  724. {
  725. PyObject *s;
  726. int res;
  727. if (Py_TYPE(v)->tp_setattr != NULL)
  728. return (*Py_TYPE(v)->tp_setattr)(v, (char*)name, w);
  729. s = PyUnicode_InternFromString(name);
  730. if (s == NULL)
  731. return -1;
  732. res = PyObject_SetAttr(v, s, w);
  733. Py_XDECREF(s);
  734. return res;
  735. }
  736. int
  737. _PyObject_IsAbstract(PyObject *obj)
  738. {
  739. int res;
  740. PyObject* isabstract;
  741. if (obj == NULL)
  742. return 0;
  743. isabstract = _PyObject_GetAttrId(obj, &PyId___isabstractmethod__);
  744. if (isabstract == NULL) {
  745. if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
  746. PyErr_Clear();
  747. return 0;
  748. }
  749. return -1;
  750. }
  751. res = PyObject_IsTrue(isabstract);
  752. Py_DECREF(isabstract);
  753. return res;
  754. }
  755. PyObject *
  756. _PyObject_GetAttrId(PyObject *v, _Py_Identifier *name)
  757. {
  758. PyObject *result;
  759. PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
  760. if (!oname)
  761. return NULL;
  762. result = PyObject_GetAttr(v, oname);
  763. return result;
  764. }
  765. int
  766. _PyObject_HasAttrId(PyObject *v, _Py_Identifier *name)
  767. {
  768. int result;
  769. PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
  770. if (!oname)
  771. return -1;
  772. result = PyObject_HasAttr(v, oname);
  773. return result;
  774. }
  775. int
  776. _PyObject_SetAttrId(PyObject *v, _Py_Identifier *name, PyObject *w)
  777. {
  778. int result;
  779. PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
  780. if (!oname)
  781. return -1;
  782. result = PyObject_SetAttr(v, oname, w);
  783. return result;
  784. }
  785. PyObject *
  786. PyObject_GetAttr(PyObject *v, PyObject *name)
  787. {
  788. PyTypeObject *tp = Py_TYPE(v);
  789. if (!PyUnicode_Check(name)) {
  790. PyErr_Format(PyExc_TypeError,
  791. "attribute name must be string, not '%.200s'",
  792. name->ob_type->tp_name);
  793. return NULL;
  794. }
  795. if (tp->tp_getattro != NULL)
  796. return (*tp->tp_getattro)(v, name);
  797. if (tp->tp_getattr != NULL) {
  798. char *name_str = _PyUnicode_AsString(name);
  799. if (name_str == NULL)
  800. return NULL;
  801. return (*tp->tp_getattr)(v, name_str);
  802. }
  803. PyErr_Format(PyExc_AttributeError,
  804. "'%.50s' object has no attribute '%U'",
  805. tp->tp_name, name);
  806. return NULL;
  807. }
  808. int
  809. PyObject_HasAttr(PyObject *v, PyObject *name)
  810. {
  811. PyObject *res = PyObject_GetAttr(v, name);
  812. if (res != NULL) {
  813. Py_DECREF(res);
  814. return 1;
  815. }
  816. PyErr_Clear();
  817. return 0;
  818. }
  819. int
  820. PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
  821. {
  822. PyTypeObject *tp = Py_TYPE(v);
  823. int err;
  824. if (!PyUnicode_Check(name)) {
  825. PyErr_Format(PyExc_TypeError,
  826. "attribute name must be string, not '%.200s'",
  827. name->ob_type->tp_name);
  828. return -1;
  829. }
  830. Py_INCREF(name);
  831. PyUnicode_InternInPlace(&name);
  832. if (tp->tp_setattro != NULL) {
  833. err = (*tp->tp_setattro)(v, name, value);
  834. Py_DECREF(name);
  835. return err;
  836. }
  837. if (tp->tp_setattr != NULL) {
  838. char *name_str = _PyUnicode_AsString(name);
  839. if (name_str == NULL)
  840. return -1;
  841. err = (*tp->tp_setattr)(v, name_str, value);
  842. Py_DECREF(name);
  843. return err;
  844. }
  845. Py_DECREF(name);
  846. assert(name->ob_refcnt >= 1);
  847. if (tp->tp_getattr == NULL && tp->tp_getattro == NULL)
  848. PyErr_Format(PyExc_TypeError,
  849. "'%.100s' object has no attributes "
  850. "(%s .%U)",
  851. tp->tp_name,
  852. value==NULL ? "del" : "assign to",
  853. name);
  854. else
  855. PyErr_Format(PyExc_TypeError,
  856. "'%.100s' object has only read-only attributes "
  857. "(%s .%U)",
  858. tp->tp_name,
  859. value==NULL ? "del" : "assign to",
  860. name);
  861. return -1;
  862. }
  863. /* Helper to get a pointer to an object's __dict__ slot, if any */
  864. PyObject **
  865. _PyObject_GetDictPtr(PyObject *obj)
  866. {
  867. Py_ssize_t dictoffset;
  868. PyTypeObject *tp = Py_TYPE(obj);
  869. dictoffset = tp->tp_dictoffset;
  870. if (dictoffset == 0)
  871. return NULL;
  872. if (dictoffset < 0) {
  873. Py_ssize_t tsize;
  874. size_t size;
  875. tsize = ((PyVarObject *)obj)->ob_size;
  876. if (tsize < 0)
  877. tsize = -tsize;
  878. size = _PyObject_VAR_SIZE(tp, tsize);
  879. dictoffset += (long)size;
  880. assert(dictoffset > 0);
  881. assert(dictoffset % SIZEOF_VOID_P == 0);
  882. }
  883. return (PyObject **) ((char *)obj + dictoffset);
  884. }
  885. PyObject *
  886. PyObject_SelfIter(PyObject *obj)
  887. {
  888. Py_INCREF(obj);
  889. return obj;
  890. }
  891. /* Convenience function to get a builtin from its name */
  892. PyObject *
  893. _PyObject_GetBuiltin(const char *name)
  894. {
  895. PyObject *mod_name, *mod, *attr;
  896. mod_name = _PyUnicode_FromId(&PyId_builtins); /* borrowed */
  897. if (mod_name == NULL)
  898. return NULL;
  899. mod = PyImport_Import(mod_name);
  900. if (mod == NULL)
  901. return NULL;
  902. attr = PyObject_GetAttrString(mod, name);
  903. Py_DECREF(mod);
  904. return attr;
  905. }
  906. /* Helper used when the __next__ method is removed from a type:
  907. tp_iternext is never NULL and can be safely called without checking
  908. on every iteration.
  909. */
  910. PyObject *
  911. _PyObject_NextNotImplemented(PyObject *self)
  912. {
  913. PyErr_Format(PyExc_TypeError,
  914. "'%.200s' object is not iterable",
  915. Py_TYPE(self)->tp_name);
  916. return NULL;
  917. }
  918. /* Generic GetAttr functions - put these in your tp_[gs]etattro slot */
  919. PyObject *
  920. _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict)
  921. {
  922. PyTypeObject *tp = Py_TYPE(obj);
  923. PyObject *descr = NULL;
  924. PyObject *res = NULL;
  925. descrgetfunc f;
  926. Py_ssize_t dictoffset;
  927. PyObject **dictptr;
  928. if (!PyUnicode_Check(name)){
  929. PyErr_Format(PyExc_TypeError,
  930. "attribute name must be string, not '%.200s'",
  931. name->ob_type->tp_name);
  932. return NULL;
  933. }
  934. else
  935. Py_INCREF(name);
  936. if (tp->tp_dict == NULL) {
  937. if (PyType_Ready(tp) < 0)
  938. goto done;
  939. }
  940. descr = _PyType_Lookup(tp, name);
  941. Py_XINCREF(descr);
  942. f = NULL;
  943. if (descr != NULL) {
  944. f = descr->ob_type->tp_descr_get;
  945. if (f != NULL && PyDescr_IsData(descr)) {
  946. res = f(descr, obj, (PyObject *)obj->ob_type);
  947. goto done;
  948. }
  949. }
  950. if (dict == NULL) {
  951. /* Inline _PyObject_GetDictPtr */
  952. dictoffset = tp->tp_dictoffset;
  953. if (dictoffset != 0) {
  954. if (dictoffset < 0) {
  955. Py_ssize_t tsize;
  956. size_t size;
  957. tsize = ((PyVarObject *)obj)->ob_size;
  958. if (tsize < 0)
  959. tsize = -tsize;
  960. size = _PyObject_VAR_SIZE(tp, tsize);
  961. dictoffset += (long)size;
  962. assert(dictoffset > 0);
  963. assert(dictoffset % SIZEOF_VOID_P == 0);
  964. }
  965. dictptr = (PyObject **) ((char *)obj + dictoffset);
  966. dict = *dictptr;
  967. }
  968. }
  969. if (dict != NULL) {
  970. Py_INCREF(dict);
  971. res = PyDict_GetItem(dict, name);
  972. if (res != NULL) {
  973. Py_INCREF(res);
  974. Py_DECREF(dict);
  975. goto done;
  976. }
  977. Py_DECREF(dict);
  978. }
  979. if (f != NULL) {
  980. res = f(descr, obj, (PyObject *)Py_TYPE(obj));
  981. goto done;
  982. }
  983. if (descr != NULL) {
  984. res = descr;
  985. descr = NULL;
  986. goto done;
  987. }
  988. PyErr_Format(PyExc_AttributeError,
  989. "'%.50s' object has no attribute '%U'",
  990. tp->tp_name, name);
  991. done:
  992. Py_XDECREF(descr);
  993. Py_DECREF(name);
  994. return res;
  995. }
  996. PyObject *
  997. PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
  998. {
  999. return _PyObject_GenericGetAttrWithDict(obj, name, NULL);
  1000. }
  1001. int
  1002. _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
  1003. PyObject *value, PyObject *dict)
  1004. {
  1005. PyTypeObject *tp = Py_TYPE(obj);
  1006. PyObject *descr;
  1007. descrsetfunc f;
  1008. PyObject **dictptr;
  1009. int res = -1;
  1010. if (!PyUnicode_Check(name)){
  1011. PyErr_Format(PyExc_TypeError,
  1012. "attribute name must be string, not '%.200s'",
  1013. name->ob_type->tp_name);
  1014. return -1;
  1015. }
  1016. if (tp->tp_dict == NULL && PyType_Ready(tp) < 0)
  1017. return -1;
  1018. Py_INCREF(name);
  1019. descr = _PyType_Lookup(tp, name);
  1020. Py_XINCREF(descr);
  1021. f = NULL;
  1022. if (descr != NULL) {
  1023. f = descr->ob_type->tp_descr_set;
  1024. if (f != NULL && PyDescr_IsData(descr)) {
  1025. res = f(descr, obj, value);
  1026. goto done;
  1027. }
  1028. }
  1029. if (dict == NULL) {
  1030. dictptr = _PyObject_GetDictPtr(obj);
  1031. if (dictptr != NULL) {
  1032. res = _PyObjectDict_SetItem(Py_TYPE(obj), dictptr, name, value);
  1033. if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
  1034. PyErr_SetObject(PyExc_AttributeError, name);
  1035. goto done;
  1036. }
  1037. }
  1038. if (dict != NULL) {
  1039. Py_INCREF(dict);
  1040. if (value == NULL)
  1041. res = PyDict_DelItem(dict, name);
  1042. else
  1043. res = PyDict_SetItem(dict, name, value);
  1044. Py_DECREF(dict);
  1045. if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
  1046. PyErr_SetObject(PyExc_AttributeError, name);
  1047. goto done;
  1048. }
  1049. if (f != NULL) {
  1050. res = f(descr, obj, value);
  1051. goto done;
  1052. }
  1053. if (descr == NULL) {
  1054. PyErr_Format(PyExc_AttributeError,
  1055. "'%.100s' object has no attribute '%U'",
  1056. tp->tp_name, name);
  1057. goto done;
  1058. }
  1059. PyErr_Format(PyExc_AttributeError,
  1060. "'%.50s' object attribute '%U' is read-only",
  1061. tp->tp_name, name);
  1062. done:
  1063. Py_XDECREF(descr);
  1064. Py_DECREF(name);
  1065. return res;
  1066. }
  1067. int
  1068. PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
  1069. {
  1070. return _PyObject_GenericSetAttrWithDict(obj, name, value, NULL);
  1071. }
  1072. int
  1073. PyObject_GenericSetDict(PyObject *obj, PyObject *value, void *context)
  1074. {
  1075. PyObject *dict, **dictptr = _PyObject_GetDictPtr(obj);
  1076. if (dictptr == NULL) {
  1077. PyErr_SetString(PyExc_AttributeError,
  1078. "This object has no __dict__");
  1079. return -1;
  1080. }
  1081. if (value == NULL) {
  1082. PyErr_SetString(PyExc_TypeError, "cannot delete __dict__");
  1083. return -1;
  1084. }
  1085. if (!PyDict_Check(value)) {
  1086. PyErr_Format(PyExc_TypeError,
  1087. "__dict__ must be set to a dictionary, "
  1088. "not a '%.200s'", Py_TYPE(value)->tp_name);
  1089. return -1;
  1090. }
  1091. dict = *dictptr;
  1092. Py_XINCREF(value);
  1093. *dictptr = value;
  1094. Py_XDECREF(dict);
  1095. return 0;
  1096. }
  1097. /* Test a value used as condition, e.g., in a for or if statement.
  1098. Return -1 if an error occurred */
  1099. int
  1100. PyObject_IsTrue(PyObject *v)
  1101. {
  1102. Py_ssize_t res;
  1103. if (v == Py_True)
  1104. return 1;
  1105. if (v == Py_False)
  1106. return 0;
  1107. if (v == Py_None)
  1108. return 0;
  1109. else if (v->ob_type->tp_as_number != NULL &&
  1110. v->ob_type->tp_as_number->nb_bool != NULL)
  1111. res = (*v->ob_type->tp_as_number->nb_bool)(v);
  1112. else if (v->ob_type->tp_as_mapping != NULL &&
  1113. v->ob_type->tp_as_mapping->mp_length != NULL)
  1114. res = (*v->ob_type->tp_as_mapping->mp_length)(v);
  1115. else if (v->ob_type->tp_as_sequence != NULL &&
  1116. v->ob_type->tp_as_sequence->sq_length != NULL)
  1117. res = (*v->ob_type->tp_as_sequence->sq_length)(v);
  1118. else
  1119. return 1;
  1120. /* if it is negative, it should be either -1 or -2 */
  1121. return (res > 0) ? 1 : Py_SAFE_DOWNCAST(res, Py_ssize_t, int);
  1122. }
  1123. /* equivalent of 'not v'
  1124. Return -1 if an error occurred */
  1125. int
  1126. PyObject_Not(PyObject *v)
  1127. {
  1128. int res;
  1129. res = PyObject_IsTrue(v);
  1130. if (res < 0)
  1131. return res;
  1132. return res == 0;
  1133. }
  1134. /* Test whether an object can be called */
  1135. int
  1136. PyCallable_Check(PyObject *x)
  1137. {
  1138. if (x == NULL)
  1139. return 0;
  1140. return x->ob_type->tp_call != NULL;
  1141. }
  1142. /* Helper for PyObject_Dir without arguments: returns the local scope. */
  1143. static PyObject *
  1144. _dir_locals(void)
  1145. {
  1146. PyObject *names;
  1147. PyObject *locals;
  1148. locals = PyEval_GetLocals();
  1149. if (locals == NULL)
  1150. return NULL;
  1151. names = PyMapping_Keys(locals);
  1152. if (!names)
  1153. return NULL;
  1154. if (!PyList_Check(names)) {
  1155. PyErr_Format(PyExc_TypeError,
  1156. "dir(): expected keys() of locals to be a list, "
  1157. "not '%.200s'", Py_TYPE(names)->tp_name);
  1158. Py_DECREF(names);
  1159. return NULL;
  1160. }
  1161. if (PyList_Sort(names)) {
  1162. Py_DECREF(names);
  1163. return NULL;
  1164. }
  1165. /* the locals don't need to be DECREF'd */
  1166. return names;
  1167. }
  1168. /* Helper for PyObject_Dir: object introspection. */
  1169. static PyObject *
  1170. _dir_object(PyObject *obj)
  1171. {
  1172. PyObject *result, *sorted;
  1173. PyObject *dirfunc = _PyObject_LookupSpecial(obj, &PyId___dir__);
  1174. assert(obj);
  1175. if (dirfunc == NULL) {
  1176. if (!PyErr_Occurred())
  1177. PyErr_SetString(PyExc_TypeError, "object does not provide __dir__");
  1178. return NULL;
  1179. }
  1180. /* use __dir__ */
  1181. result = PyObject_CallFunctionObjArgs(dirfunc, NULL);
  1182. Py_DECREF(dirfunc);
  1183. if (result == NULL)
  1184. return NULL;
  1185. /* return sorted(result) */
  1186. sorted = PySequence_List(result);
  1187. Py_DECREF(result);
  1188. if (sorted == NULL)
  1189. return NULL;
  1190. if (PyList_Sort(sorted)) {
  1191. Py_DECREF(sorted);
  1192. return NULL;
  1193. }
  1194. return sorted;
  1195. }
  1196. /* Implementation of dir() -- if obj is NULL, returns the names in the current
  1197. (local) scope. Otherwise, performs introspection of the object: returns a
  1198. sorted list of attribute names (supposedly) accessible from the object
  1199. */
  1200. PyObject *
  1201. PyObject_Dir(PyObject *obj)
  1202. {
  1203. return (obj == NULL) ? _dir_locals() : _dir_object(obj);
  1204. }
  1205. /*
  1206. None is a non-NULL undefined value.
  1207. There is (and should be!) no way to create other objects of this type,
  1208. so there is exactly one (which is indestructible, by the way).
  1209. */
  1210. /* ARGSUSED */
  1211. static PyObject *
  1212. none_repr(PyObject *op)
  1213. {
  1214. return PyUnicode_FromString("None");
  1215. }
  1216. /* ARGUSED */
  1217. static void
  1218. none_dealloc(PyObject* ignore)
  1219. {
  1220. /* This should never get called, but we also don't want to SEGV if
  1221. * we accidentally decref None out of existence.
  1222. */
  1223. Py_FatalError("deallocating None");
  1224. }
  1225. static PyObject *
  1226. none_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
  1227. {
  1228. if (PyTuple_GET_SIZE(args) || (kwargs && PyDict_Size(kwargs))) {
  1229. PyErr_SetString(PyExc_TypeError, "NoneType takes no arguments");
  1230. return NULL;
  1231. }
  1232. Py_RETURN_NONE;
  1233. }
  1234. static int
  1235. none_bool(PyObject *v)
  1236. {
  1237. return 0;
  1238. }
  1239. static PyNumberMethods none_as_number = {
  1240. 0, /* nb_add */
  1241. 0, /* nb_subtract */
  1242. 0, /* nb_multiply */
  1243. 0, /* nb_remainder */
  1244. 0, /* nb_divmod */
  1245. 0, /* nb_power */
  1246. 0, /* nb_negative */
  1247. 0, /* nb_positive */
  1248. 0, /* nb_absolute */
  1249. (inquiry)none_bool, /* nb_bool */
  1250. 0, /* nb_invert */
  1251. 0, /* nb_lshift */
  1252. 0, /* nb_rshift */
  1253. 0, /* nb_and */
  1254. 0, /* nb_xor */
  1255. 0, /* nb_or */
  1256. 0, /* nb_int */
  1257. 0, /* nb_reserved */
  1258. 0, /* nb_float */
  1259. 0, /* nb_inplace_add */
  1260. 0, /* nb_inplace_subtract */
  1261. 0, /* nb_inplace_multiply */
  1262. 0, /* nb_inplace_remainder */
  1263. 0, /* nb_inplace_power */
  1264. 0, /* nb_inplace_lshift */
  1265. 0, /* nb_inplace_rshift */
  1266. 0, /* nb_inplace_and */
  1267. 0, /* nb_inplace_xor */
  1268. 0, /* nb_inplace_or */
  1269. 0, /* nb_floor_divide */
  1270. 0, /* nb_true_divide */
  1271. 0, /* nb_inplace_floor_divide */
  1272. 0, /* nb_inplace_true_divide */
  1273. 0, /* nb_index */
  1274. };
  1275. PyTypeObject _PyNone_Type = {
  1276. PyVarObject_HEAD_INIT(&PyType_Type, 0)
  1277. "NoneType",
  1278. 0,
  1279. 0,
  1280. none_dealloc, /*tp_dealloc*/ /*never called*/
  1281. 0, /*tp_print*/
  1282. 0, /*tp_getattr*/
  1283. 0, /*tp_setattr*/
  1284. 0, /*tp_reserved*/
  1285. none_repr, /*tp_repr*/
  1286. &none_as_number, /*tp_as_number*/
  1287. 0, /*tp_as_sequence*/
  1288. 0, /*tp_as_mapping*/
  1289. 0, /*tp_hash */
  1290. 0, /*tp_call */
  1291. 0, /*tp_str */
  1292. 0, /*tp_getattro */
  1293. 0, /*tp_setattro */
  1294. 0, /*tp_as_buffer */
  1295. Py_TPFLAGS_DEFAULT, /*tp_flags */
  1296. 0, /*tp_doc */
  1297. 0, /*tp_traverse */
  1298. 0, /*tp_clear */
  1299. 0, /*tp_richcompare */
  1300. 0, /*tp_weaklistoffset */
  1301. 0, /*tp_iter */
  1302. 0, /*tp_iternext */
  1303. 0, /*tp_methods */
  1304. 0, /*tp_members */
  1305. 0, /*tp_getset */
  1306. 0, /*tp_base */
  1307. 0, /*tp_dict */
  1308. 0, /*tp_descr_get */
  1309. 0, /*tp_descr_set */
  1310. 0, /*tp_dictoffset */
  1311. 0, /*tp_init */
  1312. 0, /*tp_alloc */
  1313. none_new, /*tp_new */
  1314. };
  1315. PyObject _Py_NoneStruct = {
  1316. _PyObject_EXTRA_INIT
  1317. 1, &_PyNone_Type
  1318. };
  1319. /* NotImplemented is an object that can be used to signal that an
  1320. operation is not implemented for the given type combination. */
  1321. static PyObject *
  1322. NotImplemented_repr(PyObject *op)
  1323. {
  1324. return PyUnicode_FromString("NotImplemented");
  1325. }
  1326. static PyObject *
  1327. NotImplemented_reduce(PyObject *op)
  1328. {
  1329. return PyUnicode_FromString("NotImplemented");
  1330. }
  1331. static PyMethodDef notimplemented_methods[] = {
  1332. {"__reduce__", (PyCFunction)NotImplemented_reduce, METH_NOARGS, NULL},
  1333. {NULL, NULL}
  1334. };
  1335. static PyObject *
  1336. notimplemented_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
  1337. {
  1338. if (PyTuple_GET_SIZE(args) || (kwargs && PyDict_Size(kwargs))) {
  1339. PyErr_SetString(PyExc_TypeError, "NotImplementedType takes no arguments");
  1340. return NULL;
  1341. }
  1342. Py_RETURN_NOTIMPLEMENTED;
  1343. }
  1344. static void
  1345. notimplemented_dealloc(PyObject* ignore)
  1346. {
  1347. /* This should never get called, but we also don't want to SEGV if
  1348. * we accidentally decref NotImplemented out of existence.
  1349. */
  1350. Py_FatalError("deallocating NotImplemented");
  1351. }
  1352. PyTypeObject _PyNotImplemented_Type = {
  1353. PyVarObject_HEAD_INIT(&PyType_Type, 0)
  1354. "NotImplementedType",
  1355. 0,
  1356. 0,
  1357. notimplemented_dealloc, /*tp_dealloc*/ /*never called*/
  1358. 0, /*tp_print*/
  1359. 0, /*tp_getattr*/
  1360. 0, /*tp_setattr*/
  1361. 0, /*tp_reserved*/
  1362. NotImplemented_repr, /*tp_repr*/
  1363. 0, /*tp_as_number*/
  1364. 0, /*tp_as_sequence*/
  1365. 0, /*tp_as_mapping*/
  1366. 0, /*tp_hash */
  1367. 0, /*tp_call */
  1368. 0, /*tp_str */
  1369. 0, /*tp_getattro */
  1370. 0, /*tp_setattro */
  1371. 0, /*tp_as_buffer */
  1372. Py_TPFLAGS_DEFAULT, /*tp_flags */
  1373. 0, /*tp_doc */
  1374. 0, /*tp_traverse */
  1375. 0, /*tp_clear */
  1376. 0, /*tp_richcompare */
  1377. 0, /*tp_weaklistoffset */
  1378. 0, /*tp_iter */
  1379. 0, /*tp_iternext */
  1380. notimplemented_methods, /*tp_methods */
  1381. 0, /*tp_members */
  1382. 0, /*tp_getset */
  1383. 0, /*tp_base */
  1384. 0, /*tp_dict */
  1385. 0, /*tp_descr_get */
  1386. 0, /*tp_descr_set */
  1387. 0, /*tp_dictoffset */
  1388. 0, /*tp_init */
  1389. 0, /*tp_alloc */
  1390. notimplemented_new, /*tp_new */
  1391. };
  1392. PyObject _Py_NotImplementedStruct = {
  1393. _PyObject_EXTRA_INIT
  1394. 1, &_PyNotImplemented_Type
  1395. };
  1396. void
  1397. _Py_ReadyTypes(void)
  1398. {
  1399. if (PyType_Ready(&PyBaseObject_Type) < 0)
  1400. Py_FatalError("Can't initialize object type");
  1401. if (PyType_Ready(&PyType_Type) < 0)
  1402. Py_FatalError("Can't initialize type type");
  1403. if (PyType_Ready(&_PyWeakref_RefType) < 0)
  1404. Py_FatalError("Can't initialize weakref type");
  1405. if (PyType_Ready(&_PyWeakref_CallableProxyType) < 0)
  1406. Py_FatalError("Can't initialize callable weakref proxy type");
  1407. if (PyType_Ready(&_PyWeakref_ProxyType) < 0)
  1408. Py_FatalError("Can't initialize weakref proxy type");
  1409. if (PyType_Ready(&PyLong_Type) < 0)
  1410. Py_FatalError("Can't initialize int type");
  1411. if (PyType_Ready(&PyBool_Type) < 0)
  1412. Py_FatalError("Can't initialize bool type");
  1413. if (PyType_Ready(&PyByteArray_Type) < 0)
  1414. Py_FatalError("Can't initialize bytearray type");
  1415. if (PyType_Ready(&PyBytes_Type) < 0)
  1416. Py_FatalError("Can't initialize 'str'");
  1417. if (PyType_Ready(&PyList_Type) < 0)
  1418. Py_FatalError("Can't initialize list type");
  1419. if (PyType_Ready(&_PyNone_Type) < 0)
  1420. Py_FatalError("Can't initialize None type");
  1421. if (PyType_Ready(&_PyNotImplemented_Type) < 0)
  1422. Py_FatalError("Can't initialize NotImplemented type");
  1423. if (PyType_Ready(&PyTraceBack_Type) < 0)
  1424. Py_FatalError("Can't initialize traceback type");
  1425. if (PyType_Ready(&PySuper_Type) < 0)
  1426. Py_FatalError("Can't initialize super type");
  1427. if (PyType_Ready(&PyRange_Type) < 0)
  1428. Py_FatalError("Can't initialize range type");
  1429. if (PyType_Ready(&PyDict_Type) < 0)
  1430. Py_FatalError("Can't initialize dict type");
  1431. if (PyType_Ready(&PyODict_Type) < 0)
  1432. Py_FatalError("Can't initialize OrderedDict type");
  1433. if (PyType_Ready(&PyODictKeys_Type) < 0)
  1434. Py_FatalError("Can't initialize odict_keys type");
  1435. if (PyType_Ready(&PyODictItems_Type) < 0)
  1436. Py_FatalError("Can't initialize odict_items type");
  1437. if (PyType_Ready(&PyODictValues_Type) < 0)
  1438. Py_FatalError("Can't initialize odict_values type");
  1439. if (PyType_Ready(&PyODictIter_Type) < 0)
  1440. Py_FatalError("Can't initialize odict_keyiterator type");
  1441. if (PyType_Ready(&PySet_Type) < 0)
  1442. Py_FatalError("Can't initialize set type");
  1443. if (PyType_Ready(&PyUnicode_Type) < 0)
  1444. Py_FatalError("Can't initialize str type");
  1445. if (PyType_Ready(&PySlice_Type) < 0)
  1446. Py_FatalError("Can't initialize slice type");
  1447. if (PyType_Ready(&PyStaticMethod_Type) < 0)
  1448. Py_FatalError("Can't initialize static method type");
  1449. if (PyType_Ready(&PyComplex_Type) < 0)
  1450. Py_FatalError("Can't initialize complex type");
  1451. if (PyType_Ready(&PyFloat_Type) < 0)
  1452. Py_FatalError("Can't initialize float type");
  1453. if (PyType_Ready(&PyFrozenSet_Type) < 0)
  1454. Py_FatalError("Can't initialize frozenset type");
  1455. if (PyType_Ready(&PyProperty_Type) < 0)
  1456. Py_FatalError("Can't initialize property type");
  1457. if (PyType_Ready(&_PyManagedBuffer_Type) < 0)
  1458. Py_FatalError("Can't initialize managed buffer type");
  1459. if (PyType_Ready(&PyMemoryView_Type) < 0)
  1460. Py_FatalError("Can't initialize memoryview type");
  1461. if (PyType_Ready(&PyTuple_Type) < 0)
  1462. Py_FatalError("Can't initialize tuple type");
  1463. if (PyType_Ready(&PyEnum_Type) < 0)
  1464. Py_FatalError("Can't initialize enumerate type");
  1465. if (PyType_Ready(&PyReversed_Type) < 0)
  1466. Py_FatalError("Can't initialize reversed type");
  1467. if (PyType_Ready(&PyStdPrinter_Type) < 0)
  1468. Py_FatalError("Can't initialize StdPrinter");
  1469. if (PyType_Ready(&PyCode_Type) < 0)
  1470. Py_FatalError("Can't initialize code type");
  1471. if (PyType_Ready(&PyFrame_Type) < 0)
  1472. Py_FatalError("Can't initialize frame type");
  1473. if (PyType_Ready(&PyCFunction_Type) < 0)
  1474. Py_FatalError("Can't initialize builtin function type");
  1475. if (PyType_Ready(&PyMethod_Type) < 0)
  1476. Py_FatalError("Can't initialize method type");
  1477. if (PyType_Ready(&PyFunction_Type) < 0)
  1478. Py_FatalError("Can't initialize function type");
  1479. if (PyType_Ready(&PyDictProxy_Type) < 0)
  1480. Py_FatalError("Can't initialize dict proxy type");
  1481. if (PyType_Ready(&PyGen_Type) < 0)
  1482. Py_FatalError("Can't initialize generator type");
  1483. if (PyType_Ready(&PyGetSetDescr_Type) < 0)
  1484. Py_FatalError("Can't initialize get-set descriptor type");
  1485. if (PyType_Ready(&PyWrapperDescr_Type) < 0)
  1486. Py_FatalError("Can't initialize wrapper type");
  1487. if (PyType_Ready(&_PyMethodWrapper_Type) < 0)
  1488. Py_FatalError("Can't initialize method wrapper type");
  1489. if (PyType_Ready(&PyEllipsis_Type) < 0)
  1490. Py_FatalError("Can't initialize ellipsis type");
  1491. if (PyType_Ready(&PyMemberDescr_Type) < 0)
  1492. Py_FatalError("Can't initialize member descriptor type");
  1493. if (PyType_Ready(&_PyNamespace_Type) < 0)
  1494. Py_FatalError("Can't initialize namespace type");
  1495. if (PyType_Ready(&PyCapsule_Type) < 0)
  1496. Py_FatalError("Can't initialize capsule type");
  1497. if (PyType_Ready(&PyLongRangeIter_Type) < 0)
  1498. Py_FatalError("Can't initialize long range iterator type");
  1499. if (PyType_Ready(&PyCell_Type) < 0)
  1500. Py_FatalError("Can't initialize cell type");
  1501. if (PyType_Ready(&PyInstanceMethod_Type) < 0)
  1502. Py_FatalError("Can't initialize instance method type");
  1503. if (PyType_Ready(&PyClassMethodDescr_Type) < 0)
  1504. Py_FatalError("Can't initialize class method descr type");
  1505. if (PyType_Ready(&PyMethodDescr_Type) < 0)
  1506. Py_FatalError("Can't initialize method descr type");
  1507. if (PyType_Ready(&PyCallIter_Type) < 0)
  1508. Py_FatalError("Can't initialize call iter type");
  1509. if (PyType_Ready(&PySeqIter_Type) < 0)
  1510. Py_FatalError("Can't initialize sequence iterator type");
  1511. }
  1512. #ifdef Py_TRACE_REFS
  1513. void
  1514. _Py_NewReference(PyObject *op)
  1515. {
  1516. _Py_INC_REFTOTAL;
  1517. op->ob_refcnt = 1;
  1518. _Py_AddToAllObjects(op, 1);
  1519. _Py_INC_TPALLOCS(op);
  1520. }
  1521. void
  1522. _Py_ForgetReference(PyObject *op)
  1523. {
  1524. #ifdef SLOW_UNREF_CHECK
  1525. PyObject *p;
  1526. #endif
  1527. if (op->ob_refcnt < 0)
  1528. Py_FatalError("UNREF negative refcnt");
  1529. if (op == &refchain ||
  1530. op->_ob_prev->_ob_next != op || op->_ob_next->_ob_prev != op) {
  1531. fprintf(stderr, "* ob\n");
  1532. _PyObject_Dump(op);
  1533. fprintf(stderr, "* op->_ob_prev->_ob_next\n");
  1534. _PyObject_Dump(op->_ob_prev->_ob_next);
  1535. fprintf(stderr, "* op->_ob_next->_ob_prev\n");
  1536. _PyObject_Dump(op->_ob_next->_ob_prev);
  1537. Py_FatalError("UNREF invalid object");
  1538. }
  1539. #ifdef SLOW_UNREF_CHECK
  1540. for (p = refchain._ob_next; p != &refchain; p = p->_ob_next) {
  1541. if (p == op)
  1542. break;
  1543. }
  1544. if (p == &refchain) /* Not found */
  1545. Py_FatalError("UNREF unknown object");
  1546. #endif
  1547. op->_ob_next->_ob_prev = op->_ob_prev;
  1548. op->_ob_prev->_ob_next = op->_ob_next;
  1549. op->_ob_next = op->_ob_prev = NULL;
  1550. _Py_INC_TPFREES(op);
  1551. }
  1552. void
  1553. _Py_Dealloc(PyObject *op)
  1554. {
  1555. destructor dealloc = Py_TYPE(op)->tp_dealloc;
  1556. _Py_ForgetReference(op);
  1557. (*dealloc)(op);
  1558. }
  1559. /* Print all live objects. Because PyObject_Print is called, the
  1560. * interpreter must be in a healthy state.
  1561. */
  1562. void
  1563. _Py_PrintReferences(FILE *fp)
  1564. {
  1565. PyObject *op;
  1566. fprintf(fp, "Remaining objects:\n");
  1567. for (op = refchain._ob_next; op != &refchain; op = op->_ob_next) {
  1568. fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] ", op, op->ob_refcnt);
  1569. if (PyObject_Print(op, fp, 0) != 0)
  1570. PyErr_Clear();
  1571. putc('\n', fp);
  1572. }
  1573. }
  1574. /* Print the addresses of all live objects. Unlike _Py_PrintReferences, this
  1575. * doesn't make any calls to the Python C API, so is always safe to call.
  1576. */
  1577. void
  1578. _Py_PrintReferenceAddresses(FILE *fp)
  1579. {
  1580. PyObject *op;
  1581. fprintf(fp, "Remaining object addresses:\n");
  1582. for (op = refchain._ob_next; op != &refchain; op = op->_ob_next)
  1583. fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] %s\n", op,
  1584. op->ob_refcnt, Py_TYPE(op)->tp_name);
  1585. }
  1586. PyObject *
  1587. _Py_GetObjects(PyObject *self, PyObject *args)
  1588. {
  1589. int i, n;
  1590. PyObject *t = NULL;
  1591. PyObject *res, *op;
  1592. if (!PyArg_ParseTuple(args, "i|O", &n, &t))
  1593. return NULL;
  1594. op = refchain._ob_next;
  1595. res = PyList_New(0);
  1596. if (res == NULL)
  1597. return NULL;
  1598. for (i = 0; (n == 0 || i < n) && op != &refchain; i++) {
  1599. while (op == self || op == args || op == res || op == t ||
  1600. (t != NULL && Py_TYPE(op) != (PyTypeObject *) t)) {
  1601. op = op->_ob_next;
  1602. if (op == &refchain)
  1603. return res;
  1604. }
  1605. if (PyList_Append(res, op) < 0) {
  1606. Py_DECREF(res);
  1607. return NULL;
  1608. }
  1609. op = op->_ob_next;
  1610. }
  1611. return res;
  1612. }
  1613. #endif
  1614. /* Hack to force loading of abstract.o */
  1615. Py_ssize_t (*_Py_abstract_hack)(PyObject *) = PyObject_Size;
  1616. void
  1617. _PyObject_DebugTypeStats(FILE *out)
  1618. {
  1619. _PyCFunction_DebugMallocStats(out);
  1620. _PyDict_DebugMallocStats(out);
  1621. _PyFloat_DebugMallocStats(out);
  1622. _PyFrame_DebugMallocStats(out);
  1623. _PyList_DebugMallocStats(out);
  1624. _PyMethod_DebugMallocStats(out);
  1625. _PyTuple_DebugMallocStats(out);
  1626. }
  1627. /* These methods are used to control infinite recursion in repr, str, print,
  1628. etc. Container objects that may recursively contain themselves,
  1629. e.g. builtin dictionaries and lists, should used Py_ReprEnter() and
  1630. Py_ReprLeave() to avoid infinite recursion.
  1631. Py_ReprEnter() returns 0 the first time it is called for a particular
  1632. object and 1 every time thereafter. It returns -1 if an exception
  1633. occurred. Py_ReprLeave() has no return value.
  1634. See dictobject.c and listobject.c for examples of use.
  1635. */
  1636. int
  1637. Py_ReprEnter(PyObject *obj)
  1638. {
  1639. PyObject *dict;
  1640. PyObject *list;
  1641. Py_ssize_t i;
  1642. dict = PyThreadState_GetDict();
  1643. /* Ignore a missing thread-state, so that this function can be called
  1644. early on startup. */
  1645. if (dict == NULL)
  1646. return 0;
  1647. list = _PyDict_GetItemId(dict, &PyId_Py_Repr);
  1648. if (list == NULL) {
  1649. list = PyList_New(0);
  1650. if (list == NULL)
  1651. return -1;
  1652. if (_PyDict_SetItemId(dict, &PyId_Py_Repr, list) < 0)
  1653. return -1;
  1654. Py_DECREF(list);
  1655. }
  1656. i = PyList_GET_SIZE(list);
  1657. while (--i >= 0) {
  1658. if (PyList_GET_ITEM(list, i) == obj)
  1659. return 1;
  1660. }
  1661. if (PyList_Append(list, obj) < 0)
  1662. return -1;
  1663. return 0;
  1664. }
  1665. void
  1666. Py_ReprLeave(PyObject *obj)
  1667. {
  1668. PyObject *dict;
  1669. PyObject *list;
  1670. Py_ssize_t i;
  1671. PyObject *error_type, *error_value, *error_traceback;
  1672. PyErr_Fetch(&error_type, &error_value, &error_traceback);
  1673. dict = PyThreadState_GetDict();
  1674. if (dict == NULL)
  1675. goto finally;
  1676. list = _PyDict_GetItemId(dict, &PyId_Py_Repr);
  1677. if (list == NULL || !PyList_Check(list))
  1678. goto finally;
  1679. i = PyList_GET_SIZE(list);
  1680. /* Count backwards because we always expect obj to be list[-1] */
  1681. while (--i >= 0) {
  1682. if (PyList_GET_ITEM(list, i) == obj) {
  1683. PyList_SetSlice(list, i, i + 1, NULL);
  1684. break;
  1685. }
  1686. }
  1687. finally:
  1688. /* ignore exceptions because there is no way to report them. */
  1689. PyErr_Restore(error_type, error_value, error_traceback);
  1690. }
  1691. /* Trashcan support. */
  1692. /* Current call-stack depth of tp_dealloc calls. */
  1693. int _PyTrash_delete_nesting = 0;
  1694. /* List of objects that still need to be cleaned up, singly linked via their
  1695. * gc headers' gc_prev pointers.
  1696. */
  1697. PyObject *_PyTrash_delete_later = NULL;
  1698. /* Add op to the _PyTrash_delete_later list. Called when the current
  1699. * call-stack depth gets large. op must be a currently untracked gc'ed
  1700. * object, with refcount 0. Py_DECREF must already have been called on it.
  1701. */
  1702. void
  1703. _PyTrash_deposit_object(PyObject *op)
  1704. {
  1705. assert(PyObject_IS_GC(op));
  1706. assert(_PyGC_REFS(op) == _PyGC_REFS_UNTRACKED);
  1707. assert(op->ob_refcnt == 0);
  1708. _Py_AS_GC(op)->gc.gc_prev = (PyGC_Head *)_PyTrash_delete_later;
  1709. _PyTrash_delete_later = op;
  1710. }
  1711. /* The equivalent API, using per-thread state recursion info */
  1712. void
  1713. _PyTrash_thread_deposit_object(PyObject *op)
  1714. {
  1715. PyThreadState *tstate = PyThreadState_GET();
  1716. assert(PyObject_IS_GC(op));
  1717. assert(_PyGC_REFS(op) == _PyGC_REFS_UNTRACKED);
  1718. assert(op->ob_refcnt == 0);
  1719. _Py_AS_GC(op)->gc.gc_prev = (PyGC_Head *) tstate->trash_delete_later;
  1720. tstate->trash_delete_later = op;
  1721. }
  1722. /* Dealloccate all the objects in the _PyTrash_delete_later list. Called when
  1723. * the call-stack unwinds again.
  1724. */
  1725. void
  1726. _PyTrash_destroy_chain(void)
  1727. {
  1728. while (_PyTrash_delete_later) {
  1729. PyObject *op = _PyTrash_delete_later;
  1730. destructor dealloc = Py_TYPE(op)->tp_dealloc;
  1731. _PyTrash_delete_later =
  1732. (PyObject*) _Py_AS_GC(op)->gc.gc_prev;
  1733. /* Call the deallocator directly. This used to try to
  1734. * fool Py_DECREF into calling it indirectly, but
  1735. * Py_DECREF was already called on this object, and in
  1736. * assorted non-release builds calling Py_DECREF again ends
  1737. * up distorting allocation statistics.
  1738. */
  1739. assert(op->ob_refcnt == 0);
  1740. ++_PyTrash_delete_nesting;
  1741. (*dealloc)(op);
  1742. --_PyTrash_delete_nesting;
  1743. }
  1744. }
  1745. /* The equivalent API, using per-thread state recursion info */
  1746. void
  1747. _PyTrash_thread_destroy_chain(void)
  1748. {
  1749. PyThreadState *tstate = PyThreadState_GET();
  1750. while (tstate->trash_delete_later) {
  1751. PyObject *op = tstate->trash_delete_later;
  1752. destructor dealloc = Py_TYPE(op)->tp_dealloc;
  1753. tstate->trash_delete_later =
  1754. (PyObject*) _Py_AS_GC(op)->gc.gc_prev;
  1755. /* Call the deallocator directly. This used to try to
  1756. * fool Py_DECREF into calling it indirectly, but
  1757. * Py_DECREF was already called on this object, and in
  1758. * assorted non-release builds calling Py_DECREF again ends
  1759. * up distorting allocation statistics.
  1760. */
  1761. assert(op->ob_refcnt == 0);
  1762. ++tstate->trash_delete_nesting;
  1763. (*dealloc)(op);
  1764. --tstate->trash_delete_nesting;
  1765. }
  1766. }
  1767. #ifndef Py_TRACE_REFS
  1768. /* For Py_LIMITED_API, we need an out-of-line version of _Py_Dealloc.
  1769. Define this here, so we can undefine the macro. */
  1770. #undef _Py_Dealloc
  1771. PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
  1772. void
  1773. _Py_Dealloc(PyObject *op)
  1774. {
  1775. _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA
  1776. (*Py_TYPE(op)->tp_dealloc)(op);
  1777. }
  1778. #endif
  1779. #ifdef __cplusplus
  1780. }
  1781. #endif