Commit Graph

150 Commits

Author SHA1 Message Date
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
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
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
Guido van Rossum
e5ea439bc8 - A type can now inherit its metatype from its base type. Previously,
when PyType_Ready() was called, if ob_type was found to be NULL, it
  was always set to &PyType_Type; now it is set to base->ob_type,
  where base is tp_base, defaulting to &PyObject_Type.
2002-04-08 01:39:56 +00:00
Guido van Rossum
7e45ccb470 Backport half a patch from the trunk. This inherits tp_is_gc from a
base class.
2002-04-05 22:32:23 +00:00
Michael W. Hudson
03b54e9f37 backport gvanrossum's checkin of
revision 2.133 of typeobject.c

SF patch 537536 by Phillip J. Eby, fix for SF bug 535444, super()
broken w/ classmethods.

Bugfix candidate.
2002-04-05 15:39:31 +00:00
Tim Peters
4d761f2443 SF patch 530070: pydoc regression, from Martin and Guido.
Change the way __doc__ is handled, to avoid blowing up on non-string
__doc__ values.
2002-03-17 18:57:07 +00:00
Michael W. Hudson
18d81afd23 backport gvanrossum's checkin of
revision 2.129 of typeobject.c

"Fix" for SF bug #520644: __slots__ are not pickled.

As promised in my response to the bug report, I'm not really fixing
it; in fact, one could argule over what the proper fix should do.
Instead, I'm adding a little magic that raises TypeError if you try to
pickle an instance of a class that has __slots__ but doesn't define or
override __getstate__.  This is done by adding a bozo __getstate__
that always raises TypeError.
2002-03-16 17:56:51 +00:00
Michael W. Hudson
095fbeb55b backport gvanrossum's checkin of
revision 2.128 of typeobject.c

Bugfix candidate.
Adapter from SF patch 528038; fixes SF bug 527816.

The wrapper for __nonzero__ should be wrap_inquiry rather than
wrap_unaryfunc, since the slot returns an int, not a PyObject *.
2002-03-11 10:19:48 +00:00
Michael W. Hudson
62f0734077 backport loewis' checkin of
revision 2.127 of typeobject.c

Allow __doc__ to be of arbitrary type. Patch by James Henstridge,
fixes #504343. 2.2.1 candidate.
2002-02-22 13:31:18 +00:00
Guido van Rossum
f884b74910 - PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
NULL, so that you can call PyType_Ready() to initialize a type that
  is to be separately compiled with C on Windows.

inherit_special():  Add a long comment explaining that you have to set
tp_new if your base class is PyBaseObject_Type.
2001-12-17 17:14:22 +00:00
Guido van Rossum
e54616cb6f (Merge into trunk.)
Fix for SF bug #492345.  (I could've sworn I checked this in, but
apparently I didn't!)

This code:

    class Classic:
        pass

    class New(Classic):
        __metaclass__ = type

attempts to create a new-style class with only classic bases -- but it
doesn't work right.  Attempts to fix it so it works caused problems
elsewhere, so I'm now raising a TypeError in this case.
2001-12-14 04:19:56 +00:00