[Patches] [ python-Patches-1591996 ] `in` for classic object causes segfault

SourceForge.net noreply at sourceforge.net
Wed Nov 8 08:06:27 CET 2006


Patches item #1591996, was opened at 2006-11-07 22:32
Message generated for change (Comment added) made by ocean-city
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1591996&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core (C code)
Group: Python 2.5
Status: Closed
Resolution: Fixed
Priority: 6
Private: No
Submitted By: Hirokazu Yamamoto (ocean-city)
Assigned to: Martin v. Löwis (loewis)
Summary: `in` for classic object causes segfault

Initial Comment:
This code causes segfault.

class Foo: pass
foo = Foo()
1 in foo

E:\python-dev>py a.py
Exception exceptions.TypeError: "argument of type
'instance' is not iterable" in
 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage
collection

This bug seems to be introduced by revision 45644
change for Objects/classobject.c
# -1 (error) is converted to 0 (False)

I think this can be fixed by attached patch. Thank you.

----------------------------------------------------------------------

>Comment By: Hirokazu Yamamoto (ocean-city)
Date: 2006-11-08 16:06

Message:
Logged In: YES 
user_id=1200846

Sorry for posting to closed entry, but this is related...

Maybe similar patch is apropriate for PySequence_Contains in
Objects/abstract.c like this? Thank you.

Index: Objects/abstract.c
===================================================================
--- Objects/abstract.c	(revision 52664)
+++ Objects/abstract.c	(working copy)
@@ -1719,7 +1719,9 @@
 			return (*sqm->sq_contains)(seq, ob);
 	}
 	result = _PySequence_IterSearch(seq, ob,
PY_ITERSEARCH_CONTAINS);
-	return Py_SAFE_DOWNCAST(result, Py_ssize_t, int);
+	if (result >= 0)
+	    return result > 0;
+	return -1;
 }
 
 /* Backwards compatibility */


----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2006-11-08 15:47

Message:
Logged In: YES 
user_id=21627

I agree with Neal's patch, committed as r52662 and r52663.

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2006-11-08 15:28

Message:
Logged In: YES 
user_id=33168

I fixed the problem slightly differently without casting,
but rather checking the result.  The patch also contains a
test case.

----------------------------------------------------------------------

Comment By: Georg Brandl (gbrandl)
Date: 2006-11-08 00:39

Message:
Logged In: YES 
user_id=849994

Attaching to Martin since the mentioned revision is his.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1591996&group_id=5470


More information about the Patches mailing list