[pypy-svn] r74018 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test

afa at codespeak.net afa at codespeak.net
Fri Apr 23 14:55:39 CEST 2010


Author: afa
Date: Fri Apr 23 14:55:38 2010
New Revision: 74018

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/sysmodule.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sysmodule.py
Log:
PySys_SetObject


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	Fri Apr 23 14:55:38 2010
@@ -1,14 +1,24 @@
 from pypy.interpreter.error import OperationError
 from pypy.rpython.lltypesystem import rffi, lltype
-from pypy.module.cpyext.api import CANNOT_FAIL, cpython_api
+from pypy.module.cpyext.api import CANNOT_FAIL, cpython_api, CONST_STRING
 from pypy.module.cpyext.pyobject import PyObject, register_container
 
- at cpython_api([rffi.CCHARP], PyObject, borrowed=True, error=CANNOT_FAIL)
+ at cpython_api([CONST_STRING], 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)
+    name = rffi.charp2str(name)
     w_dict = space.sys.getdict()
-    w_obj = space.finditem_str(w_dict, w_name)
+    w_obj = space.finditem_str(w_dict, name)
     register_container(space, w_dict)
     return w_obj
+
+ at cpython_api([CONST_STRING, PyObject], rffi.INT_real, error=-1)
+def PySys_SetObject(space, name, w_obj):
+    """Set name in the sys module to v unless v is NULL, in which
+    case name is deleted from the sys module. Returns 0 on success, -1
+    on error."""
+    name = rffi.charp2str(name)
+    w_dict = space.sys.getdict()
+    space.setitem_str(w_dict, name, w_obj)
+    return 0

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	Fri Apr 23 14:55:38 2010
@@ -1,4 +1,5 @@
 from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
+from pypy.module.cpyext.test.test_api import BaseApiTest
 from pypy.rpython.lltypesystem import rffi
 
 class AppTestSysModule(AppTestCpythonExtensionBase):
@@ -13,3 +14,9 @@
         assert module.get("excepthook")
         assert not module.get("spam_spam_spam")
 
+class TestSysModule(BaseApiTest):
+    def test_sysmodule(self, space, api):
+        buf = rffi.str2charp("last_tb")
+        api.PySys_SetObject(buf, space.wrap(1))
+        rffi.free_charp(buf)
+        assert space.unwrap(space.sys.get("last_tb")) == 1



More information about the Pypy-commit mailing list