Commit Graph

1423 Commits

Author SHA1 Message Date
Guido van Rossum
96303ce055 Fix some endcase bugs in unicode rfind()/rindex() and endswith().
These were reported and fixed by Inyeol Lee in SF bug 595350.  The
endswith() bug is already fixed in 2.3; I'll fix the others in
2.3 next.
2002-08-20 16:57:58 +00:00
Guido van Rossum
6f53956a32 Backport:
PyType_Ready(): initialize the base class a bit earlier, so that if we
copy the metatype from the base, the base actually has one!
2002-08-14 17:36:26 +00:00
Guido van Rossum
e5c877f06e Backport:
Add an improvement wrinkle to Neil Schemenauer's change to int_mul
(rev. 2.79.6.3).  The other type is only disqualified from sq_repeat when
it has the CHECKTYPES flag.  This means that for extension types that
only support "old-style" numeric ops, such as Zope 2's ExtensionClass,
sq_repeat still trumps nb_multiply.
2002-08-13 10:07:17 +00:00
Neil Schemenauer
10c18d59e1 Only call sq_repeat if the object does not have a nb_multiply slot. One
example of where this changes behavior is when a new-style instance
defines '__mul__' and '__rmul__' and is multiplied by an int.  Before
the change the '__rmul__' method is never called, even if the int is the
left operand.
2002-08-09 15:46:50 +00:00
Neil Schemenauer
3d6247a3e3 Remove calls to 2.1 GC API (they are noops). 2002-08-05 14:46:29 +00:00
Raymond Hettinger
3bef3faa21 SF 582071 clarified the .split() method's docstring to note that sep=None
will trigger splitting on any whitespace.
2002-08-05 06:28:55 +00:00
Guido van Rossum
00fc1a4ed0 Backport:
Tim found that once test_longexp has run, test_sort takes very much
longer to run than normal.  A profiler run showed that this was due to
PyFrame_New() taking up an unreasonable amount of time.  A little
thinking showed that this was due to the while loop clearing the space
available for the stack.  The solution is to only clear the local
variables (and cells and free variables), not the space available for
the stack, since anything beyond the stack top is considered to be
garbage anyway.  Also, use memset() instead of a while loop counting
backwards.  This should be a time savings for normal code too!  (By a
probably unmeasurable amount. :-)
2002-08-01 19:05:07 +00:00
Guido van Rossum
f75ba0b6e5 Backport:
SF patch 588728 (Nathan Srebro).

The __delete__ method wrapper for descriptors was not supported

(I added a test, too.)
2002-08-01 19:03:43 +00:00
Neal Norwitz
5a35bb30e9 SF patch #587889, fix memory leak of tp_doc 2002-07-30 00:57:38 +00:00
Martin v. Löwis
59b5b4720b Patch #554716: Use __va_copy where available. 2002-07-28 10:21:31 +00:00
Jeremy Hylton
ea21ac9767 The object returned by tp_new() may not have a tp_init.
If the object is an ExtensionClass, for example, the slot is not even
defined.  So we must check that the type has the slot (implied by
HAVE_CLASS) before calling tp_init().
2002-07-16 19:42:21 +00:00
Tim Peters
8156b9019c Attempting to resurrect a dying instance of a new-style class in a
__del__ method died with

    Fatal Python error: GC object already in linked list

in both release and debug builds.  Fixed that.  Added a new test that
dies without the fix.
2002-07-11 07:06:44 +00:00
Tim Peters
b1fb9abf09 SF bug 578752: COUNT_ALLOCS vs heap types
Repair segfaults and infinite loops in COUNT_ALLOCS builds in the
presence of new-style (heap-allocated) classes/types.

Note:  test_gc fails in a COUNT_ALLOCS build now, because it expects
a new-style class to get garbage collected.
2002-07-08 22:30:52 +00:00
Raymond Hettinger
d605adfe2d Fix SF Bug 572567: Memory leak in object comparison 2002-06-24 13:25:41 +00:00
Guido van Rossum
36d0d69427 Backport:
Patch from SF bug 570483 (Tim Northover).

In a fresh interpreter, type.mro(tuple) would segfault, because
PyType_Ready() isn't called for tuple yet.  To fix, call
PyType_Ready(type) if type->tp_dict is NULL.
2002-06-18 16:46:57 +00:00
Guido van Rossum
63b1fcba9c Backport:
Inexplicably, recurse_down_subclasses() was comparing the object
gotten from a weak reference to NULL instead of to None.  This caused
the following assert() to fail (but only in 2.2 in the debug build --
I have to find a better test case).
2002-06-14 02:28:23 +00:00
Neal Norwitz
046b35cf44 SF # 533070 Silence AIX C Compiler Warnings
Warning caused by using &func.  & is not necessary.
2002-06-13 21:39:47 +00:00
Guido van Rossum
a9d29fed54 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]
2002-06-13 21:36:35 +00:00
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