BUG: DECREF(func) missing in classobject.instance_coerce + PATCH :-)

scharf@EMBL-Heidelberg.DE
Mon, 26 Sep 1994 21:22:49 +0100

Problem:

If an object overwrites __coerce__ and it is called from some binary operation
the object will never be deleted ==> a DECREF is missing somwhere.....

#############################################################################
## here an example that shows the problem
_x=0
class X:
def __init__(self,name=None):
if name is None:
global _x
_x=_x+1
name=`_x`
self.name=name
print "X(%s)" % self.name
def __del__(self):
print "del X(%s)" %self.name
def __or__(self,other):
return X(self.name + " | " + other.name)
def __coerce__(self,other):
return (self,other)

x=X()|X()
del x
#############################################################################

##Prints: (the first object 1 is never deleted! (expected "del X(1)"))
X(1)
X(2)
X(1 | 2)
del X(2)
del X(1 | 2)

#############################################################################

Solution:

... make OPT=-g ... gdb python ... step, stepe di step ... AHA!!!! ... the
looser is ... the function instance_coerce(pv, pw) in Objects/classobject.c ...

Michael
__________________________________________________________
**** ___ _ _ ___ _
****** | __) | \/ | | ) | | Michael Scharf
******** | _) | | | -< | |_ Tel: +49 6221 387 305 Fax: 517
* **** |___) |_||_| |___) |___) EMail: scharf@EMBL-Heidelberg.de
**** __________________________________________________________

... and here is the (very small :-) patch ...

#############################################################################

--- Objects/classobject.c.~1~ Thu Aug 25 21:42:06 1994
+++ Objects/classobject.c Mon Sep 26 20:50:18 1994
@@ -1073,6 +1073,7 @@
return 1;
}
res = call_object(func, w);
+ DECREF(func);
if (res == NULL)
return -1;
if (res == None) {