[pypy-svn] r73505 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
trundle at codespeak.net
trundle at codespeak.net
Wed Apr 7 14:17:08 CEST 2010
Author: trundle
Date: Wed Apr 7 14:17:07 2010
New Revision: 73505
Added:
pypy/branch/cpython-extension/pypy/module/cpyext/sysmodule.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sysmodule.py
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
Log:
Add PySys_GetObject.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py Wed Apr 7 14:17:07 2010
@@ -53,6 +53,7 @@
import pypy.module.cpyext.iterator
import pypy.module.cpyext.unicodeobject
import pypy.module.cpyext.pycobject
+import pypy.module.cpyext.sysmodule
# now that all rffi_platform.Struct types are registered, configure them
api.configure_types()
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py Wed Apr 7 14:17:07 2010
@@ -5409,12 +5409,6 @@
alias for void (*)(int)."""
raise NotImplementedError
- at cpython_api([rffi.CCHARP], PyObject, borrowed=True)
-def PySys_GetObject(space, name):
- """Return the object name from the sys module or NULL if it does
- not exist, without setting an exception."""
- raise NotImplementedError
-
@cpython_api([rffi.CCHARP, {FILE*}], {FILE*})
def PySys_GetFile(space, name, def):
"""Return the FILE* associated with the object name in the
Added: pypy/branch/cpython-extension/pypy/module/cpyext/sysmodule.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/sysmodule.py Wed Apr 7 14:17:07 2010
@@ -0,0 +1,17 @@
+from pypy.interpreter.error import OperationError
+from pypy.rpython.lltypesystem import rffi
+from pypy.module.cpyext.api import CANNOT_FAIL, cpython_api
+from pypy.module.cpyext.pyobject import PyObject
+
+ at 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
+ return w_obj
Added: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sysmodule.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sysmodule.py Wed Apr 7 14:17:07 2010
@@ -0,0 +1,14 @@
+from pypy.module.cpyext.test.test_api import BaseApiTest
+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)
+
+ 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