This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: `in` for classic object causes segfault
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: loewis Nosy List: georg.brandl, loewis, nnorwitz, ocean-city
Priority: high Keywords: patch

Created on 2006-11-07 13:32 by ocean-city, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
a.patch ocean-city, 2006-11-07 13:32
in.diff nnorwitz, 2006-11-08 06:28 similar fix with test case
Messages (6)
msg51337 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2006-11-07 13:32
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.
msg51338 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-11-07 15:39
Logged In: YES 
user_id=849994

Attaching to Martin since the mentioned revision is his.
msg51339 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-11-08 06:28
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.
msg51340 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-11-08 06:47
Logged In: YES 
user_id=21627

I agree with Neal's patch, committed as r52662 and r52663.
msg51341 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2006-11-08 07:06
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 */
msg51342 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-11-08 07:43
Logged In: YES 
user_id=21627

It's not strictly necessary, IMO: PY_ITERSEARCH_CONTAINS is
guaranteed to return -1, 0, 1, just as PySequence_Contains
should. So the safe downcast is correct.

IOW, your patch would have been correct, as well. I liked
Neal's patch more, because it combines the error cases into
a single return, and because it had a test case.
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44205
2006-11-07 13:32:28ocean-citycreate