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.

884 lines
33 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
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
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. #ifdef Py_TRACE_REFS
  54. /* Define pointers to support a doubly-linked list of all live heap objects. */
  55. #define _PyObject_HEAD_EXTRA \
  56. struct _object *_ob_next; \
  57. struct _object *_ob_prev;
  58. #define _PyObject_EXTRA_INIT 0, 0,
  59. #else
  60. #define _PyObject_HEAD_EXTRA
  61. #define _PyObject_EXTRA_INIT
  62. #endif
  63. /* PyObject_HEAD defines the initial segment of every PyObject. */
  64. #define PyObject_HEAD PyObject ob_base;
  65. #define PyObject_HEAD_INIT(type) \
  66. { _PyObject_EXTRA_INIT \
  67. 1, type },
  68. #define PyVarObject_HEAD_INIT(type, size) \
  69. { PyObject_HEAD_INIT(type) size },
  70. /* PyObject_VAR_HEAD defines the initial segment of all variable-size
  71. * container objects. These end with a declaration of an array with 1
  72. * element, but enough space is malloc'ed so that the array actually
  73. * has room for ob_size elements. Note that ob_size is an element count,
  74. * not necessarily a byte count.
  75. */
  76. #define PyObject_VAR_HEAD PyVarObject ob_base;
  77. #define Py_INVALID_SIZE (Py_ssize_t)-1
  78. /* Nothing is actually declared to be a PyObject, but every pointer to
  79. * a Python object can be cast to a PyObject*. This is inheritance built
  80. * by hand. Similarly every pointer to a variable-size Python object can,
  81. * in addition, be cast to PyVarObject*.
  82. */
  83. typedef struct _object {
  84. _PyObject_HEAD_EXTRA
  85. Py_ssize_t ob_refcnt;
  86. struct _typeobject *ob_type;
  87. } PyObject;
  88. typedef struct {
  89. PyObject ob_base;
  90. Py_ssize_t ob_size; /* Number of items in variable part */
  91. } PyVarObject;
  92. #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  93. #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
  94. #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
  95. /*
  96. Type objects contain a string containing the type name (to help somewhat
  97. in debugging), the allocation parameters (see PyObject_New() and
  98. PyObject_NewVar()),
  99. and methods for accessing objects of the type. Methods are optional, a
  100. nil pointer meaning that particular kind of access is not available for
  101. this type. The Py_DECREF() macro uses the tp_dealloc method without
  102. checking for a nil pointer; it should always be implemented except if
  103. the implementation can guarantee that the reference count will never
  104. reach zero (e.g., for statically allocated type objects).
  105. NB: the methods for certain type groups are now contained in separate
  106. method blocks.
  107. */
  108. typedef PyObject * (*unaryfunc)(PyObject *);
  109. typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
  110. typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
  111. typedef int (*inquiry)(PyObject *);
  112. typedef Py_ssize_t (*lenfunc)(PyObject *);
  113. typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
  114. typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
  115. typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
  116. typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
  117. typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
  118. /* buffer interface */
  119. typedef struct bufferinfo {
  120. void *buf;
  121. PyObject *obj; /* owned reference */
  122. Py_ssize_t len;
  123. Py_ssize_t itemsize; /* This is Py_ssize_t so it can be
  124. pointed to by strides in simple case.*/
  125. int readonly;
  126. int ndim;
  127. char *format;
  128. Py_ssize_t *shape;
  129. Py_ssize_t *strides;
  130. Py_ssize_t *suboffsets;
  131. Py_ssize_t smalltable[2]; /* static store for shape and strides of
  132. mono-dimensional buffers. */
  133. void *internal;
  134. } Py_buffer;
  135. typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
  136. typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
  137. /* Flags for getting buffers */
  138. #define PyBUF_SIMPLE 0
  139. #define PyBUF_WRITABLE 0x0001
  140. /* we used to include an E, backwards compatible alias */
  141. #define PyBUF_WRITEABLE PyBUF_WRITABLE
  142. #define PyBUF_FORMAT 0x0004
  143. #define PyBUF_ND 0x0008
  144. #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  145. #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  146. #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  147. #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  148. #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
  149. #define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)
  150. #define PyBUF_CONTIG_RO (PyBUF_ND)
  151. #define PyBUF_STRIDED (PyBUF_STRIDES | PyBUF_WRITABLE)
  152. #define PyBUF_STRIDED_RO (PyBUF_STRIDES)
  153. #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT)
  154. #define PyBUF_RECORDS_RO (PyBUF_STRIDES | PyBUF_FORMAT)
  155. #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT)
  156. #define PyBUF_FULL_RO (PyBUF_INDIRECT | PyBUF_FORMAT)
  157. #define PyBUF_READ 0x100
  158. #define PyBUF_WRITE 0x200
  159. #define PyBUF_SHADOW 0x400
  160. /* End buffer interface */
  161. typedef int (*objobjproc)(PyObject *, PyObject *);
  162. typedef int (*visitproc)(PyObject *, void *);
  163. typedef int (*traverseproc)(PyObject *, visitproc, void *);
  164. typedef struct {
  165. /* Number implementations must check *both*
  166. arguments for proper type and implement the necessary conversions
  167. in the slot functions themselves. */
  168. binaryfunc nb_add;
  169. binaryfunc nb_subtract;
  170. binaryfunc nb_multiply;
  171. binaryfunc nb_remainder;
  172. binaryfunc nb_divmod;
  173. ternaryfunc nb_power;
  174. unaryfunc nb_negative;
  175. unaryfunc nb_positive;
  176. unaryfunc nb_absolute;
  177. inquiry nb_bool;
  178. unaryfunc nb_invert;
  179. binaryfunc nb_lshift;
  180. binaryfunc nb_rshift;
  181. binaryfunc nb_and;
  182. binaryfunc nb_xor;
  183. binaryfunc nb_or;
  184. unaryfunc nb_int;
  185. void *nb_reserved; /* the slot formerly known as nb_long */
  186. unaryfunc nb_float;
  187. binaryfunc nb_inplace_add;
  188. binaryfunc nb_inplace_subtract;
  189. binaryfunc nb_inplace_multiply;
  190. binaryfunc nb_inplace_remainder;
  191. ternaryfunc nb_inplace_power;
  192. binaryfunc nb_inplace_lshift;
  193. binaryfunc nb_inplace_rshift;
  194. binaryfunc nb_inplace_and;
  195. binaryfunc nb_inplace_xor;
  196. binaryfunc nb_inplace_or;
  197. binaryfunc nb_floor_divide;
  198. binaryfunc nb_true_divide;
  199. binaryfunc nb_inplace_floor_divide;
  200. binaryfunc nb_inplace_true_divide;
  201. unaryfunc nb_index;
  202. } PyNumberMethods;
  203. typedef struct {
  204. lenfunc sq_length;
  205. binaryfunc sq_concat;
  206. ssizeargfunc sq_repeat;
  207. ssizeargfunc sq_item;
  208. void *was_sq_slice;
  209. ssizeobjargproc sq_ass_item;
  210. void *was_sq_ass_slice;
  211. objobjproc sq_contains;
  212. binaryfunc sq_inplace_concat;
  213. ssizeargfunc sq_inplace_repeat;
  214. } PySequenceMethods;
  215. typedef struct {
  216. lenfunc mp_length;
  217. binaryfunc mp_subscript;
  218. objobjargproc mp_ass_subscript;
  219. } PyMappingMethods;
  220. typedef struct {
  221. getbufferproc bf_getbuffer;
  222. releasebufferproc bf_releasebuffer;
  223. } PyBufferProcs;
  224. typedef void (*freefunc)(void *);
  225. typedef void (*destructor)(PyObject *);
  226. typedef int (*printfunc)(PyObject *, FILE *, int);
  227. typedef PyObject *(*getattrfunc)(PyObject *, char *);
  228. typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
  229. typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
  230. typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
  231. typedef PyObject *(*reprfunc)(PyObject *);
  232. typedef long (*hashfunc)(PyObject *);
  233. typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
  234. typedef PyObject *(*getiterfunc) (PyObject *);
  235. typedef PyObject *(*iternextfunc) (PyObject *);
  236. typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *);
  237. typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *);
  238. typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
  239. typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
  240. typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);
  241. typedef struct _typeobject {
  242. PyObject_VAR_HEAD
  243. const char *tp_name; /* For printing, in format "<module>.<name>" */
  244. Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
  245. /* Methods to implement standard operations */
  246. destructor tp_dealloc;
  247. printfunc tp_print;
  248. getattrfunc tp_getattr;
  249. setattrfunc tp_setattr;
  250. void *tp_reserved; /* formerly known as tp_compare */
  251. reprfunc tp_repr;
  252. /* Method suites for standard classes */
  253. PyNumberMethods *tp_as_number;
  254. PySequenceMethods *tp_as_sequence;
  255. PyMappingMethods *tp_as_mapping;
  256. /* More standard operations (here for binary compatibility) */
  257. hashfunc tp_hash;
  258. ternaryfunc tp_call;
  259. reprfunc tp_str;
  260. getattrofunc tp_getattro;
  261. setattrofunc tp_setattro;
  262. /* Functions to access object as input/output buffer */
  263. PyBufferProcs *tp_as_buffer;
  264. /* Flags to define presence of optional/expanded features */
  265. long tp_flags;
  266. const char *tp_doc; /* Documentation string */
  267. /* Assigned meaning in release 2.0 */
  268. /* call function for all accessible objects */
  269. traverseproc tp_traverse;
  270. /* delete references to contained objects */
  271. inquiry tp_clear;
  272. /* Assigned meaning in release 2.1 */
  273. /* rich comparisons */
  274. richcmpfunc tp_richcompare;
  275. /* weak reference enabler */
  276. Py_ssize_t tp_weaklistoffset;
  277. /* Iterators */
  278. getiterfunc tp_iter;
  279. iternextfunc tp_iternext;
  280. /* Attribute descriptor and subclassing stuff */
  281. struct PyMethodDef *tp_methods;
  282. struct PyMemberDef *tp_members;
  283. struct PyGetSetDef *tp_getset;
  284. struct _typeobject *tp_base;
  285. PyObject *tp_dict;
  286. descrgetfunc tp_descr_get;
  287. descrsetfunc tp_descr_set;
  288. Py_ssize_t tp_dictoffset;
  289. initproc tp_init;
  290. allocfunc tp_alloc;
  291. newfunc tp_new;
  292. freefunc tp_free; /* Low-level free-memory routine */
  293. inquiry tp_is_gc; /* For PyObject_IS_GC */
  294. PyObject *tp_bases;
  295. PyObject *tp_mro; /* method resolution order */
  296. PyObject *tp_cache;
  297. PyObject *tp_subclasses;
  298. PyObject *tp_weaklist;
  299. destructor tp_del;
  300. /* Type attribute cache version tag. Added in version 2.6 */
  301. unsigned int tp_version_tag;
  302. #ifdef COUNT_ALLOCS
  303. /* these must be last and never explicitly initialized */
  304. Py_ssize_t tp_allocs;
  305. Py_ssize_t tp_frees;
  306. Py_ssize_t tp_maxalloc;
  307. struct _typeobject *tp_prev;
  308. struct _typeobject *tp_next;
  309. #endif
  310. } PyTypeObject;
  311. /* The *real* layout of a type object when allocated on the heap */
  312. typedef struct _heaptypeobject {
  313. /* Note: there's a dependency on the order of these members
  314. in slotptr() in typeobject.c . */
  315. PyTypeObject ht_type;
  316. PyNumberMethods as_number;
  317. PyMappingMethods as_mapping;
  318. PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
  319. so that the mapping wins when both
  320. the mapping and the sequence define
  321. a given operator (e.g. __getitem__).
  322. see add_operators() in typeobject.c . */
  323. PyBufferProcs as_buffer;
  324. PyObject *ht_name, *ht_slots;
  325. /* here are optional user slots, followed by the members. */
  326. } PyHeapTypeObject;
  327. /* access macro to the members which are floating "behind" the object */
  328. #define PyHeapType_GET_MEMBERS(etype) \
  329. ((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))
  330. /* Generic type check */
  331. PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
  332. #define PyObject_TypeCheck(ob, tp) \
  333. (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
  334. PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
  335. PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
  336. PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
  337. #define PyType_Check(op) \
  338. PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
  339. #define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type)
  340. PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
  341. PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
  342. PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
  343. PyObject *, PyObject *);
  344. PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
  345. PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, char *, PyObject **);
  346. PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
  347. PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
  348. /* Generic operations on objects */
  349. PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
  350. PyAPI_FUNC(void) _Py_BreakPoint(void);
  351. PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
  352. PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *);
  353. PyAPI_FUNC(PyObject *) PyObject_Str(PyObject *);
  354. PyAPI_FUNC(PyObject *) PyObject_ASCII(PyObject *);
  355. PyAPI_FUNC(PyObject *) PyObject_Bytes(PyObject *);
  356. PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
  357. PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
  358. PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *);
  359. PyAPI_FUNC(int) PyObject_SetAttrString(PyObject *, const char *, PyObject *);
  360. PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *);
  361. PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
  362. PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
  363. PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
  364. PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
  365. PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
  366. PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *);
  367. PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
  368. PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *,
  369. PyObject *, PyObject *);
  370. PyAPI_FUNC(long) PyObject_Hash(PyObject *);
  371. PyAPI_FUNC(long) PyObject_HashNotImplemented(PyObject *);
  372. PyAPI_FUNC(int) PyObject_IsTrue(PyObject *);
  373. PyAPI_FUNC(int) PyObject_Not(PyObject *);
  374. PyAPI_FUNC(int) PyCallable_Check(PyObject *);
  375. PyAPI_FUNC(void) PyObject_ClearWeakRefs(PyObject *);
  376. /* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes
  377. dict as the last parameter. */
  378. PyAPI_FUNC(PyObject *)
  379. _PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *);
  380. PyAPI_FUNC(int)
  381. _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
  382. PyObject *, PyObject *);
  383. /* PyObject_Dir(obj) acts like Python builtins.dir(obj), returning a
  384. list of strings. PyObject_Dir(NULL) is like builtins.dir(),
  385. returning the names of the current locals. In this case, if there are
  386. no current locals, NULL is returned, and PyErr_Occurred() is false.
  387. */
  388. PyAPI_FUNC(PyObject *) PyObject_Dir(PyObject *);
  389. /* Helpers for printing recursive container types */
  390. PyAPI_FUNC(int) Py_ReprEnter(PyObject *);
  391. PyAPI_FUNC(void) Py_ReprLeave(PyObject *);
  392. /* Helpers for hash functions */
  393. PyAPI_FUNC(long) _Py_HashDouble(double);
  394. PyAPI_FUNC(long) _Py_HashPointer(void*);
  395. typedef struct {
  396. long prefix;
  397. long suffix;
  398. } _Py_HashSecret_t;
  399. PyAPI_DATA(_Py_HashSecret_t) _Py_HashSecret;
  400. #ifdef Py_DEBUG
  401. PyAPI_DATA(int) _Py_HashSecret_Initialized;
  402. #endif
  403. /* Helper for passing objects to printf and the like */
  404. #define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj))
  405. /* Flag bits for printing: */
  406. #define Py_PRINT_RAW 1 /* No string quotes etc. */
  407. /*
  408. `Type flags (tp_flags)
  409. These flags are used to extend the type structure in a backwards-compatible
  410. fashion. Extensions can use the flags to indicate (and test) when a given
  411. type structure contains a new feature. The Python core will use these when
  412. introducing new functionality between major revisions (to avoid mid-version
  413. changes in the PYTHON_API_VERSION).
  414. Arbitration of the flag bit positions will need to be coordinated among
  415. all extension writers who publically release their extensions (this will
  416. be fewer than you might expect!)..
  417. Most flags were removed as of Python 3.0 to make room for new flags. (Some
  418. flags are not for backwards compatibility but to indicate the presence of an
  419. optional feature; these flags remain of course.)
  420. Type definitions should use Py_TPFLAGS_DEFAULT for their tp_flags value.
  421. Code can use PyType_HasFeature(type_ob, flag_value) to test whether the
  422. given type object has a specified feature.
  423. */
  424. /* Set if the type object is dynamically allocated */
  425. #define Py_TPFLAGS_HEAPTYPE (1L<<9)
  426. /* Set if the type allows subclassing */
  427. #define Py_TPFLAGS_BASETYPE (1L<<10)
  428. /* Set if the type is 'ready' -- fully initialized */
  429. #define Py_TPFLAGS_READY (1L<<12)
  430. /* Set while the type is being 'readied', to prevent recursive ready calls */
  431. #define Py_TPFLAGS_READYING (1L<<13)
  432. /* Objects support garbage collection (see objimp.h) */
  433. #define Py_TPFLAGS_HAVE_GC (1L<<14)
  434. /* These two bits are preserved for Stackless Python, next after this is 17 */
  435. #ifdef STACKLESS
  436. #define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION (3L<<15)
  437. #else
  438. #define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
  439. #endif
  440. /* Objects support type attribute cache */
  441. #define Py_TPFLAGS_HAVE_VERSION_TAG (1L<<18)
  442. #define Py_TPFLAGS_VALID_VERSION_TAG (1L<<19)
  443. /* Type is abstract and cannot be instantiated */
  444. #define Py_TPFLAGS_IS_ABSTRACT (1L<<20)
  445. /* These flags are used to determine if a type is a subclass. */
  446. #define Py_TPFLAGS_INT_SUBCLASS (1L<<23)
  447. #define Py_TPFLAGS_LONG_SUBCLASS (1L<<24)
  448. #define Py_TPFLAGS_LIST_SUBCLASS (1L<<25)
  449. #define Py_TPFLAGS_TUPLE_SUBCLASS (1L<<26)
  450. #define Py_TPFLAGS_BYTES_SUBCLASS (1L<<27)
  451. #define Py_TPFLAGS_UNICODE_SUBCLASS (1L<<28)
  452. #define Py_TPFLAGS_DICT_SUBCLASS (1L<<29)
  453. #define Py_TPFLAGS_BASE_EXC_SUBCLASS (1L<<30)
  454. #define Py_TPFLAGS_TYPE_SUBCLASS (1L<<31)
  455. #define Py_TPFLAGS_DEFAULT ( \
  456. Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
  457. Py_TPFLAGS_HAVE_VERSION_TAG | \
  458. 0)
  459. #define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
  460. #define PyType_FastSubclass(t,f) PyType_HasFeature(t,f)
  461. /*
  462. The macros Py_INCREF(op) and Py_DECREF(op) are used to increment or decrement
  463. reference counts. Py_DECREF calls the object's deallocator function when
  464. the refcount falls to 0; for
  465. objects that don't contain references to other objects or heap memory
  466. this can be the standard function free(). Both macros can be used
  467. wherever a void expression is allowed. The argument must not be a
  468. NULL pointer. If it may be NULL, use Py_XINCREF/Py_XDECREF instead.
  469. The macro _Py_NewReference(op) initialize reference counts to 1, and
  470. in special builds (Py_REF_DEBUG, Py_TRACE_REFS) performs additional
  471. bookkeeping appropriate to the special build.
  472. We assume that the reference count field can never overflow; this can
  473. be proven when the size of the field is the same as the pointer size, so
  474. we ignore the possibility. Provided a C int is at least 32 bits (which
  475. is implicitly assumed in many parts of this code), that's enough for
  476. about 2**31 references to an object.
  477. XXX The following became out of date in Python 2.2, but I'm not sure
  478. XXX what the full truth is now. Certainly, heap-allocated type objects
  479. XXX can and should be deallocated.
  480. Type objects should never be deallocated; the type pointer in an object
  481. is not considered to be a reference to the type object, to save
  482. complications in the deallocation function. (This is actually a
  483. decision that's up to the implementer of each new type so if you want,
  484. you can count such references to the type object.)
  485. *** WARNING*** The Py_DECREF macro must have a side-effect-free argument
  486. since it may evaluate its argument multiple times. (The alternative
  487. would be to mace it a proper function or assign it to a global temporary
  488. variable first, both of which are slower; and in a multi-threaded
  489. environment the global variable trick is not safe.)
  490. */
  491. /* First define a pile of simple helper macros, one set per special
  492. * build symbol. These either expand to the obvious things, or to
  493. * nothing at all when the special mode isn't in effect. The main
  494. * macros can later be defined just once then, yet expand to different
  495. * things depending on which special build options are and aren't in effect.
  496. * Trust me <wink>: while painful, this is 20x easier to understand than,
  497. * e.g, defining _Py_NewReference five different times in a maze of nested
  498. * #ifdefs (we used to do that -- it was impenetrable).
  499. */
  500. #ifdef Py_REF_DEBUG
  501. PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
  502. PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname,
  503. int lineno, PyObject *op);
  504. PyAPI_FUNC(PyObject *) _PyDict_Dummy(void);
  505. PyAPI_FUNC(PyObject *) _PySet_Dummy(void);
  506. PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
  507. #define _Py_INC_REFTOTAL _Py_RefTotal++
  508. #define _Py_DEC_REFTOTAL _Py_RefTotal--
  509. #define _Py_REF_DEBUG_COMMA ,
  510. #define _Py_CHECK_REFCNT(OP) \
  511. { if (((PyObject*)OP)->ob_refcnt < 0) \
  512. _Py_NegativeRefcount(__FILE__, __LINE__, \
  513. (PyObject *)(OP)); \
  514. }
  515. #else
  516. #define _Py_INC_REFTOTAL
  517. #define _Py_DEC_REFTOTAL
  518. #define _Py_REF_DEBUG_COMMA
  519. #define _Py_CHECK_REFCNT(OP) /* a semicolon */;
  520. #endif /* Py_REF_DEBUG */
  521. #ifdef COUNT_ALLOCS
  522. PyAPI_FUNC(void) inc_count(PyTypeObject *);
  523. PyAPI_FUNC(void) dec_count(PyTypeObject *);
  524. #define _Py_INC_TPALLOCS(OP) inc_count(Py_TYPE(OP))
  525. #define _Py_INC_TPFREES(OP) dec_count(Py_TYPE(OP))
  526. #define _Py_DEC_TPFREES(OP) Py_TYPE(OP)->tp_frees--
  527. #define _Py_COUNT_ALLOCS_COMMA ,
  528. #else
  529. #define _Py_INC_TPALLOCS(OP)
  530. #define _Py_INC_TPFREES(OP)
  531. #define _Py_DEC_TPFREES(OP)
  532. #define _Py_COUNT_ALLOCS_COMMA
  533. #endif /* COUNT_ALLOCS */
  534. #ifdef Py_TRACE_REFS
  535. /* Py_TRACE_REFS is such major surgery that we call external routines. */
  536. PyAPI_FUNC(void) _Py_NewReference(PyObject *);
  537. PyAPI_FUNC(void) _Py_ForgetReference(PyObject *);
  538. PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
  539. PyAPI_FUNC(void) _Py_PrintReferences(FILE *);
  540. PyAPI_FUNC(void) _Py_PrintReferenceAddresses(FILE *);
  541. PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
  542. #else
  543. /* Without Py_TRACE_REFS, there's little enough to do that we expand code
  544. * inline.
  545. */
  546. #define _Py_NewReference(op) ( \
  547. _Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA \
  548. _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
  549. Py_REFCNT(op) = 1)
  550. #define _Py_ForgetReference(op) _Py_INC_TPFREES(op)
  551. #define _Py_Dealloc(op) ( \
  552. _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \
  553. (*Py_TYPE(op)->tp_dealloc)((PyObject *)(op)))
  554. #endif /* !Py_TRACE_REFS */
  555. #define Py_INCREF(op) ( \
  556. _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
  557. ((PyObject*)(op))->ob_refcnt++)
  558. #define Py_DECREF(op) \
  559. do { \
  560. if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
  561. --((PyObject*)(op))->ob_refcnt != 0) \
  562. _Py_CHECK_REFCNT(op) \
  563. else \
  564. _Py_Dealloc((PyObject *)(op)); \
  565. } while (0)
  566. /* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
  567. * and tp_dealloc implementatons.
  568. *
  569. * Note that "the obvious" code can be deadly:
  570. *
  571. * Py_XDECREF(op);
  572. * op = NULL;
  573. *
  574. * Typically, `op` is something like self->containee, and `self` is done
  575. * using its `containee` member. In the code sequence above, suppose
  576. * `containee` is non-NULL with a refcount of 1. Its refcount falls to
  577. * 0 on the first line, which can trigger an arbitrary amount of code,
  578. * possibly including finalizers (like __del__ methods or weakref callbacks)
  579. * coded in Python, which in turn can release the GIL and allow other threads
  580. * to run, etc. Such code may even invoke methods of `self` again, or cause
  581. * cyclic gc to trigger, but-- oops! --self->containee still points to the
  582. * object being torn down, and it may be in an insane state while being torn
  583. * down. This has in fact been a rich historic source of miserable (rare &
  584. * hard-to-diagnose) segfaulting (and other) bugs.
  585. *
  586. * The safe way is:
  587. *
  588. * Py_CLEAR(op);
  589. *
  590. * That arranges to set `op` to NULL _before_ decref'ing, so that any code
  591. * triggered as a side-effect of `op` getting torn down no longer believes
  592. * `op` points to a valid object.
  593. *
  594. * There are cases where it's safe to use the naive code, but they're brittle.
  595. * For example, if `op` points to a Python integer, you know that destroying
  596. * one of those can't cause problems -- but in part that relies on that
  597. * Python integers aren't currently weakly referencable. Best practice is
  598. * to use Py_CLEAR() even if you can't think of a reason for why you need to.
  599. */
  600. #define Py_CLEAR(op) \
  601. do { \
  602. if (op) { \
  603. PyObject *_py_tmp = (PyObject *)(op); \
  604. (op) = NULL; \
  605. Py_DECREF(_py_tmp); \
  606. } \
  607. } while (0)
  608. /* Macros to use in case the object pointer may be NULL: */
  609. #define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0)
  610. #define Py_XDECREF(op) do { if ((op) == NULL) ; else Py_DECREF(op); } while (0)
  611. /*
  612. These are provided as conveniences to Python runtime embedders, so that
  613. they can have object code that is not dependent on Python compilation flags.
  614. */
  615. PyAPI_FUNC(void) Py_IncRef(PyObject *);
  616. PyAPI_FUNC(void) Py_DecRef(PyObject *);
  617. /*
  618. _Py_NoneStruct is an object of undefined type which can be used in contexts
  619. where NULL (nil) is not suitable (since NULL often means 'error').
  620. Don't forget to apply Py_INCREF() when returning this value!!!
  621. */
  622. PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */
  623. #define Py_None (&_Py_NoneStruct)
  624. /* Macro for returning Py_None from a function */
  625. #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
  626. /*
  627. Py_NotImplemented is a singleton used to signal that an operation is
  628. not implemented for a given type combination.
  629. */
  630. PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
  631. #define Py_NotImplemented (&_Py_NotImplementedStruct)
  632. /* Rich comparison opcodes */
  633. #define Py_LT 0
  634. #define Py_LE 1
  635. #define Py_EQ 2
  636. #define Py_NE 3
  637. #define Py_GT 4
  638. #define Py_GE 5
  639. /* Maps Py_LT to Py_GT, ..., Py_GE to Py_LE.
  640. * Defined in object.c.
  641. */
  642. PyAPI_DATA(int) _Py_SwappedOp[];
  643. /*
  644. More conventions
  645. ================
  646. Argument Checking
  647. -----------------
  648. Functions that take objects as arguments normally don't check for nil
  649. arguments, but they do check the type of the argument, and return an
  650. error if the function doesn't apply to the type.
  651. Failure Modes
  652. -------------
  653. Functions may fail for a variety of reasons, including running out of
  654. memory. This is communicated to the caller in two ways: an error string
  655. is set (see errors.h), and the function result differs: functions that
  656. normally return a pointer return NULL for failure, functions returning
  657. an integer return -1 (which could be a legal return value too!), and
  658. other functions return 0 for success and -1 for failure.
  659. Callers should always check for errors before using the result. If
  660. an error was set, the caller must either explicitly clear it, or pass
  661. the error on to its caller.
  662. Reference Counts
  663. ----------------
  664. It takes a while to get used to the proper usage of reference counts.
  665. Functions that create an object set the reference count to 1; such new
  666. objects must be stored somewhere or destroyed again with Py_DECREF().
  667. Some functions that 'store' objects, such as PyTuple_SetItem() and
  668. PyList_SetItem(),
  669. don't increment the reference count of the object, since the most
  670. frequent use is to store a fresh object. Functions that 'retrieve'
  671. objects, such as PyTuple_GetItem() and PyDict_GetItemString(), also
  672. don't increment
  673. the reference count, since most frequently the object is only looked at
  674. quickly. Thus, to retrieve an object and store it again, the caller
  675. must call Py_INCREF() explicitly.
  676. NOTE: functions that 'consume' a reference count, like
  677. PyList_SetItem(), consume the reference even if the object wasn't
  678. successfully stored, to simplify error handling.
  679. It seems attractive to make other functions that take an object as
  680. argument consume a reference count; however, this may quickly get
  681. confusing (even the current practice is already confusing). Consider
  682. it carefully, it may save lots of calls to Py_INCREF() and Py_DECREF() at
  683. times.
  684. */
  685. /* Trashcan mechanism, thanks to Christian Tismer.
  686. When deallocating a container object, it's possible to trigger an unbounded
  687. chain of deallocations, as each Py_DECREF in turn drops the refcount on "the
  688. next" object in the chain to 0. This can easily lead to stack faults, and
  689. especially in threads (which typically have less stack space to work with).
  690. A container object that participates in cyclic gc can avoid this by
  691. bracketing the body of its tp_dealloc function with a pair of macros:
  692. static void
  693. mytype_dealloc(mytype *p)
  694. {
  695. ... declarations go here ...
  696. PyObject_GC_UnTrack(p); // must untrack first
  697. Py_TRASHCAN_SAFE_BEGIN(p)
  698. ... The body of the deallocator goes here, including all calls ...
  699. ... to Py_DECREF on contained objects. ...
  700. Py_TRASHCAN_SAFE_END(p)
  701. }
  702. CAUTION: Never return from the middle of the body! If the body needs to
  703. "get out early", put a label immediately before the Py_TRASHCAN_SAFE_END
  704. call, and goto it. Else the call-depth counter (see below) will stay
  705. above 0 forever, and the trashcan will never get emptied.
  706. How it works: The BEGIN macro increments a call-depth counter. So long
  707. as this counter is small, the body of the deallocator is run directly without
  708. further ado. But if the counter gets large, it instead adds p to a list of
  709. objects to be deallocated later, skips the body of the deallocator, and
  710. resumes execution after the END macro. The tp_dealloc routine then returns
  711. without deallocating anything (and so unbounded call-stack depth is avoided).
  712. When the call stack finishes unwinding again, code generated by the END macro
  713. notices this, and calls another routine to deallocate all the objects that
  714. may have been added to the list of deferred deallocations. In effect, a
  715. chain of N deallocations is broken into N / PyTrash_UNWIND_LEVEL pieces,
  716. with the call stack never exceeding a depth of PyTrash_UNWIND_LEVEL.
  717. */
  718. PyAPI_FUNC(void) _PyTrash_deposit_object(PyObject*);
  719. PyAPI_FUNC(void) _PyTrash_destroy_chain(void);
  720. PyAPI_DATA(int) _PyTrash_delete_nesting;
  721. PyAPI_DATA(PyObject *) _PyTrash_delete_later;
  722. #define PyTrash_UNWIND_LEVEL 50
  723. #define Py_TRASHCAN_SAFE_BEGIN(op) \
  724. if (_PyTrash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
  725. ++_PyTrash_delete_nesting;
  726. /* The body of the deallocator is here. */
  727. #define Py_TRASHCAN_SAFE_END(op) \
  728. --_PyTrash_delete_nesting; \
  729. if (_PyTrash_delete_later && _PyTrash_delete_nesting <= 0) \
  730. _PyTrash_destroy_chain(); \
  731. } \
  732. else \
  733. _PyTrash_deposit_object((PyObject*)op);
  734. #ifdef __cplusplus
  735. }
  736. #endif
  737. #endif /* !Py_OBJECT_H */