Guido van Rossum [Thu, 13 Jun 2002 21:36:35 +0000 (21:36 +0000)]
Backport:
Fix for SF bug 532646. This is a little simpler than what Neal
suggested there, based upon a better analysis (__getattr__ is a red
herring).
[This might be a 2.1 bugfix candidate we well, if people care]
Guido van Rossum [Wed, 12 Jun 2002 03:48:46 +0000 (03:48 +0000)]
Backport:
SF bug 567538: Generator can crash the interpreter (Finn Bock).
This was a simple typo. Strange that the compiler didn't catch it!
Instead of WHY_CONTINUE, two tests used CONTINUE_LOOP, which isn't a
why_code at all, but an opcode; but even though 'why' is declared as
an enum, comparing it to an int is apparently not even worth a
warning -- not in gcc, and not in VC++. :-(
Fred Drake [Tue, 11 Jun 2002 02:57:32 +0000 (02:57 +0000)]
Completely revise markup for the list of list methods; the new markup matches
the semantics and presentation used in the library reference.
Added an explanation of the use of [...] to denote optional arguments, since
this is the only use of this in a signature line.
Closes SF bug #567127.
Guido van Rossum [Mon, 10 Jun 2002 21:37:00 +0000 (21:37 +0000)]
Backport:
SF patch 560794 (Greg Chapman): deepcopy can't handle custom
metaclasses.
This is essentially the same problem as that reported in bug 494904
for pickle: deepcopy should treat instances of custom metaclasses the
same way it treats instances of type 'type'.
Guido van Rossum [Mon, 10 Jun 2002 16:02:44 +0000 (16:02 +0000)]
Backport two patches that belong together:
(2.150)
In the recent python-dev thread "Bizarre new test failure", we
discovered that subtype_traverse must traverse the type if it is a
heap type, because otherwise some cycles involving a type and its
instance would not be collected. Simplest example:
while 1:
class C(object): pass
C.ref = C()
This program grows without bounds before this fix. (It grows ever
slower since it spends ever more time in the collector.)
Simply adding the right visit() call to subtype_traverse() revealed
other problems. With MvL's help we re-learned that type_clear()
doesn't have to clear *all* references, only the ones that may not be
cleared by other means. Careful analysis (see comments in the code)
revealed that only tp_mro needs to be cleared. (The previous checkin
to this file adds a test for tp_mro==NULL to _PyType_Lookup() that's
essential to prevent crashes due to tp_mro being NULL when
subtype_dealloc() tries to look for a __del__ method.) The same kind
of analysis also revealed that subtype_clear() doesn't need to clear
the instance dict.
With this fix, a useful property of the collector is once again
guaranteed: a single gc.collect() call will clear out all garbage.
(It didn't always before, which put us on the track of this bug.)
(2.151)
Undo the last chunk of the previous patch, putting back a useful
assert into PyType_Ready(): now that we're not clearing tp_dict, we
can assert that it's non-NULL again.
Guido van Rossum [Mon, 10 Jun 2002 14:34:01 +0000 (14:34 +0000)]
Backport:
Three's a charm: yet another fix for SF bug 551412. Thinking again
about the test case, slot_nb_power gets called on behalf of its second
argument, but with a non-None modulus it wouldn't check this, and
believes it is called on behalf of its first argument. Fix this
properly, and get rid of the code in _PyType_Lookup() that tries to
call _PyType_Ready(). But do leave a check for a NULL tp_mro there,
because this can still legitimately occur.
Fred Drake [Tue, 4 Jun 2002 16:29:24 +0000 (16:29 +0000)]
Backport Guido's changes from revision 1.89:
Addressed SF bug 421973 (finally).
Rewrote the subsection on coercion rules (and made it a proper
subsection, with a label). The new section is much less precise,
because precise rules would be too hard to give (== I don't know what
they are any more :-). OTOH, the new section gives much more
up-to-date information.
Also noted that __coerce__ may return NotImplemented, with the same
meaning as None.
FLD: My modifications to Guido's markup are included from revision 1.90.
Address the residual issue with the fix for SF 551412 in
_PyType_Lookup(). Decided to clear the error condition in the
unfortunate but unlikely case that PyType_Ready() fails.
Neal Norwitz [Sat, 1 Jun 2002 18:26:22 +0000 (18:26 +0000)]
Fix SF #561858 Assertion with very long lists
if co_stacksize was > 32767 (the maximum value
which can be stored in 16 bits (signed)),
the PyCodeObject would be written wrong.
So on the second import (reading the .pyc)
would cause a crash.
Since we can't change the PYC magic, we
go on (silently), but don't write the file.
This means everything will work, but
a .pyc will not be written and the file will need
to be parsed on each import.
Guido van Rossum [Fri, 31 May 2002 21:17:53 +0000 (21:17 +0000)]
Backport to 2.2.x:
SF bug 533625 (Armin Rigo). rexec: potential security hole
If a rexec instance allows writing in the current directory (a common
thing to do), there's a way to execute bogus bytecode. Fix this by
not allowing imports from .pyc files (in a way that allows a site to
configure things so that .pyc files *are* allowed, if writing is not
allowed).
Neil Schemenauer [Wed, 29 May 2002 18:44:30 +0000 (18:44 +0000)]
The logreader object did not always refill the input buffer correctly
and got confused by certain log files. Remove logreader_refill and the
associated logic and replace with fgetc.
Neal Norwitz [Wed, 29 May 2002 01:17:47 +0000 (01:17 +0000)]
Backport fix by tismer for #210682
fixed an old buglet that caused bdb to be unable to
continue in the botframe, after a breakpoint was set.
the key idea is not to set botframe to the bottom level frame,
but its f_back, which actually might be None.
Additional changes: migrated old exception trick to use
sys._getframe(), which exists both in 2.1 and 2.2 .
Note: I believe Mark Hammond needs to look over his code now.
F5 correctly starts up in the debugger, but later on doesn't stop at a given
breakpoint any longer.
Guido van Rossum [Fri, 24 May 2002 21:41:26 +0000 (21:41 +0000)]
Fix for SF bug 551412. When _PyType_Lookup() is called on a type
whose tp_mro hasn't been initialized, it would dump core. Fix this by
checking for NULL and calling PyType_Ready(). Backport from 2.3.
Neal Norwitz [Thu, 23 May 2002 13:02:37 +0000 (13:02 +0000)]
Closes: #556025 seg fault when doing list(xrange(1e9))
A MemoryError is now raised when the list cannot be created.
There is a test, but as the comment says, it really only
works for 32 bit systems. I don't know how to improve
the test for other systems (ie, 64 bit or systems
where the data size != addressable size,
e.g. 64 bit data, but 48 bit addressable memory)
Fred Drake [Tue, 21 May 2002 03:50:49 +0000 (03:50 +0000)]
Munge the RCS keywords to avoid updates, so the version number matches that
of the PyUNIT version of the same file. This helps people understand that
this version is the same as the version from the independent PyUNIT
release (confusion was indicated on the PyUNIT mailing list).
Guido van Rossum [Mon, 13 May 2002 18:30:40 +0000 (18:30 +0000)]
Backport from 2.3:
Jim Fulton reported a segfault in dir(). A heavily proxied object
returned a proxy for __class__ whose __bases__ was also a proxy. The
merge_class_dict() helper for dir() assumed incorrectly that __bases__
would always be a tuple and used the in-line tuple API on the proxy.
Close SF bug 551673. Backport Skip Montanaro's checkin of 2.112.
Clarifies message when raising TypeError to indicate that float() accepts
strings or numbers.
Fred Drake [Fri, 3 May 2002 04:54:20 +0000 (04:54 +0000)]
Integrated SF patch #539487 by Matthias Klose:
This patch adds Milan Zamazal's conversion script and
modifies the mkinfo script to build the info doc files
from the LaTeX sources. Currently, the mac, doc and
inst TeX files are not handled.
Explicitly checks for GNU Emacs 21.
Fred Drake [Thu, 2 May 2002 18:13:48 +0000 (18:13 +0000)]
Add a regression test that was removed prematurely. This tests deprecated
(but not removed!) features of the xrange object. This test should be
maintained for all of 2.2.x to avoid regression failures.
Fred Drake [Thu, 2 May 2002 16:05:40 +0000 (16:05 +0000)]
Fix attribute access for the xrange objects. The tp_getattr and tp_getattro
handlers were both set, but were not compatible. This change uses only the
tp_getattro handler with a more "modern" approach.
This fixes SF bug #551285.
Anthony Baxter [Tue, 30 Apr 2002 04:05:33 +0000 (04:05 +0000)]
backport tim_one's patch:
Repair widespread misuse of _PyString_Resize. Since it's clear people
don't understand how this function works, also beefed up the docs. The
most common usage error is of this form (often spread out across gotos):
if (_PyString_Resize(&s, n) < 0) {
Py_DECREF(s);
s = NULL;
goto outtahere;
}
The error is that if _PyString_Resize runs out of memory, it automatically
decrefs the input string object s (which also deallocates it, since its
refcount must be 1 upon entry), and sets s to NULL. So if the "if"
branch ever triggers, it's an error to call Py_DECREF(s): s is already
NULL! A correct way to write the above is the simpler (and intended)
if (_PyString_Resize(&s, n) < 0)
goto outtahere;
Bugfix candidate.
Original patch(es):
python/dist/src/Python/bltinmodule.c:2.253
Anthony Baxter [Tue, 30 Apr 2002 03:41:53 +0000 (03:41 +0000)]
backport tim_one's patch:
Repair widespread misuse of _PyString_Resize. Since it's clear people
don't understand how this function works, also beefed up the docs. The
most common usage error is of this form (often spread out across gotos):
if (_PyString_Resize(&s, n) < 0) {
Py_DECREF(s);
s = NULL;
goto outtahere;
}
The error is that if _PyString_Resize runs out of memory, it automatically
decrefs the input string object s (which also deallocates it, since its
refcount must be 1 upon entry), and sets s to NULL. So if the "if"
branch ever triggers, it's an error to call Py_DECREF(s): s is already
NULL! A correct way to write the above is the simpler (and intended)
if (_PyString_Resize(&s, n) < 0)
goto outtahere;
Bugfix candidate.
Original patch(es):
python/dist/src/Objects/fileobject.c:2.161
python/dist/src/Objects/stringobject.c:2.161
python/dist/src/Objects/unicodeobject.c:2.147
Anthony Baxter [Tue, 30 Apr 2002 03:24:12 +0000 (03:24 +0000)]
backport tim_one's patch:
Repair widespread misuse of _PyString_Resize. Since it's clear people
don't understand how this function works, also beefed up the docs. The
most common usage error is of this form (often spread out across gotos):
if (_PyString_Resize(&s, n) < 0) {
Py_DECREF(s);
s = NULL;
goto outtahere;
}
The error is that if _PyString_Resize runs out of memory, it automatically
decrefs the input string object s (which also deallocates it, since its
refcount must be 1 upon entry), and sets s to NULL. So if the "if"
branch ever triggers, it's an error to call Py_DECREF(s): s is already
NULL! A correct way to write the above is the simpler (and intended)
if (_PyString_Resize(&s, n) < 0)
goto outtahere;
Bugfix candidate.
Original patch(es):
python/dist/src/Doc/api/concrete.tex:1.13
Fred Drake [Tue, 30 Apr 2002 02:21:32 +0000 (02:21 +0000)]
Added a missing "|" in the grammar productions used in the reference manual
(reported by François Pinard).
Added some missing "_" characters in the same cluster of productions.
Added missing floor division operator in m_expr production, and mention
floor division in the relevant portion of the text.
Anthony Baxter [Fri, 26 Apr 2002 06:31:22 +0000 (06:31 +0000)]
backport gvanrossum's patch:
Make sure that tp_free frees the int the same way as tp_dealloc would.
This fixes the problem that Barry reported on python-dev:
>>> 23000 .__class__ = bool
crashes in the deallocator. This was because int inherited tp_free
from object, which uses the default allocator.
2.2. Bugfix candidate.
(trivial change in backport: "freefunc" -> "destructor")
Original patch(es):
python/dist/src/Objects/intobject.c:2.82
Anthony Baxter [Tue, 23 Apr 2002 04:02:55 +0000 (04:02 +0000)]
backport some warnings filters to shut up complaints about complex
divmod &c. Should probably be cleaned up properly so that the tests
don't call that.
Walter Dörwald [Mon, 22 Apr 2002 18:42:45 +0000 (18:42 +0000)]
Backport checkin:
Apply patch diff.txt from SF feature request
http://www.python.org/sf/444708
This adds the optional argument for str.strip
to unicode.strip too and makes it possible
to call str.strip with a unicode argument
and unicode.strip with a str argument.
Fred Drake [Fri, 19 Apr 2002 04:06:06 +0000 (04:06 +0000)]
Clean up the use of version numbers in filenames; always use an "abstract"
version number, and explain what it is at the top of the chapter.
This closes SF bug #225003.
Anthony Baxter [Thu, 18 Apr 2002 05:37:51 +0000 (05:37 +0000)]
backport gvanrossum's patch:
SF bug #543387.
Complex numbers implement divmod() and //, neither of which makes one
lick of sense. Unfortunately this is documented, so I'm adding a
deprecation warning now, so we can delete this silliness, oh, around
2005 or so.
Bugfix candidate (At least for 2.2.2, I think.)
Original patches were:
python/dist/src/Objects/complexobject.c:2.58