Commit Graph

1405 Commits

Author SHA1 Message Date
Guido van Rossum
8418a99f37 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.
2002-06-10 16:02:44 +00:00
Guido van Rossum
c48d00d674 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.
2002-06-10 14:34:01 +00:00
Guido van Rossum
761037af5c Backport to 2.2.x:
Address SF bug 519621: slots weren't traversed by GC.

While I was at it, I added a tp_clear handler and changed the
tp_dealloc handler to use the clear_slots helper for the tp_clear
handler.

Also set mp->flags = READONLY for the __weakref__ pseudo-slot.

[Note that I am *not* backporting the part of that patch that
tightened the __slot__ rules.]
2002-06-04 21:19:55 +00:00
Guido van Rossum
5991f6522a Backport to 2.2.x:
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.
2002-06-03 19:54:10 +00:00
Guido van Rossum
6d36fd8401 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.
2002-05-24 21:41:26 +00:00
Neal Norwitz
81a09965d7 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)
2002-05-23 13:02:37 +00:00
Guido van Rossum
b4a27b9e61 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.
2002-05-13 18:30:40 +00:00
Walter Dörwald
332a458dd1 Backport checkin:
Add #ifdef PY_USING_UNICODE sections, so that
stringobject.c compiles again with --disable-unicode.

Fixes SF bug http://www.python.org/sf/554912
2002-05-13 09:11:44 +00:00
Raymond Hettinger
db581dfb02 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.
2002-05-12 17:20:38 +00:00
Fred Drake
abbad25d2c 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.
2002-05-02 16:05:40 +00:00
Anthony Baxter
3864a45cd3 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
2002-04-30 03:41:53 +00:00
Anthony Baxter
ebe9421770 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
2002-04-26 06:31:22 +00:00
Walter Dörwald
aa82bc0817 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.
2002-04-22 18:42:45 +00:00
Walter Dörwald
1c097b7102 Backport the following changes:
Misc/NEWS 1.387->1.388
Lib/test/string_tests.py 1.10->1.11, 1.12->1.14,
Lib/test/test_unicode.py 1.50->1.51, 1.53->1.54, 1.55->1.56
Lib/test/test_string.py 1.15->1.16
Lib/string.py 1.61->1.63
Lib/test/test_userstring.py 1.5->1.6, 1.11, 1.12
Objects/stringobject.c 2.156->2.159
Objects/unicodeobject.c 2.137->2.139
Doc/lib/libstdtypes.tec 1.87->1.88

Add a method zfill to str, unicode and UserString
and change Lib/string.py accordingly
(see SF patch http://www.python.org/sf/536241)

This also adds Guido's fix to test_userstring.py
and the subinstance checks in test_string.py
and test_unicode.py.
2002-04-22 11:57:06 +00:00
Jeremy Hylton
8ba1671e39 backport fix for SF buf #505315 from trunk 2002-04-20 05:07:05 +00:00
Anthony Baxter
ea89d8f235 backport gvanrossum's patch:
Deprecate % as well.  The message for deprecation of //, % and divmod
is the same in all three cases (mostly because // calls divmod :-).

Original patches were:
python/dist/src/Objects/complexobject.c:2.59
2002-04-18 05:39:54 +00:00
Anthony Baxter
c82143eb5e 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
2002-04-18 05:37:51 +00:00
Anthony Baxter
0bc13db82f backport gvanrossum's patch:
Partially implement SF feature request 444708.

Add optional arg to string methods strip(), lstrip(), rstrip().
The optional arg specifies characters to delete.

Also for UserString.

Still to do:

- Misc/NEWS
- LaTeX docs (I did the docstrings though)
- Unicode methods, and Unicode support in the string methods.




Original patches were:
python/dist/src/Objects/stringobject.c:2.156
2002-04-18 05:16:37 +00:00
Anthony Baxter
4cedb9fbb4 backport gvanrossum's patch:
SF bug #541883 (Vincent Fiack).

A stupid bug in object_set_class(): didn't check for value==NULL
before checking its type.

Bugfix candidate.


Original patches were:
python/dist/src/Objects/typeobject.c:2.142
2002-04-18 05:11:50 +00:00
Guido van Rossum
b412734cb0 Darn. Of course the warning that Tim killed on the trunk must also be
killed in the branch.
2002-04-18 04:47:10 +00:00
Anthony Baxter
f762677b69 backport gvanrossum's patch:
SF bug 544647.

PyNumber_InPlaceMultiply insisted on calling sq_inplace_repeat if it
existed, even if nb_inplace_multiply also existed and the arguments
weren't right for sq_inplace_repeat.  Change this to only use
sq_inplace_repeat if nb_inplace_multiply isn't defined.

Bugfix candidate.
2002-04-18 04:40:05 +00:00
Anthony Baxter
a2e92fcbf2 backport tim_one's patch:
SF bug 543840: complex(string) accepts strings with \0
complex_subtype_from_string():  this stopped parsing at the first 0
byte, as if that were the end of the input string.
2002-04-18 02:19:46 +00:00
Guido van Rossum
95c168cf68 Backport rev 2.143 (note: some earlier bugfix candidates still TBD).
SF bug 542984.

Change type_get_doc (the get function for __doc__) to look in tp_dict
more often, and if it finds a descriptor in tp_dict, to call it (with
a NULL instance).  This means you can add a __doc__ descriptor to a
new-style class that returns instance docs when called on an instance,
and class docs when called on a class -- or the same docs in either
case, but lazily computed.

I'll also check this into the 2.2 maintenance branch.
2002-04-18 00:36:17 +00:00
Tim Peters
19b08d3b3b SF bug 543148: Memory leak with stackframes + inspect.
Put a bound on the number of frameobjects that can live in the
frameobject free_list.

Also fixed on the trunk.  I don't intend to backport to 2.1 (too
much work -- lots of cyclic structures leak there).
2002-04-13 05:25:28 +00:00
Tim Peters
c4d332d7a5 SF bug 538827: Python open w/ MSVC6: bad error msgs.
open_the_file:  Some (not all) flavors of Windows set errno to EINVAL
when passed a syntactically invalid filename.  Python turned that into an
incomprehensible complaint about the mode string.  Fixed by special-casing
MSVC.
2002-04-08 04:19:50 +00:00