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.

1003 lines
37 KiB

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
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
36 years ago
Merged revisions 59921-59932 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r59923 | raymond.hettinger | 2008-01-11 19:04:55 +0100 (Fri, 11 Jan 2008) | 1 line Speed-up and simplify code urlparse's result objects. ........ r59924 | andrew.kuchling | 2008-01-11 20:33:24 +0100 (Fri, 11 Jan 2008) | 1 line Bug #1790: update link; remove outdated paragraph ........ r59925 | thomas.heller | 2008-01-11 20:34:06 +0100 (Fri, 11 Jan 2008) | 5 lines Raise an error instead of crashing with a segfault when a NULL function pointer is called. Will backport to release25-maint. ........ r59927 | thomas.heller | 2008-01-11 21:29:19 +0100 (Fri, 11 Jan 2008) | 4 lines Fix a potential 'SystemError: NULL result without error'. NULL may be a valid return value from PyLong_AsVoidPtr. Will backport to release25-maint. ........ r59928 | raymond.hettinger | 2008-01-12 00:25:18 +0100 (Sat, 12 Jan 2008) | 1 line Update the opcode docs for STORE_MAP and BUILD_MAP ........ r59929 | mark.dickinson | 2008-01-12 02:56:00 +0100 (Sat, 12 Jan 2008) | 4 lines Issue 1780: Allow leading and trailing whitespace in Decimal constructor, when constructing from a string. Disallow trailing newlines in Context.create_decimal. ........ r59930 | georg.brandl | 2008-01-12 11:53:29 +0100 (Sat, 12 Jan 2008) | 3 lines Move OSError docs to exceptions doc, remove obsolete descriptions from os docs, rework posix docs. ........ r59931 | georg.brandl | 2008-01-12 14:47:57 +0100 (Sat, 12 Jan 2008) | 3 lines Patch #1700288: Method cache optimization, by Armin Rigo, ported to 2.6 by Kevin Jacobs. ........ r59932 | georg.brandl | 2008-01-12 17:11:09 +0100 (Sat, 12 Jan 2008) | 2 lines Fix editing glitch. ........
18 years ago
36 years ago
36 years ago
Merged revisions 53875-53911 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r53899 | neal.norwitz | 2007-02-25 16:52:27 +0100 (Sun, 25 Feb 2007) | 1 line Add more details when releasing interned strings ........ r53900 | neal.norwitz | 2007-02-25 16:53:36 +0100 (Sun, 25 Feb 2007) | 1 line Whitespace only changes ........ r53901 | jeremy.hylton | 2007-02-25 16:57:45 +0100 (Sun, 25 Feb 2007) | 8 lines Fix crash in exec when unicode filename can't be decoded. I can't think of an easy way to test this behavior. It only occurs when the file system default encoding and the interpreter default encoding are different, such that you can open the file but not decode its name. ........ r53902 | jeremy.hylton | 2007-02-25 17:01:58 +0100 (Sun, 25 Feb 2007) | 2 lines Put declarations before code. ........ r53910 | fred.drake | 2007-02-25 18:56:27 +0100 (Sun, 25 Feb 2007) | 3 lines - SF patch #1657613: add documentation for the Element interface - clean up bogus use of the {datadescni} environment everywhere ........ r53911 | neal.norwitz | 2007-02-25 20:44:48 +0100 (Sun, 25 Feb 2007) | 17 lines Variation of patch # 1624059 to speed up checking if an object is a subclass of some of the common builtin types. Use a bit in tp_flags for each common builtin type. Check the bit to determine if any instance is a subclass of these common types. The check avoids a function call and O(n) search of the base classes. The check is done in the various Py*_Check macros rather than calling PyType_IsSubtype(). All the bits are set in tp_flags when the type is declared in the Objects/*object.c files because PyType_Ready() is not called for all the types. Should PyType_Ready() be called for all types? If so and the change is made, the changes to the Objects/*object.c files can be reverted (remove setting the tp_flags). Objects/typeobject.c would also have to be modified to add conditions for Py*_CheckExact() in addition to each the PyType_IsSubtype check. ........
19 years ago
Merged revisions 60364-60378 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r60364 | neal.norwitz | 2008-01-27 19:09:48 +0100 (Sun, 27 Jan 2008) | 4 lines Update the comment and remove the close. If we close we can't flush anymore. We might still need to close after the for loop if flushing 6! times still doesn't cause the signal/exception. ........ r60365 | georg.brandl | 2008-01-27 19:14:43 +0100 (Sun, 27 Jan 2008) | 2 lines Remove effectless expression statement. ........ r60367 | neal.norwitz | 2008-01-27 19:19:04 +0100 (Sun, 27 Jan 2008) | 1 line Try to handle socket.errors properly in is_unavailable ........ r60370 | christian.heimes | 2008-01-27 20:01:45 +0100 (Sun, 27 Jan 2008) | 1 line Change isbasestring function as discussed on the cvs list a while ago ........ r60372 | neal.norwitz | 2008-01-27 21:03:13 +0100 (Sun, 27 Jan 2008) | 3 lines socket.error doesn't have a headers attribute like ProtocolError. Handle that situation where we catch socket.errors. ........ r60375 | georg.brandl | 2008-01-27 21:25:12 +0100 (Sun, 27 Jan 2008) | 2 lines Add refcounting extension to build config. ........ r60377 | jeffrey.yasskin | 2008-01-28 00:08:46 +0100 (Mon, 28 Jan 2008) | 6 lines Moved Rational._binary_float_to_ratio() to float.as_integer_ratio() because it's useful outside of rational numbers. This is my first C code that had to do anything significant. Please be more careful when looking over it. ........ r60378 | christian.heimes | 2008-01-28 00:34:59 +0100 (Mon, 28 Jan 2008) | 1 line Added clear cache methods to clear the internal type lookup cache for ref leak test runs. ........
18 years ago
Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63724 | gregory.p.smith | 2008-05-26 22:22:14 +0200 (Mon, 26 May 2008) | 6 lines Fixes issue2791: subprocess.Popen.communicate leaked a file descripton until the last reference to the Popen instance was dropped. Adding explicit close() calls fixes it. Candidate for backport to release25-maint. ........ r63726 | benjamin.peterson | 2008-05-26 22:43:24 +0200 (Mon, 26 May 2008) | 2 lines fix minor grammar typo ........ r63732 | benjamin.peterson | 2008-05-26 23:44:26 +0200 (Mon, 26 May 2008) | 2 lines remove duplication in test module ........ r63744 | lars.gustaebel | 2008-05-27 14:39:23 +0200 (Tue, 27 May 2008) | 3 lines Do not close external file objects passed to tarfile.open(mode='w:bz2') when the TarFile is closed. ........ r63754 | benjamin.peterson | 2008-05-28 03:12:35 +0200 (Wed, 28 May 2008) | 2 lines update tutorial function with more appropiate one from Eric Smith ........ r63755 | mark.hammond | 2008-05-28 03:54:55 +0200 (Wed, 28 May 2008) | 2 lines bdist_wininst now works correctly when both --skip-build and --plat-name are specified. ........ r63757 | georg.brandl | 2008-05-28 13:21:39 +0200 (Wed, 28 May 2008) | 2 lines #2989: add PyType_Modified(). ........ r63758 | benjamin.peterson | 2008-05-28 13:51:41 +0200 (Wed, 28 May 2008) | 2 lines fix spelling ........ r63760 | georg.brandl | 2008-05-28 17:41:36 +0200 (Wed, 28 May 2008) | 2 lines #2990: prevent inconsistent state while updating method cache. ........ r63775 | georg.brandl | 2008-05-29 09:18:17 +0200 (Thu, 29 May 2008) | 2 lines Two fixes in bytearray docs. ........ r63781 | georg.brandl | 2008-05-29 09:38:37 +0200 (Thu, 29 May 2008) | 2 lines #2988: add note about catching CookieError when parsing untrusted cookie data. ........ r63782 | georg.brandl | 2008-05-29 09:45:26 +0200 (Thu, 29 May 2008) | 2 lines #2985: allow i8 in XMLRPC responses. ........ r63787 | georg.brandl | 2008-05-29 16:35:39 +0200 (Thu, 29 May 2008) | 2 lines Revert #2990 patch; it's not necessary as Armin showed. ........ r63805 | raymond.hettinger | 2008-05-30 08:37:27 +0200 (Fri, 30 May 2008) | 1 line Issue 2784: fix leaks in exception exit. ........ r63806 | raymond.hettinger | 2008-05-30 08:49:47 +0200 (Fri, 30 May 2008) | 1 line Issue 2855: Fix obscure crasher by slowing down the entire module. Mimics what was done to dictionaries in r59223. ........ r63807 | raymond.hettinger | 2008-05-30 09:16:53 +0200 (Fri, 30 May 2008) | 1 line Issue 2903: Add __name__ in globals for namedtuple namespace. ........ r63808 | georg.brandl | 2008-05-30 09:54:16 +0200 (Fri, 30 May 2008) | 2 lines #2999: fix name of third parameter in unicode.replace()'s docstring. ........ r63818 | georg.brandl | 2008-05-30 21:12:13 +0200 (Fri, 30 May 2008) | 2 lines getloadavg() is not available on Windows. ........ r63819 | georg.brandl | 2008-05-30 21:17:29 +0200 (Fri, 30 May 2008) | 2 lines Better quote with single quotes. ........ r63823 | benjamin.peterson | 2008-05-30 22:44:39 +0200 (Fri, 30 May 2008) | 2 lines fix grammar ........ r63824 | marc-andre.lemburg | 2008-05-30 22:52:18 +0200 (Fri, 30 May 2008) | 5 lines Update the locale module alias table. Closes #3011. ........
18 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
36 years ago
36 years ago
Merged revisions 59921-59932 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r59923 | raymond.hettinger | 2008-01-11 19:04:55 +0100 (Fri, 11 Jan 2008) | 1 line Speed-up and simplify code urlparse's result objects. ........ r59924 | andrew.kuchling | 2008-01-11 20:33:24 +0100 (Fri, 11 Jan 2008) | 1 line Bug #1790: update link; remove outdated paragraph ........ r59925 | thomas.heller | 2008-01-11 20:34:06 +0100 (Fri, 11 Jan 2008) | 5 lines Raise an error instead of crashing with a segfault when a NULL function pointer is called. Will backport to release25-maint. ........ r59927 | thomas.heller | 2008-01-11 21:29:19 +0100 (Fri, 11 Jan 2008) | 4 lines Fix a potential 'SystemError: NULL result without error'. NULL may be a valid return value from PyLong_AsVoidPtr. Will backport to release25-maint. ........ r59928 | raymond.hettinger | 2008-01-12 00:25:18 +0100 (Sat, 12 Jan 2008) | 1 line Update the opcode docs for STORE_MAP and BUILD_MAP ........ r59929 | mark.dickinson | 2008-01-12 02:56:00 +0100 (Sat, 12 Jan 2008) | 4 lines Issue 1780: Allow leading and trailing whitespace in Decimal constructor, when constructing from a string. Disallow trailing newlines in Context.create_decimal. ........ r59930 | georg.brandl | 2008-01-12 11:53:29 +0100 (Sat, 12 Jan 2008) | 3 lines Move OSError docs to exceptions doc, remove obsolete descriptions from os docs, rework posix docs. ........ r59931 | georg.brandl | 2008-01-12 14:47:57 +0100 (Sat, 12 Jan 2008) | 3 lines Patch #1700288: Method cache optimization, by Armin Rigo, ported to 2.6 by Kevin Jacobs. ........ r59932 | georg.brandl | 2008-01-12 17:11:09 +0100 (Sat, 12 Jan 2008) | 2 lines Fix editing glitch. ........
18 years ago
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r61098 | jeffrey.yasskin | 2008-02-28 05:45:36 +0100 (Thu, 28 Feb 2008) | 7 lines Move abc._Abstract into object by adding a new flag Py_TPFLAGS_IS_ABSTRACT, which forbids constructing types that have it set. The effect is to speed ./python.exe -m timeit -s 'import abc' -s 'class Foo(object): __metaclass__ = abc.ABCMeta' 'Foo()' up from 2.5us to 0.201us. This fixes issue 1762. ........ r61099 | jeffrey.yasskin | 2008-02-28 06:53:18 +0100 (Thu, 28 Feb 2008) | 3 lines Speed test_socketserver up from 28.739s to 0.226s, simplify the logic, and make sure all tests run even if some fail. ........ r61100 | jeffrey.yasskin | 2008-02-28 07:09:19 +0100 (Thu, 28 Feb 2008) | 21 lines Thread.start() used sleep(0.000001) to make sure it didn't return before the new thread had started. At least on my MacBook Pro, that wound up sleeping for a full 10ms (probably 1 jiffy). By using an Event instead, we can be absolutely certain that the thread has started, and return more quickly (217us). Before: $ ./python.exe -m timeit -s 'from threading import Thread' 't = Thread(); t.start(); t.join()' 100 loops, best of 3: 10.3 msec per loop $ ./python.exe -m timeit -s 'from threading import Thread; t = Thread()' 't.isAlive()' 1000000 loops, best of 3: 0.47 usec per loop After: $ ./python.exe -m timeit -s 'from threading import Thread' 't = Thread(); t.start(); t.join()' 1000 loops, best of 3: 217 usec per loop $ ./python.exe -m timeit -s 'from threading import Thread; t = Thread()' 't.isAlive()' 1000000 loops, best of 3: 0.86 usec per loop To be fair, the 10ms isn't CPU time, and other threads including the spawned one get to run during it. There are also some slightly more complicated ways to get back the .4us in isAlive() if we want. ........ r61101 | raymond.hettinger | 2008-02-28 10:23:48 +0100 (Thu, 28 Feb 2008) | 1 line Add repeat keyword argument to itertools.product(). ........ r61102 | christian.heimes | 2008-02-28 12:18:49 +0100 (Thu, 28 Feb 2008) | 1 line The empty tuple is usually a singleton with a much higher refcnt than 1 ........
18 years ago
Merged revisions 53875-53911 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r53899 | neal.norwitz | 2007-02-25 16:52:27 +0100 (Sun, 25 Feb 2007) | 1 line Add more details when releasing interned strings ........ r53900 | neal.norwitz | 2007-02-25 16:53:36 +0100 (Sun, 25 Feb 2007) | 1 line Whitespace only changes ........ r53901 | jeremy.hylton | 2007-02-25 16:57:45 +0100 (Sun, 25 Feb 2007) | 8 lines Fix crash in exec when unicode filename can't be decoded. I can't think of an easy way to test this behavior. It only occurs when the file system default encoding and the interpreter default encoding are different, such that you can open the file but not decode its name. ........ r53902 | jeremy.hylton | 2007-02-25 17:01:58 +0100 (Sun, 25 Feb 2007) | 2 lines Put declarations before code. ........ r53910 | fred.drake | 2007-02-25 18:56:27 +0100 (Sun, 25 Feb 2007) | 3 lines - SF patch #1657613: add documentation for the Element interface - clean up bogus use of the {datadescni} environment everywhere ........ r53911 | neal.norwitz | 2007-02-25 20:44:48 +0100 (Sun, 25 Feb 2007) | 17 lines Variation of patch # 1624059 to speed up checking if an object is a subclass of some of the common builtin types. Use a bit in tp_flags for each common builtin type. Check the bit to determine if any instance is a subclass of these common types. The check avoids a function call and O(n) search of the base classes. The check is done in the various Py*_Check macros rather than calling PyType_IsSubtype(). All the bits are set in tp_flags when the type is declared in the Objects/*object.c files because PyType_Ready() is not called for all the types. Should PyType_Ready() be called for all types? If so and the change is made, the changes to the Objects/*object.c files can be reverted (remove setting the tp_flags). Objects/typeobject.c would also have to be modified to add conditions for Py*_CheckExact() in addition to each the PyType_IsSubtype check. ........
19 years ago
Merged revisions 53875-53911 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r53899 | neal.norwitz | 2007-02-25 16:52:27 +0100 (Sun, 25 Feb 2007) | 1 line Add more details when releasing interned strings ........ r53900 | neal.norwitz | 2007-02-25 16:53:36 +0100 (Sun, 25 Feb 2007) | 1 line Whitespace only changes ........ r53901 | jeremy.hylton | 2007-02-25 16:57:45 +0100 (Sun, 25 Feb 2007) | 8 lines Fix crash in exec when unicode filename can't be decoded. I can't think of an easy way to test this behavior. It only occurs when the file system default encoding and the interpreter default encoding are different, such that you can open the file but not decode its name. ........ r53902 | jeremy.hylton | 2007-02-25 17:01:58 +0100 (Sun, 25 Feb 2007) | 2 lines Put declarations before code. ........ r53910 | fred.drake | 2007-02-25 18:56:27 +0100 (Sun, 25 Feb 2007) | 3 lines - SF patch #1657613: add documentation for the Element interface - clean up bogus use of the {datadescni} environment everywhere ........ r53911 | neal.norwitz | 2007-02-25 20:44:48 +0100 (Sun, 25 Feb 2007) | 17 lines Variation of patch # 1624059 to speed up checking if an object is a subclass of some of the common builtin types. Use a bit in tp_flags for each common builtin type. Check the bit to determine if any instance is a subclass of these common types. The check avoids a function call and O(n) search of the base classes. The check is done in the various Py*_Check macros rather than calling PyType_IsSubtype(). All the bits are set in tp_flags when the type is declared in the Objects/*object.c files because PyType_Ready() is not called for all the types. Should PyType_Ready() be called for all types? If so and the change is made, the changes to the Objects/*object.c files can be reverted (remove setting the tp_flags). Objects/typeobject.c would also have to be modified to add conditions for Py*_CheckExact() in addition to each the PyType_IsSubtype check. ........
19 years ago
Merged revisions 53875-53911 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r53899 | neal.norwitz | 2007-02-25 16:52:27 +0100 (Sun, 25 Feb 2007) | 1 line Add more details when releasing interned strings ........ r53900 | neal.norwitz | 2007-02-25 16:53:36 +0100 (Sun, 25 Feb 2007) | 1 line Whitespace only changes ........ r53901 | jeremy.hylton | 2007-02-25 16:57:45 +0100 (Sun, 25 Feb 2007) | 8 lines Fix crash in exec when unicode filename can't be decoded. I can't think of an easy way to test this behavior. It only occurs when the file system default encoding and the interpreter default encoding are different, such that you can open the file but not decode its name. ........ r53902 | jeremy.hylton | 2007-02-25 17:01:58 +0100 (Sun, 25 Feb 2007) | 2 lines Put declarations before code. ........ r53910 | fred.drake | 2007-02-25 18:56:27 +0100 (Sun, 25 Feb 2007) | 3 lines - SF patch #1657613: add documentation for the Element interface - clean up bogus use of the {datadescni} environment everywhere ........ r53911 | neal.norwitz | 2007-02-25 20:44:48 +0100 (Sun, 25 Feb 2007) | 17 lines Variation of patch # 1624059 to speed up checking if an object is a subclass of some of the common builtin types. Use a bit in tp_flags for each common builtin type. Check the bit to determine if any instance is a subclass of these common types. The check avoids a function call and O(n) search of the base classes. The check is done in the various Py*_Check macros rather than calling PyType_IsSubtype(). All the bits are set in tp_flags when the type is declared in the Objects/*object.c files because PyType_Ready() is not called for all the types. Should PyType_Ready() be called for all types? If so and the change is made, the changes to the Objects/*object.c files can be reverted (remove setting the tp_flags). Objects/typeobject.c would also have to be modified to add conditions for Py*_CheckExact() in addition to each the PyType_IsSubtype check. ........
19 years ago
36 years ago
36 years ago
Merged revisions 62021,62029,62035-62038,62043-62044,62052-62053 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62021 | benjamin.peterson | 2008-03-28 18:11:01 -0500 (Fri, 28 Mar 2008) | 2 lines NIL => NULL ........ r62029 | amaury.forgeotdarc | 2008-03-28 20:42:31 -0500 (Fri, 28 Mar 2008) | 3 lines Correctly call the base class tearDown(); otherwise running test_logging twice produce the errors we see on all buildbots ........ r62035 | raymond.hettinger | 2008-03-29 05:42:07 -0500 (Sat, 29 Mar 2008) | 1 line Be explicit about what efficient means. ........ r62036 | georg.brandl | 2008-03-29 06:46:18 -0500 (Sat, 29 Mar 2008) | 2 lines Fix capitalization. ........ r62037 | amaury.forgeotdarc | 2008-03-29 07:42:54 -0500 (Sat, 29 Mar 2008) | 5 lines lib2to3 should install a logging handler only when run as a main program, not when used as a library. This may please the buildbots, which fail when test_lib2to3 is run before test_logging. ........ r62043 | benjamin.peterson | 2008-03-29 10:24:25 -0500 (Sat, 29 Mar 2008) | 3 lines #2503 make singletons compared with "is" not == or != Thanks to Wummel for the patch ........ r62044 | gerhard.haering | 2008-03-29 14:11:52 -0500 (Sat, 29 Mar 2008) | 2 lines Documented the lastrowid attribute. ........ r62052 | benjamin.peterson | 2008-03-30 14:35:10 -0500 (Sun, 30 Mar 2008) | 2 lines Updated README regarding doc formats ........ r62053 | georg.brandl | 2008-03-30 14:41:39 -0500 (Sun, 30 Mar 2008) | 2 lines The other download formats will be available for 2.6 too. ........
18 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
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
36 years ago
36 years ago
  1. #ifndef Py_OBJECT_H
  2. #define Py_OBJECT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /* Object and type object interface */
  7. /*
  8. Objects are structures allocated on the heap. Special rules apply to
  9. the use of objects to ensure they are properly garbage-collected.
  10. Objects are never allocated statically or on the stack; they must be
  11. accessed through special macros and functions only. (Type objects are
  12. exceptions to the first rule; the standard types are represented by
  13. statically initialized type objects, although work on type/class unification
  14. for Python 2.2 made it possible to have heap-allocated type objects too).
  15. An object has a 'reference count' that is increased or decreased when a
  16. pointer to the object is copied or deleted; when the reference count
  17. reaches zero there are no references to the object left and it can be
  18. removed from the heap.
  19. An object has a 'type' that determines what it represents and what kind
  20. of data it contains. An object's type is fixed when it is created.
  21. Types themselves are represented as objects; an object contains a
  22. pointer to the corresponding type object. The type itself has a type
  23. pointer pointing to the object representing the type 'type', which
  24. contains a pointer to itself!).
  25. Objects do not float around in memory; once allocated an object keeps
  26. the same size and address. Objects that must hold variable-size data
  27. can contain pointers to variable-size parts of the object. Not all
  28. objects of the same type have the same size; but the size cannot change
  29. after allocation. (These restrictions are made so a reference to an
  30. object can be simply a pointer -- moving an object would require
  31. updating all the pointers, and changing an object's size would require
  32. moving it if there was another object right next to it.)
  33. Objects are always accessed through pointers of the type 'PyObject *'.
  34. The type 'PyObject' is a structure that only contains the reference count
  35. and the type pointer. The actual memory allocated for an object
  36. contains other data that can only be accessed after casting the pointer
  37. to a pointer to a longer structure type. This longer type must start
  38. with the reference count and type fields; the macro PyObject_HEAD should be
  39. used for this (to accommodate for future changes). The implementation
  40. of a particular object type can cast the object pointer to the proper
  41. type and back.
  42. A standard interface exists for objects that contain an array of items
  43. whose size is determined when the object is allocated.
  44. */
  45. /* Py_DEBUG implies Py_TRACE_REFS. */
  46. #if defined(Py_DEBUG) && !defined(Py_TRACE_REFS)
  47. #define Py_TRACE_REFS
  48. #endif
  49. /* Py_TRACE_REFS implies Py_REF_DEBUG. */
  50. #if defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG)
  51. #define Py_REF_DEBUG
  52. #endif
  53. #if defined(Py_LIMITED_API) && defined(Py_REF_DEBUG)
  54. #error Py_LIMITED_API is incompatible with Py_DEBUG, Py_TRACE_REFS, and Py_REF_DEBUG
  55. #endif
  56. #ifdef Py_TRACE_REFS
  57. /* Define pointers to support a doubly-linked list of all live heap objects. */
  58. #define _PyObject_HEAD_EXTRA \
  59. struct _object *_ob_next; \
  60. struct _object *_ob_prev;
  61. #define _PyObject_EXTRA_INIT 0, 0,
  62. #else
  63. #define _PyObject_HEAD_EXTRA
  64. #define _PyObject_EXTRA_INIT
  65. #endif
  66. /* PyObject_HEAD defines the initial segment of every PyObject. */
  67. #define PyObject_HEAD PyObject ob_base;
  68. #define PyObject_HEAD_INIT(type) \
  69. { _PyObject_EXTRA_INIT \
  70. 1, type },
  71. #define PyVarObject_HEAD_INIT(type, size) \
  72. { PyObject_HEAD_INIT(type) size },
  73. /* PyObject_VAR_HEAD defines the initial segment of all variable-size
  74. * container objects. These end with a declaration of an array with 1
  75. * element, but enough space is malloc'ed so that the array actually
  76. * has room for ob_size elements. Note that ob_size is an element count,
  77. * not necessarily a byte count.
  78. */
  79. #define PyObject_VAR_HEAD PyVarObject ob_base;
  80. #define Py_INVALID_SIZE (Py_ssize_t)-1
  81. /* Nothing is actually declared to be a PyObject, but every pointer to
  82. * a Python object can be cast to a PyObject*. This is inheritance built
  83. * by hand. Similarly every pointer to a variable-size Python object can,
  84. * in addition, be cast to PyVarObject*.
  85. */
  86. typedef struct _object {
  87. _PyObject_HEAD_EXTRA
  88. Py_ssize_t ob_refcnt;
  89. struct _typeobject *ob_type;
  90. } PyObject;
  91. typedef struct {
  92. PyObject ob_base;
  93. Py_ssize_t ob_size; /* Number of items in variable part */
  94. } PyVarObject;
  95. #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  96. #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
  97. #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
  98. /********************* String Literals ****************************************/
  99. /* This structure helps managing static strings. The basic usage goes like this:
  100. Instead of doing
  101. r = PyObject_CallMethod(o, "foo", "args", ...);
  102. do
  103. _Py_IDENTIFIER(foo);
  104. ...
  105. r = _PyObject_CallMethodId(o, &PyId_foo, "args", ...);
  106. PyId_foo is a static variable, either on block level or file level. On first
  107. usage, the string "foo" is interned, and the structures are linked. On interpreter
  108. shutdown, all strings are released (through _PyUnicode_ClearStaticStrings).
  109. Alternatively, _Py_static_string allows to choose the variable name.
  110. _PyUnicode_FromId returns a borrowed reference to the interned string.
  111. _PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*.
  112. */
  113. typedef struct _Py_Identifier {
  114. struct _Py_Identifier *next;
  115. const char* string;
  116. PyObject *object;
  117. } _Py_Identifier;
  118. #define _Py_static_string(varname, value) static _Py_Identifier varname = { 0, value, 0 }
  119. #define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)
  120. /*
  121. Type objects contain a string containing the type name (to help somewhat
  122. in debugging), the allocation parameters (see PyObject_New() and
  123. PyObject_NewVar()),
  124. and methods for accessing objects of the type. Methods are optional, a
  125. nil pointer meaning that particular kind of access is not available for
  126. this type. The Py_DECREF() macro uses the tp_dealloc method without
  127. checking for a nil pointer; it should always be implemented except if
  128. the implementation can guarantee that the reference count will never
  129. reach zero (e.g., for statically allocated type objects).
  130. NB: the methods for certain type groups are now contained in separate
  131. method blocks.
  132. */
  133. typedef PyObject * (*unaryfunc)(PyObject *);
  134. typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
  135. typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
  136. typedef int (*inquiry)(PyObject *);
  137. typedef Py_ssize_t (*lenfunc)(PyObject *);
  138. typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
  139. typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
  140. typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
  141. typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
  142. typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
  143. #ifndef Py_LIMITED_API
  144. /* buffer interface */
  145. typedef struct bufferinfo {
  146. void *buf;
  147. PyObject *obj; /* owned reference */
  148. Py_ssize_t len;
  149. Py_ssize_t itemsize; /* This is Py_ssize_t so it can be
  150. pointed to by strides in simple case.*/
  151. int readonly;
  152. int ndim;
  153. char *format;
  154. Py_ssize_t *shape;
  155. Py_ssize_t *strides;
  156. Py_ssize_t *suboffsets;
  157. void *internal;
  158. } Py_buffer;
  159. typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
  160. typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
  161. /* Maximum number of dimensions */
  162. #define PyBUF_MAX_NDIM 64
  163. /* Flags for getting buffers */
  164. #define PyBUF_SIMPLE 0
  165. #define PyBUF_WRITABLE 0x0001
  166. /* we used to include an E, backwards compatible alias */
  167. #define PyBUF_WRITEABLE PyBUF_WRITABLE
  168. #define PyBUF_FORMAT 0x0004
  169. #define PyBUF_ND 0x0008
  170. #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  171. #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  172. #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  173. #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  174. #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
  175. #define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)
  176. #define PyBUF_CONTIG_RO (PyBUF_ND)
  177. #define PyBUF_STRIDED (PyBUF_STRIDES | PyBUF_WRITABLE)
  178. #define PyBUF_STRIDED_RO (PyBUF_STRIDES)
  179. #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT)
  180. #define PyBUF_RECORDS_RO (PyBUF_STRIDES | PyBUF_FORMAT)
  181. #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT)
  182. #define PyBUF_FULL_RO (PyBUF_INDIRECT | PyBUF_FORMAT)
  183. #define PyBUF_READ 0x100
  184. #define PyBUF_WRITE 0x200
  185. /* End buffer interface */
  186. #endif /* Py_LIMITED_API */
  187. typedef int (*objobjproc)(PyObject *, PyObject *);
  188. typedef int (*visitproc)(PyObject *, void *);
  189. typedef int (*traverseproc)(PyObject *, visitproc, void *);
  190. #ifndef Py_LIMITED_API
  191. typedef struct {
  192. /* Number implementations must check *both*
  193. arguments for proper type and implement the necessary conversions
  194. in the slot functions themselves. */
  195. binaryfunc nb_add;
  196. binaryfunc nb_subtract;
  197. binaryfunc nb_multiply;
  198. binaryfunc nb_remainder;
  199. binaryfunc nb_divmod;
  200. ternaryfunc nb_power;
  201. unaryfunc nb_negative;
  202. unaryfunc nb_positive;
  203. unaryfunc nb_absolute;
  204. inquiry nb_bool;
  205. unaryfunc nb_invert;
  206. binaryfunc nb_lshift;
  207. binaryfunc nb_rshift;
  208. binaryfunc nb_and;
  209. binaryfunc nb_xor;
  210. binaryfunc nb_or;
  211. unaryfunc nb_int;
  212. void *nb_reserved; /* the slot formerly known as nb_long */
  213. unaryfunc nb_float;
  214. binaryfunc nb_inplace_add;
  215. binaryfunc nb_inplace_subtract;
  216. binaryfunc nb_inplace_multiply;
  217. binaryfunc nb_inplace_remainder;
  218. ternaryfunc nb_inplace_power;
  219. binaryfunc nb_inplace_lshift;
  220. binaryfunc nb_inplace_rshift;
  221. binaryfunc nb_inplace_and;
  222. binaryfunc nb_inplace_xor;
  223. binaryfunc nb_inplace_or;
  224. binaryfunc nb_floor_divide;
  225. binaryfunc nb_true_divide;
  226. binaryfunc nb_inplace_floor_divide;
  227. binaryfunc nb_inplace_true_divide;
  228. unaryfunc nb_index;
  229. } PyNumberMethods;
  230. typedef struct {
  231. lenfunc sq_length;
  232. binaryfunc sq_concat;
  233. ssizeargfunc sq_repeat;
  234. ssizeargfunc sq_item;
  235. void *was_sq_slice;
  236. ssizeobjargproc sq_ass_item;
  237. void *was_sq_ass_slice;
  238. objobjproc sq_contains;
  239. binaryfunc sq_inplace_concat;
  240. ssizeargfunc sq_inplace_repeat;
  241. } PySequenceMethods;
  242. typedef struct {
  243. lenfunc mp_length;
  244. binaryfunc mp_subscript;
  245. objobjargproc mp_ass_subscript;
  246. } PyMappingMethods;
  247. typedef struct {
  248. getbufferproc bf_getbuffer;
  249. releasebufferproc bf_releasebuffer;
  250. } PyBufferProcs;
  251. #endif /* Py_LIMITED_API */
  252. typedef void (*freefunc)(void *);
  253. typedef void (*destructor)(PyObject *);
  254. #ifndef Py_LIMITED_API
  255. /* We can't provide a full compile-time check that limited-API
  256. users won't implement tp_print. However, not defining printfunc
  257. and making tp_print of a different function pointer type
  258. should at least cause a warning in most cases. */
  259. typedef int (*printfunc)(PyObject *, FILE *, int);
  260. #endif
  261. typedef PyObject *(*getattrfunc)(PyObject *, char *);
  262. typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
  263. typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
  264. typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
  265. typedef PyObject *(*reprfunc)(PyObject *);
  266. typedef Py_hash_t (*hashfunc)(PyObject *);
  267. typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
  268. typedef PyObject *(*getiterfunc) (PyObject *);
  269. typedef PyObject *(*iternextfunc) (PyObject *);
  270. typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *);
  271. typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *);
  272. typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
  273. typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
  274. typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);
  275. #ifdef Py_LIMITED_API
  276. typedef struct _typeobject PyTypeObject; /* opaque */
  277. #else
  278. typedef struct _typeobject {
  279. PyObject_VAR_HEAD
  280. const char *tp_name; /* For printing, in format "<module>.<name>" */
  281. Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
  282. /* Methods to implement standard operations */
  283. destructor tp_dealloc;
  284. printfunc tp_print;
  285. getattrfunc tp_getattr;
  286. setattrfunc tp_setattr;
  287. void *tp_reserved; /* formerly known as tp_compare */
  288. reprfunc tp_repr;
  289. /* Method suites for standard classes */
  290. PyNumberMethods *tp_as_number;
  291. PySequenceMethods *tp_as_sequence;
  292. PyMappingMethods *tp_as_mapping;
  293. /* More standard operations (here for binary compatibility) */
  294. hashfunc tp_hash;
  295. ternaryfunc tp_call;
  296. reprfunc tp_str;
  297. getattrofunc tp_getattro;
  298. setattrofunc tp_setattro;
  299. /* Functions to access object as input/output buffer */
  300. PyBufferProcs *tp_as_buffer;
  301. /* Flags to define presence of optional/expanded features */
  302. long tp_flags;
  303. const char *tp_doc; /* Documentation string */
  304. /* Assigned meaning in release 2.0 */
  305. /* call function for all accessible objects */
  306. traverseproc tp_traverse;
  307. /* delete references to contained objects */
  308. inquiry tp_clear;
  309. /* Assigned meaning in release 2.1 */
  310. /* rich comparisons */
  311. richcmpfunc tp_richcompare;
  312. /* weak reference enabler */
  313. Py_ssize_t tp_weaklistoffset;
  314. /* Iterators */
  315. getiterfunc tp_iter;
  316. iternextfunc tp_iternext;
  317. /* Attribute descriptor and subclassing stuff */
  318. struct PyMethodDef *tp_methods;
  319. struct PyMemberDef *tp_members;
  320. struct PyGetSetDef *tp_getset;
  321. struct _typeobject *tp_base;
  322. PyObject *tp_dict;
  323. descrgetfunc tp_descr_get;
  324. descrsetfunc tp_descr_set;
  325. Py_ssize_t tp_dictoffset;
  326. initproc tp_init;
  327. allocfunc tp_alloc;
  328. newfunc tp_new;
  329. freefunc tp_free; /* Low-level free-memory routine */
  330. inquiry tp_is_gc; /* For PyObject_IS_GC */
  331. PyObject *tp_bases;
  332. PyObject *tp_mro; /* method resolution order */
  333. PyObject *tp_cache;
  334. PyObject *tp_subclasses;
  335. PyObject *tp_weaklist;
  336. destructor tp_del;
  337. /* Type attribute cache version tag. Added in version 2.6 */
  338. unsigned int tp_version_tag;
  339. #ifdef COUNT_ALLOCS
  340. /* these must be last and never explicitly initialized */
  341. Py_ssize_t tp_allocs;
  342. Py_ssize_t tp_frees;
  343. Py_ssize_t tp_maxalloc;
  344. struct _typeobject *tp_prev;
  345. struct _typeobject *tp_next;
  346. #endif
  347. } PyTypeObject;
  348. #endif
  349. typedef struct{
  350. int slot; /* slot id, see below */
  351. void *pfunc; /* function pointer */
  352. } PyType_Slot;
  353. typedef struct{
  354. const char* name;
  355. int basicsize;
  356. int itemsize;
  357. int flags;
  358. PyType_Slot *slots; /* terminated by slot==0. */
  359. } PyType_Spec;
  360. PyAPI_FUNC(PyObject*) PyType_FromSpec(PyType_Spec*);
  361. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
  362. PyAPI_FUNC(PyObject*) PyType_FromSpecWithBases(PyType_Spec*, PyObject*);
  363. #endif
  364. #ifndef Py_LIMITED_API
  365. /* The *real* layout of a type object when allocated on the heap */
  366. typedef struct _heaptypeobject {
  367. /* Note: there's a dependency on the order of these members
  368. in slotptr() in typeobject.c . */
  369. PyTypeObject ht_type;
  370. PyNumberMethods as_number;
  371. PyMappingMethods as_mapping;
  372. PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
  373. so that the mapping wins when both
  374. the mapping and the sequence define
  375. a given operator (e.g. __getitem__).
  376. see add_operators() in typeobject.c . */
  377. PyBufferProcs as_buffer;
  378. PyObject *ht_name, *ht_slots, *ht_qualname;
  379. struct _dictkeysobject *ht_cached_keys;
  380. /* here are optional user slots, followed by the members. */
  381. } PyHeapTypeObject;
  382. /* access macro to the members which are floating "behind" the object */
  383. #define PyHeapType_GET_MEMBERS(etype) \
  384. ((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))
  385. #endif
  386. /* Generic type check */
  387. PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
  388. #define PyObject_TypeCheck(ob, tp) \
  389. (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
  390. PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
  391. PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
  392. PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
  393. PyAPI_FUNC(long) PyType_GetFlags(PyTypeObject*);
  394. #define PyType_Check(op) \
  395. PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
  396. #define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type)
  397. PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
  398. PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
  399. PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
  400. PyObject *, PyObject *);
  401. #ifndef Py_LIMITED_API
  402. PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
  403. PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, _Py_Identifier *);
  404. PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
  405. #endif
  406. PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
  407. PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
  408. /* Generic operations on objects */
  409. struct _Py_Identifier;
  410. #ifndef Py_LIMITED_API
  411. PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
  412. PyAPI_FUNC(void) _Py_BreakPoint(void);
  413. PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
  414. #endif
  415. PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *);
  416. PyAPI_FUNC(PyObject *) PyObject_Str(PyObject *);
  417. PyAPI_FUNC(PyObject *) PyObject_ASCII(PyObject *);
  418. PyAPI_FUNC(PyObject *) PyObject_Bytes(PyObject *);
  419. PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
  420. PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
  421. PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *);
  422. PyAPI_FUNC(int) PyObject_SetAttrString(PyObject *, const char *, PyObject *);
  423. PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *);
  424. PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
  425. PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
  426. PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
  427. PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *);
  428. PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *);
  429. PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *);
  430. PyAPI_FUNC(int) _PyObject_HasAttrId(PyObject *, struct _Py_Identifier *);
  431. #ifndef Py_LIMITED_API
  432. PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
  433. #endif
  434. PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
  435. #ifndef Py_LIMITED_API
  436. PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *);
  437. #endif
  438. PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
  439. PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *,
  440. PyObject *, PyObject *);
  441. PyAPI_FUNC(int) PyObject_GenericSetDict(PyObject *, PyObject *, void *);
  442. PyAPI_FUNC(Py_hash_t) PyObject_Hash(PyObject *);
  443. PyAPI_FUNC(Py_hash_t) PyObject_HashNotImplemented(PyObject *);
  444. PyAPI_FUNC(int) PyObject_IsTrue(PyObject *);
  445. PyAPI_FUNC(int) PyObject_Not(PyObject *);
  446. PyAPI_FUNC(int) PyCallable_Check(PyObject *);
  447. PyAPI_FUNC(void) PyObject_ClearWeakRefs(PyObject *);
  448. /* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes
  449. dict as the last parameter. */
  450. PyAPI_FUNC(PyObject *)
  451. _PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *);
  452. PyAPI_FUNC(int)
  453. _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
  454. PyObject *, PyObject *);
  455. /* Helper to look up a builtin object */
  456. #ifndef Py_LIMITED_API
  457. PyAPI_FUNC(PyObject *)
  458. _PyObject_GetBuiltin(const char *name);
  459. #endif
  460. /* PyObject_Dir(obj) acts like Python builtins.dir(obj), returning a
  461. list of strings. PyObject_Dir(NULL) is like builtins.dir(),
  462. returning the names of the current locals. In this case, if there are
  463. no current locals, NULL is returned, and PyErr_Occurred() is false.
  464. */
  465. PyAPI_FUNC(PyObject *) PyObject_Dir(PyObject *);
  466. /* Helpers for printing recursive container types */
  467. PyAPI_FUNC(int) Py_ReprEnter(PyObject *);
  468. PyAPI_FUNC(void) Py_ReprLeave(PyObject *);
  469. /* Helpers for hash functions */
  470. #ifndef Py_LIMITED_API
  471. PyAPI_FUNC(Py_hash_t) _Py_HashDouble(double);
  472. PyAPI_FUNC(Py_hash_t) _Py_HashPointer(void*);
  473. PyAPI_FUNC(Py_hash_t) _Py_HashBytes(unsigned char*, Py_ssize_t);
  474. #endif
  475. typedef struct {
  476. Py_hash_t prefix;
  477. Py_hash_t suffix;
  478. } _Py_HashSecret_t;
  479. PyAPI_DATA(_Py_HashSecret_t) _Py_HashSecret;
  480. #ifdef Py_DEBUG
  481. PyAPI_DATA(int) _Py_HashSecret_Initialized;
  482. #endif
  483. /* Helper for passing objects to printf and the like */
  484. #define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj))
  485. /* Flag bits for printing: */
  486. #define Py_PRINT_RAW 1 /* No string quotes etc. */
  487. /*
  488. `Type flags (tp_flags)
  489. These flags are used to extend the type structure in a backwards-compatible
  490. fashion. Extensions can use the flags to indicate (and test) when a given
  491. type structure contains a new feature. The Python core will use these when
  492. introducing new functionality between major revisions (to avoid mid-version
  493. changes in the PYTHON_API_VERSION).
  494. Arbitration of the flag bit positions will need to be coordinated among
  495. all extension writers who publically release their extensions (this will
  496. be fewer than you might expect!)..
  497. Most flags were removed as of Python 3.0 to make room for new flags. (Some
  498. flags are not for backwards compatibility but to indicate the presence of an
  499. optional feature; these flags remain of course.)
  500. Type definitions should use Py_TPFLAGS_DEFAULT for their tp_flags value.
  501. Code can use PyType_HasFeature(type_ob, flag_value) to test whether the
  502. given type object has a specified feature.
  503. */
  504. /* Set if the type object is dynamically allocated */
  505. #define Py_TPFLAGS_HEAPTYPE (1L<<9)
  506. /* Set if the type allows subclassing */
  507. #define Py_TPFLAGS_BASETYPE (1L<<10)
  508. /* Set if the type is 'ready' -- fully initialized */
  509. #define Py_TPFLAGS_READY (1L<<12)
  510. /* Set while the type is being 'readied', to prevent recursive ready calls */
  511. #define Py_TPFLAGS_READYING (1L<<13)
  512. /* Objects support garbage collection (see objimp.h) */
  513. #define Py_TPFLAGS_HAVE_GC (1L<<14)
  514. /* These two bits are preserved for Stackless Python, next after this is 17 */
  515. #ifdef STACKLESS
  516. #define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION (3L<<15)
  517. #else
  518. #define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
  519. #endif
  520. /* Objects support type attribute cache */
  521. #define Py_TPFLAGS_HAVE_VERSION_TAG (1L<<18)
  522. #define Py_TPFLAGS_VALID_VERSION_TAG (1L<<19)
  523. /* Type is abstract and cannot be instantiated */
  524. #define Py_TPFLAGS_IS_ABSTRACT (1L<<20)
  525. /* These flags are used to determine if a type is a subclass. */
  526. #define Py_TPFLAGS_INT_SUBCLASS (1L<<23)
  527. #define Py_TPFLAGS_LONG_SUBCLASS (1L<<24)
  528. #define Py_TPFLAGS_LIST_SUBCLASS (1L<<25)
  529. #define Py_TPFLAGS_TUPLE_SUBCLASS (1L<<26)
  530. #define Py_TPFLAGS_BYTES_SUBCLASS (1L<<27)
  531. #define Py_TPFLAGS_UNICODE_SUBCLASS (1L<<28)
  532. #define Py_TPFLAGS_DICT_SUBCLASS (1L<<29)
  533. #define Py_TPFLAGS_BASE_EXC_SUBCLASS (1L<<30)
  534. #define Py_TPFLAGS_TYPE_SUBCLASS (1L<<31)
  535. #define Py_TPFLAGS_DEFAULT ( \
  536. Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
  537. Py_TPFLAGS_HAVE_VERSION_TAG | \
  538. 0)
  539. #ifdef Py_LIMITED_API
  540. #define PyType_HasFeature(t,f) ((PyType_GetFlags(t) & (f)) != 0)
  541. #else
  542. #define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
  543. #endif
  544. #define PyType_FastSubclass(t,f) PyType_HasFeature(t,f)
  545. /*
  546. The macros Py_INCREF(op) and Py_DECREF(op) are used to increment or decrement
  547. reference counts. Py_DECREF calls the object's deallocator function when
  548. the refcount falls to 0; for
  549. objects that don't contain references to other objects or heap memory
  550. this can be the standard function free(). Both macros can be used
  551. wherever a void expression is allowed. The argument must not be a
  552. NULL pointer. If it may be NULL, use Py_XINCREF/Py_XDECREF instead.
  553. The macro _Py_NewReference(op) initialize reference counts to 1, and
  554. in special builds (Py_REF_DEBUG, Py_TRACE_REFS) performs additional
  555. bookkeeping appropriate to the special build.
  556. We assume that the reference count field can never overflow; this can
  557. be proven when the size of the field is the same as the pointer size, so
  558. we ignore the possibility. Provided a C int is at least 32 bits (which
  559. is implicitly assumed in many parts of this code), that's enough for
  560. about 2**31 references to an object.
  561. XXX The following became out of date in Python 2.2, but I'm not sure
  562. XXX what the full truth is now. Certainly, heap-allocated type objects
  563. XXX can and should be deallocated.
  564. Type objects should never be deallocated; the type pointer in an object
  565. is not considered to be a reference to the type object, to save
  566. complications in the deallocation function. (This is actually a
  567. decision that's up to the implementer of each new type so if you want,
  568. you can count such references to the type object.)
  569. *** WARNING*** The Py_DECREF macro must have a side-effect-free argument
  570. since it may evaluate its argument multiple times. (The alternative
  571. would be to mace it a proper function or assign it to a global temporary
  572. variable first, both of which are slower; and in a multi-threaded
  573. environment the global variable trick is not safe.)
  574. */
  575. /* First define a pile of simple helper macros, one set per special
  576. * build symbol. These either expand to the obvious things, or to
  577. * nothing at all when the special mode isn't in effect. The main
  578. * macros can later be defined just once then, yet expand to different
  579. * things depending on which special build options are and aren't in effect.
  580. * Trust me <wink>: while painful, this is 20x easier to understand than,
  581. * e.g, defining _Py_NewReference five different times in a maze of nested
  582. * #ifdefs (we used to do that -- it was impenetrable).
  583. */
  584. #ifdef Py_REF_DEBUG
  585. PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
  586. PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname,
  587. int lineno, PyObject *op);
  588. PyAPI_FUNC(PyObject *) _PyDict_Dummy(void);
  589. PyAPI_FUNC(PyObject *) _PySet_Dummy(void);
  590. PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
  591. #define _Py_INC_REFTOTAL _Py_RefTotal++
  592. #define _Py_DEC_REFTOTAL _Py_RefTotal--
  593. #define _Py_REF_DEBUG_COMMA ,
  594. #define _Py_CHECK_REFCNT(OP) \
  595. { if (((PyObject*)OP)->ob_refcnt < 0) \
  596. _Py_NegativeRefcount(__FILE__, __LINE__, \
  597. (PyObject *)(OP)); \
  598. }
  599. #else
  600. #define _Py_INC_REFTOTAL
  601. #define _Py_DEC_REFTOTAL
  602. #define _Py_REF_DEBUG_COMMA
  603. #define _Py_CHECK_REFCNT(OP) /* a semicolon */;
  604. #endif /* Py_REF_DEBUG */
  605. #ifdef COUNT_ALLOCS
  606. PyAPI_FUNC(void) inc_count(PyTypeObject *);
  607. PyAPI_FUNC(void) dec_count(PyTypeObject *);
  608. #define _Py_INC_TPALLOCS(OP) inc_count(Py_TYPE(OP))
  609. #define _Py_INC_TPFREES(OP) dec_count(Py_TYPE(OP))
  610. #define _Py_DEC_TPFREES(OP) Py_TYPE(OP)->tp_frees--
  611. #define _Py_COUNT_ALLOCS_COMMA ,
  612. #else
  613. #define _Py_INC_TPALLOCS(OP)
  614. #define _Py_INC_TPFREES(OP)
  615. #define _Py_DEC_TPFREES(OP)
  616. #define _Py_COUNT_ALLOCS_COMMA
  617. #endif /* COUNT_ALLOCS */
  618. #ifdef Py_TRACE_REFS
  619. /* Py_TRACE_REFS is such major surgery that we call external routines. */
  620. PyAPI_FUNC(void) _Py_NewReference(PyObject *);
  621. PyAPI_FUNC(void) _Py_ForgetReference(PyObject *);
  622. PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
  623. PyAPI_FUNC(void) _Py_PrintReferences(FILE *);
  624. PyAPI_FUNC(void) _Py_PrintReferenceAddresses(FILE *);
  625. PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
  626. #else
  627. /* Without Py_TRACE_REFS, there's little enough to do that we expand code
  628. * inline.
  629. */
  630. #define _Py_NewReference(op) ( \
  631. _Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA \
  632. _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
  633. Py_REFCNT(op) = 1)
  634. #define _Py_ForgetReference(op) _Py_INC_TPFREES(op)
  635. #ifdef Py_LIMITED_API
  636. PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
  637. #else
  638. #define _Py_Dealloc(op) ( \
  639. _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \
  640. (*Py_TYPE(op)->tp_dealloc)((PyObject *)(op)))
  641. #endif
  642. #endif /* !Py_TRACE_REFS */
  643. #define Py_INCREF(op) ( \
  644. _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
  645. ((PyObject*)(op))->ob_refcnt++)
  646. #define Py_DECREF(op) \
  647. do { \
  648. if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
  649. --((PyObject*)(op))->ob_refcnt != 0) \
  650. _Py_CHECK_REFCNT(op) \
  651. else \
  652. _Py_Dealloc((PyObject *)(op)); \
  653. } while (0)
  654. /* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
  655. * and tp_dealloc implementatons.
  656. *
  657. * Note that "the obvious" code can be deadly:
  658. *
  659. * Py_XDECREF(op);
  660. * op = NULL;
  661. *
  662. * Typically, `op` is something like self->containee, and `self` is done
  663. * using its `containee` member. In the code sequence above, suppose
  664. * `containee` is non-NULL with a refcount of 1. Its refcount falls to
  665. * 0 on the first line, which can trigger an arbitrary amount of code,
  666. * possibly including finalizers (like __del__ methods or weakref callbacks)
  667. * coded in Python, which in turn can release the GIL and allow other threads
  668. * to run, etc. Such code may even invoke methods of `self` again, or cause
  669. * cyclic gc to trigger, but-- oops! --self->containee still points to the
  670. * object being torn down, and it may be in an insane state while being torn
  671. * down. This has in fact been a rich historic source of miserable (rare &
  672. * hard-to-diagnose) segfaulting (and other) bugs.
  673. *
  674. * The safe way is:
  675. *
  676. * Py_CLEAR(op);
  677. *
  678. * That arranges to set `op` to NULL _before_ decref'ing, so that any code
  679. * triggered as a side-effect of `op` getting torn down no longer believes
  680. * `op` points to a valid object.
  681. *
  682. * There are cases where it's safe to use the naive code, but they're brittle.
  683. * For example, if `op` points to a Python integer, you know that destroying
  684. * one of those can't cause problems -- but in part that relies on that
  685. * Python integers aren't currently weakly referencable. Best practice is
  686. * to use Py_CLEAR() even if you can't think of a reason for why you need to.
  687. */
  688. #define Py_CLEAR(op) \
  689. do { \
  690. if (op) { \
  691. PyObject *_py_tmp = (PyObject *)(op); \
  692. (op) = NULL; \
  693. Py_DECREF(_py_tmp); \
  694. } \
  695. } while (0)
  696. /* Macros to use in case the object pointer may be NULL: */
  697. #define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0)
  698. #define Py_XDECREF(op) do { if ((op) == NULL) ; else Py_DECREF(op); } while (0)
  699. /*
  700. These are provided as conveniences to Python runtime embedders, so that
  701. they can have object code that is not dependent on Python compilation flags.
  702. */
  703. PyAPI_FUNC(void) Py_IncRef(PyObject *);
  704. PyAPI_FUNC(void) Py_DecRef(PyObject *);
  705. /*
  706. _Py_NoneStruct is an object of undefined type which can be used in contexts
  707. where NULL (nil) is not suitable (since NULL often means 'error').
  708. Don't forget to apply Py_INCREF() when returning this value!!!
  709. */
  710. PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */
  711. #define Py_None (&_Py_NoneStruct)
  712. /* Macro for returning Py_None from a function */
  713. #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
  714. /*
  715. Py_NotImplemented is a singleton used to signal that an operation is
  716. not implemented for a given type combination.
  717. */
  718. PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
  719. #define Py_NotImplemented (&_Py_NotImplementedStruct)
  720. /* Macro for returning Py_NotImplemented from a function */
  721. #define Py_RETURN_NOTIMPLEMENTED \
  722. return Py_INCREF(Py_NotImplemented), Py_NotImplemented
  723. /* Rich comparison opcodes */
  724. #define Py_LT 0
  725. #define Py_LE 1
  726. #define Py_EQ 2
  727. #define Py_NE 3
  728. #define Py_GT 4
  729. #define Py_GE 5
  730. /* Maps Py_LT to Py_GT, ..., Py_GE to Py_LE.
  731. * Defined in object.c.
  732. */
  733. PyAPI_DATA(int) _Py_SwappedOp[];
  734. /*
  735. More conventions
  736. ================
  737. Argument Checking
  738. -----------------
  739. Functions that take objects as arguments normally don't check for nil
  740. arguments, but they do check the type of the argument, and return an
  741. error if the function doesn't apply to the type.
  742. Failure Modes
  743. -------------
  744. Functions may fail for a variety of reasons, including running out of
  745. memory. This is communicated to the caller in two ways: an error string
  746. is set (see errors.h), and the function result differs: functions that
  747. normally return a pointer return NULL for failure, functions returning
  748. an integer return -1 (which could be a legal return value too!), and
  749. other functions return 0 for success and -1 for failure.
  750. Callers should always check for errors before using the result. If
  751. an error was set, the caller must either explicitly clear it, or pass
  752. the error on to its caller.
  753. Reference Counts
  754. ----------------
  755. It takes a while to get used to the proper usage of reference counts.
  756. Functions that create an object set the reference count to 1; such new
  757. objects must be stored somewhere or destroyed again with Py_DECREF().
  758. Some functions that 'store' objects, such as PyTuple_SetItem() and
  759. PyList_SetItem(),
  760. don't increment the reference count of the object, since the most
  761. frequent use is to store a fresh object. Functions that 'retrieve'
  762. objects, such as PyTuple_GetItem() and PyDict_GetItemString(), also
  763. don't increment
  764. the reference count, since most frequently the object is only looked at
  765. quickly. Thus, to retrieve an object and store it again, the caller
  766. must call Py_INCREF() explicitly.
  767. NOTE: functions that 'consume' a reference count, like
  768. PyList_SetItem(), consume the reference even if the object wasn't
  769. successfully stored, to simplify error handling.
  770. It seems attractive to make other functions that take an object as
  771. argument consume a reference count; however, this may quickly get
  772. confusing (even the current practice is already confusing). Consider
  773. it carefully, it may save lots of calls to Py_INCREF() and Py_DECREF() at
  774. times.
  775. */
  776. /* Trashcan mechanism, thanks to Christian Tismer.
  777. When deallocating a container object, it's possible to trigger an unbounded
  778. chain of deallocations, as each Py_DECREF in turn drops the refcount on "the
  779. next" object in the chain to 0. This can easily lead to stack faults, and
  780. especially in threads (which typically have less stack space to work with).
  781. A container object that participates in cyclic gc can avoid this by
  782. bracketing the body of its tp_dealloc function with a pair of macros:
  783. static void
  784. mytype_dealloc(mytype *p)
  785. {
  786. ... declarations go here ...
  787. PyObject_GC_UnTrack(p); // must untrack first
  788. Py_TRASHCAN_SAFE_BEGIN(p)
  789. ... The body of the deallocator goes here, including all calls ...
  790. ... to Py_DECREF on contained objects. ...
  791. Py_TRASHCAN_SAFE_END(p)
  792. }
  793. CAUTION: Never return from the middle of the body! If the body needs to
  794. "get out early", put a label immediately before the Py_TRASHCAN_SAFE_END
  795. call, and goto it. Else the call-depth counter (see below) will stay
  796. above 0 forever, and the trashcan will never get emptied.
  797. How it works: The BEGIN macro increments a call-depth counter. So long
  798. as this counter is small, the body of the deallocator is run directly without
  799. further ado. But if the counter gets large, it instead adds p to a list of
  800. objects to be deallocated later, skips the body of the deallocator, and
  801. resumes execution after the END macro. The tp_dealloc routine then returns
  802. without deallocating anything (and so unbounded call-stack depth is avoided).
  803. When the call stack finishes unwinding again, code generated by the END macro
  804. notices this, and calls another routine to deallocate all the objects that
  805. may have been added to the list of deferred deallocations. In effect, a
  806. chain of N deallocations is broken into N / PyTrash_UNWIND_LEVEL pieces,
  807. with the call stack never exceeding a depth of PyTrash_UNWIND_LEVEL.
  808. */
  809. /* This is the old private API, invoked by the macros before 3.2.4.
  810. Kept for binary compatibility of extensions using the stable ABI. */
  811. PyAPI_FUNC(void) _PyTrash_deposit_object(PyObject*);
  812. PyAPI_FUNC(void) _PyTrash_destroy_chain(void);
  813. PyAPI_DATA(int) _PyTrash_delete_nesting;
  814. PyAPI_DATA(PyObject *) _PyTrash_delete_later;
  815. /* The new thread-safe private API, invoked by the macros below. */
  816. PyAPI_FUNC(void) _PyTrash_thread_deposit_object(PyObject*);
  817. PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(void);
  818. #define PyTrash_UNWIND_LEVEL 50
  819. #define Py_TRASHCAN_SAFE_BEGIN(op) \
  820. do { \
  821. PyThreadState *_tstate = PyThreadState_GET(); \
  822. if (_tstate->trash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
  823. ++_tstate->trash_delete_nesting;
  824. /* The body of the deallocator is here. */
  825. #define Py_TRASHCAN_SAFE_END(op) \
  826. --_tstate->trash_delete_nesting; \
  827. if (_tstate->trash_delete_later && _tstate->trash_delete_nesting <= 0) \
  828. _PyTrash_thread_destroy_chain(); \
  829. } \
  830. else \
  831. _PyTrash_thread_deposit_object((PyObject*)op); \
  832. } while (0);
  833. #ifndef Py_LIMITED_API
  834. PyAPI_FUNC(void)
  835. _PyDebugAllocatorStats(FILE *out, const char *block_name, int num_blocks,
  836. size_t sizeof_block);
  837. PyAPI_FUNC(void)
  838. _PyObject_DebugTypeStats(FILE *out);
  839. #endif /* ifndef Py_LIMITED_API */
  840. #ifdef __cplusplus
  841. }
  842. #endif
  843. #endif /* !Py_OBJECT_H */