Author: Richard Plangger <[email protected]>
Branch: cpyext-injection
Changeset: r87877:7634141bc595
Date: 2016-10-19 16:23 +0200
http://bitbucket.org/pypy/pypy/changeset/7634141bc595/
Log: (arigato, plan_rich) add a new test to return a pypy object
diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py
--- a/pypy/module/cpyext/pyobject.py
+++ b/pypy/module/cpyext/pyobject.py
@@ -340,3 +340,12 @@
@cpython_api([rffi.VOIDP], lltype.Signed, error=CANNOT_FAIL)
def _Py_HashPointer(space, ptr):
return rffi.cast(lltype.Signed, ptr)
+
+def _has_a_pyobj(space, w_obj):
+ """ NOT_RPYTHON only for tests """
+ assert w_obj is not None
+ assert not is_pyobj(w_obj)
+ py_obj = rawrefcount.from_obj(PyObject, w_obj)
+ if not py_obj:
+ return False
+ return True
diff --git a/pypy/module/cpyext/test/test_injection.py
b/pypy/module/cpyext/test/test_injection.py
--- a/pypy/module/cpyext/test/test_injection.py
+++ b/pypy/module/cpyext/test/test_injection.py
@@ -1,8 +1,17 @@
from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
-
+from pypy.module.cpyext.pyobject import _has_a_pyobj
+from pypy.interpreter.gateway import interp2app
class AppTestTypeObject(AppTestCpythonExtensionBase):
+ def setup_class(cls):
+ def is_there_an_pyobj_version(space, w_obj):
+ if _has_a_pyobj(space, w_obj):
+ return space.w_True
+ return space.w_False
+ cls.w_is_there_an_pyobj_version = cls.space.wrap(
+ interp2app(is_there_an_pyobj_version))
+
def test_getitem_basic(self):
module = self.import_module(name='injection')
mything = module.test_mytype()
@@ -15,3 +24,13 @@
assert mything is Ellipsis
mything = module.make(15)
assert mything[-100] == -100+15
+
+ def test_pypy_only_version_of_object(self):
+ module = self.import_module(name='injection')
+ mything = module.make(25)
+ assert not self.is_there_an_pyobj_version(mything)
+ assert mything[100] == 25*100
+ assert not self.is_there_an_pyobj_version(mything)
+ assert mything[-100] == -100+25
+ assert self.is_there_an_pyobj_version(mything)
+
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit