summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-06-13 18:07:49 (GMT)
committerGuido van Rossum <guido@python.org>2007-06-13 18:07:49 (GMT)
commitcd16bf640405065e4702539632ce577536207d88 (patch)
treef4aaa3bdd36bc4811f4441e2a0e4d3dd7957c891 /Python
parent6374bb5a699a6e21214bec2bbe2e527fd219b8ba (diff)
downloadcpython-cd16bf640405065e4702539632ce577536207d88.zip
cpython-cd16bf640405065e4702539632ce577536207d88.tar.gz
cpython-cd16bf640405065e4702539632ce577536207d88.tar.bz2
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. ................
Diffstat (limited to 'Python')
-rw-r--r--Python/ast.c35
-rw-r--r--Python/bltinmodule.c69
-rw-r--r--Python/compile.c64
-rw-r--r--Python/mystrtoul.c64
-rw-r--r--Python/peephole.c53
-rw-r--r--Python/structmember.c42
-rw-r--r--Python/symtable.c46
7 files changed, 207 insertions, 166 deletions
diff --git a/Python/ast.c b/Python/ast.c
index b313ef2..c611436 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -376,10 +376,6 @@ set_context(expr_ty e, expr_context_ty ctx, const node *n)
switch (e->kind) {
case Attribute_kind:
- if (ctx == Store &&
- !PyUnicode_CompareWithASCIIString(e->v.Attribute.attr, "None")) {
- return ast_error(n, "assignment to None");
- }
e->v.Attribute.ctx = ctx;
break;
case Subscript_kind:
@@ -600,10 +596,6 @@ compiler_arg(struct compiling *c, const node *n)
assert(TYPE(n) == tfpdef || TYPE(n) == vfpdef);
ch = CHILD(n, 0);
- if (!strcmp(STR(ch), "None")) {
- ast_error(ch, "assignment to None");
- return NULL;
- }
name = NEW_IDENTIFIER(ch);
if (!name)
return NULL;
@@ -641,10 +633,6 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
case tfpdef:
if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) {
expression = ast_for_expr(c, CHILD(n, i + 2));
- if (!expression) {
- ast_error(ch, "assignment to None");
- goto error;
- }
asdl_seq_SET(kwdefaults, j, expression);
i += 2; /* '=' and test */
}
@@ -663,10 +651,6 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
annotation = NULL;
}
ch = CHILD(ch, 0);
- if (!strcmp(STR(ch), "None")) {
- ast_error(ch, "assignment to None");
- goto error;
- }
arg = arg(NEW_IDENTIFIER(ch), annotation, c->c_arena);
if (!arg) {
ast_error(ch, "expecting name");
@@ -817,10 +801,6 @@ ast_for_arguments(struct compiling *c, const node *n)
if (res == -1) goto error;
i = res; /* res has new position to process */
}
- else if (!strcmp(STR(CHILD(ch, 0)), "None")) {
- ast_error(CHILD(ch, 0), "assignment to None");
- goto error;
- }
else {
vararg = NEW_IDENTIFIER(CHILD(ch, 0));
if (NCH(ch) > 1) {
@@ -841,10 +821,6 @@ ast_for_arguments(struct compiling *c, const node *n)
case DOUBLESTAR:
ch = CHILD(n, i+1); /* tfpdef */
assert(TYPE(ch) == tfpdef || TYPE(ch) == vfpdef);
- if (!strcmp(STR(CHILD(ch, 0)), "None")) {
- ast_error(CHILD(ch, 0), "assignment to None");
- goto error;
- }
kwarg = NEW_IDENTIFIER(CHILD(ch, 0));
if (NCH(ch) > 1) {
/* there is an annotation on the kwarg */
@@ -971,10 +947,6 @@ ast_for_funcdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
name = NEW_IDENTIFIER(CHILD(n, name_i));
if (!name)
return NULL;
- else if (!strcmp(STR(CHILD(n, name_i)), "None")) {
- ast_error(CHILD(n, name_i), "assignment to None");
- return NULL;
- }
args = ast_for_arguments(c, CHILD(n, name_i + 1));
if (!args)
return NULL;
@@ -2913,11 +2885,6 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
REQ(n, classdef);
- if (!strcmp(STR(CHILD(n, 1)), "None")) {
- ast_error(n, "assignment to None");
- return NULL;
- }
-
if (NCH(n) == 4) { /* class NAME ':' suite */
s = ast_for_suite(c, CHILD(n, 3));
if (!s)
@@ -3039,8 +3006,6 @@ parsenumber(const char *s)
#ifndef WITHOUT_COMPLEX
imflag = *end == 'j' || *end == 'J';
#endif
- if (*end == 'l' || *end == 'L')
- return PyLong_FromString((char *)s, (char **)0, 0);
if (s[0] == '0') {
x = (long) PyOS_strtoul((char *)s, (char **)&end, 0);
if (x < 0 && errno == 0) {
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 3b43ff9..a2e48b1 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -31,7 +31,8 @@ static PyObject *filtertuple (PyObject *, PyObject *);
static PyObject *
builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
{
- PyObject *func, *name, *bases, *mkw, *meta, *prep, *ns, *res;
+ PyObject *func, *name, *bases, *mkw, *meta, *prep, *ns, *cell;
+ PyObject *cls = NULL;
Py_ssize_t nargs, nbases;
assert(args != NULL);
@@ -112,22 +113,25 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
return NULL;
}
}
- res = PyObject_CallFunctionObjArgs(func, ns, NULL);
- if (res != NULL) {
+ cell = PyObject_CallFunctionObjArgs(func, ns, NULL);
+ if (cell != NULL) {
PyObject *margs;
- Py_DECREF(res);
- res = NULL;
margs = Py_BuildValue("OOO", name, bases, ns);
if (margs != NULL) {
- res = PyEval_CallObjectWithKeywords(meta, margs, mkw);
+ cls = PyEval_CallObjectWithKeywords(meta, margs, mkw);
Py_DECREF(margs);
}
+ if (cls != NULL && PyCell_Check(cell)) {
+ Py_INCREF(cls);
+ PyCell_SET(cell, cls);
+ }
+ Py_DECREF(cell);
}
Py_DECREF(ns);
Py_DECREF(meta);
Py_XDECREF(mkw);
Py_DECREF(bases);
- return res;
+ return cls;
}
PyDoc_STRVAR(build_class_doc,
@@ -245,6 +249,18 @@ Return True if bool(x) is True for any x in the iterable.");
static PyObject *
+builtin_bin(PyObject *self, PyObject *v)
+{
+ return PyNumber_ToBase(v, 2);
+}
+
+PyDoc_STRVAR(bin_doc,
+"bin(number) -> string\n\
+\n\
+Return the binary representation of an integer or long integer.");
+
+
+static PyObject *
builtin_filter(PyObject *self, PyObject *args)
{
PyObject *func, *seq, *result, *it, *arg;
@@ -1192,24 +1208,7 @@ the same hash value. The reverse is not necessarily true, but likely.");
static PyObject *
builtin_hex(PyObject *self, PyObject *v)
{
- PyNumberMethods *nb;
- PyObject *res;
-
- if ((nb = v->ob_type->tp_as_number) == NULL ||
- nb->nb_hex == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "hex() argument can't be converted to hex");
- return NULL;
- }
- res = (*nb->nb_hex)(v);
- if (res && !PyString_Check(res) && !PyUnicode_Check(res)) {
- PyErr_Format(PyExc_TypeError,
- "__hex__ returned non-string (type %.200s)",
- res->ob_type->tp_name);
- Py_DECREF(res);
- return NULL;
- }
- return res;
+ return PyNumber_ToBase(v, 16);
}
PyDoc_STRVAR(hex_doc,
@@ -1392,24 +1391,7 @@ With two or more arguments, return the largest argument.");
static PyObject *
builtin_oct(PyObject *self, PyObject *v)
{
- PyNumberMethods *nb;
- PyObject *res;
-
- if (v == NULL || (nb = v->ob_type->tp_as_number) == NULL ||
- nb->nb_oct == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "oct() argument can't be converted to oct");
- return NULL;
- }
- res = (*nb->nb_oct)(v);
- if (res && !PyString_Check(res) && !PyUnicode_Check(res)) {
- PyErr_Format(PyExc_TypeError,
- "__oct__ returned non-string (type %.200s)",
- res->ob_type->tp_name);
- Py_DECREF(res);
- return NULL;
- }
- return res;
+ return PyNumber_ToBase(v, 8);
}
PyDoc_STRVAR(oct_doc,
@@ -1949,6 +1931,7 @@ static PyMethodDef builtin_methods[] = {
{"abs", builtin_abs, METH_O, abs_doc},
{"all", builtin_all, METH_O, all_doc},
{"any", builtin_any, METH_O, any_doc},
+ {"bin", builtin_bin, METH_O, bin_doc},
{"chr", builtin_chr, METH_VARARGS, chr_doc},
{"chr8", builtin_chr8, METH_VARARGS, chr8_doc},
{"cmp", builtin_cmp, METH_VARARGS, cmp_doc},
diff --git a/Python/compile.c b/Python/compile.c
index fde4591..0f5fd2d 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -373,10 +373,12 @@ dictbytype(PyObject *src, int scope_type, int flag, int offset)
while (PyDict_Next(src, &pos, &k, &v)) {
/* XXX this should probably be a macro in symtable.h */
+ long vi;
assert(PyInt_Check(v));
- scope = (PyInt_AS_LONG(v) >> SCOPE_OFFSET) & SCOPE_MASK;
+ vi = PyInt_AS_LONG(v);
+ scope = (vi >> SCOPE_OFFSET) & SCOPE_MASK;
- if (scope == scope_type || PyInt_AS_LONG(v) & flag) {
+ if (scope == scope_type || vi & flag) {
PyObject *tuple, *item = PyInt_FromLong(i);
if (item == NULL) {
Py_DECREF(dest);
@@ -1125,7 +1127,8 @@ compiler_body(struct compiler *c, asdl_seq *stmts)
if (!asdl_seq_LEN(stmts))
return 1;
st = (stmt_ty)asdl_seq_GET(stmts, 0);
- if (compiler_isdocstring(st)) {
+ if (compiler_isdocstring(st) && Py_OptimizeFlag < 2) {
+ /* don't generate docstrings if -OO */
i = 1;
VISIT(c, expr, st->v.Expr.value);
if (!compiler_nameop(c, __doc__, Store))
@@ -1251,7 +1254,8 @@ compiler_make_closure(struct compiler *c, PyCodeObject *co, int args)
else /* (reftype == FREE) */
arg = compiler_lookup_arg(c->u->u_freevars, name);
if (arg == -1) {
- printf("lookup %s in %s %d %d\n"
+ fprintf(stderr,
+ "lookup %s in %s %d %d\n"
"freevars of %s: %s\n",
PyObject_REPR(name),
PyString_AS_STRING(c->u->u_name),
@@ -1474,7 +1478,6 @@ compiler_function(struct compiler *c, stmt_ty s)
static int
compiler_class(struct compiler *c, stmt_ty s)
{
- static PyObject *build_class = NULL;
static PyObject *locals = NULL;
PyCodeObject *co;
PyObject *str;
@@ -1485,13 +1488,7 @@ compiler_class(struct compiler *c, stmt_ty s)
if (!compiler_decorators(c, decos))
return 0;
-
/* initialize statics */
- if (build_class == NULL) {
- build_class = PyUnicode_FromString("__build_class__");
- if (build_class == NULL)
- return 0;
- }
if (locals == NULL) {
locals = PyUnicode_FromString("__locals__");
if (locals == NULL)
@@ -1501,14 +1498,16 @@ compiler_class(struct compiler *c, stmt_ty s)
/* ultimately generate code for:
<name> = __build_class__(<func>, <name>, *<bases>, **<keywords>)
where:
- <func> is a function/closure created from the class body
+ <func> is a function/closure created from the class body;
+ it has a single argument (__locals__) where the dict
+ (or MutableSequence) representing the locals is passed
<name> is the class name
<bases> is the positional arguments and *varargs argument
<keywords> is the keyword arguments and **kwds argument
This borrows from compiler_call.
*/
- /* 0. Create a fake variable named __locals__ */
+ /* 0. Create a fake argument named __locals__ */
ste = PySymtable_Lookup(c->c_st, s);
if (ste == NULL)
return 0;
@@ -1528,11 +1527,11 @@ compiler_class(struct compiler *c, stmt_ty s)
c->u->u_private = s->v.ClassDef.name;
/* force it to have one mandatory argument */
c->u->u_argcount = 1;
- /* load the first argument ... */
+ /* load the first argument (__locals__) ... */
ADDOP_I(c, LOAD_FAST, 0);
/* ... and store it into f_locals */
ADDOP_IN_SCOPE(c, STORE_LOCALS);
- /* load __name__ ... */
+ /* load (global) __name__ ... */
str = PyUnicode_InternFromString("__name__");
if (!str || !compiler_nameop(c, str, Load)) {
Py_XDECREF(str);
@@ -1553,8 +1552,24 @@ compiler_class(struct compiler *c, stmt_ty s)
compiler_exit_scope(c);
return 0;
}
- /* return None */
- ADDOP_O(c, LOAD_CONST, Py_None, consts);
+ /* return the (empty) __class__ cell */
+ str = PyUnicode_InternFromString("__class__");
+ if (str == NULL) {
+ compiler_exit_scope(c);
+ return 0;
+ }
+ i = compiler_lookup_arg(c->u->u_cellvars, str);
+ Py_DECREF(str);
+ if (i == -1) {
+ /* This happens when nobody references the cell */
+ PyErr_Clear();
+ /* Return None */
+ ADDOP_O(c, LOAD_CONST, Py_None, consts);
+ }
+ else {
+ /* Return the cell where to store __class__ */
+ ADDOP_I(c, LOAD_CLOSURE, i);
+ }
ADDOP_IN_SCOPE(c, RETURN_VALUE);
/* create the code object */
co = assemble(c, 1);
@@ -2421,7 +2436,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
return compiler_error(c, "can not assign to __debug__");
}
-mangled = _Py_Mangle(c->u->u_private, name);
+ mangled = _Py_Mangle(c->u->u_private, name);
if (!mangled)
return 0;
@@ -2947,6 +2962,7 @@ compiler_visit_keyword(struct compiler *c, keyword_ty k)
static int
expr_constant(expr_ty e)
{
+ char *id;
switch (e->kind) {
case Ellipsis_kind:
return 1;
@@ -2955,11 +2971,13 @@ expr_constant(expr_ty e)
case Str_kind:
return PyObject_IsTrue(e->v.Str.s);
case Name_kind:
- /* __debug__ is not assignable, so we can optimize
- * it away in if and while statements */
- if (PyUnicode_CompareWithASCIIString(e->v.Name.id,
- "__debug__") == 0)
- return ! Py_OptimizeFlag;
+ /* optimize away names that can't be reassigned */
+ id = _PyUnicode_AsDefaultEncodedString(e->v.Name.id, NULL);
+ if (strcmp(id, "True") == 0) return 1;
+ if (strcmp(id, "False") == 0) return 0;
+ if (strcmp(id, "None") == 0) return 0;
+ if (strcmp(id, "__debug__") == 0)
+ return ! Py_OptimizeFlag;
/* fall through */
default:
return -1;
diff --git a/Python/mystrtoul.c b/Python/mystrtoul.c
index f007057..cf23051 100644
--- a/Python/mystrtoul.c
+++ b/Python/mystrtoul.c
@@ -91,7 +91,7 @@ static int digitlimit[] = {
** This is a general purpose routine for converting
** an ascii string to an integer in an arbitrary base.
** Leading white space is ignored. If 'base' is zero
-** it looks for a leading 0, 0x or 0X to tell which
+** it looks for a leading 0b, 0o or 0x to tell which
** base. If these are absent it defaults to 10.
** Base must be 0 or between 2 and 36 (inclusive).
** If 'ptr' is non-NULL it will contain a pointer to
@@ -110,29 +110,57 @@ PyOS_strtoul(register char *str, char **ptr, int base)
while (*str && isspace(Py_CHARMASK(*str)))
++str;
- /* check for leading 0 or 0x for auto-base or base 16 */
+ /* check for leading 0b, 0o or 0x for auto-base or base 16 */
switch (base) {
- case 0: /* look for leading 0, 0x or 0X */
- if (*str == '0') {
+ case 0: /* look for leading 0b, 0o or 0x */
+ if (*str == '0') {
+ ++str;
+ if (*str == 'x' || *str == 'X') {
+ ++str;
+ base = 16;
+ } else if (*str == 'o' || *str == 'O') {
++str;
- if (*str == 'x' || *str == 'X') {
+ base = 8;
+ } else if (*str == 'b' || *str == 'B') {
+ ++str;
+ base = 2;
+ } else {
+ /* skip all zeroes... */
+ while (*str == '0')
+ ++str;
+ while (isspace(Py_CHARMASK(*str)))
++str;
- base = 16;
- }
- else
- base = 8;
+ if (ptr)
+ *ptr = str;
+ return 0;
}
- else
- base = 10;
- break;
+ }
+ else
+ base = 10;
+ break;
- case 16: /* skip leading 0x or 0X */
- if (*str == '0') {
+ /* even with explicit base, skip leading 0? prefix */
+ case 16:
+ if (*str == '0') {
+ ++str;
+ if (*str == 'x' || *str == 'X')
++str;
- if (*str == 'x' || *str == 'X')
- ++str;
- }
- break;
+ }
+ break;
+ case 8:
+ if (*str == '0') {
+ ++str;
+ if (*str == 'o' || *str == 'O')
+ ++str;
+ }
+ break;
+ case 2:
+ if(*str == '0') {
+ ++str;
+ if (*str == 'b' || *str == 'B')
+ ++str;
+ }
+ break;
}
/* catch silly bases */
diff --git a/Python/peephole.c b/Python/peephole.c
index 7c4640c..d012d39 100644
--- a/Python/peephole.c
+++ b/Python/peephole.c
@@ -257,6 +257,37 @@ markblocks(unsigned char *code, int len)
return blocks;
}
+/* Helper to replace LOAD_NAME None/True/False with LOAD_CONST
+ Returns: 0 if no change, 1 if change, -1 if error */
+static int
+load_global(unsigned char *codestr, Py_ssize_t i, char *name, PyObject *consts)
+{
+ Py_ssize_t j;
+ PyObject *obj;
+ if (name == NULL)
+ return 0;
+ if (strcmp(name, "None") == 0)
+ obj = Py_None;
+ else if (strcmp(name, "True") == 0)
+ obj = Py_True;
+ else if (strcmp(name, "False") == 0)
+ obj = Py_False;
+ else
+ return 0;
+ for (j = 0; j < PyList_GET_SIZE(consts); j++) {
+ if (PyList_GET_ITEM(consts, j) == obj)
+ break;
+ }
+ if (j == PyList_GET_SIZE(consts)) {
+ if (PyList_Append(consts, obj) < 0)
+ return -1;
+ }
+ assert(PyList_GET_ITEM(consts, j) == obj);
+ codestr[i] = LOAD_CONST;
+ SETARG(codestr, i, j);
+ return 1;
+}
+
/* Perform basic peephole optimizations to components of a code object.
The consts object should still be in list form to allow new constants
to be appended.
@@ -302,7 +333,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
/* Avoid situations where jump retargeting could overflow */
assert(PyString_Check(code));
- codelen = PyString_Size(code);
+ codelen = PyString_GET_SIZE(code);
if (codelen > 32700)
goto exitUnchanged;
@@ -371,25 +402,17 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
codestr[i+3] = NOP;
break;
- /* Replace LOAD_GLOBAL/LOAD_NAME None
- with LOAD_CONST None */
+ /* Replace LOAD_GLOBAL/LOAD_NAME None/True/False
+ with LOAD_CONST None/True/False */
case LOAD_NAME:
case LOAD_GLOBAL:
j = GETARG(codestr, i);
name = PyString_AsString(PyTuple_GET_ITEM(names, j));
- if (name == NULL || strcmp(name, "None") != 0)
+ h = load_global(codestr, i, name, consts);
+ if (h < 0)
+ goto exitUnchanged;
+ else if (h == 0)
continue;
- for (j=0 ; j < PyList_GET_SIZE(consts) ; j++) {
- if (PyList_GET_ITEM(consts, j) == Py_None)
- break;
- }
- if (j == PyList_GET_SIZE(consts)) {
- if (PyList_Append(consts, Py_None) == -1)
- goto exitUnchanged;
- }
- assert(PyList_GET_ITEM(consts, j) == Py_None);
- codestr[i] = LOAD_CONST;
- SETARG(codestr, i, j);
cumlc = lastlc + 1;
break;
diff --git a/Python/structmember.c b/Python/structmember.c
index b6cf2ac..1de2238 100644
--- a/Python/structmember.c
+++ b/Python/structmember.c
@@ -289,31 +289,25 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
}
break;
#ifdef HAVE_LONG_LONG
- case T_LONGLONG:
- if (!PyLong_Check(v)) {
- PyErr_BadArgument();
+ case T_LONGLONG:{
+ PY_LONG_LONG value;
+ *(PY_LONG_LONG*)addr = value = PyLong_AsLongLong(v);
+ if ((value == -1) && PyErr_Occurred())
return -1;
- } else {
- PY_LONG_LONG value;
- *(PY_LONG_LONG*)addr = value = PyLong_AsLongLong(v);
- if ((value == -1) && PyErr_Occurred()) {
- return -1;
- }
- }
- break;
- case T_ULONGLONG:
- if (!PyLong_Check(v)) {
- PyErr_BadArgument();
- return -1;
- } else {
- unsigned PY_LONG_LONG value;
- *(unsigned PY_LONG_LONG*)addr = value = PyLong_AsUnsignedLongLong(v);
- if ((value == (unsigned PY_LONG_LONG)-1) &&
- PyErr_Occurred()) {
- return -1;
- }
- }
- break;
+ break;
+ }
+ case T_ULONGLONG:{
+ unsigned PY_LONG_LONG value;
+ /* ??? PyLong_AsLongLong accepts an int, but PyLong_AsUnsignedLongLong
+ doesn't ??? */
+ if (PyLong_Check(v))
+ *(unsigned PY_LONG_LONG*)addr = value = PyLong_AsUnsignedLongLong(v);
+ else
+ *(unsigned PY_LONG_LONG*)addr = value = PyInt_AsLong(v);
+ if ((value == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())
+ return -1;
+ break;
+ }
#endif /* HAVE_LONG_LONG */
default:
PyErr_Format(PyExc_SystemError,
diff --git a/Python/symtable.c b/Python/symtable.c
index 68c1821..30e97d6 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -183,7 +183,7 @@ static int symtable_visit_annotations(struct symtable *st, stmt_ty s);
static identifier top = NULL, lambda = NULL, genexpr = NULL,
- listcomp = NULL, setcomp = NULL;
+ listcomp = NULL, setcomp = NULL, __class__ = NULL;
#define GET_IDENTIFIER(VAR) \
((VAR) ? (VAR) : ((VAR) = PyUnicode_InternFromString(# VAR)))
@@ -317,7 +317,7 @@ PyST_GetScope(PySTEntryObject *ste, PyObject *name)
/* Analyze raw symbol information to determine scope of each name.
- The next several functions are helpers for PySymtable_Analyze(),
+ The next several functions are helpers for symtable_analyze(),
which determines whether a name is local, global, or free. In addition,
it determines which local variables are cell variables; they provide
bindings that are used for free variables in enclosed blocks.
@@ -464,10 +464,13 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
Note that the current block's free variables are included in free.
That's safe because no name can be free and local in the same scope.
+
+ The 'restrict' argument may be set to a string to restrict the analysis
+ to the one variable whose name equals that string (e.g. "__class__").
*/
static int
-analyze_cells(PyObject *scopes, PyObject *free)
+analyze_cells(PyObject *scopes, PyObject *free, const char *restrict)
{
PyObject *name, *v, *v_cell;
int success = 0;
@@ -484,6 +487,9 @@ analyze_cells(PyObject *scopes, PyObject *free)
continue;
if (!PySet_Contains(free, name))
continue;
+ if (restrict != NULL &&
+ PyUnicode_CompareWithASCIIString(name, restrict))
+ continue;
/* Replace LOCAL with CELL for this name, and remove
from free. It is safe to replace the value of name
in the dict, because it will not cause a resize.
@@ -589,7 +595,7 @@ update_symbols(PyObject *symbols, PyObject *scopes,
}
Py_DECREF(v_new);
}
- /* It's a cell, or already a free variable in this scope */
+ /* It's a cell, or already free in this scope */
Py_DECREF(name);
continue;
}
@@ -675,8 +681,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
goto error;
}
- /* Populate global and bound sets to be passed to children.
- */
+ /* Populate global and bound sets to be passed to children. */
if (ste->ste_type != ClassBlock) {
/* Add function locals to bound set */
if (ste->ste_type == FunctionBlock) {
@@ -695,6 +700,14 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
goto error;
Py_DECREF(newglobal);
}
+ else {
+ /* Special-case __class__ */
+ if (!GET_IDENTIFIER(__class__))
+ goto error;
+ assert(PySet_Contains(local, __class__) == 1);
+ if (PySet_Add(newbound, __class__) < 0)
+ goto error;
+ }
/* Recursively call analyze_block() on each child block */
for (i = 0; i < PyList_GET_SIZE(ste->ste_children); ++i) {
@@ -709,8 +722,12 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
ste->ste_child_free = 1;
}
- /* Check if any local variables need to be converted to cell variables */
- if (ste->ste_type == FunctionBlock && !analyze_cells(scopes, newfree))
+ /* Check if any local variables must be converted to cell variables */
+ if (ste->ste_type == FunctionBlock && !analyze_cells(scopes, newfree,
+ NULL))
+ goto error;
+ else if (ste->ste_type == ClassBlock && !analyze_cells(scopes, newfree,
+ "__class__"))
goto error;
/* Records the results of the analysis in the symbol table entry */
if (!update_symbols(ste->ste_symbols, scopes, bound, newfree,
@@ -1027,6 +1044,11 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
if (!symtable_enter_block(st, s->v.ClassDef.name, ClassBlock,
(void *)s, s->lineno))
return 0;
+ if (!GET_IDENTIFIER(__class__) ||
+ !symtable_add_def(st, __class__, DEF_LOCAL)) {
+ symtable_exit_block(st, s);
+ return 0;
+ }
tmp = st->st_private;
st->st_private = s->v.ClassDef.name;
VISIT_SEQ_IN_BLOCK(st, stmt, s->v.ClassDef.body, s);
@@ -1294,6 +1316,14 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
if (!symtable_add_def(st, e->v.Name.id,
e->v.Name.ctx == Load ? USE : DEF_LOCAL))
return 0;
+ /* Special-case super: it counts as a use of __class__ */
+ if (e->v.Name.ctx == Load &&
+ st->st_cur->ste_type == FunctionBlock &&
+ !PyUnicode_CompareWithASCIIString(e->v.Name.id, "super")) {
+ if (!GET_IDENTIFIER(__class__) ||
+ !symtable_add_def(st, __class__, USE))
+ return 0;
+ }
break;
/* child nodes of List and Tuple will have expr_context set */
case List_kind: