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

1656 lines
52 KiB

Merged revisions 56154-56264 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r56155 | neal.norwitz | 2007-07-03 08:59:08 +0300 (Tue, 03 Jul 2007) | 1 line Get this test working after converting map to return an iterator ................ r56202 | neal.norwitz | 2007-07-09 04:30:09 +0300 (Mon, 09 Jul 2007) | 37 lines Merged revisions 56124-56201 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r56129 | georg.brandl | 2007-06-30 04:01:01 -0700 (Sat, 30 Jun 2007) | 2 lines Document smtp.SMTPAuthenticationError. ........ r56137 | georg.brandl | 2007-07-01 01:11:35 -0700 (Sun, 01 Jul 2007) | 2 lines Fix a few webbrowser.py problems. ........ r56143 | georg.brandl | 2007-07-02 04:54:28 -0700 (Mon, 02 Jul 2007) | 2 lines Remove duplicate sentence from alarm() doc. ........ r56170 | mark.hammond | 2007-07-03 19:03:10 -0700 (Tue, 03 Jul 2007) | 3 lines copy built files to the PCBuild directory, where tools like distutils or external build processes can find them. ........ r56176 | kurt.kaiser | 2007-07-05 15:03:39 -0700 (Thu, 05 Jul 2007) | 10 lines Many calls to tk.call involve an arglist containing a single tuple. Calls using METH_OLDARGS unpack this tuple; calls using METH_VARARG don't. Tcl's concatenation of args was affected; IDLE doesn't start. Modify Tkapp_Call() to unpack single tuple arglists. Bug 1733943 Ref http://mail.python.org/pipermail/python-checkins/2007-May/060454.html ........ r56177 | neal.norwitz | 2007-07-05 21:13:39 -0700 (Thu, 05 Jul 2007) | 1 line Fix typo in comment ........ ................ r56251 | neal.norwitz | 2007-07-11 10:01:01 +0300 (Wed, 11 Jul 2007) | 1 line Get working with map returning an iterator (had to fix whitespace too) ................ r56255 | thomas.wouters | 2007-07-11 13:41:37 +0300 (Wed, 11 Jul 2007) | 6 lines Clean up merge glitch or copy-paste error (the entire module was duplicated, except the first half even had some more copy-paste errors, referring to listcomps and genexps instead of setcomps) ................ r56256 | thomas.wouters | 2007-07-11 15:16:01 +0300 (Wed, 11 Jul 2007) | 14 lines Dict comprehensions. Still needs doc changes (like many python-3000 features ;-). It generates bytecode similar to: x = {} for k, v in (generator here): x[k] = v except there is no tuple-packing and -unpacking involved. Trivial measurement suggests it's significantly faster than dict(generator here) (in the order of 2 to 3 times as fast) but I have not done extensive measurements. ................ r56263 | guido.van.rossum | 2007-07-11 15:36:26 +0300 (Wed, 11 Jul 2007) | 3 lines Patch 1724999 by Ali Gholami Rudi -- avoid complaints about dict size change during iter in destroy call. ................
19 years ago
Merged revisions 55817-55961 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r55837 | guido.van.rossum | 2007-06-08 16:04:42 -0700 (Fri, 08 Jun 2007) | 2 lines PEP 3119 -- the abc module. ................ r55838 | guido.van.rossum | 2007-06-08 17:38:55 -0700 (Fri, 08 Jun 2007) | 2 lines Implement part of PEP 3119 -- One Trick Ponies. ................ r55847 | guido.van.rossum | 2007-06-09 08:28:06 -0700 (Sat, 09 Jun 2007) | 2 lines Different way to do one trick ponies, allowing registration (per PEP strawman). ................ r55849 | guido.van.rossum | 2007-06-09 18:06:38 -0700 (Sat, 09 Jun 2007) | 3 lines Make sure that the magic looking for __hash__ (etc.) doesn't apply to real subclasses of Hashable. ................ r55852 | guido.van.rossum | 2007-06-10 08:29:51 -0700 (Sun, 10 Jun 2007) | 2 lines Add some more examples, e.g. generators and dict views. ................ r55853 | guido.van.rossum | 2007-06-10 08:31:59 -0700 (Sun, 10 Jun 2007) | 2 lines keys() and items() *are* containers -- just values() isn't. ................ r55864 | georg.brandl | 2007-06-10 15:29:40 -0700 (Sun, 10 Jun 2007) | 2 lines PEP 3127: new octal literals, binary literals. ................ r55865 | georg.brandl | 2007-06-10 15:31:37 -0700 (Sun, 10 Jun 2007) | 2 lines Some octal literal fixes in Tools. ................ r55866 | georg.brandl | 2007-06-10 15:37:43 -0700 (Sun, 10 Jun 2007) | 2 lines Tokenizer changes for PEP 3127. ................ r55867 | georg.brandl | 2007-06-10 15:37:55 -0700 (Sun, 10 Jun 2007) | 2 lines Some docs for PEP 3127. ................ r55868 | georg.brandl | 2007-06-10 15:44:39 -0700 (Sun, 10 Jun 2007) | 2 lines Missed a place in intobject.c. Is that used anymore anyway? ................ r55871 | neal.norwitz | 2007-06-10 18:31:49 -0700 (Sun, 10 Jun 2007) | 182 lines Merged revisions 55729-55868 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55731 | neal.norwitz | 2007-06-01 00:29:12 -0700 (Fri, 01 Jun 2007) | 7 lines SF 1668596/1720897: distutils now copies data files even if package_dir is empty. This needs to be backported. I'm too tired tonight. It would be great if someone backports this if the buildbots are ok with it. Otherwise, I will try to get to it tomorrow. ........ r55732 | georg.brandl | 2007-06-01 04:33:33 -0700 (Fri, 01 Jun 2007) | 2 lines Bug #1722484: remove docstrings again when running with -OO. ........ r55735 | georg.brandl | 2007-06-01 12:20:27 -0700 (Fri, 01 Jun 2007) | 2 lines Fix wrong issue number. ........ r55739 | brett.cannon | 2007-06-01 20:02:29 -0700 (Fri, 01 Jun 2007) | 3 lines Have configure raise an error when building on AtheOS. Code specific to AtheOS will be removed in Python 2.7. ........ r55746 | neal.norwitz | 2007-06-02 11:33:53 -0700 (Sat, 02 Jun 2007) | 1 line Update expected birthday of 2.6 ........ r55751 | neal.norwitz | 2007-06-03 13:32:50 -0700 (Sun, 03 Jun 2007) | 10 lines Backout the original 'fix' to 1721309 which had no effect. Different versions of Berkeley DB handle this differently. The comments and bug report should have the details. Memory is allocated in 4.4 (and presumably earlier), but not in 4.5. Thus 4.5 has the free error, but not earlier versions. Mostly update comments, plus make the free conditional. This fix was already applied to the 2.5 branch. ........ r55752 | brett.cannon | 2007-06-03 16:13:41 -0700 (Sun, 03 Jun 2007) | 6 lines Make _strptime.TimeRE().pattern() use ``\s+`` for matching whitespace instead of ``\s*``. This prevents patterns from "stealing" bits from other patterns in order to make a match work. Closes bug #1730389. Will be backported. ........ r55766 | hyeshik.chang | 2007-06-05 11:16:52 -0700 (Tue, 05 Jun 2007) | 4 lines Fix build on FreeBSD. Bluetooth HCI API in FreeBSD is quite different from Linux's. Just fix the build for now but the code doesn't support the complete capability of HCI on FreeBSD yet. ........ r55770 | hyeshik.chang | 2007-06-05 11:58:51 -0700 (Tue, 05 Jun 2007) | 4 lines Bug #1728403: Fix a bug that CJKCodecs StreamReader hangs when it reads a file that ends with incomplete sequence and sizehint argument for .read() is specified. ........ r55775 | hyeshik.chang | 2007-06-05 12:28:15 -0700 (Tue, 05 Jun 2007) | 2 lines Fix for Windows: close a temporary file before trying to delete it. ........ r55783 | guido.van.rossum | 2007-06-05 14:24:47 -0700 (Tue, 05 Jun 2007) | 2 lines Patch by Tim Delany (missing DECREF). SF #1731330. ........ r55785 | collin.winter | 2007-06-05 17:17:35 -0700 (Tue, 05 Jun 2007) | 3 lines Patch #1731049: make threading.py use a proper "raise" when checking internal state, rather than assert statements (which get stripped out by -O). ........ r55786 | facundo.batista | 2007-06-06 08:13:37 -0700 (Wed, 06 Jun 2007) | 4 lines FTP.ntransfercmd method now uses create_connection when passive, using the timeout received in connection time. ........ r55792 | facundo.batista | 2007-06-06 10:15:23 -0700 (Wed, 06 Jun 2007) | 7 lines Added an optional timeout parameter to function urllib2.urlopen, with tests in test_urllib2net.py (must have network resource enabled to execute them). Also modified test_urllib2.py because testing mock classes must take it into acount. Docs are also updated. ........ r55793 | thomas.heller | 2007-06-06 13:19:19 -0700 (Wed, 06 Jun 2007) | 1 line Build _ctypes and _ctypes_test in the ReleaseAMD64 configuration. ........ r55802 | georg.brandl | 2007-06-07 06:23:24 -0700 (Thu, 07 Jun 2007) | 3 lines Disallow function calls like foo(None=1). Backport from py3k rev. 55708 by Guido. ........ r55804 | georg.brandl | 2007-06-07 06:30:24 -0700 (Thu, 07 Jun 2007) | 2 lines Make reindent.py executable. ........ r55805 | georg.brandl | 2007-06-07 06:34:10 -0700 (Thu, 07 Jun 2007) | 2 lines Patch #1667860: Fix UnboundLocalError in urllib2. ........ r55821 | kristjan.jonsson | 2007-06-07 16:53:49 -0700 (Thu, 07 Jun 2007) | 1 line Fixing changes to getbuildinfo.c that broke linux builds ........ r55828 | thomas.heller | 2007-06-08 09:10:27 -0700 (Fri, 08 Jun 2007) | 1 line Make this test work with older Python releases where struct has no 't' format character. ........ r55829 | martin.v.loewis | 2007-06-08 10:29:20 -0700 (Fri, 08 Jun 2007) | 3 lines Bug #1733488: Fix compilation of bufferobject.c on AIX. Will backport to 2.5. ........ r55831 | thomas.heller | 2007-06-08 11:20:09 -0700 (Fri, 08 Jun 2007) | 2 lines [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur with small modifications. ........ r55832 | thomas.heller | 2007-06-08 12:01:06 -0700 (Fri, 08 Jun 2007) | 1 line Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls. ........ r55833 | thomas.heller | 2007-06-08 12:08:31 -0700 (Fri, 08 Jun 2007) | 2 lines Fix wrong documentation, and correct the punktuation. Closes [1700455]. ........ r55834 | thomas.heller | 2007-06-08 12:14:23 -0700 (Fri, 08 Jun 2007) | 1 line Fix warnings by using proper function prototype. ........ r55839 | neal.norwitz | 2007-06-08 20:36:34 -0700 (Fri, 08 Jun 2007) | 7 lines Prevent expandtabs() on string and unicode objects from causing a segfault when a large width is passed on 32-bit platforms. Found by Google. It would be good for people to review this especially carefully and verify I don't have an off by one error and there is no other way to cause overflow. ........ r55841 | neal.norwitz | 2007-06-08 21:48:22 -0700 (Fri, 08 Jun 2007) | 1 line Use macro version of GET_SIZE to avoid Coverity warning (#150) about a possible error. ........ r55842 | martin.v.loewis | 2007-06-09 00:42:52 -0700 (Sat, 09 Jun 2007) | 3 lines Patch #1733960: Allow T_LONGLONG to accept ints. Will backport to 2.5. ........ r55843 | martin.v.loewis | 2007-06-09 00:58:05 -0700 (Sat, 09 Jun 2007) | 2 lines Fix Windows build. ........ r55845 | martin.v.loewis | 2007-06-09 03:10:26 -0700 (Sat, 09 Jun 2007) | 2 lines Provide LLONG_MAX for S390. ........ r55854 | thomas.heller | 2007-06-10 08:59:17 -0700 (Sun, 10 Jun 2007) | 4 lines First version of build scripts for Windows/AMD64 (no external components are built yet, and 'kill_python' is disabled). ........ r55855 | thomas.heller | 2007-06-10 10:55:51 -0700 (Sun, 10 Jun 2007) | 3 lines For now, disable the _bsddb, _sqlite3, _ssl, _testcapi, _tkinter modules in the ReleaseAMD64 configuration because they do not compile. ........ r55856 | thomas.heller | 2007-06-10 11:27:54 -0700 (Sun, 10 Jun 2007) | 1 line Need to set the environment variables, otherwise devenv.com is not found. ........ r55860 | thomas.heller | 2007-06-10 14:01:17 -0700 (Sun, 10 Jun 2007) | 1 line Revert commit 55855. ........ ................ r55880 | neal.norwitz | 2007-06-10 22:07:36 -0700 (Sun, 10 Jun 2007) | 5 lines Fix the refleak counter on test_collections. The ABC metaclass creates a registry which must be cleared on each run. Otherwise, there *seem* to be refleaks when there really aren't any. (The class is held within the registry even though it's no longer needed.) ................ r55884 | neal.norwitz | 2007-06-10 22:46:33 -0700 (Sun, 10 Jun 2007) | 1 line These tests have been removed, so they are no longer needed here ................ r55886 | georg.brandl | 2007-06-11 00:26:37 -0700 (Mon, 11 Jun 2007) | 3 lines Optimize access to True and False in the compiler (if True) and the peepholer (LOAD_NAME True). ................ r55905 | georg.brandl | 2007-06-11 10:02:26 -0700 (Mon, 11 Jun 2007) | 5 lines Remove __oct__ and __hex__ and use __index__ for converting non-ints before formatting in a base. Add a bin() builtin. ................ r55906 | georg.brandl | 2007-06-11 10:04:44 -0700 (Mon, 11 Jun 2007) | 2 lines int(x, 0) does not "guess". ................ r55907 | georg.brandl | 2007-06-11 10:05:47 -0700 (Mon, 11 Jun 2007) | 2 lines Add a comment to explain that nb_oct and nb_hex are nonfunctional. ................ r55908 | guido.van.rossum | 2007-06-11 10:49:18 -0700 (Mon, 11 Jun 2007) | 2 lines Get rid of unused imports and comment. ................ r55910 | guido.van.rossum | 2007-06-11 13:05:17 -0700 (Mon, 11 Jun 2007) | 2 lines _Abstract.__new__ now requires either no arguments or __init__ overridden. ................ r55911 | guido.van.rossum | 2007-06-11 13:07:49 -0700 (Mon, 11 Jun 2007) | 7 lines Move the collections ABCs to a separate file, _abcoll.py, in order to avoid needing to import _collections.so during the bootstrap (this will become apparent in the next submit of os.py). Add (plain and mutable) ABCs for Set, Mapping, Sequence. ................ r55912 | guido.van.rossum | 2007-06-11 13:09:31 -0700 (Mon, 11 Jun 2007) | 2 lines Rewrite the _Environ class to use the new collections ABCs. ................ r55913 | guido.van.rossum | 2007-06-11 13:59:45 -0700 (Mon, 11 Jun 2007) | 72 lines Merged revisions 55869-55912 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55869 | neal.norwitz | 2007-06-10 17:42:11 -0700 (Sun, 10 Jun 2007) | 1 line Add Atul Varma for patch # 1667860 ........ r55870 | neal.norwitz | 2007-06-10 18:22:03 -0700 (Sun, 10 Jun 2007) | 1 line Ignore valgrind problems on Ubuntu from ld ........ r55872 | neal.norwitz | 2007-06-10 18:48:46 -0700 (Sun, 10 Jun 2007) | 2 lines Ignore config.status.lineno which seems new (new autoconf?) ........ r55873 | neal.norwitz | 2007-06-10 19:14:39 -0700 (Sun, 10 Jun 2007) | 1 line Prevent these tests from running on Win64 since they don\'t apply there either ........ r55874 | neal.norwitz | 2007-06-10 19:16:10 -0700 (Sun, 10 Jun 2007) | 5 lines Fix a bug when there was a newline in the string expandtabs was called on. This also catches another condition that can overflow. Will backport. ........ r55879 | neal.norwitz | 2007-06-10 21:52:37 -0700 (Sun, 10 Jun 2007) | 1 line Prevent hang if the port cannot be opened. ........ r55881 | neal.norwitz | 2007-06-10 22:28:45 -0700 (Sun, 10 Jun 2007) | 4 lines Add all of the distuils modules that don't seem to have explicit tests. :-( Move an import in mworkscompiler so that this module can be imported on any platform. Hopefully this works on all platforms. ........ r55882 | neal.norwitz | 2007-06-10 22:35:10 -0700 (Sun, 10 Jun 2007) | 4 lines SF #1734732, lower case the module names per PEP 8. Will backport. ........ r55885 | neal.norwitz | 2007-06-10 23:16:48 -0700 (Sun, 10 Jun 2007) | 4 lines Not sure why this only fails sometimes on Unix machines. Better to disable it and only import msvccompiler on Windows since that's the only place it can work anyways. ........ r55887 | neal.norwitz | 2007-06-11 00:29:43 -0700 (Mon, 11 Jun 2007) | 4 lines Bug #1734723: Fix repr.Repr() so it doesn't ignore the maxtuple attribute. Will backport ........ r55889 | neal.norwitz | 2007-06-11 00:36:24 -0700 (Mon, 11 Jun 2007) | 1 line Reflow long line ........ r55896 | thomas.heller | 2007-06-11 08:58:33 -0700 (Mon, 11 Jun 2007) | 3 lines Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k" or "K" codes. ........ r55901 | facundo.batista | 2007-06-11 09:27:08 -0700 (Mon, 11 Jun 2007) | 5 lines Added versionchanged flag to all the methods which received a new optional timeout parameter, and a versionadded flag to the socket.create_connection function. ........ ................ r55914 | guido.van.rossum | 2007-06-11 14:19:50 -0700 (Mon, 11 Jun 2007) | 3 lines New super() implementation, for PEP 3135 (though the PEP is not yet updated to this design, and small tweaks may still be made later). ................ r55923 | guido.van.rossum | 2007-06-11 21:15:24 -0700 (Mon, 11 Jun 2007) | 4 lines I'm guessing this module broke when Neal ripped out the types module -- it used 'list' both as a local variable and as the built-in list type. Renamed the local variable since that was easier. ................ r55924 | guido.van.rossum | 2007-06-11 21:20:05 -0700 (Mon, 11 Jun 2007) | 5 lines Change all occurrences of super(<thisclass>, <firstarg>) to super(). Seems to have worked, all the tests still pass. Exception: test_descr and test_descrtut, which have tons of these and are there to test the various usages. ................ r55939 | collin.winter | 2007-06-12 13:57:33 -0700 (Tue, 12 Jun 2007) | 1 line Patch #1735485: remove StandardError from the exception hierarchy. ................ r55954 | neal.norwitz | 2007-06-12 21:56:32 -0700 (Tue, 12 Jun 2007) | 51 lines Merged revisions 55913-55950 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55926 | marc-andre.lemburg | 2007-06-12 02:09:58 -0700 (Tue, 12 Jun 2007) | 3 lines Apply patch #1734945 to support TurboLinux as distribution. ........ r55927 | marc-andre.lemburg | 2007-06-12 02:26:49 -0700 (Tue, 12 Jun 2007) | 3 lines Add patch #1726668: Windows Vista support. ........ r55929 | thomas.heller | 2007-06-12 08:36:22 -0700 (Tue, 12 Jun 2007) | 1 line Checkout, but do not yet try to build, exernal sources. ........ r55930 | thomas.heller | 2007-06-12 09:08:27 -0700 (Tue, 12 Jun 2007) | 6 lines Add bufferoverflowU.lib to the libraries needed by _ssl (is this the right thing to do?). Set the /XP64 /RETAIL build enviroment in the makefile when building ReleaseAMD64. ........ r55931 | thomas.heller | 2007-06-12 09:23:19 -0700 (Tue, 12 Jun 2007) | 5 lines Revert this change, since it breaks the win32 build: Add bufferoverflowU.lib to the libraries needed by _ssl (is this the right thing to do?). ........ r55934 | thomas.heller | 2007-06-12 10:28:31 -0700 (Tue, 12 Jun 2007) | 3 lines Specify the bufferoverflowU.lib to the makefile on the command line (for ReleaseAMD64 builds). ........ r55937 | thomas.heller | 2007-06-12 12:02:59 -0700 (Tue, 12 Jun 2007) | 3 lines Add bufferoverflowU.lib to PCBuild\_bsddb.vcproj. Build sqlite3.dll and bsddb. ........ r55938 | thomas.heller | 2007-06-12 12:56:12 -0700 (Tue, 12 Jun 2007) | 2 lines Don't rebuild Berkeley DB if not needed (this was committed by accident). ........ r55948 | martin.v.loewis | 2007-06-12 20:42:19 -0700 (Tue, 12 Jun 2007) | 3 lines Provide PY_LLONG_MAX on all systems having long long. Will backport to 2.5. ........ ................ r55959 | guido.van.rossum | 2007-06-13 09:22:41 -0700 (Wed, 13 Jun 2007) | 2 lines Fix a compilation warning. ................
19 years ago
Merged revisions 55817-55961 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r55837 | guido.van.rossum | 2007-06-08 16:04:42 -0700 (Fri, 08 Jun 2007) | 2 lines PEP 3119 -- the abc module. ................ r55838 | guido.van.rossum | 2007-06-08 17:38:55 -0700 (Fri, 08 Jun 2007) | 2 lines Implement part of PEP 3119 -- One Trick Ponies. ................ r55847 | guido.van.rossum | 2007-06-09 08:28:06 -0700 (Sat, 09 Jun 2007) | 2 lines Different way to do one trick ponies, allowing registration (per PEP strawman). ................ r55849 | guido.van.rossum | 2007-06-09 18:06:38 -0700 (Sat, 09 Jun 2007) | 3 lines Make sure that the magic looking for __hash__ (etc.) doesn't apply to real subclasses of Hashable. ................ r55852 | guido.van.rossum | 2007-06-10 08:29:51 -0700 (Sun, 10 Jun 2007) | 2 lines Add some more examples, e.g. generators and dict views. ................ r55853 | guido.van.rossum | 2007-06-10 08:31:59 -0700 (Sun, 10 Jun 2007) | 2 lines keys() and items() *are* containers -- just values() isn't. ................ r55864 | georg.brandl | 2007-06-10 15:29:40 -0700 (Sun, 10 Jun 2007) | 2 lines PEP 3127: new octal literals, binary literals. ................ r55865 | georg.brandl | 2007-06-10 15:31:37 -0700 (Sun, 10 Jun 2007) | 2 lines Some octal literal fixes in Tools. ................ r55866 | georg.brandl | 2007-06-10 15:37:43 -0700 (Sun, 10 Jun 2007) | 2 lines Tokenizer changes for PEP 3127. ................ r55867 | georg.brandl | 2007-06-10 15:37:55 -0700 (Sun, 10 Jun 2007) | 2 lines Some docs for PEP 3127. ................ r55868 | georg.brandl | 2007-06-10 15:44:39 -0700 (Sun, 10 Jun 2007) | 2 lines Missed a place in intobject.c. Is that used anymore anyway? ................ r55871 | neal.norwitz | 2007-06-10 18:31:49 -0700 (Sun, 10 Jun 2007) | 182 lines Merged revisions 55729-55868 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55731 | neal.norwitz | 2007-06-01 00:29:12 -0700 (Fri, 01 Jun 2007) | 7 lines SF 1668596/1720897: distutils now copies data files even if package_dir is empty. This needs to be backported. I'm too tired tonight. It would be great if someone backports this if the buildbots are ok with it. Otherwise, I will try to get to it tomorrow. ........ r55732 | georg.brandl | 2007-06-01 04:33:33 -0700 (Fri, 01 Jun 2007) | 2 lines Bug #1722484: remove docstrings again when running with -OO. ........ r55735 | georg.brandl | 2007-06-01 12:20:27 -0700 (Fri, 01 Jun 2007) | 2 lines Fix wrong issue number. ........ r55739 | brett.cannon | 2007-06-01 20:02:29 -0700 (Fri, 01 Jun 2007) | 3 lines Have configure raise an error when building on AtheOS. Code specific to AtheOS will be removed in Python 2.7. ........ r55746 | neal.norwitz | 2007-06-02 11:33:53 -0700 (Sat, 02 Jun 2007) | 1 line Update expected birthday of 2.6 ........ r55751 | neal.norwitz | 2007-06-03 13:32:50 -0700 (Sun, 03 Jun 2007) | 10 lines Backout the original 'fix' to 1721309 which had no effect. Different versions of Berkeley DB handle this differently. The comments and bug report should have the details. Memory is allocated in 4.4 (and presumably earlier), but not in 4.5. Thus 4.5 has the free error, but not earlier versions. Mostly update comments, plus make the free conditional. This fix was already applied to the 2.5 branch. ........ r55752 | brett.cannon | 2007-06-03 16:13:41 -0700 (Sun, 03 Jun 2007) | 6 lines Make _strptime.TimeRE().pattern() use ``\s+`` for matching whitespace instead of ``\s*``. This prevents patterns from "stealing" bits from other patterns in order to make a match work. Closes bug #1730389. Will be backported. ........ r55766 | hyeshik.chang | 2007-06-05 11:16:52 -0700 (Tue, 05 Jun 2007) | 4 lines Fix build on FreeBSD. Bluetooth HCI API in FreeBSD is quite different from Linux's. Just fix the build for now but the code doesn't support the complete capability of HCI on FreeBSD yet. ........ r55770 | hyeshik.chang | 2007-06-05 11:58:51 -0700 (Tue, 05 Jun 2007) | 4 lines Bug #1728403: Fix a bug that CJKCodecs StreamReader hangs when it reads a file that ends with incomplete sequence and sizehint argument for .read() is specified. ........ r55775 | hyeshik.chang | 2007-06-05 12:28:15 -0700 (Tue, 05 Jun 2007) | 2 lines Fix for Windows: close a temporary file before trying to delete it. ........ r55783 | guido.van.rossum | 2007-06-05 14:24:47 -0700 (Tue, 05 Jun 2007) | 2 lines Patch by Tim Delany (missing DECREF). SF #1731330. ........ r55785 | collin.winter | 2007-06-05 17:17:35 -0700 (Tue, 05 Jun 2007) | 3 lines Patch #1731049: make threading.py use a proper "raise" when checking internal state, rather than assert statements (which get stripped out by -O). ........ r55786 | facundo.batista | 2007-06-06 08:13:37 -0700 (Wed, 06 Jun 2007) | 4 lines FTP.ntransfercmd method now uses create_connection when passive, using the timeout received in connection time. ........ r55792 | facundo.batista | 2007-06-06 10:15:23 -0700 (Wed, 06 Jun 2007) | 7 lines Added an optional timeout parameter to function urllib2.urlopen, with tests in test_urllib2net.py (must have network resource enabled to execute them). Also modified test_urllib2.py because testing mock classes must take it into acount. Docs are also updated. ........ r55793 | thomas.heller | 2007-06-06 13:19:19 -0700 (Wed, 06 Jun 2007) | 1 line Build _ctypes and _ctypes_test in the ReleaseAMD64 configuration. ........ r55802 | georg.brandl | 2007-06-07 06:23:24 -0700 (Thu, 07 Jun 2007) | 3 lines Disallow function calls like foo(None=1). Backport from py3k rev. 55708 by Guido. ........ r55804 | georg.brandl | 2007-06-07 06:30:24 -0700 (Thu, 07 Jun 2007) | 2 lines Make reindent.py executable. ........ r55805 | georg.brandl | 2007-06-07 06:34:10 -0700 (Thu, 07 Jun 2007) | 2 lines Patch #1667860: Fix UnboundLocalError in urllib2. ........ r55821 | kristjan.jonsson | 2007-06-07 16:53:49 -0700 (Thu, 07 Jun 2007) | 1 line Fixing changes to getbuildinfo.c that broke linux builds ........ r55828 | thomas.heller | 2007-06-08 09:10:27 -0700 (Fri, 08 Jun 2007) | 1 line Make this test work with older Python releases where struct has no 't' format character. ........ r55829 | martin.v.loewis | 2007-06-08 10:29:20 -0700 (Fri, 08 Jun 2007) | 3 lines Bug #1733488: Fix compilation of bufferobject.c on AIX. Will backport to 2.5. ........ r55831 | thomas.heller | 2007-06-08 11:20:09 -0700 (Fri, 08 Jun 2007) | 2 lines [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur with small modifications. ........ r55832 | thomas.heller | 2007-06-08 12:01:06 -0700 (Fri, 08 Jun 2007) | 1 line Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls. ........ r55833 | thomas.heller | 2007-06-08 12:08:31 -0700 (Fri, 08 Jun 2007) | 2 lines Fix wrong documentation, and correct the punktuation. Closes [1700455]. ........ r55834 | thomas.heller | 2007-06-08 12:14:23 -0700 (Fri, 08 Jun 2007) | 1 line Fix warnings by using proper function prototype. ........ r55839 | neal.norwitz | 2007-06-08 20:36:34 -0700 (Fri, 08 Jun 2007) | 7 lines Prevent expandtabs() on string and unicode objects from causing a segfault when a large width is passed on 32-bit platforms. Found by Google. It would be good for people to review this especially carefully and verify I don't have an off by one error and there is no other way to cause overflow. ........ r55841 | neal.norwitz | 2007-06-08 21:48:22 -0700 (Fri, 08 Jun 2007) | 1 line Use macro version of GET_SIZE to avoid Coverity warning (#150) about a possible error. ........ r55842 | martin.v.loewis | 2007-06-09 00:42:52 -0700 (Sat, 09 Jun 2007) | 3 lines Patch #1733960: Allow T_LONGLONG to accept ints. Will backport to 2.5. ........ r55843 | martin.v.loewis | 2007-06-09 00:58:05 -0700 (Sat, 09 Jun 2007) | 2 lines Fix Windows build. ........ r55845 | martin.v.loewis | 2007-06-09 03:10:26 -0700 (Sat, 09 Jun 2007) | 2 lines Provide LLONG_MAX for S390. ........ r55854 | thomas.heller | 2007-06-10 08:59:17 -0700 (Sun, 10 Jun 2007) | 4 lines First version of build scripts for Windows/AMD64 (no external components are built yet, and 'kill_python' is disabled). ........ r55855 | thomas.heller | 2007-06-10 10:55:51 -0700 (Sun, 10 Jun 2007) | 3 lines For now, disable the _bsddb, _sqlite3, _ssl, _testcapi, _tkinter modules in the ReleaseAMD64 configuration because they do not compile. ........ r55856 | thomas.heller | 2007-06-10 11:27:54 -0700 (Sun, 10 Jun 2007) | 1 line Need to set the environment variables, otherwise devenv.com is not found. ........ r55860 | thomas.heller | 2007-06-10 14:01:17 -0700 (Sun, 10 Jun 2007) | 1 line Revert commit 55855. ........ ................ r55880 | neal.norwitz | 2007-06-10 22:07:36 -0700 (Sun, 10 Jun 2007) | 5 lines Fix the refleak counter on test_collections. The ABC metaclass creates a registry which must be cleared on each run. Otherwise, there *seem* to be refleaks when there really aren't any. (The class is held within the registry even though it's no longer needed.) ................ r55884 | neal.norwitz | 2007-06-10 22:46:33 -0700 (Sun, 10 Jun 2007) | 1 line These tests have been removed, so they are no longer needed here ................ r55886 | georg.brandl | 2007-06-11 00:26:37 -0700 (Mon, 11 Jun 2007) | 3 lines Optimize access to True and False in the compiler (if True) and the peepholer (LOAD_NAME True). ................ r55905 | georg.brandl | 2007-06-11 10:02:26 -0700 (Mon, 11 Jun 2007) | 5 lines Remove __oct__ and __hex__ and use __index__ for converting non-ints before formatting in a base. Add a bin() builtin. ................ r55906 | georg.brandl | 2007-06-11 10:04:44 -0700 (Mon, 11 Jun 2007) | 2 lines int(x, 0) does not "guess". ................ r55907 | georg.brandl | 2007-06-11 10:05:47 -0700 (Mon, 11 Jun 2007) | 2 lines Add a comment to explain that nb_oct and nb_hex are nonfunctional. ................ r55908 | guido.van.rossum | 2007-06-11 10:49:18 -0700 (Mon, 11 Jun 2007) | 2 lines Get rid of unused imports and comment. ................ r55910 | guido.van.rossum | 2007-06-11 13:05:17 -0700 (Mon, 11 Jun 2007) | 2 lines _Abstract.__new__ now requires either no arguments or __init__ overridden. ................ r55911 | guido.van.rossum | 2007-06-11 13:07:49 -0700 (Mon, 11 Jun 2007) | 7 lines Move the collections ABCs to a separate file, _abcoll.py, in order to avoid needing to import _collections.so during the bootstrap (this will become apparent in the next submit of os.py). Add (plain and mutable) ABCs for Set, Mapping, Sequence. ................ r55912 | guido.van.rossum | 2007-06-11 13:09:31 -0700 (Mon, 11 Jun 2007) | 2 lines Rewrite the _Environ class to use the new collections ABCs. ................ r55913 | guido.van.rossum | 2007-06-11 13:59:45 -0700 (Mon, 11 Jun 2007) | 72 lines Merged revisions 55869-55912 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55869 | neal.norwitz | 2007-06-10 17:42:11 -0700 (Sun, 10 Jun 2007) | 1 line Add Atul Varma for patch # 1667860 ........ r55870 | neal.norwitz | 2007-06-10 18:22:03 -0700 (Sun, 10 Jun 2007) | 1 line Ignore valgrind problems on Ubuntu from ld ........ r55872 | neal.norwitz | 2007-06-10 18:48:46 -0700 (Sun, 10 Jun 2007) | 2 lines Ignore config.status.lineno which seems new (new autoconf?) ........ r55873 | neal.norwitz | 2007-06-10 19:14:39 -0700 (Sun, 10 Jun 2007) | 1 line Prevent these tests from running on Win64 since they don\'t apply there either ........ r55874 | neal.norwitz | 2007-06-10 19:16:10 -0700 (Sun, 10 Jun 2007) | 5 lines Fix a bug when there was a newline in the string expandtabs was called on. This also catches another condition that can overflow. Will backport. ........ r55879 | neal.norwitz | 2007-06-10 21:52:37 -0700 (Sun, 10 Jun 2007) | 1 line Prevent hang if the port cannot be opened. ........ r55881 | neal.norwitz | 2007-06-10 22:28:45 -0700 (Sun, 10 Jun 2007) | 4 lines Add all of the distuils modules that don't seem to have explicit tests. :-( Move an import in mworkscompiler so that this module can be imported on any platform. Hopefully this works on all platforms. ........ r55882 | neal.norwitz | 2007-06-10 22:35:10 -0700 (Sun, 10 Jun 2007) | 4 lines SF #1734732, lower case the module names per PEP 8. Will backport. ........ r55885 | neal.norwitz | 2007-06-10 23:16:48 -0700 (Sun, 10 Jun 2007) | 4 lines Not sure why this only fails sometimes on Unix machines. Better to disable it and only import msvccompiler on Windows since that's the only place it can work anyways. ........ r55887 | neal.norwitz | 2007-06-11 00:29:43 -0700 (Mon, 11 Jun 2007) | 4 lines Bug #1734723: Fix repr.Repr() so it doesn't ignore the maxtuple attribute. Will backport ........ r55889 | neal.norwitz | 2007-06-11 00:36:24 -0700 (Mon, 11 Jun 2007) | 1 line Reflow long line ........ r55896 | thomas.heller | 2007-06-11 08:58:33 -0700 (Mon, 11 Jun 2007) | 3 lines Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k" or "K" codes. ........ r55901 | facundo.batista | 2007-06-11 09:27:08 -0700 (Mon, 11 Jun 2007) | 5 lines Added versionchanged flag to all the methods which received a new optional timeout parameter, and a versionadded flag to the socket.create_connection function. ........ ................ r55914 | guido.van.rossum | 2007-06-11 14:19:50 -0700 (Mon, 11 Jun 2007) | 3 lines New super() implementation, for PEP 3135 (though the PEP is not yet updated to this design, and small tweaks may still be made later). ................ r55923 | guido.van.rossum | 2007-06-11 21:15:24 -0700 (Mon, 11 Jun 2007) | 4 lines I'm guessing this module broke when Neal ripped out the types module -- it used 'list' both as a local variable and as the built-in list type. Renamed the local variable since that was easier. ................ r55924 | guido.van.rossum | 2007-06-11 21:20:05 -0700 (Mon, 11 Jun 2007) | 5 lines Change all occurrences of super(<thisclass>, <firstarg>) to super(). Seems to have worked, all the tests still pass. Exception: test_descr and test_descrtut, which have tons of these and are there to test the various usages. ................ r55939 | collin.winter | 2007-06-12 13:57:33 -0700 (Tue, 12 Jun 2007) | 1 line Patch #1735485: remove StandardError from the exception hierarchy. ................ r55954 | neal.norwitz | 2007-06-12 21:56:32 -0700 (Tue, 12 Jun 2007) | 51 lines Merged revisions 55913-55950 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55926 | marc-andre.lemburg | 2007-06-12 02:09:58 -0700 (Tue, 12 Jun 2007) | 3 lines Apply patch #1734945 to support TurboLinux as distribution. ........ r55927 | marc-andre.lemburg | 2007-06-12 02:26:49 -0700 (Tue, 12 Jun 2007) | 3 lines Add patch #1726668: Windows Vista support. ........ r55929 | thomas.heller | 2007-06-12 08:36:22 -0700 (Tue, 12 Jun 2007) | 1 line Checkout, but do not yet try to build, exernal sources. ........ r55930 | thomas.heller | 2007-06-12 09:08:27 -0700 (Tue, 12 Jun 2007) | 6 lines Add bufferoverflowU.lib to the libraries needed by _ssl (is this the right thing to do?). Set the /XP64 /RETAIL build enviroment in the makefile when building ReleaseAMD64. ........ r55931 | thomas.heller | 2007-06-12 09:23:19 -0700 (Tue, 12 Jun 2007) | 5 lines Revert this change, since it breaks the win32 build: Add bufferoverflowU.lib to the libraries needed by _ssl (is this the right thing to do?). ........ r55934 | thomas.heller | 2007-06-12 10:28:31 -0700 (Tue, 12 Jun 2007) | 3 lines Specify the bufferoverflowU.lib to the makefile on the command line (for ReleaseAMD64 builds). ........ r55937 | thomas.heller | 2007-06-12 12:02:59 -0700 (Tue, 12 Jun 2007) | 3 lines Add bufferoverflowU.lib to PCBuild\_bsddb.vcproj. Build sqlite3.dll and bsddb. ........ r55938 | thomas.heller | 2007-06-12 12:56:12 -0700 (Tue, 12 Jun 2007) | 2 lines Don't rebuild Berkeley DB if not needed (this was committed by accident). ........ r55948 | martin.v.loewis | 2007-06-12 20:42:19 -0700 (Tue, 12 Jun 2007) | 3 lines Provide PY_LLONG_MAX on all systems having long long. Will backport to 2.5. ........ ................ r55959 | guido.van.rossum | 2007-06-13 09:22:41 -0700 (Wed, 13 Jun 2007) | 2 lines Fix a compilation warning. ................
19 years ago
Merged revisions 55817-55961 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r55837 | guido.van.rossum | 2007-06-08 16:04:42 -0700 (Fri, 08 Jun 2007) | 2 lines PEP 3119 -- the abc module. ................ r55838 | guido.van.rossum | 2007-06-08 17:38:55 -0700 (Fri, 08 Jun 2007) | 2 lines Implement part of PEP 3119 -- One Trick Ponies. ................ r55847 | guido.van.rossum | 2007-06-09 08:28:06 -0700 (Sat, 09 Jun 2007) | 2 lines Different way to do one trick ponies, allowing registration (per PEP strawman). ................ r55849 | guido.van.rossum | 2007-06-09 18:06:38 -0700 (Sat, 09 Jun 2007) | 3 lines Make sure that the magic looking for __hash__ (etc.) doesn't apply to real subclasses of Hashable. ................ r55852 | guido.van.rossum | 2007-06-10 08:29:51 -0700 (Sun, 10 Jun 2007) | 2 lines Add some more examples, e.g. generators and dict views. ................ r55853 | guido.van.rossum | 2007-06-10 08:31:59 -0700 (Sun, 10 Jun 2007) | 2 lines keys() and items() *are* containers -- just values() isn't. ................ r55864 | georg.brandl | 2007-06-10 15:29:40 -0700 (Sun, 10 Jun 2007) | 2 lines PEP 3127: new octal literals, binary literals. ................ r55865 | georg.brandl | 2007-06-10 15:31:37 -0700 (Sun, 10 Jun 2007) | 2 lines Some octal literal fixes in Tools. ................ r55866 | georg.brandl | 2007-06-10 15:37:43 -0700 (Sun, 10 Jun 2007) | 2 lines Tokenizer changes for PEP 3127. ................ r55867 | georg.brandl | 2007-06-10 15:37:55 -0700 (Sun, 10 Jun 2007) | 2 lines Some docs for PEP 3127. ................ r55868 | georg.brandl | 2007-06-10 15:44:39 -0700 (Sun, 10 Jun 2007) | 2 lines Missed a place in intobject.c. Is that used anymore anyway? ................ r55871 | neal.norwitz | 2007-06-10 18:31:49 -0700 (Sun, 10 Jun 2007) | 182 lines Merged revisions 55729-55868 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55731 | neal.norwitz | 2007-06-01 00:29:12 -0700 (Fri, 01 Jun 2007) | 7 lines SF 1668596/1720897: distutils now copies data files even if package_dir is empty. This needs to be backported. I'm too tired tonight. It would be great if someone backports this if the buildbots are ok with it. Otherwise, I will try to get to it tomorrow. ........ r55732 | georg.brandl | 2007-06-01 04:33:33 -0700 (Fri, 01 Jun 2007) | 2 lines Bug #1722484: remove docstrings again when running with -OO. ........ r55735 | georg.brandl | 2007-06-01 12:20:27 -0700 (Fri, 01 Jun 2007) | 2 lines Fix wrong issue number. ........ r55739 | brett.cannon | 2007-06-01 20:02:29 -0700 (Fri, 01 Jun 2007) | 3 lines Have configure raise an error when building on AtheOS. Code specific to AtheOS will be removed in Python 2.7. ........ r55746 | neal.norwitz | 2007-06-02 11:33:53 -0700 (Sat, 02 Jun 2007) | 1 line Update expected birthday of 2.6 ........ r55751 | neal.norwitz | 2007-06-03 13:32:50 -0700 (Sun, 03 Jun 2007) | 10 lines Backout the original 'fix' to 1721309 which had no effect. Different versions of Berkeley DB handle this differently. The comments and bug report should have the details. Memory is allocated in 4.4 (and presumably earlier), but not in 4.5. Thus 4.5 has the free error, but not earlier versions. Mostly update comments, plus make the free conditional. This fix was already applied to the 2.5 branch. ........ r55752 | brett.cannon | 2007-06-03 16:13:41 -0700 (Sun, 03 Jun 2007) | 6 lines Make _strptime.TimeRE().pattern() use ``\s+`` for matching whitespace instead of ``\s*``. This prevents patterns from "stealing" bits from other patterns in order to make a match work. Closes bug #1730389. Will be backported. ........ r55766 | hyeshik.chang | 2007-06-05 11:16:52 -0700 (Tue, 05 Jun 2007) | 4 lines Fix build on FreeBSD. Bluetooth HCI API in FreeBSD is quite different from Linux's. Just fix the build for now but the code doesn't support the complete capability of HCI on FreeBSD yet. ........ r55770 | hyeshik.chang | 2007-06-05 11:58:51 -0700 (Tue, 05 Jun 2007) | 4 lines Bug #1728403: Fix a bug that CJKCodecs StreamReader hangs when it reads a file that ends with incomplete sequence and sizehint argument for .read() is specified. ........ r55775 | hyeshik.chang | 2007-06-05 12:28:15 -0700 (Tue, 05 Jun 2007) | 2 lines Fix for Windows: close a temporary file before trying to delete it. ........ r55783 | guido.van.rossum | 2007-06-05 14:24:47 -0700 (Tue, 05 Jun 2007) | 2 lines Patch by Tim Delany (missing DECREF). SF #1731330. ........ r55785 | collin.winter | 2007-06-05 17:17:35 -0700 (Tue, 05 Jun 2007) | 3 lines Patch #1731049: make threading.py use a proper "raise" when checking internal state, rather than assert statements (which get stripped out by -O). ........ r55786 | facundo.batista | 2007-06-06 08:13:37 -0700 (Wed, 06 Jun 2007) | 4 lines FTP.ntransfercmd method now uses create_connection when passive, using the timeout received in connection time. ........ r55792 | facundo.batista | 2007-06-06 10:15:23 -0700 (Wed, 06 Jun 2007) | 7 lines Added an optional timeout parameter to function urllib2.urlopen, with tests in test_urllib2net.py (must have network resource enabled to execute them). Also modified test_urllib2.py because testing mock classes must take it into acount. Docs are also updated. ........ r55793 | thomas.heller | 2007-06-06 13:19:19 -0700 (Wed, 06 Jun 2007) | 1 line Build _ctypes and _ctypes_test in the ReleaseAMD64 configuration. ........ r55802 | georg.brandl | 2007-06-07 06:23:24 -0700 (Thu, 07 Jun 2007) | 3 lines Disallow function calls like foo(None=1). Backport from py3k rev. 55708 by Guido. ........ r55804 | georg.brandl | 2007-06-07 06:30:24 -0700 (Thu, 07 Jun 2007) | 2 lines Make reindent.py executable. ........ r55805 | georg.brandl | 2007-06-07 06:34:10 -0700 (Thu, 07 Jun 2007) | 2 lines Patch #1667860: Fix UnboundLocalError in urllib2. ........ r55821 | kristjan.jonsson | 2007-06-07 16:53:49 -0700 (Thu, 07 Jun 2007) | 1 line Fixing changes to getbuildinfo.c that broke linux builds ........ r55828 | thomas.heller | 2007-06-08 09:10:27 -0700 (Fri, 08 Jun 2007) | 1 line Make this test work with older Python releases where struct has no 't' format character. ........ r55829 | martin.v.loewis | 2007-06-08 10:29:20 -0700 (Fri, 08 Jun 2007) | 3 lines Bug #1733488: Fix compilation of bufferobject.c on AIX. Will backport to 2.5. ........ r55831 | thomas.heller | 2007-06-08 11:20:09 -0700 (Fri, 08 Jun 2007) | 2 lines [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur with small modifications. ........ r55832 | thomas.heller | 2007-06-08 12:01:06 -0700 (Fri, 08 Jun 2007) | 1 line Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls. ........ r55833 | thomas.heller | 2007-06-08 12:08:31 -0700 (Fri, 08 Jun 2007) | 2 lines Fix wrong documentation, and correct the punktuation. Closes [1700455]. ........ r55834 | thomas.heller | 2007-06-08 12:14:23 -0700 (Fri, 08 Jun 2007) | 1 line Fix warnings by using proper function prototype. ........ r55839 | neal.norwitz | 2007-06-08 20:36:34 -0700 (Fri, 08 Jun 2007) | 7 lines Prevent expandtabs() on string and unicode objects from causing a segfault when a large width is passed on 32-bit platforms. Found by Google. It would be good for people to review this especially carefully and verify I don't have an off by one error and there is no other way to cause overflow. ........ r55841 | neal.norwitz | 2007-06-08 21:48:22 -0700 (Fri, 08 Jun 2007) | 1 line Use macro version of GET_SIZE to avoid Coverity warning (#150) about a possible error. ........ r55842 | martin.v.loewis | 2007-06-09 00:42:52 -0700 (Sat, 09 Jun 2007) | 3 lines Patch #1733960: Allow T_LONGLONG to accept ints. Will backport to 2.5. ........ r55843 | martin.v.loewis | 2007-06-09 00:58:05 -0700 (Sat, 09 Jun 2007) | 2 lines Fix Windows build. ........ r55845 | martin.v.loewis | 2007-06-09 03:10:26 -0700 (Sat, 09 Jun 2007) | 2 lines Provide LLONG_MAX for S390. ........ r55854 | thomas.heller | 2007-06-10 08:59:17 -0700 (Sun, 10 Jun 2007) | 4 lines First version of build scripts for Windows/AMD64 (no external components are built yet, and 'kill_python' is disabled). ........ r55855 | thomas.heller | 2007-06-10 10:55:51 -0700 (Sun, 10 Jun 2007) | 3 lines For now, disable the _bsddb, _sqlite3, _ssl, _testcapi, _tkinter modules in the ReleaseAMD64 configuration because they do not compile. ........ r55856 | thomas.heller | 2007-06-10 11:27:54 -0700 (Sun, 10 Jun 2007) | 1 line Need to set the environment variables, otherwise devenv.com is not found. ........ r55860 | thomas.heller | 2007-06-10 14:01:17 -0700 (Sun, 10 Jun 2007) | 1 line Revert commit 55855. ........ ................ r55880 | neal.norwitz | 2007-06-10 22:07:36 -0700 (Sun, 10 Jun 2007) | 5 lines Fix the refleak counter on test_collections. The ABC metaclass creates a registry which must be cleared on each run. Otherwise, there *seem* to be refleaks when there really aren't any. (The class is held within the registry even though it's no longer needed.) ................ r55884 | neal.norwitz | 2007-06-10 22:46:33 -0700 (Sun, 10 Jun 2007) | 1 line These tests have been removed, so they are no longer needed here ................ r55886 | georg.brandl | 2007-06-11 00:26:37 -0700 (Mon, 11 Jun 2007) | 3 lines Optimize access to True and False in the compiler (if True) and the peepholer (LOAD_NAME True). ................ r55905 | georg.brandl | 2007-06-11 10:02:26 -0700 (Mon, 11 Jun 2007) | 5 lines Remove __oct__ and __hex__ and use __index__ for converting non-ints before formatting in a base. Add a bin() builtin. ................ r55906 | georg.brandl | 2007-06-11 10:04:44 -0700 (Mon, 11 Jun 2007) | 2 lines int(x, 0) does not "guess". ................ r55907 | georg.brandl | 2007-06-11 10:05:47 -0700 (Mon, 11 Jun 2007) | 2 lines Add a comment to explain that nb_oct and nb_hex are nonfunctional. ................ r55908 | guido.van.rossum | 2007-06-11 10:49:18 -0700 (Mon, 11 Jun 2007) | 2 lines Get rid of unused imports and comment. ................ r55910 | guido.van.rossum | 2007-06-11 13:05:17 -0700 (Mon, 11 Jun 2007) | 2 lines _Abstract.__new__ now requires either no arguments or __init__ overridden. ................ r55911 | guido.van.rossum | 2007-06-11 13:07:49 -0700 (Mon, 11 Jun 2007) | 7 lines Move the collections ABCs to a separate file, _abcoll.py, in order to avoid needing to import _collections.so during the bootstrap (this will become apparent in the next submit of os.py). Add (plain and mutable) ABCs for Set, Mapping, Sequence. ................ r55912 | guido.van.rossum | 2007-06-11 13:09:31 -0700 (Mon, 11 Jun 2007) | 2 lines Rewrite the _Environ class to use the new collections ABCs. ................ r55913 | guido.van.rossum | 2007-06-11 13:59:45 -0700 (Mon, 11 Jun 2007) | 72 lines Merged revisions 55869-55912 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55869 | neal.norwitz | 2007-06-10 17:42:11 -0700 (Sun, 10 Jun 2007) | 1 line Add Atul Varma for patch # 1667860 ........ r55870 | neal.norwitz | 2007-06-10 18:22:03 -0700 (Sun, 10 Jun 2007) | 1 line Ignore valgrind problems on Ubuntu from ld ........ r55872 | neal.norwitz | 2007-06-10 18:48:46 -0700 (Sun, 10 Jun 2007) | 2 lines Ignore config.status.lineno which seems new (new autoconf?) ........ r55873 | neal.norwitz | 2007-06-10 19:14:39 -0700 (Sun, 10 Jun 2007) | 1 line Prevent these tests from running on Win64 since they don\'t apply there either ........ r55874 | neal.norwitz | 2007-06-10 19:16:10 -0700 (Sun, 10 Jun 2007) | 5 lines Fix a bug when there was a newline in the string expandtabs was called on. This also catches another condition that can overflow. Will backport. ........ r55879 | neal.norwitz | 2007-06-10 21:52:37 -0700 (Sun, 10 Jun 2007) | 1 line Prevent hang if the port cannot be opened. ........ r55881 | neal.norwitz | 2007-06-10 22:28:45 -0700 (Sun, 10 Jun 2007) | 4 lines Add all of the distuils modules that don't seem to have explicit tests. :-( Move an import in mworkscompiler so that this module can be imported on any platform. Hopefully this works on all platforms. ........ r55882 | neal.norwitz | 2007-06-10 22:35:10 -0700 (Sun, 10 Jun 2007) | 4 lines SF #1734732, lower case the module names per PEP 8. Will backport. ........ r55885 | neal.norwitz | 2007-06-10 23:16:48 -0700 (Sun, 10 Jun 2007) | 4 lines Not sure why this only fails sometimes on Unix machines. Better to disable it and only import msvccompiler on Windows since that's the only place it can work anyways. ........ r55887 | neal.norwitz | 2007-06-11 00:29:43 -0700 (Mon, 11 Jun 2007) | 4 lines Bug #1734723: Fix repr.Repr() so it doesn't ignore the maxtuple attribute. Will backport ........ r55889 | neal.norwitz | 2007-06-11 00:36:24 -0700 (Mon, 11 Jun 2007) | 1 line Reflow long line ........ r55896 | thomas.heller | 2007-06-11 08:58:33 -0700 (Mon, 11 Jun 2007) | 3 lines Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k" or "K" codes. ........ r55901 | facundo.batista | 2007-06-11 09:27:08 -0700 (Mon, 11 Jun 2007) | 5 lines Added versionchanged flag to all the methods which received a new optional timeout parameter, and a versionadded flag to the socket.create_connection function. ........ ................ r55914 | guido.van.rossum | 2007-06-11 14:19:50 -0700 (Mon, 11 Jun 2007) | 3 lines New super() implementation, for PEP 3135 (though the PEP is not yet updated to this design, and small tweaks may still be made later). ................ r55923 | guido.van.rossum | 2007-06-11 21:15:24 -0700 (Mon, 11 Jun 2007) | 4 lines I'm guessing this module broke when Neal ripped out the types module -- it used 'list' both as a local variable and as the built-in list type. Renamed the local variable since that was easier. ................ r55924 | guido.van.rossum | 2007-06-11 21:20:05 -0700 (Mon, 11 Jun 2007) | 5 lines Change all occurrences of super(<thisclass>, <firstarg>) to super(). Seems to have worked, all the tests still pass. Exception: test_descr and test_descrtut, which have tons of these and are there to test the various usages. ................ r55939 | collin.winter | 2007-06-12 13:57:33 -0700 (Tue, 12 Jun 2007) | 1 line Patch #1735485: remove StandardError from the exception hierarchy. ................ r55954 | neal.norwitz | 2007-06-12 21:56:32 -0700 (Tue, 12 Jun 2007) | 51 lines Merged revisions 55913-55950 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r55926 | marc-andre.lemburg | 2007-06-12 02:09:58 -0700 (Tue, 12 Jun 2007) | 3 lines Apply patch #1734945 to support TurboLinux as distribution. ........ r55927 | marc-andre.lemburg | 2007-06-12 02:26:49 -0700 (Tue, 12 Jun 2007) | 3 lines Add patch #1726668: Windows Vista support. ........ r55929 | thomas.heller | 2007-06-12 08:36:22 -0700 (Tue, 12 Jun 2007) | 1 line Checkout, but do not yet try to build, exernal sources. ........ r55930 | thomas.heller | 2007-06-12 09:08:27 -0700 (Tue, 12 Jun 2007) | 6 lines Add bufferoverflowU.lib to the libraries needed by _ssl (is this the right thing to do?). Set the /XP64 /RETAIL build enviroment in the makefile when building ReleaseAMD64. ........ r55931 | thomas.heller | 2007-06-12 09:23:19 -0700 (Tue, 12 Jun 2007) | 5 lines Revert this change, since it breaks the win32 build: Add bufferoverflowU.lib to the libraries needed by _ssl (is this the right thing to do?). ........ r55934 | thomas.heller | 2007-06-12 10:28:31 -0700 (Tue, 12 Jun 2007) | 3 lines Specify the bufferoverflowU.lib to the makefile on the command line (for ReleaseAMD64 builds). ........ r55937 | thomas.heller | 2007-06-12 12:02:59 -0700 (Tue, 12 Jun 2007) | 3 lines Add bufferoverflowU.lib to PCBuild\_bsddb.vcproj. Build sqlite3.dll and bsddb. ........ r55938 | thomas.heller | 2007-06-12 12:56:12 -0700 (Tue, 12 Jun 2007) | 2 lines Don't rebuild Berkeley DB if not needed (this was committed by accident). ........ r55948 | martin.v.loewis | 2007-06-12 20:42:19 -0700 (Tue, 12 Jun 2007) | 3 lines Provide PY_LLONG_MAX on all systems having long long. Will backport to 2.5. ........ ................ r55959 | guido.van.rossum | 2007-06-13 09:22:41 -0700 (Wed, 13 Jun 2007) | 2 lines Fix a compilation warning. ................
19 years ago
15 years ago
Merged revisions 56154-56264 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r56155 | neal.norwitz | 2007-07-03 08:59:08 +0300 (Tue, 03 Jul 2007) | 1 line Get this test working after converting map to return an iterator ................ r56202 | neal.norwitz | 2007-07-09 04:30:09 +0300 (Mon, 09 Jul 2007) | 37 lines Merged revisions 56124-56201 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r56129 | georg.brandl | 2007-06-30 04:01:01 -0700 (Sat, 30 Jun 2007) | 2 lines Document smtp.SMTPAuthenticationError. ........ r56137 | georg.brandl | 2007-07-01 01:11:35 -0700 (Sun, 01 Jul 2007) | 2 lines Fix a few webbrowser.py problems. ........ r56143 | georg.brandl | 2007-07-02 04:54:28 -0700 (Mon, 02 Jul 2007) | 2 lines Remove duplicate sentence from alarm() doc. ........ r56170 | mark.hammond | 2007-07-03 19:03:10 -0700 (Tue, 03 Jul 2007) | 3 lines copy built files to the PCBuild directory, where tools like distutils or external build processes can find them. ........ r56176 | kurt.kaiser | 2007-07-05 15:03:39 -0700 (Thu, 05 Jul 2007) | 10 lines Many calls to tk.call involve an arglist containing a single tuple. Calls using METH_OLDARGS unpack this tuple; calls using METH_VARARG don't. Tcl's concatenation of args was affected; IDLE doesn't start. Modify Tkapp_Call() to unpack single tuple arglists. Bug 1733943 Ref http://mail.python.org/pipermail/python-checkins/2007-May/060454.html ........ r56177 | neal.norwitz | 2007-07-05 21:13:39 -0700 (Thu, 05 Jul 2007) | 1 line Fix typo in comment ........ ................ r56251 | neal.norwitz | 2007-07-11 10:01:01 +0300 (Wed, 11 Jul 2007) | 1 line Get working with map returning an iterator (had to fix whitespace too) ................ r56255 | thomas.wouters | 2007-07-11 13:41:37 +0300 (Wed, 11 Jul 2007) | 6 lines Clean up merge glitch or copy-paste error (the entire module was duplicated, except the first half even had some more copy-paste errors, referring to listcomps and genexps instead of setcomps) ................ r56256 | thomas.wouters | 2007-07-11 15:16:01 +0300 (Wed, 11 Jul 2007) | 14 lines Dict comprehensions. Still needs doc changes (like many python-3000 features ;-). It generates bytecode similar to: x = {} for k, v in (generator here): x[k] = v except there is no tuple-packing and -unpacking involved. Trivial measurement suggests it's significantly faster than dict(generator here) (in the order of 2 to 3 times as fast) but I have not done extensive measurements. ................ r56263 | guido.van.rossum | 2007-07-11 15:36:26 +0300 (Wed, 11 Jul 2007) | 3 lines Patch 1724999 by Ali Gholami Rudi -- avoid complaints about dict size change during iter in destroy call. ................
19 years ago
Merged revisions 56154-56264 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r56155 | neal.norwitz | 2007-07-03 08:59:08 +0300 (Tue, 03 Jul 2007) | 1 line Get this test working after converting map to return an iterator ................ r56202 | neal.norwitz | 2007-07-09 04:30:09 +0300 (Mon, 09 Jul 2007) | 37 lines Merged revisions 56124-56201 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r56129 | georg.brandl | 2007-06-30 04:01:01 -0700 (Sat, 30 Jun 2007) | 2 lines Document smtp.SMTPAuthenticationError. ........ r56137 | georg.brandl | 2007-07-01 01:11:35 -0700 (Sun, 01 Jul 2007) | 2 lines Fix a few webbrowser.py problems. ........ r56143 | georg.brandl | 2007-07-02 04:54:28 -0700 (Mon, 02 Jul 2007) | 2 lines Remove duplicate sentence from alarm() doc. ........ r56170 | mark.hammond | 2007-07-03 19:03:10 -0700 (Tue, 03 Jul 2007) | 3 lines copy built files to the PCBuild directory, where tools like distutils or external build processes can find them. ........ r56176 | kurt.kaiser | 2007-07-05 15:03:39 -0700 (Thu, 05 Jul 2007) | 10 lines Many calls to tk.call involve an arglist containing a single tuple. Calls using METH_OLDARGS unpack this tuple; calls using METH_VARARG don't. Tcl's concatenation of args was affected; IDLE doesn't start. Modify Tkapp_Call() to unpack single tuple arglists. Bug 1733943 Ref http://mail.python.org/pipermail/python-checkins/2007-May/060454.html ........ r56177 | neal.norwitz | 2007-07-05 21:13:39 -0700 (Thu, 05 Jul 2007) | 1 line Fix typo in comment ........ ................ r56251 | neal.norwitz | 2007-07-11 10:01:01 +0300 (Wed, 11 Jul 2007) | 1 line Get working with map returning an iterator (had to fix whitespace too) ................ r56255 | thomas.wouters | 2007-07-11 13:41:37 +0300 (Wed, 11 Jul 2007) | 6 lines Clean up merge glitch or copy-paste error (the entire module was duplicated, except the first half even had some more copy-paste errors, referring to listcomps and genexps instead of setcomps) ................ r56256 | thomas.wouters | 2007-07-11 15:16:01 +0300 (Wed, 11 Jul 2007) | 14 lines Dict comprehensions. Still needs doc changes (like many python-3000 features ;-). It generates bytecode similar to: x = {} for k, v in (generator here): x[k] = v except there is no tuple-packing and -unpacking involved. Trivial measurement suggests it's significantly faster than dict(generator here) (in the order of 2 to 3 times as fast) but I have not done extensive measurements. ................ r56263 | guido.van.rossum | 2007-07-11 15:36:26 +0300 (Wed, 11 Jul 2007) | 3 lines Patch 1724999 by Ali Gholami Rudi -- avoid complaints about dict size change during iter in destroy call. ................
19 years ago
  1. #include "Python.h"
  2. #include "Python-ast.h"
  3. #include "code.h"
  4. #include "symtable.h"
  5. #include "structmember.h"
  6. /* error strings used for warnings */
  7. #define GLOBAL_AFTER_ASSIGN \
  8. "name '%.400s' is assigned to before global declaration"
  9. #define NONLOCAL_AFTER_ASSIGN \
  10. "name '%.400s' is assigned to before nonlocal declaration"
  11. #define GLOBAL_AFTER_USE \
  12. "name '%.400s' is used prior to global declaration"
  13. #define NONLOCAL_AFTER_USE \
  14. "name '%.400s' is used prior to nonlocal declaration"
  15. #define IMPORT_STAR_WARNING "import * only allowed at module level"
  16. static PySTEntryObject *
  17. ste_new(struct symtable *st, identifier name, _Py_block_ty block,
  18. void *key, int lineno, int col_offset)
  19. {
  20. PySTEntryObject *ste = NULL;
  21. PyObject *k;
  22. k = PyLong_FromVoidPtr(key);
  23. if (k == NULL)
  24. goto fail;
  25. ste = PyObject_New(PySTEntryObject, &PySTEntry_Type);
  26. if (ste == NULL)
  27. goto fail;
  28. ste->ste_table = st;
  29. ste->ste_id = k;
  30. ste->ste_name = name;
  31. Py_INCREF(name);
  32. ste->ste_symbols = NULL;
  33. ste->ste_varnames = NULL;
  34. ste->ste_children = NULL;
  35. ste->ste_symbols = PyDict_New();
  36. if (ste->ste_symbols == NULL)
  37. goto fail;
  38. ste->ste_varnames = PyList_New(0);
  39. if (ste->ste_varnames == NULL)
  40. goto fail;
  41. ste->ste_children = PyList_New(0);
  42. if (ste->ste_children == NULL)
  43. goto fail;
  44. ste->ste_type = block;
  45. ste->ste_unoptimized = 0;
  46. ste->ste_nested = 0;
  47. ste->ste_free = 0;
  48. ste->ste_varargs = 0;
  49. ste->ste_varkeywords = 0;
  50. ste->ste_opt_lineno = 0;
  51. ste->ste_opt_col_offset = 0;
  52. ste->ste_tmpname = 0;
  53. ste->ste_lineno = lineno;
  54. ste->ste_col_offset = col_offset;
  55. if (st->st_cur != NULL &&
  56. (st->st_cur->ste_nested ||
  57. st->st_cur->ste_type == FunctionBlock))
  58. ste->ste_nested = 1;
  59. ste->ste_child_free = 0;
  60. ste->ste_generator = 0;
  61. ste->ste_returns_value = 0;
  62. if (PyDict_SetItem(st->st_blocks, ste->ste_id, (PyObject *)ste) < 0)
  63. goto fail;
  64. return ste;
  65. fail:
  66. Py_XDECREF(ste);
  67. return NULL;
  68. }
  69. static PyObject *
  70. ste_repr(PySTEntryObject *ste)
  71. {
  72. return PyUnicode_FromFormat("<symtable entry %U(%ld), line %d>",
  73. ste->ste_name,
  74. PyLong_AS_LONG(ste->ste_id), ste->ste_lineno);
  75. }
  76. static void
  77. ste_dealloc(PySTEntryObject *ste)
  78. {
  79. ste->ste_table = NULL;
  80. Py_XDECREF(ste->ste_id);
  81. Py_XDECREF(ste->ste_name);
  82. Py_XDECREF(ste->ste_symbols);
  83. Py_XDECREF(ste->ste_varnames);
  84. Py_XDECREF(ste->ste_children);
  85. PyObject_Del(ste);
  86. }
  87. #define OFF(x) offsetof(PySTEntryObject, x)
  88. static PyMemberDef ste_memberlist[] = {
  89. {"id", T_OBJECT, OFF(ste_id), READONLY},
  90. {"name", T_OBJECT, OFF(ste_name), READONLY},
  91. {"symbols", T_OBJECT, OFF(ste_symbols), READONLY},
  92. {"varnames", T_OBJECT, OFF(ste_varnames), READONLY},
  93. {"children", T_OBJECT, OFF(ste_children), READONLY},
  94. {"optimized",T_INT, OFF(ste_unoptimized), READONLY},
  95. {"nested", T_INT, OFF(ste_nested), READONLY},
  96. {"type", T_INT, OFF(ste_type), READONLY},
  97. {"lineno", T_INT, OFF(ste_lineno), READONLY},
  98. {NULL}
  99. };
  100. PyTypeObject PySTEntry_Type = {
  101. PyVarObject_HEAD_INIT(&PyType_Type, 0)
  102. "symtable entry",
  103. sizeof(PySTEntryObject),
  104. 0,
  105. (destructor)ste_dealloc, /* tp_dealloc */
  106. 0, /* tp_print */
  107. 0, /* tp_getattr */
  108. 0, /* tp_setattr */
  109. 0, /* tp_reserved */
  110. (reprfunc)ste_repr, /* tp_repr */
  111. 0, /* tp_as_number */
  112. 0, /* tp_as_sequence */
  113. 0, /* tp_as_mapping */
  114. 0, /* tp_hash */
  115. 0, /* tp_call */
  116. 0, /* tp_str */
  117. PyObject_GenericGetAttr, /* tp_getattro */
  118. 0, /* tp_setattro */
  119. 0, /* tp_as_buffer */
  120. Py_TPFLAGS_DEFAULT, /* tp_flags */
  121. 0, /* tp_doc */
  122. 0, /* tp_traverse */
  123. 0, /* tp_clear */
  124. 0, /* tp_richcompare */
  125. 0, /* tp_weaklistoffset */
  126. 0, /* tp_iter */
  127. 0, /* tp_iternext */
  128. 0, /* tp_methods */
  129. ste_memberlist, /* tp_members */
  130. 0, /* tp_getset */
  131. 0, /* tp_base */
  132. 0, /* tp_dict */
  133. 0, /* tp_descr_get */
  134. 0, /* tp_descr_set */
  135. 0, /* tp_dictoffset */
  136. 0, /* tp_init */
  137. 0, /* tp_alloc */
  138. 0, /* tp_new */
  139. };
  140. static int symtable_analyze(struct symtable *st);
  141. static int symtable_warn(struct symtable *st, char *msg, int lineno);
  142. static int symtable_enter_block(struct symtable *st, identifier name,
  143. _Py_block_ty block, void *ast, int lineno,
  144. int col_offset);
  145. static int symtable_exit_block(struct symtable *st, void *ast);
  146. static int symtable_visit_stmt(struct symtable *st, stmt_ty s);
  147. static int symtable_visit_expr(struct symtable *st, expr_ty s);
  148. static int symtable_visit_genexp(struct symtable *st, expr_ty s);
  149. static int symtable_visit_listcomp(struct symtable *st, expr_ty s);
  150. static int symtable_visit_setcomp(struct symtable *st, expr_ty s);
  151. static int symtable_visit_dictcomp(struct symtable *st, expr_ty s);
  152. static int symtable_visit_arguments(struct symtable *st, arguments_ty);
  153. static int symtable_visit_excepthandler(struct symtable *st, excepthandler_ty);
  154. static int symtable_visit_alias(struct symtable *st, alias_ty);
  155. static int symtable_visit_comprehension(struct symtable *st, comprehension_ty);
  156. static int symtable_visit_keyword(struct symtable *st, keyword_ty);
  157. static int symtable_visit_slice(struct symtable *st, slice_ty);
  158. static int symtable_visit_params(struct symtable *st, asdl_seq *args);
  159. static int symtable_visit_argannotations(struct symtable *st, asdl_seq *args);
  160. static int symtable_implicit_arg(struct symtable *st, int pos);
  161. static int symtable_visit_annotations(struct symtable *st, stmt_ty s);
  162. static int symtable_visit_withitem(struct symtable *st, withitem_ty item);
  163. static identifier top = NULL, lambda = NULL, genexpr = NULL,
  164. listcomp = NULL, setcomp = NULL, dictcomp = NULL,
  165. __class__ = NULL, __locals__ = NULL;
  166. #define GET_IDENTIFIER(VAR) \
  167. ((VAR) ? (VAR) : ((VAR) = PyUnicode_InternFromString(# VAR)))
  168. #define DUPLICATE_ARGUMENT \
  169. "duplicate argument '%U' in function definition"
  170. static struct symtable *
  171. symtable_new(void)
  172. {
  173. struct symtable *st;
  174. st = (struct symtable *)PyMem_Malloc(sizeof(struct symtable));
  175. if (st == NULL)
  176. return NULL;
  177. st->st_filename = NULL;
  178. st->st_blocks = NULL;
  179. if ((st->st_stack = PyList_New(0)) == NULL)
  180. goto fail;
  181. if ((st->st_blocks = PyDict_New()) == NULL)
  182. goto fail;
  183. st->st_cur = NULL;
  184. st->st_private = NULL;
  185. return st;
  186. fail:
  187. PySymtable_Free(st);
  188. return NULL;
  189. }
  190. struct symtable *
  191. PySymtable_Build(mod_ty mod, const char *filename, PyFutureFeatures *future)
  192. {
  193. struct symtable *st;
  194. asdl_seq *seq;
  195. int i;
  196. if (__class__ == NULL) {
  197. __class__ = PyUnicode_InternFromString("@__class__");
  198. if (__class__ == NULL)
  199. return NULL;
  200. }
  201. st = symtable_new();
  202. if (st == NULL)
  203. return st;
  204. st->st_filename = filename;
  205. st->st_future = future;
  206. /* Make the initial symbol information gathering pass */
  207. if (!GET_IDENTIFIER(top) ||
  208. !symtable_enter_block(st, top, ModuleBlock, (void *)mod, 0, 0)) {
  209. PySymtable_Free(st);
  210. return NULL;
  211. }
  212. st->st_top = st->st_cur;
  213. st->st_cur->ste_unoptimized = OPT_TOPLEVEL;
  214. switch (mod->kind) {
  215. case Module_kind:
  216. seq = mod->v.Module.body;
  217. for (i = 0; i < asdl_seq_LEN(seq); i++)
  218. if (!symtable_visit_stmt(st,
  219. (stmt_ty)asdl_seq_GET(seq, i)))
  220. goto error;
  221. break;
  222. case Expression_kind:
  223. if (!symtable_visit_expr(st, mod->v.Expression.body))
  224. goto error;
  225. break;
  226. case Interactive_kind:
  227. seq = mod->v.Interactive.body;
  228. for (i = 0; i < asdl_seq_LEN(seq); i++)
  229. if (!symtable_visit_stmt(st,
  230. (stmt_ty)asdl_seq_GET(seq, i)))
  231. goto error;
  232. break;
  233. case Suite_kind:
  234. PyErr_SetString(PyExc_RuntimeError,
  235. "this compiler does not handle Suites");
  236. goto error;
  237. }
  238. if (!symtable_exit_block(st, (void *)mod)) {
  239. PySymtable_Free(st);
  240. return NULL;
  241. }
  242. /* Make the second symbol analysis pass */
  243. if (symtable_analyze(st))
  244. return st;
  245. PySymtable_Free(st);
  246. return NULL;
  247. error:
  248. (void) symtable_exit_block(st, (void *)mod);
  249. PySymtable_Free(st);
  250. return NULL;
  251. }
  252. void
  253. PySymtable_Free(struct symtable *st)
  254. {
  255. Py_XDECREF(st->st_blocks);
  256. Py_XDECREF(st->st_stack);
  257. PyMem_Free((void *)st);
  258. }
  259. PySTEntryObject *
  260. PySymtable_Lookup(struct symtable *st, void *key)
  261. {
  262. PyObject *k, *v;
  263. k = PyLong_FromVoidPtr(key);
  264. if (k == NULL)
  265. return NULL;
  266. v = PyDict_GetItem(st->st_blocks, k);
  267. if (v) {
  268. assert(PySTEntry_Check(v));
  269. Py_INCREF(v);
  270. }
  271. else {
  272. PyErr_SetString(PyExc_KeyError,
  273. "unknown symbol table entry");
  274. }
  275. Py_DECREF(k);
  276. return (PySTEntryObject *)v;
  277. }
  278. int
  279. PyST_GetScope(PySTEntryObject *ste, PyObject *name)
  280. {
  281. PyObject *v = PyDict_GetItem(ste->ste_symbols, name);
  282. if (!v)
  283. return 0;
  284. assert(PyLong_Check(v));
  285. return (PyLong_AS_LONG(v) >> SCOPE_OFFSET) & SCOPE_MASK;
  286. }
  287. /* Analyze raw symbol information to determine scope of each name.
  288. The next several functions are helpers for symtable_analyze(),
  289. which determines whether a name is local, global, or free. In addition,
  290. it determines which local variables are cell variables; they provide
  291. bindings that are used for free variables in enclosed blocks.
  292. There are also two kinds of global variables, implicit and explicit. An
  293. explicit global is declared with the global statement. An implicit
  294. global is a free variable for which the compiler has found no binding
  295. in an enclosing function scope. The implicit global is either a global
  296. or a builtin. Python's module and class blocks use the xxx_NAME opcodes
  297. to handle these names to implement slightly odd semantics. In such a
  298. block, the name is treated as global until it is assigned to; then it
  299. is treated as a local.
  300. The symbol table requires two passes to determine the scope of each name.
  301. The first pass collects raw facts from the AST via the symtable_visit_*
  302. functions: the name is a parameter here, the name is used but not defined
  303. here, etc. The second pass analyzes these facts during a pass over the
  304. PySTEntryObjects created during pass 1.
  305. When a function is entered during the second pass, the parent passes
  306. the set of all name bindings visible to its children. These bindings
  307. are used to determine if non-local variables are free or implicit globals.
  308. Names which are explicitly declared nonlocal must exist in this set of
  309. visible names - if they do not, a syntax error is raised. After doing
  310. the local analysis, it analyzes each of its child blocks using an
  311. updated set of name bindings.
  312. The children update the free variable set. If a local variable is added to
  313. the free variable set by the child, the variable is marked as a cell. The
  314. function object being defined must provide runtime storage for the variable
  315. that may outlive the function's frame. Cell variables are removed from the
  316. free set before the analyze function returns to its parent.
  317. During analysis, the names are:
  318. symbols: dict mapping from symbol names to flag values (including offset scope values)
  319. scopes: dict mapping from symbol names to scope values (no offset)
  320. local: set of all symbol names local to the current scope
  321. bound: set of all symbol names local to a containing function scope
  322. free: set of all symbol names referenced but not bound in child scopes
  323. global: set of all symbol names explicitly declared as global
  324. */
  325. #define SET_SCOPE(DICT, NAME, I) { \
  326. PyObject *o = PyLong_FromLong(I); \
  327. if (!o) \
  328. return 0; \
  329. if (PyDict_SetItem((DICT), (NAME), o) < 0) { \
  330. Py_DECREF(o); \
  331. return 0; \
  332. } \
  333. Py_DECREF(o); \
  334. }
  335. /* Decide on scope of name, given flags.
  336. The namespace dictionaries may be modified to record information
  337. about the new name. For example, a new global will add an entry to
  338. global. A name that was global can be changed to local.
  339. */
  340. static int
  341. analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
  342. PyObject *bound, PyObject *local, PyObject *free,
  343. PyObject *global)
  344. {
  345. if (flags & DEF_GLOBAL) {
  346. if (flags & DEF_PARAM) {
  347. PyErr_Format(PyExc_SyntaxError,
  348. "name '%U' is parameter and global",
  349. name);
  350. PyErr_SyntaxLocationEx(ste->ste_table->st_filename,
  351. ste->ste_lineno, ste->ste_col_offset);
  352. return 0;
  353. }
  354. if (flags & DEF_NONLOCAL) {
  355. PyErr_Format(PyExc_SyntaxError,
  356. "name '%U' is nonlocal and global",
  357. name);
  358. return 0;
  359. }
  360. SET_SCOPE(scopes, name, GLOBAL_EXPLICIT);
  361. if (PySet_Add(global, name) < 0)
  362. return 0;
  363. if (bound && (PySet_Discard(bound, name) < 0))
  364. return 0;
  365. return 1;
  366. }
  367. if (flags & DEF_NONLOCAL) {
  368. if (flags & DEF_PARAM) {
  369. PyErr_Format(PyExc_SyntaxError,
  370. "name '%U' is parameter and nonlocal",
  371. name);
  372. return 0;
  373. }
  374. if (!bound) {
  375. PyErr_Format(PyExc_SyntaxError,
  376. "nonlocal declaration not allowed at module level");
  377. return 0;
  378. }
  379. if (!PySet_Contains(bound, name)) {
  380. PyErr_Format(PyExc_SyntaxError,
  381. "no binding for nonlocal '%U' found",
  382. name);
  383. return 0;
  384. }
  385. SET_SCOPE(scopes, name, FREE);
  386. ste->ste_free = 1;
  387. return PySet_Add(free, name) >= 0;
  388. }
  389. if (flags & DEF_BOUND) {
  390. SET_SCOPE(scopes, name, LOCAL);
  391. if (PySet_Add(local, name) < 0)
  392. return 0;
  393. if (PySet_Discard(global, name) < 0)
  394. return 0;
  395. return 1;
  396. }
  397. /* If an enclosing block has a binding for this name, it
  398. is a free variable rather than a global variable.
  399. Note that having a non-NULL bound implies that the block
  400. is nested.
  401. */
  402. if (bound && PySet_Contains(bound, name)) {
  403. SET_SCOPE(scopes, name, FREE);
  404. ste->ste_free = 1;
  405. return PySet_Add(free, name) >= 0;
  406. }
  407. /* If a parent has a global statement, then call it global
  408. explicit? It could also be global implicit.
  409. */
  410. if (global && PySet_Contains(global, name)) {
  411. SET_SCOPE(scopes, name, GLOBAL_IMPLICIT);
  412. return 1;
  413. }
  414. if (ste->ste_nested)
  415. ste->ste_free = 1;
  416. SET_SCOPE(scopes, name, GLOBAL_IMPLICIT);
  417. return 1;
  418. }
  419. #undef SET_SCOPE
  420. /* If a name is defined in free and also in locals, then this block
  421. provides the binding for the free variable. The name should be
  422. marked CELL in this block and removed from the free list.
  423. Note that the current block's free variables are included in free.
  424. That's safe because no name can be free and local in the same scope.
  425. The 'restricted' argument may be set to a string to restrict the analysis
  426. to the one variable whose name equals that string (e.g. "__class__").
  427. */
  428. static int
  429. analyze_cells(PyObject *scopes, PyObject *free, const char *restricted)
  430. {
  431. PyObject *name, *v, *v_cell;
  432. int success = 0;
  433. Py_ssize_t pos = 0;
  434. v_cell = PyLong_FromLong(CELL);
  435. if (!v_cell)
  436. return 0;
  437. while (PyDict_Next(scopes, &pos, &name, &v)) {
  438. long scope;
  439. assert(PyLong_Check(v));
  440. scope = PyLong_AS_LONG(v);
  441. if (scope != LOCAL)
  442. continue;
  443. if (!PySet_Contains(free, name))
  444. continue;
  445. if (restricted != NULL &&
  446. PyUnicode_CompareWithASCIIString(name, restricted))
  447. continue;
  448. /* Replace LOCAL with CELL for this name, and remove
  449. from free. It is safe to replace the value of name
  450. in the dict, because it will not cause a resize.
  451. */
  452. if (PyDict_SetItem(scopes, name, v_cell) < 0)
  453. goto error;
  454. if (PySet_Discard(free, name) < 0)
  455. goto error;
  456. }
  457. success = 1;
  458. error:
  459. Py_DECREF(v_cell);
  460. return success;
  461. }
  462. /* Check for illegal statements in unoptimized namespaces */
  463. static int
  464. check_unoptimized(const PySTEntryObject* ste) {
  465. const char* trailer;
  466. if (ste->ste_type != FunctionBlock || !ste->ste_unoptimized
  467. || !(ste->ste_free || ste->ste_child_free))
  468. return 1;
  469. trailer = (ste->ste_child_free ?
  470. "contains a nested function with free variables" :
  471. "is a nested function");
  472. switch (ste->ste_unoptimized) {
  473. case OPT_TOPLEVEL: /* import * at top-level is fine */
  474. return 1;
  475. case OPT_IMPORT_STAR:
  476. PyErr_Format(PyExc_SyntaxError,
  477. "import * is not allowed in function '%U' because it %s",
  478. ste->ste_name, trailer);
  479. break;
  480. }
  481. PyErr_SyntaxLocationEx(ste->ste_table->st_filename, ste->ste_opt_lineno,
  482. ste->ste_opt_col_offset);
  483. return 0;
  484. }
  485. /* Enter the final scope information into the ste_symbols dict.
  486. *
  487. * All arguments are dicts. Modifies symbols, others are read-only.
  488. */
  489. static int
  490. update_symbols(PyObject *symbols, PyObject *scopes,
  491. PyObject *bound, PyObject *free, int classflag)
  492. {
  493. PyObject *name = NULL, *itr = NULL;
  494. PyObject *v = NULL, *v_scope = NULL, *v_new = NULL, *v_free = NULL;
  495. Py_ssize_t pos = 0;
  496. /* Update scope information for all symbols in this scope */
  497. while (PyDict_Next(symbols, &pos, &name, &v)) {
  498. long scope, flags;
  499. assert(PyLong_Check(v));
  500. flags = PyLong_AS_LONG(v);
  501. v_scope = PyDict_GetItem(scopes, name);
  502. assert(v_scope && PyLong_Check(v_scope));
  503. scope = PyLong_AS_LONG(v_scope);
  504. flags |= (scope << SCOPE_OFFSET);
  505. v_new = PyLong_FromLong(flags);
  506. if (!v_new)
  507. return 0;
  508. if (PyDict_SetItem(symbols, name, v_new) < 0) {
  509. Py_DECREF(v_new);
  510. return 0;
  511. }
  512. Py_DECREF(v_new);
  513. }
  514. /* Record not yet resolved free variables from children (if any) */
  515. v_free = PyLong_FromLong(FREE << SCOPE_OFFSET);
  516. if (!v_free)
  517. return 0;
  518. itr = PyObject_GetIter(free);
  519. if (!itr)
  520. goto error;
  521. while ((name = PyIter_Next(itr))) {
  522. v = PyDict_GetItem(symbols, name);
  523. /* Handle symbol that already exists in this scope */
  524. if (v) {
  525. /* Handle a free variable in a method of
  526. the class that has the same name as a local
  527. or global in the class scope.
  528. */
  529. if (classflag &&
  530. PyLong_AS_LONG(v) & (DEF_BOUND | DEF_GLOBAL)) {
  531. long flags = PyLong_AS_LONG(v) | DEF_FREE_CLASS;
  532. v_new = PyLong_FromLong(flags);
  533. if (!v_new) {
  534. goto error;
  535. }
  536. if (PyDict_SetItem(symbols, name, v_new) < 0) {
  537. Py_DECREF(v_new);
  538. goto error;
  539. }
  540. Py_DECREF(v_new);
  541. }
  542. /* It's a cell, or already free in this scope */
  543. Py_DECREF(name);
  544. continue;
  545. }
  546. /* Handle global symbol */
  547. if (!PySet_Contains(bound, name)) {
  548. Py_DECREF(name);
  549. continue; /* it's a global */
  550. }
  551. /* Propagate new free symbol up the lexical stack */
  552. if (PyDict_SetItem(symbols, name, v_free) < 0) {
  553. goto error;
  554. }
  555. Py_DECREF(name);
  556. }
  557. Py_DECREF(itr);
  558. Py_DECREF(v_free);
  559. return 1;
  560. error:
  561. Py_XDECREF(v_free);
  562. Py_XDECREF(itr);
  563. Py_XDECREF(name);
  564. return 0;
  565. }
  566. /* Make final symbol table decisions for block of ste.
  567. Arguments:
  568. ste -- current symtable entry (input/output)
  569. bound -- set of variables bound in enclosing scopes (input). bound
  570. is NULL for module blocks.
  571. free -- set of free variables in enclosed scopes (output)
  572. globals -- set of declared global variables in enclosing scopes (input)
  573. The implementation uses two mutually recursive functions,
  574. analyze_block() and analyze_child_block(). analyze_block() is
  575. responsible for analyzing the individual names defined in a block.
  576. analyze_child_block() prepares temporary namespace dictionaries
  577. used to evaluated nested blocks.
  578. The two functions exist because a child block should see the name
  579. bindings of its enclosing blocks, but those bindings should not
  580. propagate back to a parent block.
  581. */
  582. static int
  583. analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free,
  584. PyObject *global, PyObject* child_free);
  585. static int
  586. analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
  587. PyObject *global)
  588. {
  589. PyObject *name, *v, *local = NULL, *scopes = NULL, *newbound = NULL;
  590. PyObject *newglobal = NULL, *newfree = NULL, *allfree = NULL;
  591. PyObject *temp;
  592. int i, success = 0;
  593. Py_ssize_t pos = 0;
  594. local = PySet_New(NULL); /* collect new names bound in block */
  595. if (!local)
  596. goto error;
  597. scopes = PyDict_New(); /* collect scopes defined for each name */
  598. if (!scopes)
  599. goto error;
  600. /* Allocate new global and bound variable dictionaries. These
  601. dictionaries hold the names visible in nested blocks. For
  602. ClassBlocks, the bound and global names are initialized
  603. before analyzing names, because class bindings aren't
  604. visible in methods. For other blocks, they are initialized
  605. after names are analyzed.
  606. */
  607. /* TODO(jhylton): Package these dicts in a struct so that we
  608. can write reasonable helper functions?
  609. */
  610. newglobal = PySet_New(NULL);
  611. if (!newglobal)
  612. goto error;
  613. newfree = PySet_New(NULL);
  614. if (!newfree)
  615. goto error;
  616. newbound = PySet_New(NULL);
  617. if (!newbound)
  618. goto error;
  619. /* Class namespace has no effect on names visible in
  620. nested functions, so populate the global and bound
  621. sets to be passed to child blocks before analyzing
  622. this one.
  623. */
  624. if (ste->ste_type == ClassBlock) {
  625. /* Pass down known globals */
  626. temp = PyNumber_InPlaceOr(newglobal, global);
  627. if (!temp)
  628. goto error;
  629. Py_DECREF(temp);
  630. /* Pass down previously bound symbols */
  631. if (bound) {
  632. temp = PyNumber_InPlaceOr(newbound, bound);
  633. if (!temp)
  634. goto error;
  635. Py_DECREF(temp);
  636. }
  637. }
  638. while (PyDict_Next(ste->ste_symbols, &pos, &name, &v)) {
  639. long flags = PyLong_AS_LONG(v);
  640. if (!analyze_name(ste, scopes, name, flags,
  641. bound, local, free, global))
  642. goto error;
  643. }
  644. /* Populate global and bound sets to be passed to children. */
  645. if (ste->ste_type != ClassBlock) {
  646. /* Add function locals to bound set */
  647. if (ste->ste_type == FunctionBlock) {
  648. temp = PyNumber_InPlaceOr(newbound, local);
  649. if (!temp)
  650. goto error;
  651. Py_DECREF(temp);
  652. }
  653. /* Pass down previously bound symbols */
  654. if (bound) {
  655. temp = PyNumber_InPlaceOr(newbound, bound);
  656. if (!temp)
  657. goto error;
  658. Py_DECREF(temp);
  659. }
  660. /* Pass down known globals */
  661. temp = PyNumber_InPlaceOr(newglobal, global);
  662. if (!temp)
  663. goto error;
  664. Py_DECREF(temp);
  665. }
  666. else {
  667. /* Special-case __class__ */
  668. assert(PySet_Contains(local, __class__) == 1);
  669. if (PySet_Add(newbound, __class__) < 0)
  670. goto error;
  671. }
  672. /* Recursively call analyze_child_block() on each child block.
  673. newbound, newglobal now contain the names visible in
  674. nested blocks. The free variables in the children will
  675. be collected in allfree.
  676. */
  677. allfree = PySet_New(NULL);
  678. if (!allfree)
  679. goto error;
  680. for (i = 0; i < PyList_GET_SIZE(ste->ste_children); ++i) {
  681. PyObject *c = PyList_GET_ITEM(ste->ste_children, i);
  682. PySTEntryObject* entry;
  683. assert(c && PySTEntry_Check(c));
  684. entry = (PySTEntryObject*)c;
  685. if (!analyze_child_block(entry, newbound, newfree, newglobal,
  686. allfree))
  687. goto error;
  688. /* Check if any children have free variables */
  689. if (entry->ste_free || entry->ste_child_free)
  690. ste->ste_child_free = 1;
  691. }
  692. temp = PyNumber_InPlaceOr(newfree, allfree);
  693. if (!temp)
  694. goto error;
  695. Py_DECREF(temp);
  696. /* Check if any local variables must be converted to cell variables */
  697. if (ste->ste_type == FunctionBlock && !analyze_cells(scopes, newfree,
  698. NULL))
  699. goto error;
  700. else if (ste->ste_type == ClassBlock && !analyze_cells(scopes, newfree,
  701. "@__class__"))
  702. goto error;
  703. /* Records the results of the analysis in the symbol table entry */
  704. if (!update_symbols(ste->ste_symbols, scopes, bound, newfree,
  705. ste->ste_type == ClassBlock))
  706. goto error;
  707. if (!check_unoptimized(ste))
  708. goto error;
  709. temp = PyNumber_InPlaceOr(free, newfree);
  710. if (!temp)
  711. goto error;
  712. Py_DECREF(temp);
  713. success = 1;
  714. error:
  715. Py_XDECREF(scopes);
  716. Py_XDECREF(local);
  717. Py_XDECREF(newbound);
  718. Py_XDECREF(newglobal);
  719. Py_XDECREF(newfree);
  720. Py_XDECREF(allfree);
  721. if (!success)
  722. assert(PyErr_Occurred());
  723. return success;
  724. }
  725. static int
  726. analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free,
  727. PyObject *global, PyObject* child_free)
  728. {
  729. PyObject *temp_bound = NULL, *temp_global = NULL, *temp_free = NULL;
  730. PyObject *temp;
  731. /* Copy the bound and global dictionaries.
  732. These dictionary are used by all blocks enclosed by the
  733. current block. The analyze_block() call modifies these
  734. dictionaries.
  735. */
  736. temp_bound = PySet_New(bound);
  737. if (!temp_bound)
  738. goto error;
  739. temp_free = PySet_New(free);
  740. if (!temp_free)
  741. goto error;
  742. temp_global = PySet_New(global);
  743. if (!temp_global)
  744. goto error;
  745. if (!analyze_block(entry, temp_bound, temp_free, temp_global))
  746. goto error;
  747. temp = PyNumber_InPlaceOr(child_free, temp_free);
  748. if (!temp)
  749. goto error;
  750. Py_DECREF(temp);
  751. Py_DECREF(temp_bound);
  752. Py_DECREF(temp_free);
  753. Py_DECREF(temp_global);
  754. return 1;
  755. error:
  756. Py_XDECREF(temp_bound);
  757. Py_XDECREF(temp_free);
  758. Py_XDECREF(temp_global);
  759. return 0;
  760. }
  761. static int
  762. symtable_analyze(struct symtable *st)
  763. {
  764. PyObject *free, *global;
  765. int r;
  766. free = PySet_New(NULL);
  767. if (!free)
  768. return 0;
  769. global = PySet_New(NULL);
  770. if (!global) {
  771. Py_DECREF(free);
  772. return 0;
  773. }
  774. r = analyze_block(st->st_top, NULL, free, global);
  775. Py_DECREF(free);
  776. Py_DECREF(global);
  777. return r;
  778. }
  779. static int
  780. symtable_warn(struct symtable *st, char *msg, int lineno)
  781. {
  782. if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, st->st_filename,
  783. lineno, NULL, NULL) < 0) {
  784. if (PyErr_ExceptionMatches(PyExc_SyntaxWarning)) {
  785. PyErr_SetString(PyExc_SyntaxError, msg);
  786. PyErr_SyntaxLocationEx(st->st_filename, st->st_cur->ste_lineno,
  787. st->st_cur->ste_col_offset);
  788. }
  789. return 0;
  790. }
  791. return 1;
  792. }
  793. /* symtable_enter_block() gets a reference via ste_new.
  794. This reference is released when the block is exited, via the DECREF
  795. in symtable_exit_block().
  796. */
  797. static int
  798. symtable_exit_block(struct symtable *st, void *ast)
  799. {
  800. Py_ssize_t size;
  801. st->st_cur = NULL;
  802. size = PyList_GET_SIZE(st->st_stack);
  803. if (size) {
  804. if (PyList_SetSlice(st->st_stack, size - 1, size, NULL) < 0)
  805. return 0;
  806. if (--size)
  807. st->st_cur = (PySTEntryObject *)PyList_GET_ITEM(st->st_stack, size - 1);
  808. }
  809. return 1;
  810. }
  811. static int
  812. symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
  813. void *ast, int lineno, int col_offset)
  814. {
  815. PySTEntryObject *prev = NULL, *ste;
  816. ste = ste_new(st, name, block, ast, lineno, col_offset);
  817. if (ste == NULL)
  818. return 0;
  819. if (PyList_Append(st->st_stack, (PyObject *)ste) < 0) {
  820. Py_DECREF(ste);
  821. return 0;
  822. }
  823. prev = st->st_cur;
  824. /* The entry is owned by the stack. Borrow it for st_cur. */
  825. Py_DECREF(ste);
  826. st->st_cur = ste;
  827. if (block == ModuleBlock)
  828. st->st_global = st->st_cur->ste_symbols;
  829. if (prev) {
  830. if (PyList_Append(prev->ste_children, (PyObject *)ste) < 0) {
  831. return 0;
  832. }
  833. }
  834. return 1;
  835. }
  836. static long
  837. symtable_lookup(struct symtable *st, PyObject *name)
  838. {
  839. PyObject *o;
  840. PyObject *mangled = _Py_Mangle(st->st_private, name);
  841. if (!mangled)
  842. return 0;
  843. o = PyDict_GetItem(st->st_cur->ste_symbols, mangled);
  844. Py_DECREF(mangled);
  845. if (!o)
  846. return 0;
  847. return PyLong_AsLong(o);
  848. }
  849. static int
  850. symtable_add_def(struct symtable *st, PyObject *name, int flag)
  851. {
  852. PyObject *o;
  853. PyObject *dict;
  854. long val;
  855. PyObject *mangled = _Py_Mangle(st->st_private, name);
  856. if (!mangled)
  857. return 0;
  858. dict = st->st_cur->ste_symbols;
  859. if ((o = PyDict_GetItem(dict, mangled))) {
  860. val = PyLong_AS_LONG(o);
  861. if ((flag & DEF_PARAM) && (val & DEF_PARAM)) {
  862. /* Is it better to use 'mangled' or 'name' here? */
  863. PyErr_Format(PyExc_SyntaxError, DUPLICATE_ARGUMENT, name);
  864. PyErr_SyntaxLocationEx(st->st_filename,
  865. st->st_cur->ste_lineno,
  866. st->st_cur->ste_col_offset);
  867. goto error;
  868. }
  869. val |= flag;
  870. } else
  871. val = flag;
  872. o = PyLong_FromLong(val);
  873. if (o == NULL)
  874. goto error;
  875. if (PyDict_SetItem(dict, mangled, o) < 0) {
  876. Py_DECREF(o);
  877. goto error;
  878. }
  879. Py_DECREF(o);
  880. if (flag & DEF_PARAM) {
  881. if (PyList_Append(st->st_cur->ste_varnames, mangled) < 0)
  882. goto error;
  883. } else if (flag & DEF_GLOBAL) {
  884. /* XXX need to update DEF_GLOBAL for other flags too;
  885. perhaps only DEF_FREE_GLOBAL */
  886. val = flag;
  887. if ((o = PyDict_GetItem(st->st_global, mangled))) {
  888. val |= PyLong_AS_LONG(o);
  889. }
  890. o = PyLong_FromLong(val);
  891. if (o == NULL)
  892. goto error;
  893. if (PyDict_SetItem(st->st_global, mangled, o) < 0) {
  894. Py_DECREF(o);
  895. goto error;
  896. }
  897. Py_DECREF(o);
  898. }
  899. Py_DECREF(mangled);
  900. return 1;
  901. error:
  902. Py_DECREF(mangled);
  903. return 0;
  904. }
  905. /* VISIT, VISIT_SEQ and VIST_SEQ_TAIL take an ASDL type as their second argument.
  906. They use the ASDL name to synthesize the name of the C type and the visit
  907. function.
  908. VISIT_SEQ_TAIL permits the start of an ASDL sequence to be skipped, which is
  909. useful if the first node in the sequence requires special treatment.
  910. */
  911. #define VISIT(ST, TYPE, V) \
  912. if (!symtable_visit_ ## TYPE((ST), (V))) \
  913. return 0;
  914. #define VISIT_SEQ(ST, TYPE, SEQ) { \
  915. int i; \
  916. asdl_seq *seq = (SEQ); /* avoid variable capture */ \
  917. for (i = 0; i < asdl_seq_LEN(seq); i++) { \
  918. TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
  919. if (!symtable_visit_ ## TYPE((ST), elt)) \
  920. return 0; \
  921. } \
  922. }
  923. #define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) { \
  924. int i; \
  925. asdl_seq *seq = (SEQ); /* avoid variable capture */ \
  926. for (i = (START); i < asdl_seq_LEN(seq); i++) { \
  927. TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
  928. if (!symtable_visit_ ## TYPE((ST), elt)) \
  929. return 0; \
  930. } \
  931. }
  932. #define VISIT_KWONLYDEFAULTS(ST, KW_DEFAULTS) { \
  933. int i = 0; \
  934. asdl_seq *seq = (KW_DEFAULTS); /* avoid variable capture */ \
  935. for (i = 0; i < asdl_seq_LEN(seq); i++) { \
  936. expr_ty elt = (expr_ty)asdl_seq_GET(seq, i); \
  937. if (!elt) continue; /* can be NULL */ \
  938. if (!symtable_visit_expr((ST), elt)) \
  939. return 0; \
  940. } \
  941. }
  942. static int
  943. symtable_new_tmpname(struct symtable *st)
  944. {
  945. char tmpname[256];
  946. identifier tmp;
  947. PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
  948. ++st->st_cur->ste_tmpname);
  949. tmp = PyUnicode_InternFromString(tmpname);
  950. if (!tmp)
  951. return 0;
  952. if (!symtable_add_def(st, tmp, DEF_LOCAL))
  953. return 0;
  954. Py_DECREF(tmp);
  955. return 1;
  956. }
  957. static int
  958. symtable_visit_stmt(struct symtable *st, stmt_ty s)
  959. {
  960. switch (s->kind) {
  961. case FunctionDef_kind:
  962. if (!symtable_add_def(st, s->v.FunctionDef.name, DEF_LOCAL))
  963. return 0;
  964. if (s->v.FunctionDef.args->defaults)
  965. VISIT_SEQ(st, expr, s->v.FunctionDef.args->defaults);
  966. if (s->v.FunctionDef.args->kw_defaults)
  967. VISIT_KWONLYDEFAULTS(st,
  968. s->v.FunctionDef.args->kw_defaults);
  969. if (!symtable_visit_annotations(st, s))
  970. return 0;
  971. if (s->v.FunctionDef.decorator_list)
  972. VISIT_SEQ(st, expr, s->v.FunctionDef.decorator_list);
  973. if (!symtable_enter_block(st, s->v.FunctionDef.name,
  974. FunctionBlock, (void *)s, s->lineno,
  975. s->col_offset))
  976. return 0;
  977. VISIT(st, arguments, s->v.FunctionDef.args);
  978. VISIT_SEQ(st, stmt, s->v.FunctionDef.body);
  979. if (!symtable_exit_block(st, s))
  980. return 0;
  981. break;
  982. case ClassDef_kind: {
  983. PyObject *tmp;
  984. if (!symtable_add_def(st, s->v.ClassDef.name, DEF_LOCAL))
  985. return 0;
  986. VISIT_SEQ(st, expr, s->v.ClassDef.bases);
  987. VISIT_SEQ(st, keyword, s->v.ClassDef.keywords);
  988. if (s->v.ClassDef.starargs)
  989. VISIT(st, expr, s->v.ClassDef.starargs);
  990. if (s->v.ClassDef.kwargs)
  991. VISIT(st, expr, s->v.ClassDef.kwargs);
  992. if (s->v.ClassDef.decorator_list)
  993. VISIT_SEQ(st, expr, s->v.ClassDef.decorator_list);
  994. if (!symtable_enter_block(st, s->v.ClassDef.name, ClassBlock,
  995. (void *)s, s->lineno, s->col_offset))
  996. return 0;
  997. if (!symtable_add_def(st, __class__, DEF_LOCAL) ||
  998. !GET_IDENTIFIER(__locals__) ||
  999. !symtable_add_def(st, __locals__, DEF_PARAM)) {
  1000. symtable_exit_block(st, s);
  1001. return 0;
  1002. }
  1003. tmp = st->st_private;
  1004. st->st_private = s->v.ClassDef.name;
  1005. VISIT_SEQ(st, stmt, s->v.ClassDef.body);
  1006. st->st_private = tmp;
  1007. if (!symtable_exit_block(st, s))
  1008. return 0;
  1009. break;
  1010. }
  1011. case Return_kind:
  1012. if (s->v.Return.value) {
  1013. VISIT(st, expr, s->v.Return.value);
  1014. st->st_cur->ste_returns_value = 1;
  1015. }
  1016. break;
  1017. case Delete_kind:
  1018. VISIT_SEQ(st, expr, s->v.Delete.targets);
  1019. break;
  1020. case Assign_kind:
  1021. VISIT_SEQ(st, expr, s->v.Assign.targets);
  1022. VISIT(st, expr, s->v.Assign.value);
  1023. break;
  1024. case AugAssign_kind:
  1025. VISIT(st, expr, s->v.AugAssign.target);
  1026. VISIT(st, expr, s->v.AugAssign.value);
  1027. break;
  1028. case For_kind:
  1029. VISIT(st, expr, s->v.For.target);
  1030. VISIT(st, expr, s->v.For.iter);
  1031. VISIT_SEQ(st, stmt, s->v.For.body);
  1032. if (s->v.For.orelse)
  1033. VISIT_SEQ(st, stmt, s->v.For.orelse);
  1034. break;
  1035. case While_kind:
  1036. VISIT(st, expr, s->v.While.test);
  1037. VISIT_SEQ(st, stmt, s->v.While.body);
  1038. if (s->v.While.orelse)
  1039. VISIT_SEQ(st, stmt, s->v.While.orelse);
  1040. break;
  1041. case If_kind:
  1042. /* XXX if 0: and lookup_yield() hacks */
  1043. VISIT(st, expr, s->v.If.test);
  1044. VISIT_SEQ(st, stmt, s->v.If.body);
  1045. if (s->v.If.orelse)
  1046. VISIT_SEQ(st, stmt, s->v.If.orelse);
  1047. break;
  1048. case Raise_kind:
  1049. if (s->v.Raise.exc) {
  1050. VISIT(st, expr, s->v.Raise.exc);
  1051. if (s->v.Raise.cause) {
  1052. VISIT(st, expr, s->v.Raise.cause);
  1053. }
  1054. }
  1055. break;
  1056. case Try_kind:
  1057. VISIT_SEQ(st, stmt, s->v.Try.body);
  1058. VISIT_SEQ(st, stmt, s->v.Try.orelse);
  1059. VISIT_SEQ(st, excepthandler, s->v.Try.handlers);
  1060. VISIT_SEQ(st, stmt, s->v.Try.finalbody);
  1061. break;
  1062. case Assert_kind:
  1063. VISIT(st, expr, s->v.Assert.test);
  1064. if (s->v.Assert.msg)
  1065. VISIT(st, expr, s->v.Assert.msg);
  1066. break;
  1067. case Import_kind:
  1068. VISIT_SEQ(st, alias, s->v.Import.names);
  1069. /* XXX Don't have the lineno available inside
  1070. visit_alias */
  1071. if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno) {
  1072. st->st_cur->ste_opt_lineno = s->lineno;
  1073. st->st_cur->ste_opt_col_offset = s->col_offset;
  1074. }
  1075. break;
  1076. case ImportFrom_kind:
  1077. VISIT_SEQ(st, alias, s->v.ImportFrom.names);
  1078. /* XXX Don't have the lineno available inside
  1079. visit_alias */
  1080. if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno) {
  1081. st->st_cur->ste_opt_lineno = s->lineno;
  1082. st->st_cur->ste_opt_col_offset = s->col_offset;
  1083. }
  1084. break;
  1085. case Global_kind: {
  1086. int i;
  1087. asdl_seq *seq = s->v.Global.names;
  1088. for (i = 0; i < asdl_seq_LEN(seq); i++) {
  1089. identifier name = (identifier)asdl_seq_GET(seq, i);
  1090. char *c_name = _PyUnicode_AsString(name);
  1091. long cur = symtable_lookup(st, name);
  1092. if (cur < 0)
  1093. return 0;
  1094. if (cur & (DEF_LOCAL | USE)) {
  1095. char buf[256];
  1096. if (cur & DEF_LOCAL)
  1097. PyOS_snprintf(buf, sizeof(buf),
  1098. GLOBAL_AFTER_ASSIGN,
  1099. c_name);
  1100. else
  1101. PyOS_snprintf(buf, sizeof(buf),
  1102. GLOBAL_AFTER_USE,
  1103. c_name);
  1104. if (!symtable_warn(st, buf, s->lineno))
  1105. return 0;
  1106. }
  1107. if (!symtable_add_def(st, name, DEF_GLOBAL))
  1108. return 0;
  1109. }
  1110. break;
  1111. }
  1112. case Nonlocal_kind: {
  1113. int i;
  1114. asdl_seq *seq = s->v.Nonlocal.names;
  1115. for (i = 0; i < asdl_seq_LEN(seq); i++) {
  1116. identifier name = (identifier)asdl_seq_GET(seq, i);
  1117. char *c_name = _PyUnicode_AsString(name);
  1118. long cur = symtable_lookup(st, name);
  1119. if (cur < 0)
  1120. return 0;
  1121. if (cur & (DEF_LOCAL | USE)) {
  1122. char buf[256];
  1123. if (cur & DEF_LOCAL)
  1124. PyOS_snprintf(buf, sizeof(buf),
  1125. NONLOCAL_AFTER_ASSIGN,
  1126. c_name);
  1127. else
  1128. PyOS_snprintf(buf, sizeof(buf),
  1129. NONLOCAL_AFTER_USE,
  1130. c_name);
  1131. if (!symtable_warn(st, buf, s->lineno))
  1132. return 0;
  1133. }
  1134. if (!symtable_add_def(st, name, DEF_NONLOCAL))
  1135. return 0;
  1136. }
  1137. break;
  1138. }
  1139. case Expr_kind:
  1140. VISIT(st, expr, s->v.Expr.value);
  1141. break;
  1142. case Pass_kind:
  1143. case Break_kind:
  1144. case Continue_kind:
  1145. /* nothing to do here */
  1146. break;
  1147. case With_kind:
  1148. VISIT_SEQ(st, withitem, s->v.With.items);
  1149. VISIT_SEQ(st, stmt, s->v.With.body);
  1150. break;
  1151. }
  1152. return 1;
  1153. }
  1154. static int
  1155. symtable_visit_expr(struct symtable *st, expr_ty e)
  1156. {
  1157. switch (e->kind) {
  1158. case BoolOp_kind:
  1159. VISIT_SEQ(st, expr, e->v.BoolOp.values);
  1160. break;
  1161. case BinOp_kind:
  1162. VISIT(st, expr, e->v.BinOp.left);
  1163. VISIT(st, expr, e->v.BinOp.right);
  1164. break;
  1165. case UnaryOp_kind:
  1166. VISIT(st, expr, e->v.UnaryOp.operand);
  1167. break;
  1168. case Lambda_kind: {
  1169. if (!GET_IDENTIFIER(lambda))
  1170. return 0;
  1171. if (e->v.Lambda.args->defaults)
  1172. VISIT_SEQ(st, expr, e->v.Lambda.args->defaults);
  1173. if (e->v.Lambda.args->kw_defaults)
  1174. VISIT_KWONLYDEFAULTS(st,
  1175. e->v.Lambda.args->kw_defaults);
  1176. if (!symtable_enter_block(st, lambda,
  1177. FunctionBlock, (void *)e, e->lineno,
  1178. e->col_offset))
  1179. return 0;
  1180. VISIT(st, arguments, e->v.Lambda.args);
  1181. VISIT(st, expr, e->v.Lambda.body);
  1182. if (!symtable_exit_block(st, (void *)e))
  1183. return 0;
  1184. break;
  1185. }
  1186. case IfExp_kind:
  1187. VISIT(st, expr, e->v.IfExp.test);
  1188. VISIT(st, expr, e->v.IfExp.body);
  1189. VISIT(st, expr, e->v.IfExp.orelse);
  1190. break;
  1191. case Dict_kind:
  1192. VISIT_SEQ(st, expr, e->v.Dict.keys);
  1193. VISIT_SEQ(st, expr, e->v.Dict.values);
  1194. break;
  1195. case Set_kind:
  1196. VISIT_SEQ(st, expr, e->v.Set.elts);
  1197. break;
  1198. case GeneratorExp_kind:
  1199. if (!symtable_visit_genexp(st, e))
  1200. return 0;
  1201. break;
  1202. case ListComp_kind:
  1203. if (!symtable_visit_listcomp(st, e))
  1204. return 0;
  1205. break;
  1206. case SetComp_kind:
  1207. if (!symtable_visit_setcomp(st, e))
  1208. return 0;
  1209. break;
  1210. case DictComp_kind:
  1211. if (!symtable_visit_dictcomp(st, e))
  1212. return 0;
  1213. break;
  1214. case Yield_kind:
  1215. case YieldFrom_kind: {
  1216. expr_ty value;
  1217. value = (e->kind == YieldFrom_kind) ? e->v.YieldFrom.value : e->v.Yield.value;
  1218. if (value)
  1219. VISIT(st, expr, value);
  1220. st->st_cur->ste_generator = 1;
  1221. break;
  1222. }
  1223. case Compare_kind:
  1224. VISIT(st, expr, e->v.Compare.left);
  1225. VISIT_SEQ(st, expr, e->v.Compare.comparators);
  1226. break;
  1227. case Call_kind:
  1228. VISIT(st, expr, e->v.Call.func);
  1229. VISIT_SEQ(st, expr, e->v.Call.args);
  1230. VISIT_SEQ(st, keyword, e->v.Call.keywords);
  1231. if (e->v.Call.starargs)
  1232. VISIT(st, expr, e->v.Call.starargs);
  1233. if (e->v.Call.kwargs)
  1234. VISIT(st, expr, e->v.Call.kwargs);
  1235. break;
  1236. case Num_kind:
  1237. case Str_kind:
  1238. case Bytes_kind:
  1239. case Ellipsis_kind:
  1240. /* Nothing to do here. */
  1241. break;
  1242. /* The following exprs can be assignment targets. */
  1243. case Attribute_kind:
  1244. VISIT(st, expr, e->v.Attribute.value);
  1245. break;
  1246. case Subscript_kind:
  1247. VISIT(st, expr, e->v.Subscript.value);
  1248. VISIT(st, slice, e->v.Subscript.slice);
  1249. break;
  1250. case Starred_kind:
  1251. VISIT(st, expr, e->v.Starred.value);
  1252. break;
  1253. case Name_kind:
  1254. if (!symtable_add_def(st, e->v.Name.id,
  1255. e->v.Name.ctx == Load ? USE : DEF_LOCAL))
  1256. return 0;
  1257. /* Special-case super: it counts as a use of __class__ */
  1258. if (e->v.Name.ctx == Load &&
  1259. st->st_cur->ste_type == FunctionBlock &&
  1260. !PyUnicode_CompareWithASCIIString(e->v.Name.id, "super")) {
  1261. if (!symtable_add_def(st, __class__, USE))
  1262. return 0;
  1263. }
  1264. break;
  1265. /* child nodes of List and Tuple will have expr_context set */
  1266. case List_kind:
  1267. VISIT_SEQ(st, expr, e->v.List.elts);
  1268. break;
  1269. case Tuple_kind:
  1270. VISIT_SEQ(st, expr, e->v.Tuple.elts);
  1271. break;
  1272. }
  1273. return 1;
  1274. }
  1275. static int
  1276. symtable_implicit_arg(struct symtable *st, int pos)
  1277. {
  1278. PyObject *id = PyUnicode_FromFormat(".%d", pos);
  1279. if (id == NULL)
  1280. return 0;
  1281. if (!symtable_add_def(st, id, DEF_PARAM)) {
  1282. Py_DECREF(id);
  1283. return 0;
  1284. }
  1285. Py_DECREF(id);
  1286. return 1;
  1287. }
  1288. static int
  1289. symtable_visit_params(struct symtable *st, asdl_seq *args)
  1290. {
  1291. int i;
  1292. if (!args)
  1293. return -1;
  1294. for (i = 0; i < asdl_seq_LEN(args); i++) {
  1295. arg_ty arg = (arg_ty)asdl_seq_GET(args, i);
  1296. if (!symtable_add_def(st, arg->arg, DEF_PARAM))
  1297. return 0;
  1298. }
  1299. return 1;
  1300. }
  1301. static int
  1302. symtable_visit_argannotations(struct symtable *st, asdl_seq *args)
  1303. {
  1304. int i;
  1305. if (!args)
  1306. return -1;
  1307. for (i = 0; i < asdl_seq_LEN(args); i++) {
  1308. arg_ty arg = (arg_ty)asdl_seq_GET(args, i);
  1309. if (arg->annotation)
  1310. VISIT(st, expr, arg->annotation);
  1311. }
  1312. return 1;
  1313. }
  1314. static int
  1315. symtable_visit_annotations(struct symtable *st, stmt_ty s)
  1316. {
  1317. arguments_ty a = s->v.FunctionDef.args;
  1318. if (a->args && !symtable_visit_argannotations(st, a->args))
  1319. return 0;
  1320. if (a->varargannotation)
  1321. VISIT(st, expr, a->varargannotation);
  1322. if (a->kwargannotation)
  1323. VISIT(st, expr, a->kwargannotation);
  1324. if (a->kwonlyargs && !symtable_visit_argannotations(st, a->kwonlyargs))
  1325. return 0;
  1326. if (s->v.FunctionDef.returns)
  1327. VISIT(st, expr, s->v.FunctionDef.returns);
  1328. return 1;
  1329. }
  1330. static int
  1331. symtable_visit_arguments(struct symtable *st, arguments_ty a)
  1332. {
  1333. /* skip default arguments inside function block
  1334. XXX should ast be different?
  1335. */
  1336. if (a->args && !symtable_visit_params(st, a->args))
  1337. return 0;
  1338. if (a->kwonlyargs && !symtable_visit_params(st, a->kwonlyargs))
  1339. return 0;
  1340. if (a->vararg) {
  1341. if (!symtable_add_def(st, a->vararg, DEF_PARAM))
  1342. return 0;
  1343. st->st_cur->ste_varargs = 1;
  1344. }
  1345. if (a->kwarg) {
  1346. if (!symtable_add_def(st, a->kwarg, DEF_PARAM))
  1347. return 0;
  1348. st->st_cur->ste_varkeywords = 1;
  1349. }
  1350. return 1;
  1351. }
  1352. static int
  1353. symtable_visit_excepthandler(struct symtable *st, excepthandler_ty eh)
  1354. {
  1355. if (eh->v.ExceptHandler.type)
  1356. VISIT(st, expr, eh->v.ExceptHandler.type);
  1357. if (eh->v.ExceptHandler.name)
  1358. if (!symtable_add_def(st, eh->v.ExceptHandler.name, DEF_LOCAL))
  1359. return 0;
  1360. VISIT_SEQ(st, stmt, eh->v.ExceptHandler.body);
  1361. return 1;
  1362. }
  1363. static int
  1364. symtable_visit_withitem(struct symtable *st, withitem_ty item)
  1365. {
  1366. VISIT(st, expr, item->context_expr);
  1367. if (item->optional_vars) {
  1368. VISIT(st, expr, item->optional_vars);
  1369. }
  1370. return 1;
  1371. }
  1372. static int
  1373. symtable_visit_alias(struct symtable *st, alias_ty a)
  1374. {
  1375. /* Compute store_name, the name actually bound by the import
  1376. operation. It is different than a->name when a->name is a
  1377. dotted package name (e.g. spam.eggs)
  1378. */
  1379. PyObject *store_name;
  1380. PyObject *name = (a->asname == NULL) ? a->name : a->asname;
  1381. Py_ssize_t dot = PyUnicode_FindChar(name, '.', 0,
  1382. PyUnicode_GET_LENGTH(name), 1);
  1383. if (dot != -1) {
  1384. store_name = PyUnicode_Substring(name, 0, dot);
  1385. if (!store_name)
  1386. return 0;
  1387. }
  1388. else {
  1389. store_name = name;
  1390. Py_INCREF(store_name);
  1391. }
  1392. if (PyUnicode_CompareWithASCIIString(name, "*")) {
  1393. int r = symtable_add_def(st, store_name, DEF_IMPORT);
  1394. Py_DECREF(store_name);
  1395. return r;
  1396. }
  1397. else {
  1398. if (st->st_cur->ste_type != ModuleBlock) {
  1399. int lineno = st->st_cur->ste_lineno;
  1400. int col_offset = st->st_cur->ste_col_offset;
  1401. PyErr_SetString(PyExc_SyntaxError, IMPORT_STAR_WARNING);
  1402. PyErr_SyntaxLocationEx(st->st_filename, lineno, col_offset);
  1403. Py_DECREF(store_name);
  1404. return 0;
  1405. }
  1406. st->st_cur->ste_unoptimized |= OPT_IMPORT_STAR;
  1407. Py_DECREF(store_name);
  1408. return 1;
  1409. }
  1410. }
  1411. static int
  1412. symtable_visit_comprehension(struct symtable *st, comprehension_ty lc)
  1413. {
  1414. VISIT(st, expr, lc->target);
  1415. VISIT(st, expr, lc->iter);
  1416. VISIT_SEQ(st, expr, lc->ifs);
  1417. return 1;
  1418. }
  1419. static int
  1420. symtable_visit_keyword(struct symtable *st, keyword_ty k)
  1421. {
  1422. VISIT(st, expr, k->value);
  1423. return 1;
  1424. }
  1425. static int
  1426. symtable_visit_slice(struct symtable *st, slice_ty s)
  1427. {
  1428. switch (s->kind) {
  1429. case Slice_kind:
  1430. if (s->v.Slice.lower)
  1431. VISIT(st, expr, s->v.Slice.lower)
  1432. if (s->v.Slice.upper)
  1433. VISIT(st, expr, s->v.Slice.upper)
  1434. if (s->v.Slice.step)
  1435. VISIT(st, expr, s->v.Slice.step)
  1436. break;
  1437. case ExtSlice_kind:
  1438. VISIT_SEQ(st, slice, s->v.ExtSlice.dims)
  1439. break;
  1440. case Index_kind:
  1441. VISIT(st, expr, s->v.Index.value)
  1442. break;
  1443. }
  1444. return 1;
  1445. }
  1446. static int
  1447. symtable_handle_comprehension(struct symtable *st, expr_ty e,
  1448. identifier scope_name, asdl_seq *generators,
  1449. expr_ty elt, expr_ty value)
  1450. {
  1451. int is_generator = (e->kind == GeneratorExp_kind);
  1452. int needs_tmp = !is_generator;
  1453. comprehension_ty outermost = ((comprehension_ty)
  1454. asdl_seq_GET(generators, 0));
  1455. /* Outermost iterator is evaluated in current scope */
  1456. VISIT(st, expr, outermost->iter);
  1457. /* Create comprehension scope for the rest */
  1458. if (!scope_name ||
  1459. !symtable_enter_block(st, scope_name, FunctionBlock, (void *)e,
  1460. e->lineno, e->col_offset)) {
  1461. return 0;
  1462. }
  1463. st->st_cur->ste_generator = is_generator;
  1464. /* Outermost iter is received as an argument */
  1465. if (!symtable_implicit_arg(st, 0)) {
  1466. symtable_exit_block(st, (void *)e);
  1467. return 0;
  1468. }
  1469. /* Allocate temporary name if needed */
  1470. if (needs_tmp && !symtable_new_tmpname(st)) {
  1471. symtable_exit_block(st, (void *)e);
  1472. return 0;
  1473. }
  1474. VISIT(st, expr, outermost->target);
  1475. VISIT_SEQ(st, expr, outermost->ifs);
  1476. VISIT_SEQ_TAIL(st, comprehension, generators, 1);
  1477. if (value)
  1478. VISIT(st, expr, value);
  1479. VISIT(st, expr, elt);
  1480. return symtable_exit_block(st, (void *)e);
  1481. }
  1482. static int
  1483. symtable_visit_genexp(struct symtable *st, expr_ty e)
  1484. {
  1485. return symtable_handle_comprehension(st, e, GET_IDENTIFIER(genexpr),
  1486. e->v.GeneratorExp.generators,
  1487. e->v.GeneratorExp.elt, NULL);
  1488. }
  1489. static int
  1490. symtable_visit_listcomp(struct symtable *st, expr_ty e)
  1491. {
  1492. return symtable_handle_comprehension(st, e, GET_IDENTIFIER(listcomp),
  1493. e->v.ListComp.generators,
  1494. e->v.ListComp.elt, NULL);
  1495. }
  1496. static int
  1497. symtable_visit_setcomp(struct symtable *st, expr_ty e)
  1498. {
  1499. return symtable_handle_comprehension(st, e, GET_IDENTIFIER(setcomp),
  1500. e->v.SetComp.generators,
  1501. e->v.SetComp.elt, NULL);
  1502. }
  1503. static int
  1504. symtable_visit_dictcomp(struct symtable *st, expr_ty e)
  1505. {
  1506. return symtable_handle_comprehension(st, e, GET_IDENTIFIER(dictcomp),
  1507. e->v.DictComp.generators,
  1508. e->v.DictComp.key,
  1509. e->v.DictComp.value);
  1510. }