[pypy-svn] r73511 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
trundle at codespeak.net
trundle at codespeak.net
Wed Apr 7 18:25:17 CEST 2010
Author: trundle
Date: Wed Apr 7 18:25:15 2010
New Revision: 73511
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/sysmodule.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sysmodule.py
Log:
Fix borrowed reference handling in PySys_GetObject and write the tests in C.
The tests fail though because the test runner can't really handle that the
borrowed references still live on shutdown.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/sysmodule.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/sysmodule.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/sysmodule.py Wed Apr 7 18:25:15 2010
@@ -1,17 +1,14 @@
from pypy.interpreter.error import OperationError
-from pypy.rpython.lltypesystem import rffi
+from pypy.rpython.lltypesystem import rffi, lltype
from pypy.module.cpyext.api import CANNOT_FAIL, cpython_api
-from pypy.module.cpyext.pyobject import PyObject
+from pypy.module.cpyext.pyobject import PyObject, register_container
@cpython_api([rffi.CCHARP], PyObject, borrowed=True, error=CANNOT_FAIL)
def PySys_GetObject(space, name):
"""Return the object name from the sys module or NULL if it does
not exist, without setting an exception."""
w_name = rffi.charp2str(name)
- try:
- w_obj = space.sys.get(w_name)
- except OperationError, e:
- if not e.match(space, space.w_AttributeError):
- raise
- w_obj = None
+ w_dict = space.sys.getdict()
+ w_obj = space.finditem_str(w_dict, w_name)
+ register_container(space, w_dict)
return w_obj
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sysmodule.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sysmodule.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sysmodule.py Wed Apr 7 18:25:15 2010
@@ -1,14 +1,15 @@
-from pypy.module.cpyext.test.test_api import BaseApiTest
+from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
from pypy.rpython.lltypesystem import rffi
-class TestSysModule(BaseApiTest):
- def test_sysmodule(self, space, api):
- version_info = rffi.str2charp("version_info")
- assert api.PySys_GetObject(version_info)
- assert not api.PyErr_Occurred()
- rffi.free_charp(version_info)
+class AppTestSysModule(AppTestCpythonExtensionBase):
+ def test_sysmodule(self):
+ module = self.import_extension('foo', [
+ ("get", "METH_VARARGS",
+ """
+ char *name = PyString_AsString(PyTuple_GetItem(args, 0));
+ PyObject *retval = PySys_GetObject(name);
+ return PyBool_FromLong(retval != NULL);
+ """)])
+ assert module.get("excepthook")
+ assert not module.get("spam_spam_spam")
- i_do_not_exist = rffi.str2charp("i_do_not_exist")
- assert not api.PySys_GetObject(i_do_not_exist)
- assert not api.PyErr_Occurred()
- rffi.free_charp(i_do_not_exist)
More information about the Pypy-commit
mailing list