[pypy-commit] pypy default: Fix for test_py_string_as_string_None, which passed apparently

arigo noreply at buildbot.pypy.org
Thu Mar 15 02:10:55 CET 2012

Author: Armin Rigo <arigo at tunes.org>
Changeset: r53633:3ccd266220ca
Date: 2012-03-14 18:10 -0700

Log:	Fix for test_py_string_as_string_None, which passed apparently only
	by chance on 32-bit.

diff --git a/pypy/module/cpyext/stringobject.py b/pypy/module/cpyext/stringobject.py
--- a/pypy/module/cpyext/stringobject.py
+++ b/pypy/module/cpyext/stringobject.py
@@ -130,6 +130,11 @@
 @cpython_api([PyObject], rffi.CCHARP, error=0)
 def PyString_AsString(space, ref):
+    if from_ref(space, rffi.cast(PyObject, ref.c_ob_type)) is space.w_str:
+        pass    # typecheck returned "ok" without forcing 'ref' at all
+    elif not PyString_Check(space, ref):   # otherwise, use the alternate way
+        raise OperationError(space.w_TypeError, space.wrap(
+            "PyString_AsString only support strings"))
     ref_str = rffi.cast(PyStringObject, ref)
     if not ref_str.c_buffer:
         # copy string buffer

More information about the pypy-commit mailing list