mirror of
https://github.com/python/cpython.git
synced 2025-07-13 22:35:18 +00:00

Merged revisions 51434-53004 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r51434 | neal.norwitz | 2006-08-21 20:20:10 +0200 (Mon, 21 Aug 2006) | 1 line Fix a couple of ssize-t issues reported by Alexander Belopolsky on python-dev ........ r51439 | neal.norwitz | 2006-08-21 21:47:08 +0200 (Mon, 21 Aug 2006) | 6 lines Patch #1542451: disallow continue anywhere under a finally I'm undecided if this should be backported to 2.5 or 2.5.1. Armin suggested to wait (I'm of the same opinion). Thomas W thinks it's fine to go in 2.5. ........ r51443 | neal.norwitz | 2006-08-21 22:16:24 +0200 (Mon, 21 Aug 2006) | 4 lines Handle a few more error conditions. Klocwork 301 and 302. Will backport. ........ r51450 | neal.norwitz | 2006-08-22 00:21:19 +0200 (Tue, 22 Aug 2006) | 5 lines Patch #1541585: fix buffer overrun when performing repr() on a unicode string in a build with wide unicode (UCS-4) support. This code could be improved, so add an XXX comment. ........ r51456 | neal.norwitz | 2006-08-22 01:44:48 +0200 (Tue, 22 Aug 2006) | 1 line Try to get the windows bots working again with the new peephole.c ........ r51461 | anthony.baxter | 2006-08-22 09:36:59 +0200 (Tue, 22 Aug 2006) | 1 line patch for documentation for recent uuid changes (from ping) ........ r51473 | neal.norwitz | 2006-08-22 15:56:56 +0200 (Tue, 22 Aug 2006) | 1 line Alexander Belopolsky pointed out that pos is a size_t ........ r51489 | jeremy.hylton | 2006-08-22 22:46:00 +0200 (Tue, 22 Aug 2006) | 2 lines Expose column offset information in parse trees. ........ r51497 | andrew.kuchling | 2006-08-23 01:13:43 +0200 (Wed, 23 Aug 2006) | 1 line Move functional howto into trunk ........ r51515 | jeremy.hylton | 2006-08-23 20:37:43 +0200 (Wed, 23 Aug 2006) | 2 lines Baby steps towards better tests for tokenize ........ r51525 | alex.martelli | 2006-08-23 22:42:02 +0200 (Wed, 23 Aug 2006) | 6 lines x**2 should about equal x*x (including for a float x such that the result is inf) but didn't; added a test to test_float to verify that, and ignored the ERANGE value for errno in the pow operation to make the new test pass (with help from Marilyn Davis at the Google Python Sprint -- thanks!). ........ r51526 | jeremy.hylton | 2006-08-23 23:14:03 +0200 (Wed, 23 Aug 2006) | 20 lines Bug fixes large and small for tokenize. Small: Always generate a NL or NEWLINE token following a COMMENT token. The old code did not generate an NL token if the comment was on a line by itself. Large: The output of untokenize() will now match the input exactly if it is passed the full token sequence. The old, crufty output is still generated if a limited input sequence is provided, where limited means that it does not include position information for tokens. Remaining bug: There is no CONTINUATION token (\) so there is no way for untokenize() to handle such code. Also, expanded the number of doctests in hopes of eventually removing the old-style tests that compare against a golden file. Bug fix candidate for Python 2.5.1. (Sigh.) ........ r51527 | jeremy.hylton | 2006-08-23 23:26:46 +0200 (Wed, 23 Aug 2006) | 5 lines Replace dead code with an assert. Now that COMMENT tokens are reliably followed by NL or NEWLINE, there is never a need to add extra newlines in untokenize. ........ r51530 | alex.martelli | 2006-08-24 00:17:59 +0200 (Thu, 24 Aug 2006) | 7 lines Reverting the patch that tried to fix the issue whereby x**2 raises OverflowError while x*x succeeds and produces infinity; apparently these inconsistencies cannot be fixed across ``all'' platforms and there's a widespread feeling that therefore ``every'' platform should keep suffering forevermore. Ah well. ........ r51565 | thomas.wouters | 2006-08-24 20:40:20 +0200 (Thu, 24 Aug 2006) | 6 lines Fix SF bug #1545837: array.array borks on deepcopy. array.__deepcopy__() needs to take an argument, even if it doesn't actually use it. Will backport to 2.5 and 2.4 (if applicable.) ........ r51580 | martin.v.loewis | 2006-08-25 02:03:34 +0200 (Fri, 25 Aug 2006) | 3 lines Patch #1545507: Exclude ctypes package in Win64 MSI file. Will backport to 2.5. ........ r51589 | neal.norwitz | 2006-08-25 03:52:49 +0200 (Fri, 25 Aug 2006) | 1 line importing types is not necessary if we use isinstance ........ r51604 | thomas.heller | 2006-08-25 09:27:33 +0200 (Fri, 25 Aug 2006) | 3 lines Port _ctypes.pyd to win64 on AMD64. ........ r51605 | thomas.heller | 2006-08-25 09:34:51 +0200 (Fri, 25 Aug 2006) | 3 lines Add missing file for _ctypes.pyd port to win64 on AMD64. ........ r51606 | thomas.heller | 2006-08-25 11:26:33 +0200 (Fri, 25 Aug 2006) | 6 lines Build _ctypes.pyd for win AMD64 into the MSVC project file. Since MSVC doesn't know about .asm files, a helper batch file is needed to find ml64.exe in predefined locations. The helper script hardcodes the path to the MS Platform SDK. ........ r51608 | armin.rigo | 2006-08-25 14:44:28 +0200 (Fri, 25 Aug 2006) | 4 lines The regular expression engine in '_sre' can segfault when interpreting bogus bytecode. It is unclear whether this is a real bug or a "won't fix" case like bogus_code_obj.py. ........ r51617 | tim.peters | 2006-08-26 00:05:39 +0200 (Sat, 26 Aug 2006) | 2 lines Whitespace normalization. ........ r51618 | tim.peters | 2006-08-26 00:06:44 +0200 (Sat, 26 Aug 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r51619 | tim.peters | 2006-08-26 00:26:21 +0200 (Sat, 26 Aug 2006) | 3 lines A new test here relied on preserving invisible trailing whitespace in expected output. Stop that. ........ r51624 | jack.diederich | 2006-08-26 20:42:06 +0200 (Sat, 26 Aug 2006) | 4 lines - Move functions common to all path modules into genericpath.py and have the OS speicifc path modules import them. - Have os2emxpath import common functions fron ntpath instead of using copies ........ r51642 | neal.norwitz | 2006-08-29 07:40:58 +0200 (Tue, 29 Aug 2006) | 1 line Fix a couple of typos. ........ r51647 | marc-andre.lemburg | 2006-08-29 12:34:12 +0200 (Tue, 29 Aug 2006) | 5 lines Fix a buglet in the error reporting (SF bug report #1546372). This should probably go into Python 2.5 or 2.5.1 as well. ........ r51663 | armin.rigo | 2006-08-31 10:51:06 +0200 (Thu, 31 Aug 2006) | 3 lines Doc fix: hashlib objects don't always return a digest of 16 bytes. Backport candidate for 2.5. ........ r51664 | nick.coghlan | 2006-08-31 14:00:43 +0200 (Thu, 31 Aug 2006) | 1 line Fix the wrongheaded implementation of context management in the decimal module and add unit tests. (python-dev discussion is ongoing regarding what we do about Python 2.5) ........ r51665 | nick.coghlan | 2006-08-31 14:51:25 +0200 (Thu, 31 Aug 2006) | 1 line Remove the old decimal context management tests from test_contextlib (guess who didn't run the test suite before committing...) ........ r51669 | brett.cannon | 2006-08-31 20:54:26 +0200 (Thu, 31 Aug 2006) | 4 lines Make sure memory is properly cleaned up in file_init. Backport candidate. ........ r51671 | brett.cannon | 2006-08-31 23:47:52 +0200 (Thu, 31 Aug 2006) | 2 lines Fix comment about indentation level in C files. ........ r51674 | brett.cannon | 2006-09-01 00:42:37 +0200 (Fri, 01 Sep 2006) | 3 lines Have pre-existing C files use 8 spaces indents (to match old PEP 7 style), but have all new files use 4 spaces (to match current PEP 7 style). ........ r51676 | fred.drake | 2006-09-01 05:57:19 +0200 (Fri, 01 Sep 2006) | 3 lines - SF patch #1550263: Enhance and correct unittest docs - various minor cleanups for improved consistency ........ r51677 | georg.brandl | 2006-09-02 00:30:52 +0200 (Sat, 02 Sep 2006) | 2 lines evalfile() should be execfile(). ........ r51681 | neal.norwitz | 2006-09-02 04:43:17 +0200 (Sat, 02 Sep 2006) | 1 line SF #1547931, fix typo (missing and). Will backport to 2.5 ........ r51683 | neal.norwitz | 2006-09-02 04:50:35 +0200 (Sat, 02 Sep 2006) | 1 line Bug #1548092: fix curses.tparm seg fault on invalid input. Needs backport to 2.5.1 and earlier. ........ r51684 | neal.norwitz | 2006-09-02 04:58:13 +0200 (Sat, 02 Sep 2006) | 4 lines Bug #1550714: fix SystemError from itertools.tee on negative value for n. Needs backport to 2.5.1 and earlier. ........ r51685 | nick.coghlan | 2006-09-02 05:54:17 +0200 (Sat, 02 Sep 2006) | 1 line Make decimal.ContextManager a private implementation detail of decimal.localcontext() ........ r51686 | nick.coghlan | 2006-09-02 06:04:18 +0200 (Sat, 02 Sep 2006) | 1 line Further corrections to the decimal module context management documentation ........ r51688 | raymond.hettinger | 2006-09-02 19:07:23 +0200 (Sat, 02 Sep 2006) | 1 line Fix documentation nits for decimal context managers. ........ r51690 | neal.norwitz | 2006-09-02 20:51:34 +0200 (Sat, 02 Sep 2006) | 1 line Add missing word in comment ........ r51691 | neal.norwitz | 2006-09-02 21:40:19 +0200 (Sat, 02 Sep 2006) | 7 lines Hmm, this test has failed at least twice recently on the OpenBSD and Debian sparc buildbots. Since this goes through a lot of tests and hits the disk a lot it could be slow (especially if NFS is involved). I'm not sure if that's the problem, but printing periodic msgs shouldn't hurt. The code was stolen from test_compiler. ........ r51693 | nick.coghlan | 2006-09-03 03:02:00 +0200 (Sun, 03 Sep 2006) | 1 line Fix final documentation nits before backporting decimal module fixes to 2.5 ........ r51694 | nick.coghlan | 2006-09-03 03:06:07 +0200 (Sun, 03 Sep 2006) | 1 line Typo fix for decimal docs ........ r51697 | nick.coghlan | 2006-09-03 03:20:46 +0200 (Sun, 03 Sep 2006) | 1 line NEWS entry on trunk for decimal module changes ........ r51704 | raymond.hettinger | 2006-09-04 17:32:48 +0200 (Mon, 04 Sep 2006) | 1 line Fix endcase for str.rpartition() ........ r51716 | tim.peters | 2006-09-05 04:18:09 +0200 (Tue, 05 Sep 2006) | 12 lines "Conceptual" merge of rev 51711 from the 2.5 branch. i_divmod(): As discussed on Python-Dev, changed the overflow checking to live happily with recent gcc optimizations that assume signed integer arithmetic never overflows. This differs from the corresponding change on the 2.5 and 2.4 branches, using a less obscure approach, but one that /may/ tickle platform idiocies in their definitions of LONG_MIN. The 2.4 + 2.5 change avoided introducing a dependence on LONG_MIN, at the cost of substantially goofier code. ........ r51717 | tim.peters | 2006-09-05 04:21:19 +0200 (Tue, 05 Sep 2006) | 2 lines Whitespace normalization. ........ r51719 | tim.peters | 2006-09-05 04:22:17 +0200 (Tue, 05 Sep 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r51720 | neal.norwitz | 2006-09-05 04:24:03 +0200 (Tue, 05 Sep 2006) | 2 lines Fix SF bug #1546288, crash in dict_equal. ........ r51721 | neal.norwitz | 2006-09-05 04:25:41 +0200 (Tue, 05 Sep 2006) | 1 line Fix SF #1552093, eval docstring typo (3 ps in mapping) ........ r51724 | neal.norwitz | 2006-09-05 04:35:08 +0200 (Tue, 05 Sep 2006) | 1 line This was found by Guido AFAIK on p3yk (sic) branch. ........ r51725 | neal.norwitz | 2006-09-05 04:36:20 +0200 (Tue, 05 Sep 2006) | 1 line Add a NEWS entry for str.rpartition() change ........ r51728 | neal.norwitz | 2006-09-05 04:57:01 +0200 (Tue, 05 Sep 2006) | 1 line Patch #1540470, for OpenBSD 4.0. Backport candidate for 2.[34]. ........ r51729 | neal.norwitz | 2006-09-05 05:53:08 +0200 (Tue, 05 Sep 2006) | 12 lines Bug #1520864 (again): unpacking singleton tuples in list comprehensions and generator expressions (x for x, in ... ) works again. Sigh, I only fixed for loops the first time, not list comps and genexprs too. I couldn't find any more unpacking cases where there is a similar bug lurking. This code should be refactored to eliminate the duplication. I'm sure the listcomp/genexpr code can be refactored. I'm not sure if the for loop can re-use any of the same code though. Will backport to 2.5 (the only place it matters). ........ r51731 | neal.norwitz | 2006-09-05 05:58:26 +0200 (Tue, 05 Sep 2006) | 1 line Add a comment about some refactoring. (There's probably more that should be done.) I will reformat this file in the next checkin due to the inconsistent tabs/spaces. ........ r51732 | neal.norwitz | 2006-09-05 06:00:12 +0200 (Tue, 05 Sep 2006) | 1 line M-x untabify ........ r51737 | hyeshik.chang | 2006-09-05 14:07:09 +0200 (Tue, 05 Sep 2006) | 7 lines Fix a few bugs on cjkcodecs found by Oren Tirosh: - gbk and gb18030 codec now handle U+30FB KATAKANA MIDDLE DOT correctly. - iso2022_jp_2 codec now encodes into G0 for KS X 1001, GB2312 codepoints to conform the standard. - iso2022_jp_3 and iso2022_jp_2004 codec can encode JIS X 2013:2 codepoints now. ........ r51738 | hyeshik.chang | 2006-09-05 14:14:57 +0200 (Tue, 05 Sep 2006) | 2 lines Fix a typo: 2013 -> 0213 ........ r51740 | georg.brandl | 2006-09-05 14:44:58 +0200 (Tue, 05 Sep 2006) | 3 lines Bug #1552618: change docs of dict.has_key() to reflect recommendation to use "in". ........ r51742 | andrew.kuchling | 2006-09-05 15:02:40 +0200 (Tue, 05 Sep 2006) | 1 line Rearrange example a bit, and show rpartition() when separator is not found ........ r51744 | andrew.kuchling | 2006-09-05 15:15:41 +0200 (Tue, 05 Sep 2006) | 1 line [Bug #1525469] SimpleXMLRPCServer still uses the sys.exc_{value,type} module-level globals instead of calling sys.exc_info(). Reported by Russell Warren ........ r51745 | andrew.kuchling | 2006-09-05 15:19:18 +0200 (Tue, 05 Sep 2006) | 3 lines [Bug #1526834] Fix crash in pdb when you do 'b f('; the function name was placed into a regex pattern and the unbalanced paren caused re.compile() to report an error ........ r51751 | kristjan.jonsson | 2006-09-05 19:58:12 +0200 (Tue, 05 Sep 2006) | 6 lines Update the PCBuild8 solution. Facilitate cross-compilation by having binaries in separate Win32 and x64 directories. Rationalized configs by making proper use of platforms/configurations. Remove pythoncore_pgo project. Add new PGIRelease and PGORelease configurations to perform Profile Guided Optimisation. Removed I64 support, but this can be easily added by copying the x64 platform settings. ........ r51758 | gustavo.niemeyer | 2006-09-06 03:58:52 +0200 (Wed, 06 Sep 2006) | 3 lines Fixing #1531862: Do not close standard file descriptors in the subprocess module. ........ r51760 | neal.norwitz | 2006-09-06 05:58:34 +0200 (Wed, 06 Sep 2006) | 1 line Revert 51758 because it broke all the buildbots ........ r51762 | georg.brandl | 2006-09-06 08:03:59 +0200 (Wed, 06 Sep 2006) | 3 lines Bug #1551427: fix a wrong NULL pointer check in the win32 version of os.urandom(). ........ r51765 | georg.brandl | 2006-09-06 08:09:31 +0200 (Wed, 06 Sep 2006) | 3 lines Bug #1550983: emit better error messages for erroneous relative imports (if not in package and if beyond toplevel package). ........ r51767 | neal.norwitz | 2006-09-06 08:28:06 +0200 (Wed, 06 Sep 2006) | 1 line with and as are now keywords. There are some generated files I can't recreate. ........ r51770 | georg.brandl | 2006-09-06 08:50:05 +0200 (Wed, 06 Sep 2006) | 5 lines Bug #1542051: Exceptions now correctly call PyObject_GC_UnTrack. Also make sure that every exception class has __module__ set to 'exceptions'. ........ r51785 | georg.brandl | 2006-09-06 22:05:58 +0200 (Wed, 06 Sep 2006) | 2 lines Fix missing import of the types module in logging.config. ........ r51789 | marc-andre.lemburg | 2006-09-06 22:40:22 +0200 (Wed, 06 Sep 2006) | 3 lines Add news item for bug fix of SF bug report #1546372. ........ r51797 | gustavo.niemeyer | 2006-09-07 02:48:33 +0200 (Thu, 07 Sep 2006) | 3 lines Fixed subprocess bug #1531862 again, after removing tests offending buildbot ........ r51798 | raymond.hettinger | 2006-09-07 04:42:48 +0200 (Thu, 07 Sep 2006) | 1 line Fix refcounts and add error checks. ........ r51803 | nick.coghlan | 2006-09-07 12:50:34 +0200 (Thu, 07 Sep 2006) | 1 line Fix the speed regression in inspect.py by adding another cache to speed up getmodule(). Patch #1553314 ........ r51805 | ronald.oussoren | 2006-09-07 14:03:10 +0200 (Thu, 07 Sep 2006) | 2 lines Fix a glaring error and update some version numbers. ........ r51814 | andrew.kuchling | 2006-09-07 15:56:23 +0200 (Thu, 07 Sep 2006) | 1 line Typo fix ........ r51815 | andrew.kuchling | 2006-09-07 15:59:38 +0200 (Thu, 07 Sep 2006) | 8 lines [Bug #1552726] Avoid repeatedly polling in interactive mode -- only put a timeout on the select() if an input hook has been defined. Patch by Richard Boulton. This select() code is only executed with readline 2.1, or if READLINE_CALLBACKS is defined. Backport candidate for 2.5, 2.4, probably earlier versions too. ........ r51816 | armin.rigo | 2006-09-07 17:06:00 +0200 (Thu, 07 Sep 2006) | 2 lines Add a warning notice on top of the generated grammar.txt. ........ r51819 | thomas.heller | 2006-09-07 20:56:28 +0200 (Thu, 07 Sep 2006) | 5 lines Anonymous structure fields that have a bit-width specified did not work, and they gave a strange error message from PyArg_ParseTuple: function takes exactly 2 arguments (3 given). With tests. ........ r51820 | thomas.heller | 2006-09-07 21:09:54 +0200 (Thu, 07 Sep 2006) | 4 lines The cast function did not accept c_char_p or c_wchar_p instances as first argument, and failed with a 'bad argument to internal function' error message. ........ r51827 | nick.coghlan | 2006-09-08 12:04:38 +0200 (Fri, 08 Sep 2006) | 1 line Add missing NEWS entry for rev 51803 ........ r51828 | andrew.kuchling | 2006-09-08 15:25:23 +0200 (Fri, 08 Sep 2006) | 1 line Add missing word ........ r51829 | andrew.kuchling | 2006-09-08 15:35:49 +0200 (Fri, 08 Sep 2006) | 1 line Explain SQLite a bit more clearly ........ r51830 | andrew.kuchling | 2006-09-08 15:36:36 +0200 (Fri, 08 Sep 2006) | 1 line Explain SQLite a bit more clearly ........ r51832 | andrew.kuchling | 2006-09-08 16:02:45 +0200 (Fri, 08 Sep 2006) | 1 line Use native SQLite types ........ r51833 | andrew.kuchling | 2006-09-08 16:03:01 +0200 (Fri, 08 Sep 2006) | 1 line Use native SQLite types ........ r51835 | andrew.kuchling | 2006-09-08 16:05:10 +0200 (Fri, 08 Sep 2006) | 1 line Fix typo in example ........ r51837 | brett.cannon | 2006-09-09 09:11:46 +0200 (Sat, 09 Sep 2006) | 6 lines Remove the __unicode__ method from exceptions. Allows unicode() to be called on exception classes. Would require introducing a tp_unicode slot to make it work otherwise. Fixes bug #1551432 and will be backported. ........ r51854 | neal.norwitz | 2006-09-11 06:24:09 +0200 (Mon, 11 Sep 2006) | 8 lines Forward port of 51850 from release25-maint branch. As mentioned on python-dev, reverting patch #1504333 because it introduced an infinite loop in rev 47154. This patch also adds a test to prevent the regression. ........ r51855 | neal.norwitz | 2006-09-11 06:28:16 +0200 (Mon, 11 Sep 2006) | 5 lines Properly handle a NULL returned from PyArena_New(). (Also fix some whitespace) Klocwork #364. ........ r51856 | neal.norwitz | 2006-09-11 06:32:57 +0200 (Mon, 11 Sep 2006) | 1 line Add a "crasher" taken from the sgml bug report referenced in the comment ........ r51858 | georg.brandl | 2006-09-11 11:38:35 +0200 (Mon, 11 Sep 2006) | 12 lines Forward-port of rev. 51857: Building with HP's cc on HP-UX turned up a couple of problems. _PyGILState_NoteThreadState was declared as static inconsistently. Make it static as it's not necessary outside of this module. Some tests failed because errno was reset to 0. (I think the tests that failed were at least: test_fcntl and test_mailbox). Ensure that errno doesn't change after a call to Py_END_ALLOW_THREADS. This only affected debug builds. ........ r51865 | martin.v.loewis | 2006-09-12 21:49:20 +0200 (Tue, 12 Sep 2006) | 2 lines Forward-port 51862: Add sgml_input.html. ........ r51866 | andrew.kuchling | 2006-09-12 22:50:23 +0200 (Tue, 12 Sep 2006) | 1 line Markup typo fix ........ r51867 | andrew.kuchling | 2006-09-12 23:09:02 +0200 (Tue, 12 Sep 2006) | 1 line Some editing, markup fixes ........ r51868 | andrew.kuchling | 2006-09-12 23:21:51 +0200 (Tue, 12 Sep 2006) | 1 line More wordsmithing ........ r51877 | andrew.kuchling | 2006-09-14 13:22:18 +0200 (Thu, 14 Sep 2006) | 1 line Make --help mention that -v can be supplied multiple times ........ r51878 | andrew.kuchling | 2006-09-14 13:28:50 +0200 (Thu, 14 Sep 2006) | 1 line Rewrite help message to remove some of the parentheticals. (There were a lot of them.) ........ r51883 | ka-ping.yee | 2006-09-15 02:34:19 +0200 (Fri, 15 Sep 2006) | 2 lines Fix grammar errors and improve clarity. ........ r51885 | georg.brandl | 2006-09-15 07:22:24 +0200 (Fri, 15 Sep 2006) | 3 lines Correct elementtree module index entry. ........ r51889 | fred.drake | 2006-09-15 17:18:04 +0200 (Fri, 15 Sep 2006) | 4 lines - fix module name in links in formatted documentation - minor markup cleanup (forward-ported from release25-maint revision 51888) ........ r51891 | fred.drake | 2006-09-15 18:11:27 +0200 (Fri, 15 Sep 2006) | 3 lines revise explanation of returns_unicode to reflect bool values and to include the default value (merged from release25-maint revision 51890) ........ r51897 | martin.v.loewis | 2006-09-16 19:36:37 +0200 (Sat, 16 Sep 2006) | 2 lines Patch #1557515: Add RLIMIT_SBSIZE. ........ r51903 | ronald.oussoren | 2006-09-17 20:42:53 +0200 (Sun, 17 Sep 2006) | 2 lines Port of revision 51902 in release25-maint to the trunk ........ r51904 | ronald.oussoren | 2006-09-17 21:23:27 +0200 (Sun, 17 Sep 2006) | 3 lines Tweak Mac/Makefile in to ensure that pythonw gets rebuild when the major version of python changes (2.5 -> 2.6). Bug #1552935. ........ r51913 | guido.van.rossum | 2006-09-18 23:36:16 +0200 (Mon, 18 Sep 2006) | 2 lines Make this thing executable. ........ r51920 | gregory.p.smith | 2006-09-19 19:35:04 +0200 (Tue, 19 Sep 2006) | 5 lines Fixes a bug with bsddb.DB.stat where the flags and txn keyword arguments are transposed. (reported by Louis Zechtzer) ..already committed to release24-maint ..needs committing to release25-maint ........ r51926 | brett.cannon | 2006-09-20 20:34:28 +0200 (Wed, 20 Sep 2006) | 3 lines Accidentally didn't commit Misc/NEWS entry on when __unicode__() was removed from exceptions. ........ r51927 | brett.cannon | 2006-09-20 20:43:13 +0200 (Wed, 20 Sep 2006) | 6 lines Allow exceptions to be directly sliced again (e.g., ``BaseException(1,2,3)[0:2]``). Discovered in Python 2.5.0 by Thomas Heller and reported to python-dev. This should be backported to 2.5 . ........ r51928 | brett.cannon | 2006-09-20 21:28:35 +0200 (Wed, 20 Sep 2006) | 2 lines Make python.vim output more deterministic. ........ r51949 | walter.doerwald | 2006-09-21 17:09:55 +0200 (Thu, 21 Sep 2006) | 2 lines Fix typo. ........ r51950 | jack.diederich | 2006-09-21 19:50:26 +0200 (Thu, 21 Sep 2006) | 5 lines * regression bug, count_next was coercing a Py_ssize_t to an unsigned Py_size_t which breaks negative counts * added test for negative numbers will backport to 2.5.1 ........ r51953 | jack.diederich | 2006-09-21 22:34:49 +0200 (Thu, 21 Sep 2006) | 1 line added itertools.count(-n) fix ........ r51971 | neal.norwitz | 2006-09-22 10:16:26 +0200 (Fri, 22 Sep 2006) | 10 lines Fix %zd string formatting on Mac OS X so it prints negative numbers. In addition to testing positive numbers, verify negative numbers work in configure. In order to avoid compiler warnings on OS X 10.4, also change the order of the check for the format character to use (PY_FORMAT_SIZE_T) in the sprintf format for Py_ssize_t. This patch changes PY_FORMAT_SIZE_T from "" to "l" if it wasn't defined at configure time. Need to verify the buildbot results. Backport candidate (if everyone thinks this patch can't be improved). ........ r51972 | neal.norwitz | 2006-09-22 10:18:10 +0200 (Fri, 22 Sep 2006) | 7 lines Bug #1557232: fix seg fault with def f((((x)))) and def f(((x),)). These tests should be improved. Hopefully this fixes variations when flipping back and forth between fpdef and fplist. Backport candidate. ........ r51975 | neal.norwitz | 2006-09-22 10:47:23 +0200 (Fri, 22 Sep 2006) | 4 lines Mostly revert this file to the same version as before. Only force setting of PY_FORMAT_SIZE_T to "l" for Mac OSX. I don't know a better define to use. This should get rid of the warnings on other platforms and Mac too. ........ r51986 | fred.drake | 2006-09-23 02:26:31 +0200 (Sat, 23 Sep 2006) | 1 line add boilerplate "What's New" document so the docs will build ........ r51987 | neal.norwitz | 2006-09-23 06:11:38 +0200 (Sat, 23 Sep 2006) | 1 line Remove extra semi-colons reported by Johnny Lee on python-dev. Backport if anyone cares. ........ r51989 | neal.norwitz | 2006-09-23 20:11:58 +0200 (Sat, 23 Sep 2006) | 1 line SF Bug #1563963, add missing word and cleanup first sentance ........ r51990 | brett.cannon | 2006-09-23 21:53:20 +0200 (Sat, 23 Sep 2006) | 3 lines Make output on test_strptime() be more verbose in face of failure. This is in hopes that more information will help debug the failing test on HPPA Ubuntu. ........ r51991 | georg.brandl | 2006-09-24 12:36:01 +0200 (Sun, 24 Sep 2006) | 2 lines Fix webbrowser.BackgroundBrowser on Windows. ........ r51993 | georg.brandl | 2006-09-24 14:35:36 +0200 (Sun, 24 Sep 2006) | 4 lines Fix a bug in the parser's future statement handling that led to "with" not being recognized as a keyword after, e.g., this statement: from __future__ import division, with_statement ........ r51995 | georg.brandl | 2006-09-24 14:50:24 +0200 (Sun, 24 Sep 2006) | 4 lines Fix a bug in traceback.format_exception_only() that led to an error being raised when print_exc() was called without an exception set. In version 2.4, this printed "None", restored that behavior. ........ r52000 | armin.rigo | 2006-09-25 17:16:26 +0200 (Mon, 25 Sep 2006) | 2 lines Another crasher. ........ r52011 | brett.cannon | 2006-09-27 01:38:24 +0200 (Wed, 27 Sep 2006) | 2 lines Make the error message for when the time data and format do not match clearer. ........ r52014 | andrew.kuchling | 2006-09-27 18:37:30 +0200 (Wed, 27 Sep 2006) | 1 line Add news item for rev. 51815 ........ r52018 | andrew.kuchling | 2006-09-27 21:23:05 +0200 (Wed, 27 Sep 2006) | 1 line Make examples do error checking on Py_InitModule ........ r52032 | brett.cannon | 2006-09-29 00:10:14 +0200 (Fri, 29 Sep 2006) | 2 lines Very minor grammatical fix in a comment. ........ r52048 | george.yoshida | 2006-09-30 07:14:02 +0200 (Sat, 30 Sep 2006) | 4 lines SF bug #1567976 : fix typo Will backport to 2.5. ........ r52051 | gregory.p.smith | 2006-09-30 08:08:20 +0200 (Sat, 30 Sep 2006) | 2 lines wording change ........ r52053 | georg.brandl | 2006-09-30 09:24:48 +0200 (Sat, 30 Sep 2006) | 2 lines Bug #1567375: a minor logical glitch in example description. ........ r52056 | georg.brandl | 2006-09-30 09:31:57 +0200 (Sat, 30 Sep 2006) | 3 lines Bug #1565661: in webbrowser, split() the command for the default GNOME browser in case it is a command with args. ........ r52058 | georg.brandl | 2006-09-30 10:43:30 +0200 (Sat, 30 Sep 2006) | 4 lines Patch #1567691: super() and new.instancemethod() now don't accept keyword arguments any more (previously they accepted them, but didn't use them). ........ r52061 | georg.brandl | 2006-09-30 11:03:42 +0200 (Sat, 30 Sep 2006) | 3 lines Bug #1566800: make sure that EnvironmentError can be called with any number of arguments, as was the case in Python 2.4. ........ r52063 | georg.brandl | 2006-09-30 11:06:45 +0200 (Sat, 30 Sep 2006) | 2 lines Bug #1566663: remove obsolete example from datetime docs. ........ r52065 | georg.brandl | 2006-09-30 11:13:21 +0200 (Sat, 30 Sep 2006) | 3 lines Bug #1566602: correct failure of posixpath unittest when $HOME ends with a slash. ........ r52068 | georg.brandl | 2006-09-30 12:58:01 +0200 (Sat, 30 Sep 2006) | 3 lines Bug #1457823: cgi.(Sv)FormContentDict's constructor now takes keep_blank_values and strict_parsing keyword arguments. ........ r52069 | georg.brandl | 2006-09-30 13:06:47 +0200 (Sat, 30 Sep 2006) | 3 lines Bug #1560617: in pyclbr, return full module name not only for classes, but also for functions. ........ r52072 | georg.brandl | 2006-09-30 13:17:34 +0200 (Sat, 30 Sep 2006) | 3 lines Bug #1556784: allow format strings longer than 127 characters in datetime's strftime function. ........ r52075 | georg.brandl | 2006-09-30 13:22:28 +0200 (Sat, 30 Sep 2006) | 3 lines Bug #1446043: correctly raise a LookupError if an encoding name given to encodings.search_function() contains a dot. ........ r52078 | georg.brandl | 2006-09-30 14:02:57 +0200 (Sat, 30 Sep 2006) | 3 lines Bug #1546052: clarify that PyString_FromString(AndSize) copies the string pointed to by its parameter. ........ r52080 | georg.brandl | 2006-09-30 14:16:03 +0200 (Sat, 30 Sep 2006) | 3 lines Convert test_import to unittest. ........ r52083 | kurt.kaiser | 2006-10-01 23:16:45 +0200 (Sun, 01 Oct 2006) | 5 lines Some syntax errors were being caught by tokenize during the tabnanny check, resulting in obscure error messages. Do the syntax check first. Bug 1562716, 1562719 ........ r52084 | kurt.kaiser | 2006-10-01 23:54:37 +0200 (Sun, 01 Oct 2006) | 3 lines Add comment explaining that error msgs may be due to user code when running w/o subprocess. ........ r52086 | martin.v.loewis | 2006-10-02 16:55:51 +0200 (Mon, 02 Oct 2006) | 3 lines Fix test for uintptr_t. Fixes #1568842. Will backport. ........ r52089 | martin.v.loewis | 2006-10-02 17:20:37 +0200 (Mon, 02 Oct 2006) | 3 lines Guard uintptr_t test with HAVE_STDINT_H, test for stdint.h. Will backport. ........ r52100 | vinay.sajip | 2006-10-03 20:02:37 +0200 (Tue, 03 Oct 2006) | 1 line Documentation omitted the additional parameter to LogRecord.__init__ which was added in 2.5. (See SF #1569622). ........ r52101 | vinay.sajip | 2006-10-03 20:20:26 +0200 (Tue, 03 Oct 2006) | 1 line Documentation clarified to mention optional parameters. ........ r52102 | vinay.sajip | 2006-10-03 20:21:56 +0200 (Tue, 03 Oct 2006) | 1 line Modified LogRecord.__init__ to make the func parameter optional. (See SF #1569622). ........ r52121 | brett.cannon | 2006-10-03 23:58:55 +0200 (Tue, 03 Oct 2006) | 2 lines Fix minor typo in a comment. ........ r52123 | brett.cannon | 2006-10-04 01:23:14 +0200 (Wed, 04 Oct 2006) | 2 lines Convert test_imp over to unittest. ........ r52128 | barry.warsaw | 2006-10-04 04:06:36 +0200 (Wed, 04 Oct 2006) | 3 lines decode_rfc2231(): As Christian Robottom Reis points out, it makes no sense to test for parts > 3 when we use .split(..., 2). ........ r52129 | jeremy.hylton | 2006-10-04 04:24:52 +0200 (Wed, 04 Oct 2006) | 9 lines Fix for SF bug 1569998: break permitted inside try. The compiler was checking that there was something on the fblock stack, but not that there was a loop on the stack. Fixed that and added a test for the specific syntax error. Bug fix candidate. ........ r52130 | martin.v.loewis | 2006-10-04 07:47:34 +0200 (Wed, 04 Oct 2006) | 4 lines Fix integer negation and absolute value to not rely on undefined behaviour of the C compiler anymore. Will backport to 2.5 and 2.4. ........ r52135 | martin.v.loewis | 2006-10-04 11:21:20 +0200 (Wed, 04 Oct 2006) | 1 line Forward port r52134: Add uuids for 2.4.4. ........ r52137 | armin.rigo | 2006-10-04 12:23:57 +0200 (Wed, 04 Oct 2006) | 3 lines Compilation problem caused by conflicting typedefs for uint32_t (unsigned long vs. unsigned int). ........ r52139 | armin.rigo | 2006-10-04 14:17:45 +0200 (Wed, 04 Oct 2006) | 23 lines Forward-port of r52136,52138: a review of overflow-detecting code. * unified the way intobject, longobject and mystrtoul handle values around -sys.maxint-1. * in general, trying to entierely avoid overflows in any computation involving signed ints or longs is extremely involved. Fixed a few simple cases where a compiler might be too clever (but that's all guesswork). * more overflow checks against bad data in marshal.c. * 2.5 specific: fixed a number of places that were still confusing int and Py_ssize_t. Some of them could potentially have caused "real-world" breakage. * list.pop(x): fixing overflow issues on x was messy. I just reverted to PyArg_ParseTuple("n"), which does the right thing. (An obscure test was trying to give a Decimal to list.pop()... doesn't make sense any more IMHO) * trying to write a few tests... ........ r52147 | andrew.kuchling | 2006-10-04 15:42:43 +0200 (Wed, 04 Oct 2006) | 6 lines Cause a PyObject_Malloc() failure to trigger a MemoryError, and then add 'if (PyErr_Occurred())' checks to various places so that NULL is returned properly. 2.4 backport candidate. ........ r52148 | martin.v.loewis | 2006-10-04 17:25:28 +0200 (Wed, 04 Oct 2006) | 1 line Add MSVC8 project files to create wininst-8.exe. ........ r52196 | brett.cannon | 2006-10-06 00:02:31 +0200 (Fri, 06 Oct 2006) | 7 lines Clarify what "re-initialization" means for init_builtin() and init_dynamic(). Also remove warning about re-initialization as possibly raising an execption as both call _PyImport_FindExtension() which pulls any module that was already imported from the Python process' extension cache and just copies the __dict__ into the module stored in sys.modules. ........ r52200 | fred.drake | 2006-10-06 02:03:45 +0200 (Fri, 06 Oct 2006) | 3 lines - update links - remove Sleepycat name now that they have been bought ........ r52204 | andrew.kuchling | 2006-10-06 12:41:01 +0200 (Fri, 06 Oct 2006) | 1 line Case fix ........ r52208 | georg.brandl | 2006-10-06 14:46:08 +0200 (Fri, 06 Oct 2006) | 3 lines Fix name. ........ r52211 | andrew.kuchling | 2006-10-06 15:18:26 +0200 (Fri, 06 Oct 2006) | 1 line [Bug #1545341] Allow 'classifier' parameter to be a tuple as well as a list. Will backport. ........ r52212 | armin.rigo | 2006-10-06 18:33:22 +0200 (Fri, 06 Oct 2006) | 4 lines A very minor bug fix: this code looks like it is designed to accept any hue value and do the modulo itself, except it doesn't quite do it in all cases. At least, the "cannot get here" comment was wrong. ........ r52213 | andrew.kuchling | 2006-10-06 20:51:55 +0200 (Fri, 06 Oct 2006) | 1 line Comment grammar ........ r52218 | skip.montanaro | 2006-10-07 13:05:02 +0200 (Sat, 07 Oct 2006) | 6 lines Note that the excel_tab class is registered as the "excel-tab" dialect. Fixes 1572471. Make a similar change for the excel class and clean up references to the Dialects and Formatting Parameters section in a few places. ........ r52221 | georg.brandl | 2006-10-08 09:11:54 +0200 (Sun, 08 Oct 2006) | 3 lines Add missing NEWS entry for rev. 52129. ........ r52223 | hyeshik.chang | 2006-10-08 15:48:34 +0200 (Sun, 08 Oct 2006) | 3 lines Bug #1572832: fix a bug in ISO-2022 codecs which may cause segfault when encoding non-BMP unicode characters. (Submitted by Ray Chason) ........ r52227 | ronald.oussoren | 2006-10-08 19:37:58 +0200 (Sun, 08 Oct 2006) | 4 lines Add version number to the link to the python documentation in /Developer/Documentation/Python, better for users that install multiple versions of python. ........ r52229 | ronald.oussoren | 2006-10-08 19:40:02 +0200 (Sun, 08 Oct 2006) | 2 lines Fix for bug #1570284 ........ r52233 | ronald.oussoren | 2006-10-08 19:49:52 +0200 (Sun, 08 Oct 2006) | 6 lines MacOSX: distutils changes the values of BASECFLAGS and LDFLAGS when using a universal build of python on OSX 10.3 to ensure that those flags can be used to compile code (the universal build uses compiler flags that aren't supported on 10.3). This patches gives the same treatment to CFLAGS, PY_CFLAGS and BLDSHARED. ........ r52236 | ronald.oussoren | 2006-10-08 19:51:46 +0200 (Sun, 08 Oct 2006) | 5 lines MacOSX: The universal build requires that users have the MacOSX10.4u SDK installed to build extensions. This patch makes distutils emit a warning when the compiler should use an SDK but that SDK is not installed, hopefully reducing some confusion. ........ r52238 | ronald.oussoren | 2006-10-08 20:18:26 +0200 (Sun, 08 Oct 2006) | 3 lines MacOSX: add more logic to recognize the correct startup file to patch to the shell profile patching post-install script. ........ r52242 | andrew.kuchling | 2006-10-09 19:10:12 +0200 (Mon, 09 Oct 2006) | 1 line Add news item for rev. 52211 change ........ r52245 | andrew.kuchling | 2006-10-09 20:05:19 +0200 (Mon, 09 Oct 2006) | 1 line Fix wording in comment ........ r52251 | georg.brandl | 2006-10-09 21:03:06 +0200 (Mon, 09 Oct 2006) | 2 lines Patch #1572724: fix typo ('=' instead of '==') in _msi.c. ........ r52255 | barry.warsaw | 2006-10-09 21:43:24 +0200 (Mon, 09 Oct 2006) | 2 lines List gc.get_count() in the module docstring. ........ r52257 | martin.v.loewis | 2006-10-09 22:44:25 +0200 (Mon, 09 Oct 2006) | 1 line Bug #1565150: Fix subsecond processing for os.utime on Windows. ........ r52268 | ronald.oussoren | 2006-10-10 09:55:06 +0200 (Tue, 10 Oct 2006) | 2 lines MacOSX: fix permission problem in the generated installer ........ r52293 | georg.brandl | 2006-10-12 09:38:04 +0200 (Thu, 12 Oct 2006) | 2 lines Bug #1575746: fix typo in property() docs. ........ r52295 | georg.brandl | 2006-10-12 09:57:21 +0200 (Thu, 12 Oct 2006) | 3 lines Bug #813342: Start the IDLE subprocess with -Qnew if the parent is started with that option. ........ r52297 | georg.brandl | 2006-10-12 10:22:53 +0200 (Thu, 12 Oct 2006) | 2 lines Bug #1565919: document set types in the Language Reference. ........ r52299 | georg.brandl | 2006-10-12 11:20:33 +0200 (Thu, 12 Oct 2006) | 3 lines Bug #1550524: better heuristics to find correct class definition in inspect.findsource(). ........ r52301 | georg.brandl | 2006-10-12 11:47:12 +0200 (Thu, 12 Oct 2006) | 4 lines Bug #1548891: The cStringIO.StringIO() constructor now encodes unicode arguments with the system default encoding just like the write() method does, instead of converting it to a raw buffer. ........ r52303 | georg.brandl | 2006-10-12 13:14:40 +0200 (Thu, 12 Oct 2006) | 2 lines Bug #1546628: add a note about urlparse.urljoin() and absolute paths. ........ r52305 | georg.brandl | 2006-10-12 13:27:59 +0200 (Thu, 12 Oct 2006) | 3 lines Bug #1545497: when given an explicit base, int() did ignore NULs embedded in the string to convert. ........ r52307 | georg.brandl | 2006-10-12 13:41:11 +0200 (Thu, 12 Oct 2006) | 3 lines Add a note to fpectl docs that it's not built by default (bug #1556261). ........ r52309 | georg.brandl | 2006-10-12 13:46:57 +0200 (Thu, 12 Oct 2006) | 3 lines Bug #1560114: the Mac filesystem does have accurate information about the case of filenames. ........ r52311 | georg.brandl | 2006-10-12 13:59:27 +0200 (Thu, 12 Oct 2006) | 2 lines Small grammar fix, thanks Sjoerd. ........ r52313 | georg.brandl | 2006-10-12 14:03:07 +0200 (Thu, 12 Oct 2006) | 2 lines Fix tarfile depending on buggy int('1\0', base) behavior. ........ r52315 | georg.brandl | 2006-10-12 14:33:07 +0200 (Thu, 12 Oct 2006) | 2 lines Bug #1283491: follow docstring convention wrt. keyword-able args in sum(). ........ r52316 | georg.brandl | 2006-10-12 15:08:16 +0200 (Thu, 12 Oct 2006) | 3 lines Bug #1560179: speed up posixpath.(dir|base)name ........ r52327 | brett.cannon | 2006-10-14 08:36:45 +0200 (Sat, 14 Oct 2006) | 3 lines Clean up the language of a sentence relating to the connect() function and user-defined datatypes. ........ r52332 | neal.norwitz | 2006-10-14 23:33:38 +0200 (Sat, 14 Oct 2006) | 3 lines Update the peephole optimizer to remove more dead code (jumps after returns) and inline jumps to returns. ........ r52333 | martin.v.loewis | 2006-10-15 09:54:40 +0200 (Sun, 15 Oct 2006) | 4 lines Patch #1576954: Update VC6 build directory; remove redundant files in VC7. Will backport to 2.5. ........ r52335 | martin.v.loewis | 2006-10-15 10:43:33 +0200 (Sun, 15 Oct 2006) | 1 line Patch #1576166: Support os.utime for directories on Windows NT+. ........ r52336 | martin.v.loewis | 2006-10-15 10:51:22 +0200 (Sun, 15 Oct 2006) | 2 lines Patch #1577551: Add ctypes and ET build support for VC6. Will backport to 2.5. ........ r52338 | martin.v.loewis | 2006-10-15 11:35:51 +0200 (Sun, 15 Oct 2006) | 1 line Loosen the test for equal time stamps. ........ r52339 | martin.v.loewis | 2006-10-15 11:43:39 +0200 (Sun, 15 Oct 2006) | 2 lines Bug #1567666: Emulate GetFileAttributesExA for Win95. Will backport to 2.5. ........ r52341 | martin.v.loewis | 2006-10-15 13:02:07 +0200 (Sun, 15 Oct 2006) | 2 lines Round to int, because some systems support sub-second time stamps in stat, but not in utime. Also be consistent with modifying only mtime, not atime. ........ r52342 | martin.v.loewis | 2006-10-15 13:57:40 +0200 (Sun, 15 Oct 2006) | 2 lines Set the eol-style for project files to "CRLF". ........ r52343 | martin.v.loewis | 2006-10-15 13:59:56 +0200 (Sun, 15 Oct 2006) | 3 lines Drop binary property on dsp files, set eol-style to CRLF instead. ........ r52344 | martin.v.loewis | 2006-10-15 14:01:43 +0200 (Sun, 15 Oct 2006) | 2 lines Remove binary property, set eol-style to CRLF instead. ........ r52346 | martin.v.loewis | 2006-10-15 16:30:38 +0200 (Sun, 15 Oct 2006) | 2 lines Mention the bdist_msi module. Will backport to 2.5. ........ r52354 | brett.cannon | 2006-10-16 05:09:52 +0200 (Mon, 16 Oct 2006) | 3 lines Fix turtle so that you can launch the demo2 function on its own instead of only when the module is launched as a script. ........ r52356 | martin.v.loewis | 2006-10-17 17:18:06 +0200 (Tue, 17 Oct 2006) | 2 lines Patch #1457736: Update VC6 to use current PCbuild settings. Will backport to 2.5. ........ r52360 | martin.v.loewis | 2006-10-17 20:09:55 +0200 (Tue, 17 Oct 2006) | 2 lines Remove obsolete file. Will backport. ........ r52363 | martin.v.loewis | 2006-10-17 20:59:23 +0200 (Tue, 17 Oct 2006) | 4 lines Forward-port r52358: - Bug #1578513: Cross compilation was broken by a change to configure. Repair so that it's back to how it was in 2.4.3. ........ r52365 | thomas.heller | 2006-10-17 21:30:48 +0200 (Tue, 17 Oct 2006) | 6 lines ctypes callback functions only support 'fundamental' result types. Check this and raise an error when something else is used - before this change ctypes would hang or crash when such a callback was called. This is a partial fix for #1574584. Will backport to release25-maint. ........ r52377 | tim.peters | 2006-10-18 07:06:06 +0200 (Wed, 18 Oct 2006) | 2 lines newIobject(): repaired incorrect cast to quiet MSVC warning. ........ r52378 | tim.peters | 2006-10-18 07:09:12 +0200 (Wed, 18 Oct 2006) | 2 lines Whitespace normalization. ........ r52379 | tim.peters | 2006-10-18 07:10:28 +0200 (Wed, 18 Oct 2006) | 2 lines Add missing svn:eol-style to text files. ........ r52387 | martin.v.loewis | 2006-10-19 12:58:46 +0200 (Thu, 19 Oct 2006) | 3 lines Add check for the PyArg_ParseTuple format, and declare it if it is supported. ........ r52388 | martin.v.loewis | 2006-10-19 13:00:37 +0200 (Thu, 19 Oct 2006) | 3 lines Fix various minor errors in passing arguments to PyArg_ParseTuple. ........ r52389 | martin.v.loewis | 2006-10-19 18:01:37 +0200 (Thu, 19 Oct 2006) | 2 lines Restore CFLAGS after checking for __attribute__ ........ r52390 | andrew.kuchling | 2006-10-19 23:55:55 +0200 (Thu, 19 Oct 2006) | 1 line [Bug #1576348] Fix typo in example ........ r52414 | walter.doerwald | 2006-10-22 10:59:41 +0200 (Sun, 22 Oct 2006) | 2 lines Port test___future__ to unittest. ........ r52415 | ronald.oussoren | 2006-10-22 12:45:18 +0200 (Sun, 22 Oct 2006) | 3 lines Patch #1580674: with this patch os.readlink uses the filesystem encoding to decode unicode objects and returns an unicode object when the argument is one. ........ r52416 | martin.v.loewis | 2006-10-22 12:46:18 +0200 (Sun, 22 Oct 2006) | 3 lines Patch #1580872: Remove duplicate declaration of PyCallable_Check. Will backport to 2.5. ........ r52418 | martin.v.loewis | 2006-10-22 12:55:15 +0200 (Sun, 22 Oct 2006) | 4 lines - Patch #1560695: Add .note.GNU-stack to ctypes' sysv.S so that ctypes isn't considered as requiring executable stacks. Will backport to 2.5. ........ r52420 | martin.v.loewis | 2006-10-22 15:45:13 +0200 (Sun, 22 Oct 2006) | 3 lines Remove passwd.adjunct.byname from list of maps for test_nis. Will backport to 2.5. ........ r52431 | georg.brandl | 2006-10-24 18:54:16 +0200 (Tue, 24 Oct 2006) | 2 lines Patch [ 1583506 ] tarfile.py: 100-char filenames are truncated ........ r52446 | andrew.kuchling | 2006-10-26 21:10:46 +0200 (Thu, 26 Oct 2006) | 1 line [Bug #1579796] Wrong syntax for PyDateTime_IMPORT in documentation. Reported by David Faure. ........ r52449 | andrew.kuchling | 2006-10-26 21:16:46 +0200 (Thu, 26 Oct 2006) | 1 line Typo fix ........ r52452 | martin.v.loewis | 2006-10-27 08:16:31 +0200 (Fri, 27 Oct 2006) | 3 lines Patch #1549049: Rewrite type conversion in structmember. Fixes #1545696 and #1566140. Will backport to 2.5. ........ r52454 | martin.v.loewis | 2006-10-27 08:42:27 +0200 (Fri, 27 Oct 2006) | 2 lines Check for values.h. Will backport. ........ r52456 | martin.v.loewis | 2006-10-27 09:06:52 +0200 (Fri, 27 Oct 2006) | 2 lines Get DBL_MAX from float.h not values.h. Will backport. ........ r52458 | martin.v.loewis | 2006-10-27 09:13:28 +0200 (Fri, 27 Oct 2006) | 2 lines Patch #1567274: Support SMTP over TLS. ........ r52459 | andrew.kuchling | 2006-10-27 13:33:29 +0200 (Fri, 27 Oct 2006) | 1 line Set svn:keywords property ........ r52460 | andrew.kuchling | 2006-10-27 13:36:41 +0200 (Fri, 27 Oct 2006) | 1 line Add item ........ r52461 | andrew.kuchling | 2006-10-27 13:37:01 +0200 (Fri, 27 Oct 2006) | 1 line Some wording changes and markup fixes ........ r52462 | andrew.kuchling | 2006-10-27 14:18:38 +0200 (Fri, 27 Oct 2006) | 1 line [Bug #1585690] Note that line_num was added in Python 2.5 ........ r52464 | andrew.kuchling | 2006-10-27 14:50:38 +0200 (Fri, 27 Oct 2006) | 1 line [Bug #1583946] Reword description of server and issuer ........ r52466 | andrew.kuchling | 2006-10-27 15:06:25 +0200 (Fri, 27 Oct 2006) | 1 line [Bug #1562583] Mention the set_reuse_addr() method ........ r52469 | andrew.kuchling | 2006-10-27 15:22:46 +0200 (Fri, 27 Oct 2006) | 4 lines [Bug #1542016] Report PCALL_POP value. This makes the return value of sys.callstats() match its docstring. Backport candidate. Though it's an API change, this is a pretty obscure portion of the API. ........ r52473 | andrew.kuchling | 2006-10-27 16:53:41 +0200 (Fri, 27 Oct 2006) | 1 line Point users to the subprocess module in the docs for os.system, os.spawn*, os.popen2, and the popen2 and commands modules ........ r52476 | andrew.kuchling | 2006-10-27 18:39:10 +0200 (Fri, 27 Oct 2006) | 1 line [Bug #1576241] Let functools.wraps work with built-in functions ........ r52478 | andrew.kuchling | 2006-10-27 18:55:34 +0200 (Fri, 27 Oct 2006) | 1 line [Bug #1575506] The _singlefileMailbox class was using the wrong file object in its flush() method, causing an error ........ r52480 | andrew.kuchling | 2006-10-27 19:06:16 +0200 (Fri, 27 Oct 2006) | 1 line Clarify docstring ........ r52481 | andrew.kuchling | 2006-10-27 19:11:23 +0200 (Fri, 27 Oct 2006) | 5 lines [Patch #1574068 by Scott Dial] urllib and urllib2 were using base64.encodestring() for encoding authentication data. encodestring() can include newlines for very long input, which produced broken HTTP headers. ........ r52483 | andrew.kuchling | 2006-10-27 20:13:46 +0200 (Fri, 27 Oct 2006) | 1 line Check db_setup_debug for a few print statements; change sqlite_setup_debug to False ........ r52484 | andrew.kuchling | 2006-10-27 20:15:02 +0200 (Fri, 27 Oct 2006) | 1 line [Patch #1503717] Tiny patch from Chris AtLee to stop a lengthy line from being printed ........ r52485 | thomas.heller | 2006-10-27 20:31:36 +0200 (Fri, 27 Oct 2006) | 5 lines WindowsError.str should display the windows error code, not the posix error code; with test. Fixes #1576174. Will backport to release25-maint. ........ r52487 | thomas.heller | 2006-10-27 21:05:53 +0200 (Fri, 27 Oct 2006) | 4 lines Modulefinder now handles absolute and relative imports, including tests. Will backport to release25-maint. ........ r52488 | georg.brandl | 2006-10-27 22:39:43 +0200 (Fri, 27 Oct 2006) | 2 lines Patch #1552024: add decorator support to unparse.py demo script. ........ r52492 | walter.doerwald | 2006-10-28 12:47:12 +0200 (Sat, 28 Oct 2006) | 2 lines Port test_bufio to unittest. ........ r52493 | georg.brandl | 2006-10-28 15:10:17 +0200 (Sat, 28 Oct 2006) | 6 lines Convert test_global, test_scope and test_grammar to unittest. I tried to enclose all tests which must be run at the toplevel (instead of inside a method) in exec statements. ........ r52494 | georg.brandl | 2006-10-28 15:11:41 +0200 (Sat, 28 Oct 2006) | 3 lines Update outstanding bugs test file. ........ r52495 | georg.brandl | 2006-10-28 15:51:49 +0200 (Sat, 28 Oct 2006) | 3 lines Convert test_math to unittest. ........ r52496 | georg.brandl | 2006-10-28 15:56:58 +0200 (Sat, 28 Oct 2006) | 3 lines Convert test_opcodes to unittest. ........ r52497 | georg.brandl | 2006-10-28 18:04:04 +0200 (Sat, 28 Oct 2006) | 2 lines Fix nth() itertool recipe. ........ r52500 | georg.brandl | 2006-10-28 22:25:09 +0200 (Sat, 28 Oct 2006) | 2 lines make test_grammar pass with python -O ........ r52501 | neal.norwitz | 2006-10-28 23:15:30 +0200 (Sat, 28 Oct 2006) | 6 lines Add some asserts. In sysmodule, I think these were to try to silence some warnings from Klokwork. They verify the assumptions of the format of svn version output. The assert in the thread module helped debug a problem on HP-UX. ........ r52502 | neal.norwitz | 2006-10-28 23:16:54 +0200 (Sat, 28 Oct 2006) | 5 lines Fix warnings with HP's C compiler. It doesn't recognize that infinite loops are, um, infinite. These conditions should not be able to happen. Will backport. ........ r52503 | neal.norwitz | 2006-10-28 23:17:51 +0200 (Sat, 28 Oct 2006) | 5 lines Fix crash in test on HP-UX. Apparently, it's not possible to delete a lock if it's held (even by the current thread). Will backport. ........ r52504 | neal.norwitz | 2006-10-28 23:19:07 +0200 (Sat, 28 Oct 2006) | 6 lines Fix bug #1565514, SystemError not raised on too many nested blocks. It seems like this should be a different error than SystemError, but I don't have any great ideas and SystemError was raised in 2.4 and earlier. Will backport. ........ r52505 | neal.norwitz | 2006-10-28 23:20:12 +0200 (Sat, 28 Oct 2006) | 4 lines Prevent crash if alloc of garbage fails. Found by Typo.pl. Will backport. ........ r52506 | neal.norwitz | 2006-10-28 23:21:00 +0200 (Sat, 28 Oct 2006) | 4 lines Don't inline Py_ADDRESS_IN_RANGE with gcc 4+ either. Will backport. ........ r52513 | neal.norwitz | 2006-10-28 23:56:49 +0200 (Sat, 28 Oct 2006) | 2 lines Fix test_modulefinder so it doesn't fail when run after test_distutils. ........ r52514 | neal.norwitz | 2006-10-29 00:12:26 +0200 (Sun, 29 Oct 2006) | 4 lines From SF 1557890, fix problem of using wrong type in example. Will backport. ........ r52517 | georg.brandl | 2006-10-29 09:39:22 +0100 (Sun, 29 Oct 2006) | 4 lines Fix codecs.EncodedFile which did not use file_encoding in 2.5.0, and fix all codecs file wrappers to work correctly with the "with" statement (bug #1586513). ........ r52519 | georg.brandl | 2006-10-29 09:47:08 +0100 (Sun, 29 Oct 2006) | 3 lines Clean up a leftover from old listcomp generation code. ........ r52520 | georg.brandl | 2006-10-29 09:53:06 +0100 (Sun, 29 Oct 2006) | 4 lines Bug #1586448: the compiler module now emits the same bytecode for list comprehensions as the builtin compiler, using the LIST_APPEND opcode. ........ r52521 | georg.brandl | 2006-10-29 10:01:01 +0100 (Sun, 29 Oct 2006) | 3 lines Remove trailing comma. ........ r52522 | georg.brandl | 2006-10-29 10:05:04 +0100 (Sun, 29 Oct 2006) | 3 lines Bug #1357915: allow all sequence types for shell arguments in subprocess. ........ r52524 | georg.brandl | 2006-10-29 10:16:12 +0100 (Sun, 29 Oct 2006) | 3 lines Patch #1583880: fix tarfile's problems with long names and posix/ GNU modes. ........ r52526 | georg.brandl | 2006-10-29 10:18:00 +0100 (Sun, 29 Oct 2006) | 3 lines Test assert if __debug__ is true. ........ r52527 | georg.brandl | 2006-10-29 10:32:16 +0100 (Sun, 29 Oct 2006) | 2 lines Fix the new EncodedFile test to work with big endian platforms. ........ r52529 | georg.brandl | 2006-10-29 15:39:09 +0100 (Sun, 29 Oct 2006) | 2 lines Bug #1586613: fix zlib and bz2 codecs' incremental en/decoders. ........ r52532 | georg.brandl | 2006-10-29 19:01:08 +0100 (Sun, 29 Oct 2006) | 2 lines Bug #1586773: extend hashlib docstring. ........ r52534 | neal.norwitz | 2006-10-29 19:30:10 +0100 (Sun, 29 Oct 2006) | 4 lines Update comments, remove commented out code. Move assembler structure next to assembler code to make it easier to move it to a separate file. ........ r52535 | georg.brandl | 2006-10-29 19:31:42 +0100 (Sun, 29 Oct 2006) | 3 lines Bug #1576657: when setting a KeyError for a tuple key, make sure that the tuple isn't used as the "exception arguments tuple". ........ r52537 | georg.brandl | 2006-10-29 20:13:40 +0100 (Sun, 29 Oct 2006) | 3 lines Convert test_mmap to unittest. ........ r52538 | georg.brandl | 2006-10-29 20:20:45 +0100 (Sun, 29 Oct 2006) | 3 lines Convert test_poll to unittest. ........ r52539 | georg.brandl | 2006-10-29 20:24:43 +0100 (Sun, 29 Oct 2006) | 3 lines Convert test_nis to unittest. ........ r52540 | georg.brandl | 2006-10-29 20:35:03 +0100 (Sun, 29 Oct 2006) | 3 lines Convert test_types to unittest. ........ r52541 | georg.brandl | 2006-10-29 20:51:16 +0100 (Sun, 29 Oct 2006) | 3 lines Convert test_cookie to unittest. ........ r52542 | georg.brandl | 2006-10-29 21:09:12 +0100 (Sun, 29 Oct 2006) | 3 lines Convert test_cgi to unittest. ........ r52543 | georg.brandl | 2006-10-29 21:24:01 +0100 (Sun, 29 Oct 2006) | 3 lines Completely convert test_httplib to unittest. ........ r52544 | georg.brandl | 2006-10-29 21:28:26 +0100 (Sun, 29 Oct 2006) | 2 lines Convert test_MimeWriter to unittest. ........ r52545 | georg.brandl | 2006-10-29 21:31:17 +0100 (Sun, 29 Oct 2006) | 3 lines Convert test_openpty to unittest. ........ r52546 | georg.brandl | 2006-10-29 21:35:12 +0100 (Sun, 29 Oct 2006) | 3 lines Remove leftover test output file. ........ r52547 | georg.brandl | 2006-10-29 22:54:18 +0100 (Sun, 29 Oct 2006) | 3 lines Move the check for openpty to the beginning. ........ r52548 | walter.doerwald | 2006-10-29 23:06:28 +0100 (Sun, 29 Oct 2006) | 2 lines Add tests for basic argument errors. ........ r52549 | walter.doerwald | 2006-10-30 00:02:27 +0100 (Mon, 30 Oct 2006) | 3 lines Add tests for incremental codecs with an errors argument. ........ r52550 | neal.norwitz | 2006-10-30 00:39:03 +0100 (Mon, 30 Oct 2006) | 1 line Fix refleak ........ r52552 | neal.norwitz | 2006-10-30 00:58:36 +0100 (Mon, 30 Oct 2006) | 1 line I'm assuming this is correct, it fixes the tests so they pass again ........ r52555 | vinay.sajip | 2006-10-31 18:32:37 +0100 (Tue, 31 Oct 2006) | 1 line Change to improve speed of _fixupChildren ........ r52556 | vinay.sajip | 2006-10-31 18:34:31 +0100 (Tue, 31 Oct 2006) | 1 line Added relativeCreated to Formatter doc (has been in the system for a long time - was unaccountably left out of the docs and not noticed until now). ........ r52588 | thomas.heller | 2006-11-02 20:48:24 +0100 (Thu, 02 Nov 2006) | 5 lines Replace the XXX marker in the 'Arrays and pointers' reference manual section with a link to the tutorial sections. Will backport to release25-maint. ........ r52592 | thomas.heller | 2006-11-02 21:22:29 +0100 (Thu, 02 Nov 2006) | 6 lines Fix a code example by adding a missing import. Fixes #1557890. Will backport to release25-maint. ........ r52598 | tim.peters | 2006-11-03 03:32:46 +0100 (Fri, 03 Nov 2006) | 2 lines Whitespace normalization. ........ r52619 | martin.v.loewis | 2006-11-04 19:14:06 +0100 (Sat, 04 Nov 2006) | 4 lines - Patch #1060577: Extract list of RPM files from spec file in bdist_rpm Will backport to 2.5. ........ r52621 | neal.norwitz | 2006-11-04 20:25:22 +0100 (Sat, 04 Nov 2006) | 4 lines Bug #1588287: fix invalid assertion for `1,2` in debug builds. Will backport ........ r52630 | andrew.kuchling | 2006-11-05 22:04:37 +0100 (Sun, 05 Nov 2006) | 1 line Update link ........ r52631 | skip.montanaro | 2006-11-06 15:34:52 +0100 (Mon, 06 Nov 2006) | 1 line note that user can control directory location even if default dir is used ........ r52644 | ronald.oussoren | 2006-11-07 16:53:38 +0100 (Tue, 07 Nov 2006) | 2 lines Fix a number of typos in strings and comments (sf#1589070) ........ r52647 | ronald.oussoren | 2006-11-07 17:00:34 +0100 (Tue, 07 Nov 2006) | 2 lines Whitespace changes to make the source more compliant with PEP8 (SF#1589070) ........ r52651 | thomas.heller | 2006-11-07 19:01:18 +0100 (Tue, 07 Nov 2006) | 3 lines Fix markup. Will backport to release25-maint. ........ r52653 | thomas.heller | 2006-11-07 19:20:47 +0100 (Tue, 07 Nov 2006) | 3 lines Fix grammatical error as well. Will backport to release25-maint. ........ r52657 | andrew.kuchling | 2006-11-07 21:39:16 +0100 (Tue, 07 Nov 2006) | 1 line Add missing word ........ r52662 | martin.v.loewis | 2006-11-08 07:46:37 +0100 (Wed, 08 Nov 2006) | 4 lines Correctly forward exception in instance_contains(). Fixes #1591996. Patch contributed by Neal Norwitz. Will backport. ........ r52664 | martin.v.loewis | 2006-11-08 07:48:36 +0100 (Wed, 08 Nov 2006) | 2 lines News entry for 52662. ........ r52665 | martin.v.loewis | 2006-11-08 08:35:55 +0100 (Wed, 08 Nov 2006) | 2 lines Patch #1351744: Add askyesnocancel helper for tkMessageBox. ........ r52666 | georg.brandl | 2006-11-08 08:45:59 +0100 (Wed, 08 Nov 2006) | 2 lines Patch #1592072: fix docs for return value of PyErr_CheckSignals. ........ r52668 | georg.brandl | 2006-11-08 11:04:29 +0100 (Wed, 08 Nov 2006) | 3 lines Bug #1592533: rename variable in heapq doc example, to avoid shadowing "sorted". ........ r52671 | andrew.kuchling | 2006-11-08 14:35:34 +0100 (Wed, 08 Nov 2006) | 1 line Add section on the functional module ........ r52672 | andrew.kuchling | 2006-11-08 15:14:30 +0100 (Wed, 08 Nov 2006) | 1 line Add section on operator module; make a few edits ........ r52673 | andrew.kuchling | 2006-11-08 15:24:03 +0100 (Wed, 08 Nov 2006) | 1 line Add table of contents; this required fixing a few headings. Some more smalle edits. ........ r52674 | andrew.kuchling | 2006-11-08 15:30:14 +0100 (Wed, 08 Nov 2006) | 1 line More edits ........ r52686 | martin.v.loewis | 2006-11-09 12:06:03 +0100 (Thu, 09 Nov 2006) | 3 lines Patch #838546: Make terminal become controlling in pty.fork(). Will backport to 2.5. ........ r52688 | martin.v.loewis | 2006-11-09 12:27:32 +0100 (Thu, 09 Nov 2006) | 2 lines Patch #1592250: Add elidge argument to Tkinter.Text.search. ........ r52690 | andrew.kuchling | 2006-11-09 14:27:07 +0100 (Thu, 09 Nov 2006) | 7 lines [Bug #1569790] mailbox.Maildir.get_folder() loses factory information Both the Maildir and MH classes had this bug; the patch fixes both classes and adds a test. Will backport to 25-maint. ........ r52692 | andrew.kuchling | 2006-11-09 14:51:14 +0100 (Thu, 09 Nov 2006) | 1 line [Patch #1514544 by David Watson] use fsync() to ensure data is really on disk ........ r52695 | walter.doerwald | 2006-11-09 17:23:26 +0100 (Thu, 09 Nov 2006) | 2 lines Replace C++ comment with C comment (fixes SF bug #1593525). ........ r52712 | andrew.kuchling | 2006-11-09 22:16:46 +0100 (Thu, 09 Nov 2006) | 11 lines [Patch #1514543] mailbox (Maildir): avoid losing messages on name clash Two changes: Where possible, use link()/remove() to move files into a directory; this makes it easier to avoid overwriting an existing file. Use _create_carefully() to create files in tmp/, which uses O_EXCL. Backport candidate. ........ r52716 | phillip.eby | 2006-11-10 01:33:36 +0100 (Fri, 10 Nov 2006) | 4 lines Fix SF#1566719: not creating site-packages (or other target directory) when installing .egg-info for a project that contains no modules or packages, while using --root (as in bdist_rpm). ........ r52719 | andrew.kuchling | 2006-11-10 14:14:01 +0100 (Fri, 10 Nov 2006) | 1 line Reword entry ........ r52725 | andrew.kuchling | 2006-11-10 15:39:01 +0100 (Fri, 10 Nov 2006) | 1 line [Feature request #1542920] Link to wsgi.org ........ r52731 | georg.brandl | 2006-11-11 19:29:11 +0100 (Sat, 11 Nov 2006) | 2 lines Bug #1594742: wrong word in stringobject doc. ........ r52733 | georg.brandl | 2006-11-11 19:32:47 +0100 (Sat, 11 Nov 2006) | 2 lines Bug #1594758: wording improvement for dict.update() docs. ........ r52736 | martin.v.loewis | 2006-11-12 11:32:47 +0100 (Sun, 12 Nov 2006) | 3 lines Patch #1065257: Support passing open files as body in HTTPConnection.request(). ........ r52737 | martin.v.loewis | 2006-11-12 11:41:39 +0100 (Sun, 12 Nov 2006) | 2 lines Patch #1355023: support whence argument for GzipFile.seek. ........ r52738 | martin.v.loewis | 2006-11-12 19:24:26 +0100 (Sun, 12 Nov 2006) | 2 lines Bug #1067760: Deprecate passing floats to file.seek. ........ r52739 | martin.v.loewis | 2006-11-12 19:48:13 +0100 (Sun, 12 Nov 2006) | 3 lines Patch #1359217: Ignore 2xx response before 150 response. Will backport to 2.5. ........ r52741 | martin.v.loewis | 2006-11-12 19:56:03 +0100 (Sun, 12 Nov 2006) | 4 lines Patch #1360200: Use unmangled_version RPM spec field to deal with file name mangling. Will backport to 2.5. ........ r52753 | walter.doerwald | 2006-11-15 17:23:46 +0100 (Wed, 15 Nov 2006) | 2 lines Fix typo. ........ r52754 | georg.brandl | 2006-11-15 18:42:03 +0100 (Wed, 15 Nov 2006) | 2 lines Bug #1594809: add a note to README regarding PYTHONPATH and make install. ........ r52762 | georg.brandl | 2006-11-16 16:05:14 +0100 (Thu, 16 Nov 2006) | 2 lines Bug #1597576: mention that the new base64 api has been introduced in py2.4. ........ r52764 | georg.brandl | 2006-11-16 17:50:59 +0100 (Thu, 16 Nov 2006) | 3 lines Bug #1597824: return the registered function from atexit.register() to facilitate usage as a decorator. ........ r52765 | georg.brandl | 2006-11-16 18:08:45 +0100 (Thu, 16 Nov 2006) | 4 lines Bug #1588217: don't parse "= " as a soft line break in binascii's a2b_qp() function, instead leave it in the string as quopri.decode() does. ........ r52776 | andrew.kuchling | 2006-11-17 14:30:25 +0100 (Fri, 17 Nov 2006) | 17 lines Remove file-locking in MH.pack() method. This change looks massive but it's mostly a re-indenting after removing some try...finally blocks. Also adds a test case that does a pack() while the mailbox is locked; this test would have turned up bugs in the original code on some platforms. In both nmh and GNU Mailutils' implementation of MH-format mailboxes, no locking is done of individual message files when renaming them. The original mailbox.py code did do locking, which meant that message files had to be opened. This code was buggy on certain platforms (found through reading the code); there were code paths that closed the file object and then called _unlock_file() on it. Will backport to 25-maint once I see how the buildbots react to this patch. ........ r52780 | martin.v.loewis | 2006-11-18 19:00:23 +0100 (Sat, 18 Nov 2006) | 5 lines Patch #1538878: Don't make tkSimpleDialog dialogs transient if the parent window is withdrawn. This mirrors what dialog.tcl does. Will backport to 2.5. ........ r52782 | martin.v.loewis | 2006-11-18 19:05:35 +0100 (Sat, 18 Nov 2006) | 4 lines Patch #1594554: Always close a tkSimpleDialog on ok(), even if an exception occurs. Will backport to 2.5. ........ r52784 | martin.v.loewis | 2006-11-18 19:42:11 +0100 (Sat, 18 Nov 2006) | 3 lines Patch #1472877: Fix Tix subwidget name resolution. Will backport to 2.5. ........ r52786 | andrew.kuchling | 2006-11-18 23:17:33 +0100 (Sat, 18 Nov 2006) | 1 line Expand checking in test_sha ........ r52787 | georg.brandl | 2006-11-19 09:48:30 +0100 (Sun, 19 Nov 2006) | 3 lines Patch [ 1586791 ] better error msgs for some TypeErrors ........ r52788 | martin.v.loewis | 2006-11-19 11:41:41 +0100 (Sun, 19 Nov 2006) | 4 lines Make cStringIO.truncate raise IOError for negative arguments (even for -1). Fixes the last bit of #1359365. ........ r52789 | andrew.kuchling | 2006-11-19 19:40:01 +0100 (Sun, 19 Nov 2006) | 1 line Add a test case of data w/ bytes > 127 ........ r52790 | martin.v.loewis | 2006-11-19 19:51:54 +0100 (Sun, 19 Nov 2006) | 3 lines Patch #1070046: Marshal new-style objects like InstanceType in xmlrpclib. ........ r52792 | neal.norwitz | 2006-11-19 22:26:53 +0100 (Sun, 19 Nov 2006) | 4 lines Speed up function calls into the math module by using METH_O. There should be no functional changes. However, the error msgs are slightly different. Also verified that the module dict is not NULL on init. ........ r52794 | george.yoshida | 2006-11-20 03:24:48 +0100 (Mon, 20 Nov 2006) | 2 lines markup fix ........ r52795 | georg.brandl | 2006-11-20 08:12:58 +0100 (Mon, 20 Nov 2006) | 3 lines Further markup fix. ........ r52800 | andrew.kuchling | 2006-11-20 14:39:37 +0100 (Mon, 20 Nov 2006) | 2 lines Jython compatibility fix: if uu.decode() opened its output file, be sure to close it. ........ r52811 | neal.norwitz | 2006-11-21 06:26:22 +0100 (Tue, 21 Nov 2006) | 9 lines Bug #1599782: Fix segfault on bsddb.db.DB().type(). The problem is that _DB_get_type() can't be called without the GIL because it calls a bunch of PyErr_* APIs when an error occurs. There were no other cases in this file that it was called without the GIL. Removing the BEGIN/END THREAD around _DB_get_type() made everything work. Will backport. ........ r52814 | neal.norwitz | 2006-11-21 06:51:51 +0100 (Tue, 21 Nov 2006) | 1 line Oops, convert tabs to spaces ........ r52815 | neal.norwitz | 2006-11-21 07:23:44 +0100 (Tue, 21 Nov 2006) | 1 line Fix SF #1599879, socket.gethostname should ref getfqdn directly. ........ r52817 | martin.v.loewis | 2006-11-21 19:20:25 +0100 (Tue, 21 Nov 2006) | 4 lines Conditionalize definition of _CRT_SECURE_NO_DEPRECATE and _CRT_NONSTDC_NO_DEPRECATE. Will backport. ........ r52821 | martin.v.loewis | 2006-11-22 09:50:02 +0100 (Wed, 22 Nov 2006) | 4 lines Patch #1362975: Rework CodeContext indentation algorithm to avoid hard-coding pixel widths. Also make the text's scrollbar a child of the text frame, not the top widget. ........ r52826 | walter.doerwald | 2006-11-23 06:03:56 +0100 (Thu, 23 Nov 2006) | 3 lines Change decode() so that it works with a buffer (i.e. unicode(..., 'utf-8-sig')) SF bug #1601501. ........ r52833 | georg.brandl | 2006-11-23 10:55:07 +0100 (Thu, 23 Nov 2006) | 2 lines Bug #1601630: little improvement to getopt docs ........ r52835 | michael.hudson | 2006-11-23 14:54:04 +0100 (Thu, 23 Nov 2006) | 3 lines a test for an error condition not covered by existing tests (noticed this when writing the equivalent code for pypy) ........ r52839 | raymond.hettinger | 2006-11-23 22:06:03 +0100 (Thu, 23 Nov 2006) | 1 line Fix and/add typo ........ r52840 | raymond.hettinger | 2006-11-23 22:35:19 +0100 (Thu, 23 Nov 2006) | 1 line ... and the number of the counting shall be three. ........ r52841 | thomas.heller | 2006-11-24 19:45:39 +0100 (Fri, 24 Nov 2006) | 1 line Fix bug #1598620: A ctypes structure cannot contain itself. ........ r52843 | martin.v.loewis | 2006-11-25 16:39:19 +0100 (Sat, 25 Nov 2006) | 3 lines Disable _XOPEN_SOURCE on NetBSD 1.x. Will backport to 2.5 ........ r52845 | georg.brandl | 2006-11-26 20:27:47 +0100 (Sun, 26 Nov 2006) | 2 lines Bug #1603321: make pstats.Stats accept Unicode file paths. ........ r52850 | georg.brandl | 2006-11-27 19:46:21 +0100 (Mon, 27 Nov 2006) | 2 lines Bug #1603789: grammatical error in Tkinter docs. ........ r52855 | thomas.heller | 2006-11-28 21:21:54 +0100 (Tue, 28 Nov 2006) | 7 lines Fix #1563807: _ctypes built on AIX fails with ld ffi error. The contents of ffi_darwin.c must be compiled unless __APPLE__ is defined and __ppc__ is not. Will backport. ........ r52862 | armin.rigo | 2006-11-29 22:59:22 +0100 (Wed, 29 Nov 2006) | 3 lines Forgot a case where the locals can now be a general mapping instead of just a dictionary. (backporting...) ........ r52872 | guido.van.rossum | 2006-11-30 20:23:13 +0100 (Thu, 30 Nov 2006) | 2 lines Update version. ........ r52890 | walter.doerwald | 2006-12-01 17:59:47 +0100 (Fri, 01 Dec 2006) | 3 lines Move xdrlib tests from the module into a separate test script, port the tests to unittest and add a few new tests. ........ r52900 | raymond.hettinger | 2006-12-02 03:00:39 +0100 (Sat, 02 Dec 2006) | 1 line Add name to credits (for untokenize). ........ r52905 | martin.v.loewis | 2006-12-03 10:54:46 +0100 (Sun, 03 Dec 2006) | 2 lines Move IDLE news into NEWS.txt. ........ r52906 | martin.v.loewis | 2006-12-03 12:23:45 +0100 (Sun, 03 Dec 2006) | 4 lines Patch #1544279: Improve thread-safety of the socket module by moving the sock_addr_t storage out of the socket object. Will backport to 2.5. ........ r52908 | martin.v.loewis | 2006-12-03 13:01:53 +0100 (Sun, 03 Dec 2006) | 3 lines Patch #1371075: Make ConfigParser accept optional dict type for ordering, sorting, etc. ........ r52910 | matthias.klose | 2006-12-03 18:16:41 +0100 (Sun, 03 Dec 2006) | 2 lines - Fix build failure on kfreebsd and on the hurd. ........ r52915 | george.yoshida | 2006-12-04 12:41:54 +0100 (Mon, 04 Dec 2006) | 2 lines fix a versionchanged tag ........ r52917 | george.yoshida | 2006-12-05 06:39:50 +0100 (Tue, 05 Dec 2006) | 3 lines Fix pickle doc typo Patch #1608758 ........ r52938 | georg.brandl | 2006-12-06 23:21:18 +0100 (Wed, 06 Dec 2006) | 2 lines Patch #1610437: fix a tarfile bug with long filename headers. ........ r52945 | brett.cannon | 2006-12-07 00:38:48 +0100 (Thu, 07 Dec 2006) | 3 lines Fix a bad assumption that all objects assigned to '__loader__' on a module will have a '_files' attribute. ........ r52951 | georg.brandl | 2006-12-07 10:30:06 +0100 (Thu, 07 Dec 2006) | 3 lines RFE #1592899: mention string.maketrans() in docs for str.translate, remove reference to the old regex module in the former's doc. ........ r52962 | raymond.hettinger | 2006-12-08 04:17:18 +0100 (Fri, 08 Dec 2006) | 1 line Eliminate two redundant calls to PyObject_Hash(). ........ r52963 | raymond.hettinger | 2006-12-08 05:24:33 +0100 (Fri, 08 Dec 2006) | 3 lines Port Armin's fix for a dict resize vulnerability (svn revision 46589, sf bug 1456209). ........ r52964 | raymond.hettinger | 2006-12-08 05:57:50 +0100 (Fri, 08 Dec 2006) | 4 lines Port Georg's dictobject.c fix keys that were tuples got unpacked on the way to setting a KeyError (svn revision 52535, sf bug 1576657). ........ r52966 | raymond.hettinger | 2006-12-08 18:35:25 +0100 (Fri, 08 Dec 2006) | 2 lines Add test for SF bug 1576657 ........ r52970 | georg.brandl | 2006-12-08 21:46:11 +0100 (Fri, 08 Dec 2006) | 3 lines #1577756: svnversion doesn't react to LANG=C, use LC_ALL=C to force English output. ........ r52972 | georg.brandl | 2006-12-09 10:08:29 +0100 (Sat, 09 Dec 2006) | 3 lines Patch #1608267: fix a race condition in os.makedirs() is the directory to be created is already there. ........ r52975 | matthias.klose | 2006-12-09 13:15:27 +0100 (Sat, 09 Dec 2006) | 2 lines - Fix the build of the library reference in info format. ........ r52994 | neal.norwitz | 2006-12-11 02:01:06 +0100 (Mon, 11 Dec 2006) | 1 line Fix a typo ........ r52996 | georg.brandl | 2006-12-11 08:56:33 +0100 (Mon, 11 Dec 2006) | 2 lines Move errno imports back to individual functions. ........ r52998 | vinay.sajip | 2006-12-11 15:07:16 +0100 (Mon, 11 Dec 2006) | 1 line Patch by Jeremy Katz (SF #1609407) ........ r53000 | vinay.sajip | 2006-12-11 15:26:23 +0100 (Mon, 11 Dec 2006) | 1 line Patch by "cuppatea" (SF #1503765) ........
3134 lines
77 KiB
C
3134 lines
77 KiB
C
|
|
/* Module definition and import implementation */
|
|
|
|
#include "Python.h"
|
|
|
|
#include "Python-ast.h"
|
|
#include "pyarena.h"
|
|
#include "pythonrun.h"
|
|
#include "errcode.h"
|
|
#include "marshal.h"
|
|
#include "code.h"
|
|
#include "compile.h"
|
|
#include "eval.h"
|
|
#include "osdefs.h"
|
|
#include "importdl.h"
|
|
|
|
#ifdef HAVE_FCNTL_H
|
|
#include <fcntl.h>
|
|
#endif
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
extern time_t PyOS_GetLastModificationTime(char *, FILE *);
|
|
/* In getmtime.c */
|
|
|
|
/* Magic word to reject .pyc files generated by other Python versions.
|
|
It should change for each incompatible change to the bytecode.
|
|
|
|
The value of CR and LF is incorporated so if you ever read or write
|
|
a .pyc file in text mode the magic number will be wrong; also, the
|
|
Apple MPW compiler swaps their values, botching string constants.
|
|
|
|
The magic numbers must be spaced apart at least 2 values, as the
|
|
-U interpeter flag will cause MAGIC+1 being used. They have been
|
|
odd numbers for some time now.
|
|
|
|
There were a variety of old schemes for setting the magic number.
|
|
The current working scheme is to increment the previous value by
|
|
10.
|
|
|
|
Known values:
|
|
Python 1.5: 20121
|
|
Python 1.5.1: 20121
|
|
Python 1.5.2: 20121
|
|
Python 1.6: 50428
|
|
Python 2.0: 50823
|
|
Python 2.0.1: 50823
|
|
Python 2.1: 60202
|
|
Python 2.1.1: 60202
|
|
Python 2.1.2: 60202
|
|
Python 2.2: 60717
|
|
Python 2.3a0: 62011
|
|
Python 2.3a0: 62021
|
|
Python 2.3a0: 62011 (!)
|
|
Python 2.4a0: 62041
|
|
Python 2.4a3: 62051
|
|
Python 2.4b1: 62061
|
|
Python 2.5a0: 62071
|
|
Python 2.5a0: 62081 (ast-branch)
|
|
Python 2.5a0: 62091 (with)
|
|
Python 2.5a0: 62092 (changed WITH_CLEANUP opcode)
|
|
Python 2.5b3: 62101 (fix wrong code: for x, in ...)
|
|
Python 2.5b3: 62111 (fix wrong code: x += yield)
|
|
Python 2.5c1: 62121 (fix wrong lnotab with for loops and
|
|
storing constants that should have been removed)
|
|
Python 2.5c2: 62131 (fix wrong code: for x, in ... in listcomp/genexp)
|
|
Python 2.6a0: 62141 (peephole optimizations)
|
|
Python 3000: 3000
|
|
3010 (removed UNARY_CONVERT)
|
|
3020 (added BUILD_SET)
|
|
3030 (added keyword-only parameters)
|
|
.
|
|
*/
|
|
#define MAGIC (3030 | ((long)'\r'<<16) | ((long)'\n'<<24))
|
|
|
|
/* Magic word as global; note that _PyImport_Init() can change the
|
|
value of this global to accommodate for alterations of how the
|
|
compiler works which are enabled by command line switches. */
|
|
static long pyc_magic = MAGIC;
|
|
|
|
/* See _PyImport_FixupExtension() below */
|
|
static PyObject *extensions = NULL;
|
|
|
|
/* This table is defined in config.c: */
|
|
extern struct _inittab _PyImport_Inittab[];
|
|
|
|
struct _inittab *PyImport_Inittab = _PyImport_Inittab;
|
|
|
|
/* these tables define the module suffixes that Python recognizes */
|
|
struct filedescr * _PyImport_Filetab = NULL;
|
|
|
|
#ifdef RISCOS
|
|
static const struct filedescr _PyImport_StandardFiletab[] = {
|
|
{"/py", "U", PY_SOURCE},
|
|
{"/pyc", "rb", PY_COMPILED},
|
|
{0, 0}
|
|
};
|
|
#else
|
|
static const struct filedescr _PyImport_StandardFiletab[] = {
|
|
{".py", "U", PY_SOURCE},
|
|
#ifdef MS_WINDOWS
|
|
{".pyw", "U", PY_SOURCE},
|
|
#endif
|
|
{".pyc", "rb", PY_COMPILED},
|
|
{0, 0}
|
|
};
|
|
#endif
|
|
|
|
static PyTypeObject NullImporterType; /* Forward reference */
|
|
|
|
/* Initialize things */
|
|
|
|
void
|
|
_PyImport_Init(void)
|
|
{
|
|
const struct filedescr *scan;
|
|
struct filedescr *filetab;
|
|
int countD = 0;
|
|
int countS = 0;
|
|
|
|
/* prepare _PyImport_Filetab: copy entries from
|
|
_PyImport_DynLoadFiletab and _PyImport_StandardFiletab.
|
|
*/
|
|
for (scan = _PyImport_DynLoadFiletab; scan->suffix != NULL; ++scan)
|
|
++countD;
|
|
for (scan = _PyImport_StandardFiletab; scan->suffix != NULL; ++scan)
|
|
++countS;
|
|
filetab = PyMem_NEW(struct filedescr, countD + countS + 1);
|
|
if (filetab == NULL)
|
|
Py_FatalError("Can't initialize import file table.");
|
|
memcpy(filetab, _PyImport_DynLoadFiletab,
|
|
countD * sizeof(struct filedescr));
|
|
memcpy(filetab + countD, _PyImport_StandardFiletab,
|
|
countS * sizeof(struct filedescr));
|
|
filetab[countD + countS].suffix = NULL;
|
|
|
|
_PyImport_Filetab = filetab;
|
|
|
|
if (Py_OptimizeFlag) {
|
|
/* Replace ".pyc" with ".pyo" in _PyImport_Filetab */
|
|
for (; filetab->suffix != NULL; filetab++) {
|
|
#ifndef RISCOS
|
|
if (strcmp(filetab->suffix, ".pyc") == 0)
|
|
filetab->suffix = ".pyo";
|
|
#else
|
|
if (strcmp(filetab->suffix, "/pyc") == 0)
|
|
filetab->suffix = "/pyo";
|
|
#endif
|
|
}
|
|
}
|
|
|
|
if (Py_UnicodeFlag) {
|
|
/* Fix the pyc_magic so that byte compiled code created
|
|
using the all-Unicode method doesn't interfere with
|
|
code created in normal operation mode. */
|
|
pyc_magic = MAGIC + 1;
|
|
}
|
|
}
|
|
|
|
void
|
|
_PyImportHooks_Init(void)
|
|
{
|
|
PyObject *v, *path_hooks = NULL, *zimpimport;
|
|
int err = 0;
|
|
|
|
/* adding sys.path_hooks and sys.path_importer_cache, setting up
|
|
zipimport */
|
|
if (PyType_Ready(&NullImporterType) < 0)
|
|
goto error;
|
|
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# installing zipimport hook\n");
|
|
|
|
v = PyList_New(0);
|
|
if (v == NULL)
|
|
goto error;
|
|
err = PySys_SetObject("meta_path", v);
|
|
Py_DECREF(v);
|
|
if (err)
|
|
goto error;
|
|
v = PyDict_New();
|
|
if (v == NULL)
|
|
goto error;
|
|
err = PySys_SetObject("path_importer_cache", v);
|
|
Py_DECREF(v);
|
|
if (err)
|
|
goto error;
|
|
path_hooks = PyList_New(0);
|
|
if (path_hooks == NULL)
|
|
goto error;
|
|
err = PySys_SetObject("path_hooks", path_hooks);
|
|
if (err) {
|
|
error:
|
|
PyErr_Print();
|
|
Py_FatalError("initializing sys.meta_path, sys.path_hooks, "
|
|
"path_importer_cache, or NullImporter failed"
|
|
);
|
|
}
|
|
|
|
zimpimport = PyImport_ImportModule("zipimport");
|
|
if (zimpimport == NULL) {
|
|
PyErr_Clear(); /* No zip import module -- okay */
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# can't import zipimport\n");
|
|
}
|
|
else {
|
|
PyObject *zipimporter = PyObject_GetAttrString(zimpimport,
|
|
"zipimporter");
|
|
Py_DECREF(zimpimport);
|
|
if (zipimporter == NULL) {
|
|
PyErr_Clear(); /* No zipimporter object -- okay */
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr(
|
|
"# can't import zipimport.zipimporter\n");
|
|
}
|
|
else {
|
|
/* sys.path_hooks.append(zipimporter) */
|
|
err = PyList_Append(path_hooks, zipimporter);
|
|
Py_DECREF(zipimporter);
|
|
if (err)
|
|
goto error;
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr(
|
|
"# installed zipimport hook\n");
|
|
}
|
|
}
|
|
Py_DECREF(path_hooks);
|
|
}
|
|
|
|
void
|
|
_PyImport_Fini(void)
|
|
{
|
|
Py_XDECREF(extensions);
|
|
extensions = NULL;
|
|
PyMem_DEL(_PyImport_Filetab);
|
|
_PyImport_Filetab = NULL;
|
|
}
|
|
|
|
|
|
/* Locking primitives to prevent parallel imports of the same module
|
|
in different threads to return with a partially loaded module.
|
|
These calls are serialized by the global interpreter lock. */
|
|
|
|
#ifdef WITH_THREAD
|
|
|
|
#include "pythread.h"
|
|
|
|
static PyThread_type_lock import_lock = 0;
|
|
static long import_lock_thread = -1;
|
|
static int import_lock_level = 0;
|
|
|
|
static void
|
|
lock_import(void)
|
|
{
|
|
long me = PyThread_get_thread_ident();
|
|
if (me == -1)
|
|
return; /* Too bad */
|
|
if (import_lock == NULL) {
|
|
import_lock = PyThread_allocate_lock();
|
|
if (import_lock == NULL)
|
|
return; /* Nothing much we can do. */
|
|
}
|
|
if (import_lock_thread == me) {
|
|
import_lock_level++;
|
|
return;
|
|
}
|
|
if (import_lock_thread != -1 || !PyThread_acquire_lock(import_lock, 0))
|
|
{
|
|
PyThreadState *tstate = PyEval_SaveThread();
|
|
PyThread_acquire_lock(import_lock, 1);
|
|
PyEval_RestoreThread(tstate);
|
|
}
|
|
import_lock_thread = me;
|
|
import_lock_level = 1;
|
|
}
|
|
|
|
static int
|
|
unlock_import(void)
|
|
{
|
|
long me = PyThread_get_thread_ident();
|
|
if (me == -1 || import_lock == NULL)
|
|
return 0; /* Too bad */
|
|
if (import_lock_thread != me)
|
|
return -1;
|
|
import_lock_level--;
|
|
if (import_lock_level == 0) {
|
|
import_lock_thread = -1;
|
|
PyThread_release_lock(import_lock);
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
/* This function is called from PyOS_AfterFork to ensure that newly
|
|
created child processes do not share locks with the parent. */
|
|
|
|
void
|
|
_PyImport_ReInitLock(void)
|
|
{
|
|
#ifdef _AIX
|
|
if (import_lock != NULL)
|
|
import_lock = PyThread_allocate_lock();
|
|
#endif
|
|
}
|
|
|
|
#else
|
|
|
|
#define lock_import()
|
|
#define unlock_import() 0
|
|
|
|
#endif
|
|
|
|
static PyObject *
|
|
imp_lock_held(PyObject *self, PyObject *noargs)
|
|
{
|
|
#ifdef WITH_THREAD
|
|
return PyBool_FromLong(import_lock_thread != -1);
|
|
#else
|
|
return PyBool_FromLong(0);
|
|
#endif
|
|
}
|
|
|
|
static PyObject *
|
|
imp_acquire_lock(PyObject *self, PyObject *noargs)
|
|
{
|
|
#ifdef WITH_THREAD
|
|
lock_import();
|
|
#endif
|
|
Py_INCREF(Py_None);
|
|
return Py_None;
|
|
}
|
|
|
|
static PyObject *
|
|
imp_release_lock(PyObject *self, PyObject *noargs)
|
|
{
|
|
#ifdef WITH_THREAD
|
|
if (unlock_import() < 0) {
|
|
PyErr_SetString(PyExc_RuntimeError,
|
|
"not holding the import lock");
|
|
return NULL;
|
|
}
|
|
#endif
|
|
Py_INCREF(Py_None);
|
|
return Py_None;
|
|
}
|
|
|
|
/* Helper for sys */
|
|
|
|
PyObject *
|
|
PyImport_GetModuleDict(void)
|
|
{
|
|
PyInterpreterState *interp = PyThreadState_GET()->interp;
|
|
if (interp->modules == NULL)
|
|
Py_FatalError("PyImport_GetModuleDict: no module dictionary!");
|
|
return interp->modules;
|
|
}
|
|
|
|
|
|
/* List of names to clear in sys */
|
|
static char* sys_deletes[] = {
|
|
"path", "argv", "ps1", "ps2", "exitfunc",
|
|
"exc_type", "exc_value", "exc_traceback",
|
|
"last_type", "last_value", "last_traceback",
|
|
"path_hooks", "path_importer_cache", "meta_path",
|
|
NULL
|
|
};
|
|
|
|
static char* sys_files[] = {
|
|
"stdin", "__stdin__",
|
|
"stdout", "__stdout__",
|
|
"stderr", "__stderr__",
|
|
NULL
|
|
};
|
|
|
|
|
|
/* Un-initialize things, as good as we can */
|
|
|
|
void
|
|
PyImport_Cleanup(void)
|
|
{
|
|
Py_ssize_t pos, ndone;
|
|
char *name;
|
|
PyObject *key, *value, *dict;
|
|
PyInterpreterState *interp = PyThreadState_GET()->interp;
|
|
PyObject *modules = interp->modules;
|
|
|
|
if (modules == NULL)
|
|
return; /* Already done */
|
|
|
|
/* Delete some special variables first. These are common
|
|
places where user values hide and people complain when their
|
|
destructors fail. Since the modules containing them are
|
|
deleted *last* of all, they would come too late in the normal
|
|
destruction order. Sigh. */
|
|
|
|
value = PyDict_GetItemString(modules, "__builtin__");
|
|
if (value != NULL && PyModule_Check(value)) {
|
|
dict = PyModule_GetDict(value);
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# clear __builtin__._\n");
|
|
PyDict_SetItemString(dict, "_", Py_None);
|
|
}
|
|
value = PyDict_GetItemString(modules, "sys");
|
|
if (value != NULL && PyModule_Check(value)) {
|
|
char **p;
|
|
PyObject *v;
|
|
dict = PyModule_GetDict(value);
|
|
for (p = sys_deletes; *p != NULL; p++) {
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# clear sys.%s\n", *p);
|
|
PyDict_SetItemString(dict, *p, Py_None);
|
|
}
|
|
for (p = sys_files; *p != NULL; p+=2) {
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# restore sys.%s\n", *p);
|
|
v = PyDict_GetItemString(dict, *(p+1));
|
|
if (v == NULL)
|
|
v = Py_None;
|
|
PyDict_SetItemString(dict, *p, v);
|
|
}
|
|
}
|
|
|
|
/* First, delete __main__ */
|
|
value = PyDict_GetItemString(modules, "__main__");
|
|
if (value != NULL && PyModule_Check(value)) {
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# cleanup __main__\n");
|
|
_PyModule_Clear(value);
|
|
PyDict_SetItemString(modules, "__main__", Py_None);
|
|
}
|
|
|
|
/* The special treatment of __builtin__ here is because even
|
|
when it's not referenced as a module, its dictionary is
|
|
referenced by almost every module's __builtins__. Since
|
|
deleting a module clears its dictionary (even if there are
|
|
references left to it), we need to delete the __builtin__
|
|
module last. Likewise, we don't delete sys until the very
|
|
end because it is implicitly referenced (e.g. by print).
|
|
|
|
Also note that we 'delete' modules by replacing their entry
|
|
in the modules dict with None, rather than really deleting
|
|
them; this avoids a rehash of the modules dictionary and
|
|
also marks them as "non existent" so they won't be
|
|
re-imported. */
|
|
|
|
/* Next, repeatedly delete modules with a reference count of
|
|
one (skipping __builtin__ and sys) and delete them */
|
|
do {
|
|
ndone = 0;
|
|
pos = 0;
|
|
while (PyDict_Next(modules, &pos, &key, &value)) {
|
|
if (value->ob_refcnt != 1)
|
|
continue;
|
|
if (PyString_Check(key) && PyModule_Check(value)) {
|
|
name = PyString_AS_STRING(key);
|
|
if (strcmp(name, "__builtin__") == 0)
|
|
continue;
|
|
if (strcmp(name, "sys") == 0)
|
|
continue;
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr(
|
|
"# cleanup[1] %s\n", name);
|
|
_PyModule_Clear(value);
|
|
PyDict_SetItem(modules, key, Py_None);
|
|
ndone++;
|
|
}
|
|
}
|
|
} while (ndone > 0);
|
|
|
|
/* Next, delete all modules (still skipping __builtin__ and sys) */
|
|
pos = 0;
|
|
while (PyDict_Next(modules, &pos, &key, &value)) {
|
|
if (PyString_Check(key) && PyModule_Check(value)) {
|
|
name = PyString_AS_STRING(key);
|
|
if (strcmp(name, "__builtin__") == 0)
|
|
continue;
|
|
if (strcmp(name, "sys") == 0)
|
|
continue;
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# cleanup[2] %s\n", name);
|
|
_PyModule_Clear(value);
|
|
PyDict_SetItem(modules, key, Py_None);
|
|
}
|
|
}
|
|
|
|
/* Next, delete sys and __builtin__ (in that order) */
|
|
value = PyDict_GetItemString(modules, "sys");
|
|
if (value != NULL && PyModule_Check(value)) {
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# cleanup sys\n");
|
|
_PyModule_Clear(value);
|
|
PyDict_SetItemString(modules, "sys", Py_None);
|
|
}
|
|
value = PyDict_GetItemString(modules, "__builtin__");
|
|
if (value != NULL && PyModule_Check(value)) {
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# cleanup __builtin__\n");
|
|
_PyModule_Clear(value);
|
|
PyDict_SetItemString(modules, "__builtin__", Py_None);
|
|
}
|
|
|
|
/* Finally, clear and delete the modules directory */
|
|
PyDict_Clear(modules);
|
|
interp->modules = NULL;
|
|
Py_DECREF(modules);
|
|
}
|
|
|
|
|
|
/* Helper for pythonrun.c -- return magic number */
|
|
|
|
long
|
|
PyImport_GetMagicNumber(void)
|
|
{
|
|
return pyc_magic;
|
|
}
|
|
|
|
|
|
/* Magic for extension modules (built-in as well as dynamically
|
|
loaded). To prevent initializing an extension module more than
|
|
once, we keep a static dictionary 'extensions' keyed by module name
|
|
(for built-in modules) or by filename (for dynamically loaded
|
|
modules), containing these modules. A copy of the module's
|
|
dictionary is stored by calling _PyImport_FixupExtension()
|
|
immediately after the module initialization function succeeds. A
|
|
copy can be retrieved from there by calling
|
|
_PyImport_FindExtension(). */
|
|
|
|
PyObject *
|
|
_PyImport_FixupExtension(char *name, char *filename)
|
|
{
|
|
PyObject *modules, *mod, *dict, *copy;
|
|
if (extensions == NULL) {
|
|
extensions = PyDict_New();
|
|
if (extensions == NULL)
|
|
return NULL;
|
|
}
|
|
modules = PyImport_GetModuleDict();
|
|
mod = PyDict_GetItemString(modules, name);
|
|
if (mod == NULL || !PyModule_Check(mod)) {
|
|
PyErr_Format(PyExc_SystemError,
|
|
"_PyImport_FixupExtension: module %.200s not loaded", name);
|
|
return NULL;
|
|
}
|
|
dict = PyModule_GetDict(mod);
|
|
if (dict == NULL)
|
|
return NULL;
|
|
copy = PyDict_Copy(dict);
|
|
if (copy == NULL)
|
|
return NULL;
|
|
PyDict_SetItemString(extensions, filename, copy);
|
|
Py_DECREF(copy);
|
|
return copy;
|
|
}
|
|
|
|
PyObject *
|
|
_PyImport_FindExtension(char *name, char *filename)
|
|
{
|
|
PyObject *dict, *mod, *mdict;
|
|
if (extensions == NULL)
|
|
return NULL;
|
|
dict = PyDict_GetItemString(extensions, filename);
|
|
if (dict == NULL)
|
|
return NULL;
|
|
mod = PyImport_AddModule(name);
|
|
if (mod == NULL)
|
|
return NULL;
|
|
mdict = PyModule_GetDict(mod);
|
|
if (mdict == NULL)
|
|
return NULL;
|
|
if (PyDict_Update(mdict, dict))
|
|
return NULL;
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("import %s # previously loaded (%s)\n",
|
|
name, filename);
|
|
return mod;
|
|
}
|
|
|
|
|
|
/* Get the module object corresponding to a module name.
|
|
First check the modules dictionary if there's one there,
|
|
if not, create a new one and insert it in the modules dictionary.
|
|
Because the former action is most common, THIS DOES NOT RETURN A
|
|
'NEW' REFERENCE! */
|
|
|
|
PyObject *
|
|
PyImport_AddModule(const char *name)
|
|
{
|
|
PyObject *modules = PyImport_GetModuleDict();
|
|
PyObject *m;
|
|
|
|
if ((m = PyDict_GetItemString(modules, name)) != NULL &&
|
|
PyModule_Check(m))
|
|
return m;
|
|
m = PyModule_New(name);
|
|
if (m == NULL)
|
|
return NULL;
|
|
if (PyDict_SetItemString(modules, name, m) != 0) {
|
|
Py_DECREF(m);
|
|
return NULL;
|
|
}
|
|
Py_DECREF(m); /* Yes, it still exists, in modules! */
|
|
|
|
return m;
|
|
}
|
|
|
|
/* Remove name from sys.modules, if it's there. */
|
|
static void
|
|
_RemoveModule(const char *name)
|
|
{
|
|
PyObject *modules = PyImport_GetModuleDict();
|
|
if (PyDict_GetItemString(modules, name) == NULL)
|
|
return;
|
|
if (PyDict_DelItemString(modules, name) < 0)
|
|
Py_FatalError("import: deleting existing key in"
|
|
"sys.modules failed");
|
|
}
|
|
|
|
/* Execute a code object in a module and return the module object
|
|
* WITH INCREMENTED REFERENCE COUNT. If an error occurs, name is
|
|
* removed from sys.modules, to avoid leaving damaged module objects
|
|
* in sys.modules. The caller may wish to restore the original
|
|
* module object (if any) in this case; PyImport_ReloadModule is an
|
|
* example.
|
|
*/
|
|
PyObject *
|
|
PyImport_ExecCodeModule(char *name, PyObject *co)
|
|
{
|
|
return PyImport_ExecCodeModuleEx(name, co, (char *)NULL);
|
|
}
|
|
|
|
PyObject *
|
|
PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname)
|
|
{
|
|
PyObject *modules = PyImport_GetModuleDict();
|
|
PyObject *m, *d, *v;
|
|
|
|
m = PyImport_AddModule(name);
|
|
if (m == NULL)
|
|
return NULL;
|
|
/* If the module is being reloaded, we get the old module back
|
|
and re-use its dict to exec the new code. */
|
|
d = PyModule_GetDict(m);
|
|
if (PyDict_GetItemString(d, "__builtins__") == NULL) {
|
|
if (PyDict_SetItemString(d, "__builtins__",
|
|
PyEval_GetBuiltins()) != 0)
|
|
goto error;
|
|
}
|
|
/* Remember the filename as the __file__ attribute */
|
|
v = NULL;
|
|
if (pathname != NULL) {
|
|
v = PyString_FromString(pathname);
|
|
if (v == NULL)
|
|
PyErr_Clear();
|
|
}
|
|
if (v == NULL) {
|
|
v = ((PyCodeObject *)co)->co_filename;
|
|
Py_INCREF(v);
|
|
}
|
|
if (PyDict_SetItemString(d, "__file__", v) != 0)
|
|
PyErr_Clear(); /* Not important enough to report */
|
|
Py_DECREF(v);
|
|
|
|
v = PyEval_EvalCode((PyCodeObject *)co, d, d);
|
|
if (v == NULL)
|
|
goto error;
|
|
Py_DECREF(v);
|
|
|
|
if ((m = PyDict_GetItemString(modules, name)) == NULL) {
|
|
PyErr_Format(PyExc_ImportError,
|
|
"Loaded module %.200s not found in sys.modules",
|
|
name);
|
|
return NULL;
|
|
}
|
|
|
|
Py_INCREF(m);
|
|
|
|
return m;
|
|
|
|
error:
|
|
_RemoveModule(name);
|
|
return NULL;
|
|
}
|
|
|
|
|
|
/* Given a pathname for a Python source file, fill a buffer with the
|
|
pathname for the corresponding compiled file. Return the pathname
|
|
for the compiled file, or NULL if there's no space in the buffer.
|
|
Doesn't set an exception. */
|
|
|
|
static char *
|
|
make_compiled_pathname(char *pathname, char *buf, size_t buflen)
|
|
{
|
|
size_t len = strlen(pathname);
|
|
if (len+2 > buflen)
|
|
return NULL;
|
|
|
|
#ifdef MS_WINDOWS
|
|
/* Treat .pyw as if it were .py. The case of ".pyw" must match
|
|
that used in _PyImport_StandardFiletab. */
|
|
if (len >= 4 && strcmp(&pathname[len-4], ".pyw") == 0)
|
|
--len; /* pretend 'w' isn't there */
|
|
#endif
|
|
memcpy(buf, pathname, len);
|
|
buf[len] = Py_OptimizeFlag ? 'o' : 'c';
|
|
buf[len+1] = '\0';
|
|
|
|
return buf;
|
|
}
|
|
|
|
|
|
/* Given a pathname for a Python source file, its time of last
|
|
modification, and a pathname for a compiled file, check whether the
|
|
compiled file represents the same version of the source. If so,
|
|
return a FILE pointer for the compiled file, positioned just after
|
|
the header; if not, return NULL.
|
|
Doesn't set an exception. */
|
|
|
|
static FILE *
|
|
check_compiled_module(char *pathname, time_t mtime, char *cpathname)
|
|
{
|
|
FILE *fp;
|
|
long magic;
|
|
long pyc_mtime;
|
|
|
|
fp = fopen(cpathname, "rb");
|
|
if (fp == NULL)
|
|
return NULL;
|
|
magic = PyMarshal_ReadLongFromFile(fp);
|
|
if (magic != pyc_magic) {
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# %s has bad magic\n", cpathname);
|
|
fclose(fp);
|
|
return NULL;
|
|
}
|
|
pyc_mtime = PyMarshal_ReadLongFromFile(fp);
|
|
if (pyc_mtime != mtime) {
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# %s has bad mtime\n", cpathname);
|
|
fclose(fp);
|
|
return NULL;
|
|
}
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# %s matches %s\n", cpathname, pathname);
|
|
return fp;
|
|
}
|
|
|
|
|
|
/* Read a code object from a file and check it for validity */
|
|
|
|
static PyCodeObject *
|
|
read_compiled_module(char *cpathname, FILE *fp)
|
|
{
|
|
PyObject *co;
|
|
|
|
co = PyMarshal_ReadLastObjectFromFile(fp);
|
|
if (co == NULL)
|
|
return NULL;
|
|
if (!PyCode_Check(co)) {
|
|
PyErr_Format(PyExc_ImportError,
|
|
"Non-code object in %.200s", cpathname);
|
|
Py_DECREF(co);
|
|
return NULL;
|
|
}
|
|
return (PyCodeObject *)co;
|
|
}
|
|
|
|
|
|
/* Load a module from a compiled file, execute it, and return its
|
|
module object WITH INCREMENTED REFERENCE COUNT */
|
|
|
|
static PyObject *
|
|
load_compiled_module(char *name, char *cpathname, FILE *fp)
|
|
{
|
|
long magic;
|
|
PyCodeObject *co;
|
|
PyObject *m;
|
|
|
|
magic = PyMarshal_ReadLongFromFile(fp);
|
|
if (magic != pyc_magic) {
|
|
PyErr_Format(PyExc_ImportError,
|
|
"Bad magic number in %.200s", cpathname);
|
|
return NULL;
|
|
}
|
|
(void) PyMarshal_ReadLongFromFile(fp);
|
|
co = read_compiled_module(cpathname, fp);
|
|
if (co == NULL)
|
|
return NULL;
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("import %s # precompiled from %s\n",
|
|
name, cpathname);
|
|
m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, cpathname);
|
|
Py_DECREF(co);
|
|
|
|
return m;
|
|
}
|
|
|
|
/* Parse a source file and return the corresponding code object */
|
|
|
|
static PyCodeObject *
|
|
parse_source_module(const char *pathname, FILE *fp)
|
|
{
|
|
PyCodeObject *co = NULL;
|
|
mod_ty mod;
|
|
PyArena *arena = PyArena_New();
|
|
if (arena == NULL)
|
|
return NULL;
|
|
|
|
mod = PyParser_ASTFromFile(fp, pathname, Py_file_input, 0, 0, 0,
|
|
NULL, arena);
|
|
if (mod) {
|
|
co = PyAST_Compile(mod, pathname, NULL, arena);
|
|
}
|
|
PyArena_Free(arena);
|
|
return co;
|
|
}
|
|
|
|
|
|
/* Helper to open a bytecode file for writing in exclusive mode */
|
|
|
|
static FILE *
|
|
open_exclusive(char *filename)
|
|
{
|
|
#if defined(O_EXCL)&&defined(O_CREAT)&&defined(O_WRONLY)&&defined(O_TRUNC)
|
|
/* Use O_EXCL to avoid a race condition when another process tries to
|
|
write the same file. When that happens, our open() call fails,
|
|
which is just fine (since it's only a cache).
|
|
XXX If the file exists and is writable but the directory is not
|
|
writable, the file will never be written. Oh well.
|
|
*/
|
|
int fd;
|
|
(void) unlink(filename);
|
|
fd = open(filename, O_EXCL|O_CREAT|O_WRONLY|O_TRUNC
|
|
#ifdef O_BINARY
|
|
|O_BINARY /* necessary for Windows */
|
|
#endif
|
|
#ifdef __VMS
|
|
, 0666, "ctxt=bin", "shr=nil"
|
|
#else
|
|
, 0666
|
|
#endif
|
|
);
|
|
if (fd < 0)
|
|
return NULL;
|
|
return fdopen(fd, "wb");
|
|
#else
|
|
/* Best we can do -- on Windows this can't happen anyway */
|
|
return fopen(filename, "wb");
|
|
#endif
|
|
}
|
|
|
|
|
|
/* Write a compiled module to a file, placing the time of last
|
|
modification of its source into the header.
|
|
Errors are ignored, if a write error occurs an attempt is made to
|
|
remove the file. */
|
|
|
|
static void
|
|
write_compiled_module(PyCodeObject *co, char *cpathname, time_t mtime)
|
|
{
|
|
FILE *fp;
|
|
|
|
fp = open_exclusive(cpathname);
|
|
if (fp == NULL) {
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr(
|
|
"# can't create %s\n", cpathname);
|
|
return;
|
|
}
|
|
PyMarshal_WriteLongToFile(pyc_magic, fp, Py_MARSHAL_VERSION);
|
|
/* First write a 0 for mtime */
|
|
PyMarshal_WriteLongToFile(0L, fp, Py_MARSHAL_VERSION);
|
|
PyMarshal_WriteObjectToFile((PyObject *)co, fp, Py_MARSHAL_VERSION);
|
|
if (fflush(fp) != 0 || ferror(fp)) {
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# can't write %s\n", cpathname);
|
|
/* Don't keep partial file */
|
|
fclose(fp);
|
|
(void) unlink(cpathname);
|
|
return;
|
|
}
|
|
/* Now write the true mtime */
|
|
fseek(fp, 4L, 0);
|
|
assert(mtime < LONG_MAX);
|
|
PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
|
|
fflush(fp);
|
|
fclose(fp);
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("# wrote %s\n", cpathname);
|
|
}
|
|
|
|
|
|
/* Load a source module from a given file and return its module
|
|
object WITH INCREMENTED REFERENCE COUNT. If there's a matching
|
|
byte-compiled file, use that instead. */
|
|
|
|
static PyObject *
|
|
load_source_module(char *name, char *pathname, FILE *fp)
|
|
{
|
|
time_t mtime;
|
|
FILE *fpc;
|
|
char buf[MAXPATHLEN+1];
|
|
char *cpathname;
|
|
PyCodeObject *co;
|
|
PyObject *m;
|
|
|
|
mtime = PyOS_GetLastModificationTime(pathname, fp);
|
|
if (mtime == (time_t)(-1)) {
|
|
PyErr_Format(PyExc_RuntimeError,
|
|
"unable to get modification time from '%s'",
|
|
pathname);
|
|
return NULL;
|
|
}
|
|
#if SIZEOF_TIME_T > 4
|
|
/* Python's .pyc timestamp handling presumes that the timestamp fits
|
|
in 4 bytes. This will be fine until sometime in the year 2038,
|
|
when a 4-byte signed time_t will overflow.
|
|
*/
|
|
if (mtime >> 32) {
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
"modification time overflows a 4 byte field");
|
|
return NULL;
|
|
}
|
|
#endif
|
|
cpathname = make_compiled_pathname(pathname, buf,
|
|
(size_t)MAXPATHLEN + 1);
|
|
if (cpathname != NULL &&
|
|
(fpc = check_compiled_module(pathname, mtime, cpathname))) {
|
|
co = read_compiled_module(cpathname, fpc);
|
|
fclose(fpc);
|
|
if (co == NULL)
|
|
return NULL;
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("import %s # precompiled from %s\n",
|
|
name, cpathname);
|
|
pathname = cpathname;
|
|
}
|
|
else {
|
|
co = parse_source_module(pathname, fp);
|
|
if (co == NULL)
|
|
return NULL;
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("import %s # from %s\n",
|
|
name, pathname);
|
|
if (cpathname)
|
|
write_compiled_module(co, cpathname, mtime);
|
|
}
|
|
m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, pathname);
|
|
Py_DECREF(co);
|
|
|
|
return m;
|
|
}
|
|
|
|
|
|
/* Forward */
|
|
static PyObject *load_module(char *, FILE *, char *, int, PyObject *);
|
|
static struct filedescr *find_module(char *, char *, PyObject *,
|
|
char *, size_t, FILE **, PyObject **);
|
|
static struct _frozen *find_frozen(char *name);
|
|
|
|
/* Load a package and return its module object WITH INCREMENTED
|
|
REFERENCE COUNT */
|
|
|
|
static PyObject *
|
|
load_package(char *name, char *pathname)
|
|
{
|
|
PyObject *m, *d;
|
|
PyObject *file = NULL;
|
|
PyObject *path = NULL;
|
|
int err;
|
|
char buf[MAXPATHLEN+1];
|
|
FILE *fp = NULL;
|
|
struct filedescr *fdp;
|
|
|
|
m = PyImport_AddModule(name);
|
|
if (m == NULL)
|
|
return NULL;
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("import %s # directory %s\n",
|
|
name, pathname);
|
|
d = PyModule_GetDict(m);
|
|
file = PyString_FromString(pathname);
|
|
if (file == NULL)
|
|
goto error;
|
|
path = Py_BuildValue("[O]", file);
|
|
if (path == NULL)
|
|
goto error;
|
|
err = PyDict_SetItemString(d, "__file__", file);
|
|
if (err == 0)
|
|
err = PyDict_SetItemString(d, "__path__", path);
|
|
if (err != 0)
|
|
goto error;
|
|
buf[0] = '\0';
|
|
fdp = find_module(name, "__init__", path, buf, sizeof(buf), &fp, NULL);
|
|
if (fdp == NULL) {
|
|
if (PyErr_ExceptionMatches(PyExc_ImportError)) {
|
|
PyErr_Clear();
|
|
Py_INCREF(m);
|
|
}
|
|
else
|
|
m = NULL;
|
|
goto cleanup;
|
|
}
|
|
m = load_module(name, fp, buf, fdp->type, NULL);
|
|
if (fp != NULL)
|
|
fclose(fp);
|
|
goto cleanup;
|
|
|
|
error:
|
|
m = NULL;
|
|
cleanup:
|
|
Py_XDECREF(path);
|
|
Py_XDECREF(file);
|
|
return m;
|
|
}
|
|
|
|
|
|
/* Helper to test for built-in module */
|
|
|
|
static int
|
|
is_builtin(char *name)
|
|
{
|
|
int i;
|
|
for (i = 0; PyImport_Inittab[i].name != NULL; i++) {
|
|
if (strcmp(name, PyImport_Inittab[i].name) == 0) {
|
|
if (PyImport_Inittab[i].initfunc == NULL)
|
|
return -1;
|
|
else
|
|
return 1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
/* Return an importer object for a sys.path/pkg.__path__ item 'p',
|
|
possibly by fetching it from the path_importer_cache dict. If it
|
|
wasn't yet cached, traverse path_hooks until a hook is found
|
|
that can handle the path item. Return None if no hook could;
|
|
this tells our caller it should fall back to the builtin
|
|
import mechanism. Cache the result in path_importer_cache.
|
|
Returns a borrowed reference. */
|
|
|
|
static PyObject *
|
|
get_path_importer(PyObject *path_importer_cache, PyObject *path_hooks,
|
|
PyObject *p)
|
|
{
|
|
PyObject *importer;
|
|
Py_ssize_t j, nhooks;
|
|
|
|
/* These conditions are the caller's responsibility: */
|
|
assert(PyList_Check(path_hooks));
|
|
assert(PyDict_Check(path_importer_cache));
|
|
|
|
nhooks = PyList_Size(path_hooks);
|
|
if (nhooks < 0)
|
|
return NULL; /* Shouldn't happen */
|
|
|
|
importer = PyDict_GetItem(path_importer_cache, p);
|
|
if (importer != NULL)
|
|
return importer;
|
|
|
|
/* set path_importer_cache[p] to None to avoid recursion */
|
|
if (PyDict_SetItem(path_importer_cache, p, Py_None) != 0)
|
|
return NULL;
|
|
|
|
for (j = 0; j < nhooks; j++) {
|
|
PyObject *hook = PyList_GetItem(path_hooks, j);
|
|
if (hook == NULL)
|
|
return NULL;
|
|
importer = PyObject_CallFunctionObjArgs(hook, p, NULL);
|
|
if (importer != NULL)
|
|
break;
|
|
|
|
if (!PyErr_ExceptionMatches(PyExc_ImportError)) {
|
|
return NULL;
|
|
}
|
|
PyErr_Clear();
|
|
}
|
|
if (importer == NULL) {
|
|
importer = PyObject_CallFunctionObjArgs(
|
|
(PyObject *)&NullImporterType, p, NULL
|
|
);
|
|
if (importer == NULL) {
|
|
if (PyErr_ExceptionMatches(PyExc_ImportError)) {
|
|
PyErr_Clear();
|
|
return Py_None;
|
|
}
|
|
}
|
|
}
|
|
if (importer != NULL) {
|
|
int err = PyDict_SetItem(path_importer_cache, p, importer);
|
|
Py_DECREF(importer);
|
|
if (err != 0)
|
|
return NULL;
|
|
}
|
|
return importer;
|
|
}
|
|
|
|
/* Search the path (default sys.path) for a module. Return the
|
|
corresponding filedescr struct, and (via return arguments) the
|
|
pathname and an open file. Return NULL if the module is not found. */
|
|
|
|
#ifdef MS_COREDLL
|
|
extern FILE *PyWin_FindRegisteredModule(const char *, struct filedescr **,
|
|
char *, Py_ssize_t);
|
|
#endif
|
|
|
|
static int case_ok(char *, Py_ssize_t, Py_ssize_t, char *);
|
|
static int find_init_module(char *); /* Forward */
|
|
static struct filedescr importhookdescr = {"", "", IMP_HOOK};
|
|
|
|
static struct filedescr *
|
|
find_module(char *fullname, char *subname, PyObject *path, char *buf,
|
|
size_t buflen, FILE **p_fp, PyObject **p_loader)
|
|
{
|
|
Py_ssize_t i, npath;
|
|
size_t len, namelen;
|
|
struct filedescr *fdp = NULL;
|
|
char *filemode;
|
|
FILE *fp = NULL;
|
|
PyObject *path_hooks, *path_importer_cache;
|
|
#ifndef RISCOS
|
|
struct stat statbuf;
|
|
#endif
|
|
static struct filedescr fd_frozen = {"", "", PY_FROZEN};
|
|
static struct filedescr fd_builtin = {"", "", C_BUILTIN};
|
|
static struct filedescr fd_package = {"", "", PKG_DIRECTORY};
|
|
char name[MAXPATHLEN+1];
|
|
#if defined(PYOS_OS2)
|
|
size_t saved_len;
|
|
size_t saved_namelen;
|
|
char *saved_buf = NULL;
|
|
#endif
|
|
if (p_loader != NULL)
|
|
*p_loader = NULL;
|
|
|
|
if (strlen(subname) > MAXPATHLEN) {
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
"module name is too long");
|
|
return NULL;
|
|
}
|
|
strcpy(name, subname);
|
|
|
|
/* sys.meta_path import hook */
|
|
if (p_loader != NULL) {
|
|
PyObject *meta_path;
|
|
|
|
meta_path = PySys_GetObject("meta_path");
|
|
if (meta_path == NULL || !PyList_Check(meta_path)) {
|
|
PyErr_SetString(PyExc_ImportError,
|
|
"sys.meta_path must be a list of "
|
|
"import hooks");
|
|
return NULL;
|
|
}
|
|
Py_INCREF(meta_path); /* zap guard */
|
|
npath = PyList_Size(meta_path);
|
|
for (i = 0; i < npath; i++) {
|
|
PyObject *loader;
|
|
PyObject *hook = PyList_GetItem(meta_path, i);
|
|
loader = PyObject_CallMethod(hook, "find_module",
|
|
"sO", fullname,
|
|
path != NULL ?
|
|
path : Py_None);
|
|
if (loader == NULL) {
|
|
Py_DECREF(meta_path);
|
|
return NULL; /* true error */
|
|
}
|
|
if (loader != Py_None) {
|
|
/* a loader was found */
|
|
*p_loader = loader;
|
|
Py_DECREF(meta_path);
|
|
return &importhookdescr;
|
|
}
|
|
Py_DECREF(loader);
|
|
}
|
|
Py_DECREF(meta_path);
|
|
}
|
|
|
|
if (path != NULL && PyString_Check(path)) {
|
|
/* The only type of submodule allowed inside a "frozen"
|
|
package are other frozen modules or packages. */
|
|
if (PyString_Size(path) + 1 + strlen(name) >= (size_t)buflen) {
|
|
PyErr_SetString(PyExc_ImportError,
|
|
"full frozen module name too long");
|
|
return NULL;
|
|
}
|
|
strcpy(buf, PyString_AsString(path));
|
|
strcat(buf, ".");
|
|
strcat(buf, name);
|
|
strcpy(name, buf);
|
|
if (find_frozen(name) != NULL) {
|
|
strcpy(buf, name);
|
|
return &fd_frozen;
|
|
}
|
|
PyErr_Format(PyExc_ImportError,
|
|
"No frozen submodule named %.200s", name);
|
|
return NULL;
|
|
}
|
|
if (path == NULL) {
|
|
if (is_builtin(name)) {
|
|
strcpy(buf, name);
|
|
return &fd_builtin;
|
|
}
|
|
if ((find_frozen(name)) != NULL) {
|
|
strcpy(buf, name);
|
|
return &fd_frozen;
|
|
}
|
|
|
|
#ifdef MS_COREDLL
|
|
fp = PyWin_FindRegisteredModule(name, &fdp, buf, buflen);
|
|
if (fp != NULL) {
|
|
*p_fp = fp;
|
|
return fdp;
|
|
}
|
|
#endif
|
|
path = PySys_GetObject("path");
|
|
}
|
|
if (path == NULL || !PyList_Check(path)) {
|
|
PyErr_SetString(PyExc_ImportError,
|
|
"sys.path must be a list of directory names");
|
|
return NULL;
|
|
}
|
|
|
|
path_hooks = PySys_GetObject("path_hooks");
|
|
if (path_hooks == NULL || !PyList_Check(path_hooks)) {
|
|
PyErr_SetString(PyExc_ImportError,
|
|
"sys.path_hooks must be a list of "
|
|
"import hooks");
|
|
return NULL;
|
|
}
|
|
path_importer_cache = PySys_GetObject("path_importer_cache");
|
|
if (path_importer_cache == NULL ||
|
|
!PyDict_Check(path_importer_cache)) {
|
|
PyErr_SetString(PyExc_ImportError,
|
|
"sys.path_importer_cache must be a dict");
|
|
return NULL;
|
|
}
|
|
|
|
npath = PyList_Size(path);
|
|
namelen = strlen(name);
|
|
for (i = 0; i < npath; i++) {
|
|
PyObject *copy = NULL;
|
|
PyObject *v = PyList_GetItem(path, i);
|
|
if (!v)
|
|
return NULL;
|
|
#ifdef Py_USING_UNICODE
|
|
if (PyUnicode_Check(v)) {
|
|
copy = PyUnicode_Encode(PyUnicode_AS_UNICODE(v),
|
|
PyUnicode_GET_SIZE(v), Py_FileSystemDefaultEncoding, NULL);
|
|
if (copy == NULL)
|
|
return NULL;
|
|
v = copy;
|
|
}
|
|
else
|
|
#endif
|
|
if (!PyString_Check(v))
|
|
continue;
|
|
len = PyString_GET_SIZE(v);
|
|
if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) {
|
|
Py_XDECREF(copy);
|
|
continue; /* Too long */
|
|
}
|
|
strcpy(buf, PyString_AS_STRING(v));
|
|
if (strlen(buf) != len) {
|
|
Py_XDECREF(copy);
|
|
continue; /* v contains '\0' */
|
|
}
|
|
|
|
/* sys.path_hooks import hook */
|
|
if (p_loader != NULL) {
|
|
PyObject *importer;
|
|
|
|
importer = get_path_importer(path_importer_cache,
|
|
path_hooks, v);
|
|
if (importer == NULL) {
|
|
Py_XDECREF(copy);
|
|
return NULL;
|
|
}
|
|
/* Note: importer is a borrowed reference */
|
|
if (importer != Py_None) {
|
|
PyObject *loader;
|
|
loader = PyObject_CallMethod(importer,
|
|
"find_module",
|
|
"s", fullname);
|
|
Py_XDECREF(copy);
|
|
if (loader == NULL)
|
|
return NULL; /* error */
|
|
if (loader != Py_None) {
|
|
/* a loader was found */
|
|
*p_loader = loader;
|
|
return &importhookdescr;
|
|
}
|
|
Py_DECREF(loader);
|
|
continue;
|
|
}
|
|
}
|
|
/* no hook was found, use builtin import */
|
|
|
|
if (len > 0 && buf[len-1] != SEP
|
|
#ifdef ALTSEP
|
|
&& buf[len-1] != ALTSEP
|
|
#endif
|
|
)
|
|
buf[len++] = SEP;
|
|
strcpy(buf+len, name);
|
|
len += namelen;
|
|
|
|
/* Check for package import (buf holds a directory name,
|
|
and there's an __init__ module in that directory */
|
|
#ifdef HAVE_STAT
|
|
if (stat(buf, &statbuf) == 0 && /* it exists */
|
|
S_ISDIR(statbuf.st_mode) && /* it's a directory */
|
|
case_ok(buf, len, namelen, name)) { /* case matches */
|
|
if (find_init_module(buf)) { /* and has __init__.py */
|
|
Py_XDECREF(copy);
|
|
return &fd_package;
|
|
}
|
|
else {
|
|
char warnstr[MAXPATHLEN+80];
|
|
sprintf(warnstr, "Not importing directory "
|
|
"'%.*s': missing __init__.py",
|
|
MAXPATHLEN, buf);
|
|
if (PyErr_Warn(PyExc_ImportWarning,
|
|
warnstr)) {
|
|
Py_XDECREF(copy);
|
|
return NULL;
|
|
}
|
|
}
|
|
}
|
|
#else
|
|
/* XXX How are you going to test for directories? */
|
|
#ifdef RISCOS
|
|
if (isdir(buf) &&
|
|
case_ok(buf, len, namelen, name)) {
|
|
if (find_init_module(buf)) {
|
|
Py_XDECREF(copy);
|
|
return &fd_package;
|
|
}
|
|
else {
|
|
char warnstr[MAXPATHLEN+80];
|
|
sprintf(warnstr, "Not importing directory "
|
|
"'%.*s': missing __init__.py",
|
|
MAXPATHLEN, buf);
|
|
if (PyErr_Warn(PyExc_ImportWarning,
|
|
warnstr)) {
|
|
Py_XDECREF(copy);
|
|
return NULL;
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
#if defined(PYOS_OS2)
|
|
/* take a snapshot of the module spec for restoration
|
|
* after the 8 character DLL hackery
|
|
*/
|
|
saved_buf = strdup(buf);
|
|
saved_len = len;
|
|
saved_namelen = namelen;
|
|
#endif /* PYOS_OS2 */
|
|
for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
|
|
#if defined(PYOS_OS2)
|
|
/* OS/2 limits DLLs to 8 character names (w/o
|
|
extension)
|
|
* so if the name is longer than that and its a
|
|
* dynamically loaded module we're going to try,
|
|
* truncate the name before trying
|
|
*/
|
|
if (strlen(subname) > 8) {
|
|
/* is this an attempt to load a C extension? */
|
|
const struct filedescr *scan;
|
|
scan = _PyImport_DynLoadFiletab;
|
|
while (scan->suffix != NULL) {
|
|
if (!strcmp(scan->suffix, fdp->suffix))
|
|
break;
|
|
else
|
|
scan++;
|
|
}
|
|
if (scan->suffix != NULL) {
|
|
/* yes, so truncate the name */
|
|
namelen = 8;
|
|
len -= strlen(subname) - namelen;
|
|
buf[len] = '\0';
|
|
}
|
|
}
|
|
#endif /* PYOS_OS2 */
|
|
strcpy(buf+len, fdp->suffix);
|
|
if (Py_VerboseFlag > 1)
|
|
PySys_WriteStderr("# trying %s\n", buf);
|
|
filemode = fdp->mode;
|
|
if (filemode[0] == 'U')
|
|
filemode = "r" PY_STDIOTEXTMODE;
|
|
fp = fopen(buf, filemode);
|
|
if (fp != NULL) {
|
|
if (case_ok(buf, len, namelen, name))
|
|
break;
|
|
else { /* continue search */
|
|
fclose(fp);
|
|
fp = NULL;
|
|
}
|
|
}
|
|
#if defined(PYOS_OS2)
|
|
/* restore the saved snapshot */
|
|
strcpy(buf, saved_buf);
|
|
len = saved_len;
|
|
namelen = saved_namelen;
|
|
#endif
|
|
}
|
|
#if defined(PYOS_OS2)
|
|
/* don't need/want the module name snapshot anymore */
|
|
if (saved_buf)
|
|
{
|
|
free(saved_buf);
|
|
saved_buf = NULL;
|
|
}
|
|
#endif
|
|
Py_XDECREF(copy);
|
|
if (fp != NULL)
|
|
break;
|
|
}
|
|
if (fp == NULL) {
|
|
PyErr_Format(PyExc_ImportError,
|
|
"No module named %.200s", name);
|
|
return NULL;
|
|
}
|
|
*p_fp = fp;
|
|
return fdp;
|
|
}
|
|
|
|
/* Helpers for main.c
|
|
* Find the source file corresponding to a named module
|
|
*/
|
|
struct filedescr *
|
|
_PyImport_FindModule(const char *name, PyObject *path, char *buf,
|
|
size_t buflen, FILE **p_fp, PyObject **p_loader)
|
|
{
|
|
return find_module((char *) name, (char *) name, path,
|
|
buf, buflen, p_fp, p_loader);
|
|
}
|
|
|
|
PyAPI_FUNC(int) _PyImport_IsScript(struct filedescr * fd)
|
|
{
|
|
return fd->type == PY_SOURCE || fd->type == PY_COMPILED;
|
|
}
|
|
|
|
/* case_ok(char* buf, Py_ssize_t len, Py_ssize_t namelen, char* name)
|
|
* The arguments here are tricky, best shown by example:
|
|
* /a/b/c/d/e/f/g/h/i/j/k/some_long_module_name.py\0
|
|
* ^ ^ ^ ^
|
|
* |--------------------- buf ---------------------|
|
|
* |------------------- len ------------------|
|
|
* |------ name -------|
|
|
* |----- namelen -----|
|
|
* buf is the full path, but len only counts up to (& exclusive of) the
|
|
* extension. name is the module name, also exclusive of extension.
|
|
*
|
|
* We've already done a successful stat() or fopen() on buf, so know that
|
|
* there's some match, possibly case-insensitive.
|
|
*
|
|
* case_ok() is to return 1 if there's a case-sensitive match for
|
|
* name, else 0. case_ok() is also to return 1 if envar PYTHONCASEOK
|
|
* exists.
|
|
*
|
|
* case_ok() is used to implement case-sensitive import semantics even
|
|
* on platforms with case-insensitive filesystems. It's trivial to implement
|
|
* for case-sensitive filesystems. It's pretty much a cross-platform
|
|
* nightmare for systems with case-insensitive filesystems.
|
|
*/
|
|
|
|
/* First we may need a pile of platform-specific header files; the sequence
|
|
* of #if's here should match the sequence in the body of case_ok().
|
|
*/
|
|
#if defined(MS_WINDOWS)
|
|
#include <windows.h>
|
|
|
|
#elif defined(DJGPP)
|
|
#include <dir.h>
|
|
|
|
#elif (defined(__MACH__) && defined(__APPLE__) || defined(__CYGWIN__)) && defined(HAVE_DIRENT_H)
|
|
#include <sys/types.h>
|
|
#include <dirent.h>
|
|
|
|
#elif defined(PYOS_OS2)
|
|
#define INCL_DOS
|
|
#define INCL_DOSERRORS
|
|
#define INCL_NOPMAPI
|
|
#include <os2.h>
|
|
|
|
#elif defined(RISCOS)
|
|
#include "oslib/osfscontrol.h"
|
|
#endif
|
|
|
|
static int
|
|
case_ok(char *buf, Py_ssize_t len, Py_ssize_t namelen, char *name)
|
|
{
|
|
/* Pick a platform-specific implementation; the sequence of #if's here should
|
|
* match the sequence just above.
|
|
*/
|
|
|
|
/* MS_WINDOWS */
|
|
#if defined(MS_WINDOWS)
|
|
WIN32_FIND_DATA data;
|
|
HANDLE h;
|
|
|
|
if (Py_GETENV("PYTHONCASEOK") != NULL)
|
|
return 1;
|
|
|
|
h = FindFirstFile(buf, &data);
|
|
if (h == INVALID_HANDLE_VALUE) {
|
|
PyErr_Format(PyExc_NameError,
|
|
"Can't find file for module %.100s\n(filename %.300s)",
|
|
name, buf);
|
|
return 0;
|
|
}
|
|
FindClose(h);
|
|
return strncmp(data.cFileName, name, namelen) == 0;
|
|
|
|
/* DJGPP */
|
|
#elif defined(DJGPP)
|
|
struct ffblk ffblk;
|
|
int done;
|
|
|
|
if (Py_GETENV("PYTHONCASEOK") != NULL)
|
|
return 1;
|
|
|
|
done = findfirst(buf, &ffblk, FA_ARCH|FA_RDONLY|FA_HIDDEN|FA_DIREC);
|
|
if (done) {
|
|
PyErr_Format(PyExc_NameError,
|
|
"Can't find file for module %.100s\n(filename %.300s)",
|
|
name, buf);
|
|
return 0;
|
|
}
|
|
return strncmp(ffblk.ff_name, name, namelen) == 0;
|
|
|
|
/* new-fangled macintosh (macosx) or Cygwin */
|
|
#elif (defined(__MACH__) && defined(__APPLE__) || defined(__CYGWIN__)) && defined(HAVE_DIRENT_H)
|
|
DIR *dirp;
|
|
struct dirent *dp;
|
|
char dirname[MAXPATHLEN + 1];
|
|
const int dirlen = len - namelen - 1; /* don't want trailing SEP */
|
|
|
|
if (Py_GETENV("PYTHONCASEOK") != NULL)
|
|
return 1;
|
|
|
|
/* Copy the dir component into dirname; substitute "." if empty */
|
|
if (dirlen <= 0) {
|
|
dirname[0] = '.';
|
|
dirname[1] = '\0';
|
|
}
|
|
else {
|
|
assert(dirlen <= MAXPATHLEN);
|
|
memcpy(dirname, buf, dirlen);
|
|
dirname[dirlen] = '\0';
|
|
}
|
|
/* Open the directory and search the entries for an exact match. */
|
|
dirp = opendir(dirname);
|
|
if (dirp) {
|
|
char *nameWithExt = buf + len - namelen;
|
|
while ((dp = readdir(dirp)) != NULL) {
|
|
const int thislen =
|
|
#ifdef _DIRENT_HAVE_D_NAMELEN
|
|
dp->d_namlen;
|
|
#else
|
|
strlen(dp->d_name);
|
|
#endif
|
|
if (thislen >= namelen &&
|
|
strcmp(dp->d_name, nameWithExt) == 0) {
|
|
(void)closedir(dirp);
|
|
return 1; /* Found */
|
|
}
|
|
}
|
|
(void)closedir(dirp);
|
|
}
|
|
return 0 ; /* Not found */
|
|
|
|
/* RISC OS */
|
|
#elif defined(RISCOS)
|
|
char canon[MAXPATHLEN+1]; /* buffer for the canonical form of the path */
|
|
char buf2[MAXPATHLEN+2];
|
|
char *nameWithExt = buf+len-namelen;
|
|
int canonlen;
|
|
os_error *e;
|
|
|
|
if (Py_GETENV("PYTHONCASEOK") != NULL)
|
|
return 1;
|
|
|
|
/* workaround:
|
|
append wildcard, otherwise case of filename wouldn't be touched */
|
|
strcpy(buf2, buf);
|
|
strcat(buf2, "*");
|
|
|
|
e = xosfscontrol_canonicalise_path(buf2,canon,0,0,MAXPATHLEN+1,&canonlen);
|
|
canonlen = MAXPATHLEN+1-canonlen;
|
|
if (e || canonlen<=0 || canonlen>(MAXPATHLEN+1) )
|
|
return 0;
|
|
if (strcmp(nameWithExt, canon+canonlen-strlen(nameWithExt))==0)
|
|
return 1; /* match */
|
|
|
|
return 0;
|
|
|
|
/* OS/2 */
|
|
#elif defined(PYOS_OS2)
|
|
HDIR hdir = 1;
|
|
ULONG srchcnt = 1;
|
|
FILEFINDBUF3 ffbuf;
|
|
APIRET rc;
|
|
|
|
if (getenv("PYTHONCASEOK") != NULL)
|
|
return 1;
|
|
|
|
rc = DosFindFirst(buf,
|
|
&hdir,
|
|
FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY,
|
|
&ffbuf, sizeof(ffbuf),
|
|
&srchcnt,
|
|
FIL_STANDARD);
|
|
if (rc != NO_ERROR)
|
|
return 0;
|
|
return strncmp(ffbuf.achName, name, namelen) == 0;
|
|
|
|
/* assuming it's a case-sensitive filesystem, so there's nothing to do! */
|
|
#else
|
|
return 1;
|
|
|
|
#endif
|
|
}
|
|
|
|
|
|
#ifdef HAVE_STAT
|
|
/* Helper to look for __init__.py or __init__.py[co] in potential package */
|
|
static int
|
|
find_init_module(char *buf)
|
|
{
|
|
const size_t save_len = strlen(buf);
|
|
size_t i = save_len;
|
|
char *pname; /* pointer to start of __init__ */
|
|
struct stat statbuf;
|
|
|
|
/* For calling case_ok(buf, len, namelen, name):
|
|
* /a/b/c/d/e/f/g/h/i/j/k/some_long_module_name.py\0
|
|
* ^ ^ ^ ^
|
|
* |--------------------- buf ---------------------|
|
|
* |------------------- len ------------------|
|
|
* |------ name -------|
|
|
* |----- namelen -----|
|
|
*/
|
|
if (save_len + 13 >= MAXPATHLEN)
|
|
return 0;
|
|
buf[i++] = SEP;
|
|
pname = buf + i;
|
|
strcpy(pname, "__init__.py");
|
|
if (stat(buf, &statbuf) == 0) {
|
|
if (case_ok(buf,
|
|
save_len + 9, /* len("/__init__") */
|
|
8, /* len("__init__") */
|
|
pname)) {
|
|
buf[save_len] = '\0';
|
|
return 1;
|
|
}
|
|
}
|
|
i += strlen(pname);
|
|
strcpy(buf+i, Py_OptimizeFlag ? "o" : "c");
|
|
if (stat(buf, &statbuf) == 0) {
|
|
if (case_ok(buf,
|
|
save_len + 9, /* len("/__init__") */
|
|
8, /* len("__init__") */
|
|
pname)) {
|
|
buf[save_len] = '\0';
|
|
return 1;
|
|
}
|
|
}
|
|
buf[save_len] = '\0';
|
|
return 0;
|
|
}
|
|
|
|
#else
|
|
|
|
#ifdef RISCOS
|
|
static int
|
|
find_init_module(buf)
|
|
char *buf;
|
|
{
|
|
int save_len = strlen(buf);
|
|
int i = save_len;
|
|
|
|
if (save_len + 13 >= MAXPATHLEN)
|
|
return 0;
|
|
buf[i++] = SEP;
|
|
strcpy(buf+i, "__init__/py");
|
|
if (isfile(buf)) {
|
|
buf[save_len] = '\0';
|
|
return 1;
|
|
}
|
|
|
|
if (Py_OptimizeFlag)
|
|
strcpy(buf+i, "o");
|
|
else
|
|
strcpy(buf+i, "c");
|
|
if (isfile(buf)) {
|
|
buf[save_len] = '\0';
|
|
return 1;
|
|
}
|
|
buf[save_len] = '\0';
|
|
return 0;
|
|
}
|
|
#endif /*RISCOS*/
|
|
|
|
#endif /* HAVE_STAT */
|
|
|
|
|
|
static int init_builtin(char *); /* Forward */
|
|
|
|
/* Load an external module using the default search path and return
|
|
its module object WITH INCREMENTED REFERENCE COUNT */
|
|
|
|
static PyObject *
|
|
load_module(char *name, FILE *fp, char *buf, int type, PyObject *loader)
|
|
{
|
|
PyObject *modules;
|
|
PyObject *m;
|
|
int err;
|
|
|
|
/* First check that there's an open file (if we need one) */
|
|
switch (type) {
|
|
case PY_SOURCE:
|
|
case PY_COMPILED:
|
|
if (fp == NULL) {
|
|
PyErr_Format(PyExc_ValueError,
|
|
"file object required for import (type code %d)",
|
|
type);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
switch (type) {
|
|
|
|
case PY_SOURCE:
|
|
m = load_source_module(name, buf, fp);
|
|
break;
|
|
|
|
case PY_COMPILED:
|
|
m = load_compiled_module(name, buf, fp);
|
|
break;
|
|
|
|
#ifdef HAVE_DYNAMIC_LOADING
|
|
case C_EXTENSION:
|
|
m = _PyImport_LoadDynamicModule(name, buf, fp);
|
|
break;
|
|
#endif
|
|
|
|
case PKG_DIRECTORY:
|
|
m = load_package(name, buf);
|
|
break;
|
|
|
|
case C_BUILTIN:
|
|
case PY_FROZEN:
|
|
if (buf != NULL && buf[0] != '\0')
|
|
name = buf;
|
|
if (type == C_BUILTIN)
|
|
err = init_builtin(name);
|
|
else
|
|
err = PyImport_ImportFrozenModule(name);
|
|
if (err < 0)
|
|
return NULL;
|
|
if (err == 0) {
|
|
PyErr_Format(PyExc_ImportError,
|
|
"Purported %s module %.200s not found",
|
|
type == C_BUILTIN ?
|
|
"builtin" : "frozen",
|
|
name);
|
|
return NULL;
|
|
}
|
|
modules = PyImport_GetModuleDict();
|
|
m = PyDict_GetItemString(modules, name);
|
|
if (m == NULL) {
|
|
PyErr_Format(
|
|
PyExc_ImportError,
|
|
"%s module %.200s not properly initialized",
|
|
type == C_BUILTIN ?
|
|
"builtin" : "frozen",
|
|
name);
|
|
return NULL;
|
|
}
|
|
Py_INCREF(m);
|
|
break;
|
|
|
|
case IMP_HOOK: {
|
|
if (loader == NULL) {
|
|
PyErr_SetString(PyExc_ImportError,
|
|
"import hook without loader");
|
|
return NULL;
|
|
}
|
|
m = PyObject_CallMethod(loader, "load_module", "s", name);
|
|
break;
|
|
}
|
|
|
|
default:
|
|
PyErr_Format(PyExc_ImportError,
|
|
"Don't know how to import %.200s (type code %d)",
|
|
name, type);
|
|
m = NULL;
|
|
|
|
}
|
|
|
|
return m;
|
|
}
|
|
|
|
|
|
/* Initialize a built-in module.
|
|
Return 1 for success, 0 if the module is not found, and -1 with
|
|
an exception set if the initialization failed. */
|
|
|
|
static int
|
|
init_builtin(char *name)
|
|
{
|
|
struct _inittab *p;
|
|
|
|
if (_PyImport_FindExtension(name, name) != NULL)
|
|
return 1;
|
|
|
|
for (p = PyImport_Inittab; p->name != NULL; p++) {
|
|
if (strcmp(name, p->name) == 0) {
|
|
if (p->initfunc == NULL) {
|
|
PyErr_Format(PyExc_ImportError,
|
|
"Cannot re-init internal module %.200s",
|
|
name);
|
|
return -1;
|
|
}
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("import %s # builtin\n", name);
|
|
(*p->initfunc)();
|
|
if (PyErr_Occurred())
|
|
return -1;
|
|
if (_PyImport_FixupExtension(name, name) == NULL)
|
|
return -1;
|
|
return 1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
/* Frozen modules */
|
|
|
|
static struct _frozen *
|
|
find_frozen(char *name)
|
|
{
|
|
struct _frozen *p;
|
|
|
|
for (p = PyImport_FrozenModules; ; p++) {
|
|
if (p->name == NULL)
|
|
return NULL;
|
|
if (strcmp(p->name, name) == 0)
|
|
break;
|
|
}
|
|
return p;
|
|
}
|
|
|
|
static PyObject *
|
|
get_frozen_object(char *name)
|
|
{
|
|
struct _frozen *p = find_frozen(name);
|
|
int size;
|
|
|
|
if (p == NULL) {
|
|
PyErr_Format(PyExc_ImportError,
|
|
"No such frozen object named %.200s",
|
|
name);
|
|
return NULL;
|
|
}
|
|
if (p->code == NULL) {
|
|
PyErr_Format(PyExc_ImportError,
|
|
"Excluded frozen object named %.200s",
|
|
name);
|
|
return NULL;
|
|
}
|
|
size = p->size;
|
|
if (size < 0)
|
|
size = -size;
|
|
return PyMarshal_ReadObjectFromString((char *)p->code, size);
|
|
}
|
|
|
|
/* Initialize a frozen module.
|
|
Return 1 for succes, 0 if the module is not found, and -1 with
|
|
an exception set if the initialization failed.
|
|
This function is also used from frozenmain.c */
|
|
|
|
int
|
|
PyImport_ImportFrozenModule(char *name)
|
|
{
|
|
struct _frozen *p = find_frozen(name);
|
|
PyObject *co;
|
|
PyObject *m;
|
|
int ispackage;
|
|
int size;
|
|
|
|
if (p == NULL)
|
|
return 0;
|
|
if (p->code == NULL) {
|
|
PyErr_Format(PyExc_ImportError,
|
|
"Excluded frozen object named %.200s",
|
|
name);
|
|
return -1;
|
|
}
|
|
size = p->size;
|
|
ispackage = (size < 0);
|
|
if (ispackage)
|
|
size = -size;
|
|
if (Py_VerboseFlag)
|
|
PySys_WriteStderr("import %s # frozen%s\n",
|
|
name, ispackage ? " package" : "");
|
|
co = PyMarshal_ReadObjectFromString((char *)p->code, size);
|
|
if (co == NULL)
|
|
return -1;
|
|
if (!PyCode_Check(co)) {
|
|
PyErr_Format(PyExc_TypeError,
|
|
"frozen object %.200s is not a code object",
|
|
name);
|
|
goto err_return;
|
|
}
|
|
if (ispackage) {
|
|
/* Set __path__ to the package name */
|
|
PyObject *d, *s;
|
|
int err;
|
|
m = PyImport_AddModule(name);
|
|
if (m == NULL)
|
|
goto err_return;
|
|
d = PyModule_GetDict(m);
|
|
s = PyString_InternFromString(name);
|
|
if (s == NULL)
|
|
goto err_return;
|
|
err = PyDict_SetItemString(d, "__path__", s);
|
|
Py_DECREF(s);
|
|
if (err != 0)
|
|
goto err_return;
|
|
}
|
|
m = PyImport_ExecCodeModuleEx(name, co, "<frozen>");
|
|
if (m == NULL)
|
|
goto err_return;
|
|
Py_DECREF(co);
|
|
Py_DECREF(m);
|
|
return 1;
|
|
err_return:
|
|
Py_DECREF(co);
|
|
return -1;
|
|
}
|
|
|
|
|
|
/* Import a module, either built-in, frozen, or external, and return
|
|
its module object WITH INCREMENTED REFERENCE COUNT */
|
|
|
|
PyObject *
|
|
PyImport_ImportModule(const char *name)
|
|
{
|
|
PyObject *pname;
|
|
PyObject *result;
|
|
|
|
pname = PyString_FromString(name);
|
|
if (pname == NULL)
|
|
return NULL;
|
|
result = PyImport_Import(pname);
|
|
Py_DECREF(pname);
|
|
return result;
|
|
}
|
|
|
|
/* Forward declarations for helper routines */
|
|
static PyObject *get_parent(PyObject *globals, char *buf,
|
|
Py_ssize_t *p_buflen, int level);
|
|
static PyObject *load_next(PyObject *mod, PyObject *altmod,
|
|
char **p_name, char *buf, Py_ssize_t *p_buflen);
|
|
static int mark_miss(char *name);
|
|
static int ensure_fromlist(PyObject *mod, PyObject *fromlist,
|
|
char *buf, Py_ssize_t buflen, int recursive);
|
|
static PyObject * import_submodule(PyObject *mod, char *name, char *fullname);
|
|
|
|
/* The Magnum Opus of dotted-name import :-) */
|
|
|
|
static PyObject *
|
|
import_module_level(char *name, PyObject *globals, PyObject *locals,
|
|
PyObject *fromlist, int level)
|
|
{
|
|
char buf[MAXPATHLEN+1];
|
|
Py_ssize_t buflen = 0;
|
|
PyObject *parent, *head, *next, *tail;
|
|
|
|
parent = get_parent(globals, buf, &buflen, level);
|
|
if (parent == NULL)
|
|
return NULL;
|
|
|
|
head = load_next(parent, Py_None, &name, buf, &buflen);
|
|
if (head == NULL)
|
|
return NULL;
|
|
|
|
tail = head;
|
|
Py_INCREF(tail);
|
|
while (name) {
|
|
next = load_next(tail, tail, &name, buf, &buflen);
|
|
Py_DECREF(tail);
|
|
if (next == NULL) {
|
|
Py_DECREF(head);
|
|
return NULL;
|
|
}
|
|
tail = next;
|
|
}
|
|
if (tail == Py_None) {
|
|
/* If tail is Py_None, both get_parent and load_next found
|
|
an empty module name: someone called __import__("") or
|
|
doctored faulty bytecode */
|
|
Py_DECREF(tail);
|
|
Py_DECREF(head);
|
|
PyErr_SetString(PyExc_ValueError,
|
|
"Empty module name");
|
|
return NULL;
|
|
}
|
|
|
|
if (fromlist != NULL) {
|
|
if (fromlist == Py_None || !PyObject_IsTrue(fromlist))
|
|
fromlist = NULL;
|
|
}
|
|
|
|
if (fromlist == NULL) {
|
|
Py_DECREF(tail);
|
|
return head;
|
|
}
|
|
|
|
Py_DECREF(head);
|
|
if (!ensure_fromlist(tail, fromlist, buf, buflen, 0)) {
|
|
Py_DECREF(tail);
|
|
return NULL;
|
|
}
|
|
|
|
return tail;
|
|
}
|
|
|
|
/* For DLL compatibility */
|
|
#undef PyImport_ImportModuleEx
|
|
PyObject *
|
|
PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals,
|
|
PyObject *fromlist)
|
|
{
|
|
PyObject *result;
|
|
lock_import();
|
|
result = import_module_level(name, globals, locals, fromlist, -1);
|
|
if (unlock_import() < 0) {
|
|
Py_XDECREF(result);
|
|
PyErr_SetString(PyExc_RuntimeError,
|
|
"not holding the import lock");
|
|
return NULL;
|
|
}
|
|
return result;
|
|
}
|
|
#define PyImport_ImportModuleEx(n, g, l, f) \
|
|
PyImport_ImportModuleLevel(n, g, l, f, -1);
|
|
|
|
PyObject *
|
|
PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals,
|
|
PyObject *fromlist, int level)
|
|
{
|
|
PyObject *result;
|
|
lock_import();
|
|
result = import_module_level(name, globals, locals, fromlist, level);
|
|
if (unlock_import() < 0) {
|
|
Py_XDECREF(result);
|
|
PyErr_SetString(PyExc_RuntimeError,
|
|
"not holding the import lock");
|
|
return NULL;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/* Return the package that an import is being performed in. If globals comes
|
|
from the module foo.bar.bat (not itself a package), this returns the
|
|
sys.modules entry for foo.bar. If globals is from a package's __init__.py,
|
|
the package's entry in sys.modules is returned, as a borrowed reference.
|
|
|
|
The *name* of the returned package is returned in buf, with the length of
|
|
the name in *p_buflen.
|
|
|
|
If globals doesn't come from a package or a module in a package, or a
|
|
corresponding entry is not found in sys.modules, Py_None is returned.
|
|
*/
|
|
static PyObject *
|
|
get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
|
|
{
|
|
static PyObject *namestr = NULL;
|
|
static PyObject *pathstr = NULL;
|
|
PyObject *modname, *modpath, *modules, *parent;
|
|
|
|
if (globals == NULL || !PyDict_Check(globals) || !level)
|
|
return Py_None;
|
|
|
|
if (namestr == NULL) {
|
|
namestr = PyString_InternFromString("__name__");
|
|
if (namestr == NULL)
|
|
return NULL;
|
|
}
|
|
if (pathstr == NULL) {
|
|
pathstr = PyString_InternFromString("__path__");
|
|
if (pathstr == NULL)
|
|
return NULL;
|
|
}
|
|
|
|
*buf = '\0';
|
|
*p_buflen = 0;
|
|
modname = PyDict_GetItem(globals, namestr);
|
|
if (modname == NULL || !PyString_Check(modname))
|
|
return Py_None;
|
|
|
|
modpath = PyDict_GetItem(globals, pathstr);
|
|
if (modpath != NULL) {
|
|
Py_ssize_t len = PyString_GET_SIZE(modname);
|
|
if (len > MAXPATHLEN) {
|
|
PyErr_SetString(PyExc_ValueError,
|
|
"Module name too long");
|
|
return NULL;
|
|
}
|
|
strcpy(buf, PyString_AS_STRING(modname));
|
|
}
|
|
else {
|
|
char *start = PyString_AS_STRING(modname);
|
|
char *lastdot = strrchr(start, '.');
|
|
size_t len;
|
|
if (lastdot == NULL && level > 0) {
|
|
PyErr_SetString(PyExc_ValueError,
|
|
"Attempted relative import in non-package");
|
|
return NULL;
|
|
}
|
|
if (lastdot == NULL)
|
|
return Py_None;
|
|
len = lastdot - start;
|
|
if (len >= MAXPATHLEN) {
|
|
PyErr_SetString(PyExc_ValueError,
|
|
"Module name too long");
|
|
return NULL;
|
|
}
|
|
strncpy(buf, start, len);
|
|
buf[len] = '\0';
|
|
}
|
|
|
|
while (--level > 0) {
|
|
char *dot = strrchr(buf, '.');
|
|
if (dot == NULL) {
|
|
PyErr_SetString(PyExc_ValueError,
|
|
"Attempted relative import beyond "
|
|
"toplevel package");
|
|
return NULL;
|
|
}
|
|
*dot = '\0';
|
|
}
|
|
*p_buflen = strlen(buf);
|
|
|
|
modules = PyImport_GetModuleDict();
|
|
parent = PyDict_GetItemString(modules, buf);
|
|
if (parent == NULL)
|
|
PyErr_Format(PyExc_SystemError,
|
|
"Parent module '%.200s' not loaded", buf);
|
|
return parent;
|
|
/* We expect, but can't guarantee, if parent != None, that:
|
|
- parent.__name__ == buf
|
|
- parent.__dict__ is globals
|
|
If this is violated... Who cares? */
|
|
}
|
|
|
|
/* altmod is either None or same as mod */
|
|
static PyObject *
|
|
load_next(PyObject *mod, PyObject *altmod, char **p_name, char *buf,
|
|
Py_ssize_t *p_buflen)
|
|
{
|
|
char *name = *p_name;
|
|
char *dot = strchr(name, '.');
|
|
size_t len;
|
|
char *p;
|
|
PyObject *result;
|
|
|
|
if (strlen(name) == 0) {
|
|
/* completely empty module name should only happen in
|
|
'from . import' (or '__import__("")')*/
|
|
Py_INCREF(mod);
|
|
*p_name = NULL;
|
|
return mod;
|
|
}
|
|
|
|
if (dot == NULL) {
|
|
*p_name = NULL;
|
|
len = strlen(name);
|
|
}
|
|
else {
|
|
*p_name = dot+1;
|
|
len = dot-name;
|
|
}
|
|
if (len == 0) {
|
|
PyErr_SetString(PyExc_ValueError,
|
|
"Empty module name");
|
|
return NULL;
|
|
}
|
|
|
|
p = buf + *p_buflen;
|
|
if (p != buf)
|
|
*p++ = '.';
|
|
if (p+len-buf >= MAXPATHLEN) {
|
|
PyErr_SetString(PyExc_ValueError,
|
|
"Module name too long");
|
|
return NULL;
|
|
}
|
|
strncpy(p, name, len);
|
|
p[len] = '\0';
|
|
*p_buflen = p+len-buf;
|
|
|
|
result = import_submodule(mod, p, buf);
|
|
if (result == Py_None && altmod != mod) {
|
|
Py_DECREF(result);
|
|
/* Here, altmod must be None and mod must not be None */
|
|
result = import_submodule(altmod, p, p);
|
|
if (result != NULL && result != Py_None) {
|
|
if (mark_miss(buf) != 0) {
|
|
Py_DECREF(result);
|
|
return NULL;
|
|
}
|
|
strncpy(buf, name, len);
|
|
buf[len] = '\0';
|
|
*p_buflen = len;
|
|
}
|
|
}
|
|
if (result == NULL)
|
|
return NULL;
|
|
|
|
if (result == Py_None) {
|
|
Py_DECREF(result);
|
|
PyErr_Format(PyExc_ImportError,
|
|
"No module named %.200s", name);
|
|
return NULL;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
static int
|
|
mark_miss(char *name)
|
|
{
|
|
PyObject *modules = PyImport_GetModuleDict();
|
|
return PyDict_SetItemString(modules, name, Py_None);
|
|
}
|
|
|
|
static int
|
|
ensure_fromlist(PyObject *mod, PyObject *fromlist, char *buf, Py_ssize_t buflen,
|
|
int recursive)
|
|
{
|
|
int i;
|
|
|
|
if (!PyObject_HasAttrString(mod, "__path__"))
|
|
return 1;
|
|
|
|
for (i = 0; ; i++) {
|
|
PyObject *item = PySequence_GetItem(fromlist, i);
|
|
int hasit;
|
|
if (item == NULL) {
|
|
if (PyErr_ExceptionMatches(PyExc_IndexError)) {
|
|
PyErr_Clear();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
if (!PyString_Check(item)) {
|
|
PyErr_SetString(PyExc_TypeError,
|
|
"Item in ``from list'' not a string");
|
|
Py_DECREF(item);
|
|
return 0;
|
|
}
|
|
if (PyString_AS_STRING(item)[0] == '*') {
|
|
PyObject *all;
|
|
Py_DECREF(item);
|
|
/* See if the package defines __all__ */
|
|
if (recursive)
|
|
continue; /* Avoid endless recursion */
|
|
all = PyObject_GetAttrString(mod, "__all__");
|
|
if (all == NULL)
|
|
PyErr_Clear();
|
|
else {
|
|
int ret = ensure_fromlist(mod, all, buf, buflen, 1);
|
|
Py_DECREF(all);
|
|
if (!ret)
|
|
return 0;
|
|
}
|
|
continue;
|
|
}
|
|
hasit = PyObject_HasAttr(mod, item);
|
|
if (!hasit) {
|
|
char *subname = PyString_AS_STRING(item);
|
|
PyObject *submod;
|
|
char *p;
|
|
if (buflen + strlen(subname) >= MAXPATHLEN) {
|
|
PyErr_SetString(PyExc_ValueError,
|
|
"Module name too long");
|
|
Py_DECREF(item);
|
|
return 0;
|
|
}
|
|
p = buf + buflen;
|
|
*p++ = '.';
|
|
strcpy(p, subname);
|
|
submod = import_submodule(mod, subname, buf);
|
|
Py_XDECREF(submod);
|
|
if (submod == NULL) {
|
|
Py_DECREF(item);
|
|
return 0;
|
|
}
|
|
}
|
|
Py_DECREF(item);
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
}
|
|
|
|
static int
|
|
add_submodule(PyObject *mod, PyObject *submod, char *fullname, char *subname,
|
|
PyObject *modules)
|
|
{
|
|
if (mod == Py_None)
|
|
return 1;
|
|
/* Irrespective of the success of this load, make a
|
|
reference to it in the parent package module. A copy gets
|
|
saved in the modules dictionary under the full name, so get a
|
|
reference from there, if need be. (The exception is when the
|
|
load failed with a SyntaxError -- then there's no trace in
|
|
sys.modules. In that case, of course, do nothing extra.) */
|
|
if (submod == NULL) {
|
|
submod = PyDict_GetItemString(modules, fullname);
|
|
if (submod == NULL)
|
|
return 1;
|
|
}
|
|
if (PyModule_Check(mod)) {
|
|
/* We can't use setattr here since it can give a
|
|
* spurious warning if the submodule name shadows a
|
|
* builtin name */
|
|
PyObject *dict = PyModule_GetDict(mod);
|
|
if (!dict)
|
|
return 0;
|
|
if (PyDict_SetItemString(dict, subname, submod) < 0)
|
|
return 0;
|
|
}
|
|
else {
|
|
if (PyObject_SetAttrString(mod, subname, submod) < 0)
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static PyObject *
|
|
import_submodule(PyObject *mod, char *subname, char *fullname)
|
|
{
|
|
PyObject *modules = PyImport_GetModuleDict();
|
|
PyObject *m = NULL;
|
|
|
|
/* Require:
|
|
if mod == None: subname == fullname
|
|
else: mod.__name__ + "." + subname == fullname
|
|
*/
|
|
|
|
if ((m = PyDict_GetItemString(modules, fullname)) != NULL) {
|
|
Py_INCREF(m);
|
|
}
|
|
else {
|
|
PyObject *path, *loader = NULL;
|
|
char buf[MAXPATHLEN+1];
|
|
struct filedescr *fdp;
|
|
FILE *fp = NULL;
|
|
|
|
if (mod == Py_None)
|
|
path = NULL;
|
|
else {
|
|
path = PyObject_GetAttrString(mod, "__path__");
|
|
if (path == NULL) {
|
|
PyErr_Clear();
|
|
Py_INCREF(Py_None);
|
|
return Py_None;
|
|
}
|
|
}
|
|
|
|
buf[0] = '\0';
|
|
fdp = find_module(fullname, subname, path, buf, MAXPATHLEN+1,
|
|
&fp, &loader);
|
|
Py_XDECREF(path);
|
|
if (fdp == NULL) {
|
|
if (!PyErr_ExceptionMatches(PyExc_ImportError))
|
|
return NULL;
|
|
PyErr_Clear();
|
|
Py_INCREF(Py_None);
|
|
return Py_None;
|
|
}
|
|
m = load_module(fullname, fp, buf, fdp->type, loader);
|
|
Py_XDECREF(loader);
|
|
if (fp)
|
|
fclose(fp);
|
|
if (!add_submodule(mod, m, fullname, subname, modules)) {
|
|
Py_XDECREF(m);
|
|
m = NULL;
|
|
}
|
|
}
|
|
|
|
return m;
|
|
}
|
|
|
|
|
|
/* Re-import a module of any kind and return its module object, WITH
|
|
INCREMENTED REFERENCE COUNT */
|
|
|
|
PyObject *
|
|
PyImport_ReloadModule(PyObject *m)
|
|
{
|
|
PyObject *modules = PyImport_GetModuleDict();
|
|
PyObject *path = NULL, *loader = NULL;
|
|
char *name, *subname;
|
|
char buf[MAXPATHLEN+1];
|
|
struct filedescr *fdp;
|
|
FILE *fp = NULL;
|
|
PyObject *newm;
|
|
|
|
if (m == NULL || !PyModule_Check(m)) {
|
|
PyErr_SetString(PyExc_TypeError,
|
|
"reload() argument must be module");
|
|
return NULL;
|
|
}
|
|
name = PyModule_GetName(m);
|
|
if (name == NULL)
|
|
return NULL;
|
|
if (m != PyDict_GetItemString(modules, name)) {
|
|
PyErr_Format(PyExc_ImportError,
|
|
"reload(): module %.200s not in sys.modules",
|
|
name);
|
|
return NULL;
|
|
}
|
|
subname = strrchr(name, '.');
|
|
if (subname == NULL)
|
|
subname = name;
|
|
else {
|
|
PyObject *parentname, *parent;
|
|
parentname = PyString_FromStringAndSize(name, (subname-name));
|
|
if (parentname == NULL)
|
|
return NULL;
|
|
parent = PyDict_GetItem(modules, parentname);
|
|
if (parent == NULL) {
|
|
PyErr_Format(PyExc_ImportError,
|
|
"reload(): parent %.200s not in sys.modules",
|
|
PyString_AS_STRING(parentname));
|
|
Py_DECREF(parentname);
|
|
return NULL;
|
|
}
|
|
Py_DECREF(parentname);
|
|
subname++;
|
|
path = PyObject_GetAttrString(parent, "__path__");
|
|
if (path == NULL)
|
|
PyErr_Clear();
|
|
}
|
|
buf[0] = '\0';
|
|
fdp = find_module(name, subname, path, buf, MAXPATHLEN+1, &fp, &loader);
|
|
Py_XDECREF(path);
|
|
|
|
if (fdp == NULL) {
|
|
Py_XDECREF(loader);
|
|
return NULL;
|
|
}
|
|
|
|
newm = load_module(name, fp, buf, fdp->type, loader);
|
|
Py_XDECREF(loader);
|
|
|
|
if (fp)
|
|
fclose(fp);
|
|
if (newm == NULL) {
|
|
/* load_module probably removed name from modules because of
|
|
* the error. Put back the original module object. We're
|
|
* going to return NULL in this case regardless of whether
|
|
* replacing name succeeds, so the return value is ignored.
|
|
*/
|
|
PyDict_SetItemString(modules, name, m);
|
|
}
|
|
return newm;
|
|
}
|
|
|
|
|
|
/* Higher-level import emulator which emulates the "import" statement
|
|
more accurately -- it invokes the __import__() function from the
|
|
builtins of the current globals. This means that the import is
|
|
done using whatever import hooks are installed in the current
|
|
environment, e.g. by "rexec".
|
|
A dummy list ["__doc__"] is passed as the 4th argument so that
|
|
e.g. PyImport_Import(PyString_FromString("win32com.client.gencache"))
|
|
will return <module "gencache"> instead of <module "win32com">. */
|
|
|
|
PyObject *
|
|
PyImport_Import(PyObject *module_name)
|
|
{
|
|
static PyObject *silly_list = NULL;
|
|
static PyObject *builtins_str = NULL;
|
|
static PyObject *import_str = NULL;
|
|
PyObject *globals = NULL;
|
|
PyObject *import = NULL;
|
|
PyObject *builtins = NULL;
|
|
PyObject *r = NULL;
|
|
|
|
/* Initialize constant string objects */
|
|
if (silly_list == NULL) {
|
|
import_str = PyString_InternFromString("__import__");
|
|
if (import_str == NULL)
|
|
return NULL;
|
|
builtins_str = PyString_InternFromString("__builtins__");
|
|
if (builtins_str == NULL)
|
|
return NULL;
|
|
silly_list = Py_BuildValue("[s]", "__doc__");
|
|
if (silly_list == NULL)
|
|
return NULL;
|
|
}
|
|
|
|
/* Get the builtins from current globals */
|
|
globals = PyEval_GetGlobals();
|
|
if (globals != NULL) {
|
|
Py_INCREF(globals);
|
|
builtins = PyObject_GetItem(globals, builtins_str);
|
|
if (builtins == NULL)
|
|
goto err;
|
|
}
|
|
else {
|
|
/* No globals -- use standard builtins, and fake globals */
|
|
PyErr_Clear();
|
|
|
|
builtins = PyImport_ImportModuleLevel("__builtin__",
|
|
NULL, NULL, NULL, 0);
|
|
if (builtins == NULL)
|
|
return NULL;
|
|
globals = Py_BuildValue("{OO}", builtins_str, builtins);
|
|
if (globals == NULL)
|
|
goto err;
|
|
}
|
|
|
|
/* Get the __import__ function from the builtins */
|
|
if (PyDict_Check(builtins)) {
|
|
import = PyObject_GetItem(builtins, import_str);
|
|
if (import == NULL)
|
|
PyErr_SetObject(PyExc_KeyError, import_str);
|
|
}
|
|
else
|
|
import = PyObject_GetAttr(builtins, import_str);
|
|
if (import == NULL)
|
|
goto err;
|
|
|
|
/* Call the _import__ function with the proper argument list */
|
|
r = PyObject_CallFunctionObjArgs(import, module_name, globals,
|
|
globals, silly_list, NULL);
|
|
|
|
err:
|
|
Py_XDECREF(globals);
|
|
Py_XDECREF(builtins);
|
|
Py_XDECREF(import);
|
|
|
|
return r;
|
|
}
|
|
|
|
|
|
/* Module 'imp' provides Python access to the primitives used for
|
|
importing modules.
|
|
*/
|
|
|
|
static PyObject *
|
|
imp_get_magic(PyObject *self, PyObject *noargs)
|
|
{
|
|
char buf[4];
|
|
|
|
buf[0] = (char) ((pyc_magic >> 0) & 0xff);
|
|
buf[1] = (char) ((pyc_magic >> 8) & 0xff);
|
|
buf[2] = (char) ((pyc_magic >> 16) & 0xff);
|
|
buf[3] = (char) ((pyc_magic >> 24) & 0xff);
|
|
|
|
return PyString_FromStringAndSize(buf, 4);
|
|
}
|
|
|
|
static PyObject *
|
|
imp_get_suffixes(PyObject *self, PyObject *noargs)
|
|
{
|
|
PyObject *list;
|
|
struct filedescr *fdp;
|
|
|
|
list = PyList_New(0);
|
|
if (list == NULL)
|
|
return NULL;
|
|
for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
|
|
PyObject *item = Py_BuildValue("ssi",
|
|
fdp->suffix, fdp->mode, fdp->type);
|
|
if (item == NULL) {
|
|
Py_DECREF(list);
|
|
return NULL;
|
|
}
|
|
if (PyList_Append(list, item) < 0) {
|
|
Py_DECREF(list);
|
|
Py_DECREF(item);
|
|
return NULL;
|
|
}
|
|
Py_DECREF(item);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
static PyObject *
|
|
call_find_module(char *name, PyObject *path)
|
|
{
|
|
extern int fclose(FILE *);
|
|
PyObject *fob, *ret;
|
|
struct filedescr *fdp;
|
|
char pathname[MAXPATHLEN+1];
|
|
FILE *fp = NULL;
|
|
|
|
pathname[0] = '\0';
|
|
if (path == Py_None)
|
|
path = NULL;
|
|
fdp = find_module(NULL, name, path, pathname, MAXPATHLEN+1, &fp, NULL);
|
|
if (fdp == NULL)
|
|
return NULL;
|
|
if (fp != NULL) {
|
|
fob = PyFile_FromFile(fp, pathname, fdp->mode, fclose);
|
|
if (fob == NULL) {
|
|
fclose(fp);
|
|
return NULL;
|
|
}
|
|
}
|
|
else {
|
|
fob = Py_None;
|
|
Py_INCREF(fob);
|
|
}
|
|
ret = Py_BuildValue("Os(ssi)",
|
|
fob, pathname, fdp->suffix, fdp->mode, fdp->type);
|
|
Py_DECREF(fob);
|
|
return ret;
|
|
}
|
|
|
|
static PyObject *
|
|
imp_find_module(PyObject *self, PyObject *args)
|
|
{
|
|
char *name;
|
|
PyObject *path = NULL;
|
|
if (!PyArg_ParseTuple(args, "s|O:find_module", &name, &path))
|
|
return NULL;
|
|
return call_find_module(name, path);
|
|
}
|
|
|
|
static PyObject *
|
|
imp_init_builtin(PyObject *self, PyObject *args)
|
|
{
|
|
char *name;
|
|
int ret;
|
|
PyObject *m;
|
|
if (!PyArg_ParseTuple(args, "s:init_builtin", &name))
|
|
return NULL;
|
|
ret = init_builtin(name);
|
|
if (ret < 0)
|
|
return NULL;
|
|
if (ret == 0) {
|
|
Py_INCREF(Py_None);
|
|
return Py_None;
|
|
}
|
|
m = PyImport_AddModule(name);
|
|
Py_XINCREF(m);
|
|
return m;
|
|
}
|
|
|
|
static PyObject *
|
|
imp_init_frozen(PyObject *self, PyObject *args)
|
|
{
|
|
char *name;
|
|
int ret;
|
|
PyObject *m;
|
|
if (!PyArg_ParseTuple(args, "s:init_frozen", &name))
|
|
return NULL;
|
|
ret = PyImport_ImportFrozenModule(name);
|
|
if (ret < 0)
|
|
return NULL;
|
|
if (ret == 0) {
|
|
Py_INCREF(Py_None);
|
|
return Py_None;
|
|
}
|
|
m = PyImport_AddModule(name);
|
|
Py_XINCREF(m);
|
|
return m;
|
|
}
|
|
|
|
static PyObject *
|
|
imp_get_frozen_object(PyObject *self, PyObject *args)
|
|
{
|
|
char *name;
|
|
|
|
if (!PyArg_ParseTuple(args, "s:get_frozen_object", &name))
|
|
return NULL;
|
|
return get_frozen_object(name);
|
|
}
|
|
|
|
static PyObject *
|
|
imp_is_builtin(PyObject *self, PyObject *args)
|
|
{
|
|
char *name;
|
|
if (!PyArg_ParseTuple(args, "s:is_builtin", &name))
|
|
return NULL;
|
|
return PyInt_FromLong(is_builtin(name));
|
|
}
|
|
|
|
static PyObject *
|
|
imp_is_frozen(PyObject *self, PyObject *args)
|
|
{
|
|
char *name;
|
|
struct _frozen *p;
|
|
if (!PyArg_ParseTuple(args, "s:is_frozen", &name))
|
|
return NULL;
|
|
p = find_frozen(name);
|
|
return PyBool_FromLong((long) (p == NULL ? 0 : p->size));
|
|
}
|
|
|
|
static FILE *
|
|
get_file(char *pathname, PyObject *fob, char *mode)
|
|
{
|
|
FILE *fp;
|
|
if (fob == NULL) {
|
|
if (mode[0] == 'U')
|
|
mode = "r" PY_STDIOTEXTMODE;
|
|
fp = fopen(pathname, mode);
|
|
if (fp == NULL)
|
|
PyErr_SetFromErrno(PyExc_IOError);
|
|
}
|
|
else {
|
|
fp = PyFile_AsFile(fob);
|
|
if (fp == NULL)
|
|
PyErr_SetString(PyExc_ValueError,
|
|
"bad/closed file object");
|
|
}
|
|
return fp;
|
|
}
|
|
|
|
static PyObject *
|
|
imp_load_compiled(PyObject *self, PyObject *args)
|
|
{
|
|
char *name;
|
|
char *pathname;
|
|
PyObject *fob = NULL;
|
|
PyObject *m;
|
|
FILE *fp;
|
|
if (!PyArg_ParseTuple(args, "ss|O!:load_compiled", &name, &pathname,
|
|
&PyFile_Type, &fob))
|
|
return NULL;
|
|
fp = get_file(pathname, fob, "rb");
|
|
if (fp == NULL)
|
|
return NULL;
|
|
m = load_compiled_module(name, pathname, fp);
|
|
if (fob == NULL)
|
|
fclose(fp);
|
|
return m;
|
|
}
|
|
|
|
#ifdef HAVE_DYNAMIC_LOADING
|
|
|
|
static PyObject *
|
|
imp_load_dynamic(PyObject *self, PyObject *args)
|
|
{
|
|
char *name;
|
|
char *pathname;
|
|
PyObject *fob = NULL;
|
|
PyObject *m;
|
|
FILE *fp = NULL;
|
|
if (!PyArg_ParseTuple(args, "ss|O!:load_dynamic", &name, &pathname,
|
|
&PyFile_Type, &fob))
|
|
return NULL;
|
|
if (fob) {
|
|
fp = get_file(pathname, fob, "r");
|
|
if (fp == NULL)
|
|
return NULL;
|
|
}
|
|
m = _PyImport_LoadDynamicModule(name, pathname, fp);
|
|
return m;
|
|
}
|
|
|
|
#endif /* HAVE_DYNAMIC_LOADING */
|
|
|
|
static PyObject *
|
|
imp_load_source(PyObject *self, PyObject *args)
|
|
{
|
|
char *name;
|
|
char *pathname;
|
|
PyObject *fob = NULL;
|
|
PyObject *m;
|
|
FILE *fp;
|
|
if (!PyArg_ParseTuple(args, "ss|O!:load_source", &name, &pathname,
|
|
&PyFile_Type, &fob))
|
|
return NULL;
|
|
fp = get_file(pathname, fob, "r");
|
|
if (fp == NULL)
|
|
return NULL;
|
|
m = load_source_module(name, pathname, fp);
|
|
if (fob == NULL)
|
|
fclose(fp);
|
|
return m;
|
|
}
|
|
|
|
static PyObject *
|
|
imp_load_module(PyObject *self, PyObject *args)
|
|
{
|
|
char *name;
|
|
PyObject *fob;
|
|
char *pathname;
|
|
char *suffix; /* Unused */
|
|
char *mode;
|
|
int type;
|
|
FILE *fp;
|
|
|
|
if (!PyArg_ParseTuple(args, "sOs(ssi):load_module",
|
|
&name, &fob, &pathname,
|
|
&suffix, &mode, &type))
|
|
return NULL;
|
|
if (*mode) {
|
|
/* Mode must start with 'r' or 'U' and must not contain '+'.
|
|
Implicit in this test is the assumption that the mode
|
|
may contain other modifiers like 'b' or 't'. */
|
|
|
|
if (!(*mode == 'r' || *mode == 'U') || strchr(mode, '+')) {
|
|
PyErr_Format(PyExc_ValueError,
|
|
"invalid file open mode %.200s", mode);
|
|
return NULL;
|
|
}
|
|
}
|
|
if (fob == Py_None)
|
|
fp = NULL;
|
|
else {
|
|
if (!PyFile_Check(fob)) {
|
|
PyErr_SetString(PyExc_ValueError,
|
|
"load_module arg#2 should be a file or None");
|
|
return NULL;
|
|
}
|
|
fp = get_file(pathname, fob, mode);
|
|
if (fp == NULL)
|
|
return NULL;
|
|
}
|
|
return load_module(name, fp, pathname, type, NULL);
|
|
}
|
|
|
|
static PyObject *
|
|
imp_load_package(PyObject *self, PyObject *args)
|
|
{
|
|
char *name;
|
|
char *pathname;
|
|
if (!PyArg_ParseTuple(args, "ss:load_package", &name, &pathname))
|
|
return NULL;
|
|
return load_package(name, pathname);
|
|
}
|
|
|
|
static PyObject *
|
|
imp_new_module(PyObject *self, PyObject *args)
|
|
{
|
|
char *name;
|
|
if (!PyArg_ParseTuple(args, "s:new_module", &name))
|
|
return NULL;
|
|
return PyModule_New(name);
|
|
}
|
|
|
|
/* Doc strings */
|
|
|
|
PyDoc_STRVAR(doc_imp,
|
|
"This module provides the components needed to build your own\n\
|
|
__import__ function. Undocumented functions are obsolete.");
|
|
|
|
PyDoc_STRVAR(doc_find_module,
|
|
"find_module(name, [path]) -> (file, filename, (suffix, mode, type))\n\
|
|
Search for a module. If path is omitted or None, search for a\n\
|
|
built-in, frozen or special module and continue search in sys.path.\n\
|
|
The module name cannot contain '.'; to search for a submodule of a\n\
|
|
package, pass the submodule name and the package's __path__.");
|
|
|
|
PyDoc_STRVAR(doc_load_module,
|
|
"load_module(name, file, filename, (suffix, mode, type)) -> module\n\
|
|
Load a module, given information returned by find_module().\n\
|
|
The module name must include the full package name, if any.");
|
|
|
|
PyDoc_STRVAR(doc_get_magic,
|
|
"get_magic() -> string\n\
|
|
Return the magic number for .pyc or .pyo files.");
|
|
|
|
PyDoc_STRVAR(doc_get_suffixes,
|
|
"get_suffixes() -> [(suffix, mode, type), ...]\n\
|
|
Return a list of (suffix, mode, type) tuples describing the files\n\
|
|
that find_module() looks for.");
|
|
|
|
PyDoc_STRVAR(doc_new_module,
|
|
"new_module(name) -> module\n\
|
|
Create a new module. Do not enter it in sys.modules.\n\
|
|
The module name must include the full package name, if any.");
|
|
|
|
PyDoc_STRVAR(doc_lock_held,
|
|
"lock_held() -> boolean\n\
|
|
Return True if the import lock is currently held, else False.\n\
|
|
On platforms without threads, return False.");
|
|
|
|
PyDoc_STRVAR(doc_acquire_lock,
|
|
"acquire_lock() -> None\n\
|
|
Acquires the interpreter's import lock for the current thread.\n\
|
|
This lock should be used by import hooks to ensure thread-safety\n\
|
|
when importing modules.\n\
|
|
On platforms without threads, this function does nothing.");
|
|
|
|
PyDoc_STRVAR(doc_release_lock,
|
|
"release_lock() -> None\n\
|
|
Release the interpreter's import lock.\n\
|
|
On platforms without threads, this function does nothing.");
|
|
|
|
static PyMethodDef imp_methods[] = {
|
|
{"find_module", imp_find_module, METH_VARARGS, doc_find_module},
|
|
{"get_magic", imp_get_magic, METH_NOARGS, doc_get_magic},
|
|
{"get_suffixes", imp_get_suffixes, METH_NOARGS, doc_get_suffixes},
|
|
{"load_module", imp_load_module, METH_VARARGS, doc_load_module},
|
|
{"new_module", imp_new_module, METH_VARARGS, doc_new_module},
|
|
{"lock_held", imp_lock_held, METH_NOARGS, doc_lock_held},
|
|
{"acquire_lock", imp_acquire_lock, METH_NOARGS, doc_acquire_lock},
|
|
{"release_lock", imp_release_lock, METH_NOARGS, doc_release_lock},
|
|
/* The rest are obsolete */
|
|
{"get_frozen_object", imp_get_frozen_object, METH_VARARGS},
|
|
{"init_builtin", imp_init_builtin, METH_VARARGS},
|
|
{"init_frozen", imp_init_frozen, METH_VARARGS},
|
|
{"is_builtin", imp_is_builtin, METH_VARARGS},
|
|
{"is_frozen", imp_is_frozen, METH_VARARGS},
|
|
{"load_compiled", imp_load_compiled, METH_VARARGS},
|
|
#ifdef HAVE_DYNAMIC_LOADING
|
|
{"load_dynamic", imp_load_dynamic, METH_VARARGS},
|
|
#endif
|
|
{"load_package", imp_load_package, METH_VARARGS},
|
|
{"load_source", imp_load_source, METH_VARARGS},
|
|
{NULL, NULL} /* sentinel */
|
|
};
|
|
|
|
static int
|
|
setint(PyObject *d, char *name, int value)
|
|
{
|
|
PyObject *v;
|
|
int err;
|
|
|
|
v = PyInt_FromLong((long)value);
|
|
err = PyDict_SetItemString(d, name, v);
|
|
Py_XDECREF(v);
|
|
return err;
|
|
}
|
|
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
} NullImporter;
|
|
|
|
static int
|
|
NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
|
|
{
|
|
char *path;
|
|
|
|
if (!_PyArg_NoKeywords("NullImporter()", kwds))
|
|
return -1;
|
|
|
|
if (!PyArg_ParseTuple(args, "s:NullImporter",
|
|
&path))
|
|
return -1;
|
|
|
|
if (strlen(path) == 0) {
|
|
PyErr_SetString(PyExc_ImportError, "empty pathname");
|
|
return -1;
|
|
} else {
|
|
#ifndef RISCOS
|
|
struct stat statbuf;
|
|
int rv;
|
|
|
|
rv = stat(path, &statbuf);
|
|
if (rv == 0) {
|
|
/* it exists */
|
|
if (S_ISDIR(statbuf.st_mode)) {
|
|
/* it's a directory */
|
|
PyErr_SetString(PyExc_ImportError,
|
|
"existing directory");
|
|
return -1;
|
|
}
|
|
}
|
|
#else
|
|
if (object_exists(path)) {
|
|
/* it exists */
|
|
if (isdir(path)) {
|
|
/* it's a directory */
|
|
PyErr_SetString(PyExc_ImportError,
|
|
"existing directory");
|
|
return -1;
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static PyObject *
|
|
NullImporter_find_module(NullImporter *self, PyObject *args)
|
|
{
|
|
Py_RETURN_NONE;
|
|
}
|
|
|
|
static PyMethodDef NullImporter_methods[] = {
|
|
{"find_module", (PyCFunction)NullImporter_find_module, METH_VARARGS,
|
|
"Always return None"
|
|
},
|
|
{NULL} /* Sentinel */
|
|
};
|
|
|
|
|
|
static PyTypeObject NullImporterType = {
|
|
PyObject_HEAD_INIT(NULL)
|
|
0, /*ob_size*/
|
|
"imp.NullImporter", /*tp_name*/
|
|
sizeof(NullImporter), /*tp_basicsize*/
|
|
0, /*tp_itemsize*/
|
|
0, /*tp_dealloc*/
|
|
0, /*tp_print*/
|
|
0, /*tp_getattr*/
|
|
0, /*tp_setattr*/
|
|
0, /*tp_compare*/
|
|
0, /*tp_repr*/
|
|
0, /*tp_as_number*/
|
|
0, /*tp_as_sequence*/
|
|
0, /*tp_as_mapping*/
|
|
0, /*tp_hash */
|
|
0, /*tp_call*/
|
|
0, /*tp_str*/
|
|
0, /*tp_getattro*/
|
|
0, /*tp_setattro*/
|
|
0, /*tp_as_buffer*/
|
|
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
|
"Null importer object", /* tp_doc */
|
|
0, /* tp_traverse */
|
|
0, /* tp_clear */
|
|
0, /* tp_richcompare */
|
|
0, /* tp_weaklistoffset */
|
|
0, /* tp_iter */
|
|
0, /* tp_iternext */
|
|
NullImporter_methods, /* tp_methods */
|
|
0, /* tp_members */
|
|
0, /* tp_getset */
|
|
0, /* tp_base */
|
|
0, /* tp_dict */
|
|
0, /* tp_descr_get */
|
|
0, /* tp_descr_set */
|
|
0, /* tp_dictoffset */
|
|
(initproc)NullImporter_init, /* tp_init */
|
|
0, /* tp_alloc */
|
|
PyType_GenericNew /* tp_new */
|
|
};
|
|
|
|
|
|
PyMODINIT_FUNC
|
|
initimp(void)
|
|
{
|
|
PyObject *m, *d;
|
|
|
|
if (PyType_Ready(&NullImporterType) < 0)
|
|
goto failure;
|
|
|
|
m = Py_InitModule4("imp", imp_methods, doc_imp,
|
|
NULL, PYTHON_API_VERSION);
|
|
if (m == NULL)
|
|
goto failure;
|
|
d = PyModule_GetDict(m);
|
|
if (d == NULL)
|
|
goto failure;
|
|
|
|
if (setint(d, "SEARCH_ERROR", SEARCH_ERROR) < 0) goto failure;
|
|
if (setint(d, "PY_SOURCE", PY_SOURCE) < 0) goto failure;
|
|
if (setint(d, "PY_COMPILED", PY_COMPILED) < 0) goto failure;
|
|
if (setint(d, "C_EXTENSION", C_EXTENSION) < 0) goto failure;
|
|
if (setint(d, "PY_RESOURCE", PY_RESOURCE) < 0) goto failure;
|
|
if (setint(d, "PKG_DIRECTORY", PKG_DIRECTORY) < 0) goto failure;
|
|
if (setint(d, "C_BUILTIN", C_BUILTIN) < 0) goto failure;
|
|
if (setint(d, "PY_FROZEN", PY_FROZEN) < 0) goto failure;
|
|
if (setint(d, "PY_CODERESOURCE", PY_CODERESOURCE) < 0) goto failure;
|
|
if (setint(d, "IMP_HOOK", IMP_HOOK) < 0) goto failure;
|
|
|
|
Py_INCREF(&NullImporterType);
|
|
PyModule_AddObject(m, "NullImporter", (PyObject *)&NullImporterType);
|
|
failure:
|
|
;
|
|
}
|
|
|
|
|
|
/* API for embedding applications that want to add their own entries
|
|
to the table of built-in modules. This should normally be called
|
|
*before* Py_Initialize(). When the table resize fails, -1 is
|
|
returned and the existing table is unchanged.
|
|
|
|
After a similar function by Just van Rossum. */
|
|
|
|
int
|
|
PyImport_ExtendInittab(struct _inittab *newtab)
|
|
{
|
|
static struct _inittab *our_copy = NULL;
|
|
struct _inittab *p;
|
|
int i, n;
|
|
|
|
/* Count the number of entries in both tables */
|
|
for (n = 0; newtab[n].name != NULL; n++)
|
|
;
|
|
if (n == 0)
|
|
return 0; /* Nothing to do */
|
|
for (i = 0; PyImport_Inittab[i].name != NULL; i++)
|
|
;
|
|
|
|
/* Allocate new memory for the combined table */
|
|
p = our_copy;
|
|
PyMem_RESIZE(p, struct _inittab, i+n+1);
|
|
if (p == NULL)
|
|
return -1;
|
|
|
|
/* Copy the tables into the new memory */
|
|
if (our_copy != PyImport_Inittab)
|
|
memcpy(p, PyImport_Inittab, (i+1) * sizeof(struct _inittab));
|
|
PyImport_Inittab = our_copy = p;
|
|
memcpy(p+i, newtab, (n+1) * sizeof(struct _inittab));
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Shorthand to add a single entry given a name and a function */
|
|
|
|
int
|
|
PyImport_AppendInittab(char *name, void (*initfunc)(void))
|
|
{
|
|
struct _inittab newtab[2];
|
|
|
|
memset(newtab, '\0', sizeof newtab);
|
|
|
|
newtab[0].name = name;
|
|
newtab[0].initfunc = initfunc;
|
|
|
|
return PyImport_ExtendInittab(newtab);
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|