Commit Graph

161 Commits

Author SHA1 Message Date
Guido van Rossum
4f017eb311 Backport the Carlo Verre fix. 2003-04-25 05:40:32 +00:00
Neal Norwitz
0dc63d404a Backport Tim's checkin 2.218:
slot_sq_contains():  This leaked a reference to the result of calling
    __contains__().
2003-03-23 14:36:50 +00:00
Neal Norwitz
e8c4f9457e backport:
revision 2.196
date: 2002/12/07 21:39:16;  author: tim_one;  state: Exp;  lines: +27 -28
slot_nb_nonzero():  Another leak uncovered by the sandbox datetime
tests.  I found the logic too confusing to follow here, so rewrote more
than was likely absolutely necessary.
2003-02-02 19:59:59 +00:00
Guido van Rossum
bec7972a2c Backport typeobject.c revision 2.201 plus associated tests from 2.3:
Add a refinement to SLOT1BINFULL() that fixes the problem reported in
SF bug #623669: only try (e.g.) __rdiv__ before __div__ if the right
class actually overrides it.
2003-01-07 21:47:44 +00:00
Neal Norwitz
89b8e84072 Fix SF #658106, Setting __class__ to NoneType
Backport Guido's checkin 2.171:

Disallow class assignment completely unless both old and new are heap
types.  This prevents nonsense like 2.__class__ = bool or
True.__class__ = int.
2002-12-24 14:48:41 +00:00
Tim Peters
5e016f4491 Backport from head.
slot_tp_hash():  In the normal path, this leaked a reference to the
integer hash object returned by __hash__().
2002-12-07 02:28:17 +00:00
Neal Norwitz
96a85300f6 Backport:
Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman

Don't crash when getting value of a property raises an exception
2002-10-18 16:45:39 +00:00
Guido van Rossum
38a22a961c Sigh. That wasn't a memory leak, that was Guido committing before
running tests.  Withdraw 2.183 and its backport.
2002-10-18 13:52:42 +00:00
Guido van Rossum
3cdc2c6de2 Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
2002-10-18 13:42:21 +00:00
Guido van Rossum
ebc6a65f93 New in 2.2.2!
In inherit_slots(), get rid of the COPYSLOT(tp_dictoffset).  Copying
the offset from a non-dominant base makes no sense: either the
non-dominant base has a nonzero tp_dictoffset, and then we should have
already copied it from the dominant base (at the very end of
inherit_special()), or the non-dominant base has no tp_dictoffset and
for some reason type_new() decided not to add one.  The tp_dictoffset
from a non-dominant base is likely to conflict with the instance
layout of the dominant base, so copying the tp_dictoffset from the
non-dominant base would be a really bad idea in that case.  This bug
can only be triggered by multiple inheritance from an extension class
that doesn't set tp_dictoffset and a new-style user-level class that
does have one.  There are no such extension classes in the
distribution, but there are 3rd party ones.  (Zope3 now has one,
that's how I found this. :-)

I've asked a few heavy users of new-style classes, extension classes
and metaclasses (David Abrahams and Kevin Jacobs), and neither of them
found any problems in their test suite after applying this fix, so I
assume it's safe.
2002-10-11 00:22:22 +00:00
Guido van Rossum
0df0b42f7c Backport, at the reqest of Kevin Jacobs:
- Changed new-style class instantiation so that when C's __new__
  method returns something that's not a C instance, its __init__ is
  not called.  [SF bug #537450]

XXX This is arguably a semantic change, but it's hard to imagine a
reason for wanting to depend on the old behavior.  If problems with
this are reported within a week of the release of 2.2.2 beta 1, we may
revert this change.
2002-10-07 18:08:27 +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
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
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
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
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
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