Commits

Amaury Forgeot d'Arc  committed b418623

(moguri) Implement PyRun_SimpleString in cpyext

  • Participants
  • Parent commits 955e244

Comments (0)

Files changed (3)

File pypy/module/cpyext/eval.py

     w_code = compiling.compile(space, w_source, filename, mode)
     return compiling.eval(space, w_code, w_globals, w_locals)
 
+@cpython_api([CONST_STRING], rffi.INT_real, error=-1)
+def PyRun_SimpleString(space, command):
+    """This is a simplified interface to PyRun_SimpleStringFlags() below,
+    leaving the PyCompilerFlags* argument set to NULL."""
+    command = rffi.charp2str(command)
+    run_string(space, command, "<string>", Py_file_input,
+               space.w_None, space.w_None)
+    return 0
+
 @cpython_api([CONST_STRING, rffi.INT_real,PyObject, PyObject], PyObject)
 def PyRun_String(space, source, start, w_globals, w_locals):
     """This is a simplified interface to PyRun_StringFlags() below, leaving

File pypy/module/cpyext/stubs.py

     "???" as the filename."""
     raise NotImplementedError
 
-@cpython_api([rffi.CCHARP], rffi.INT_real, error=-1)
-def PyRun_SimpleString(space, command):
-    """This is a simplified interface to PyRun_SimpleStringFlags() below,
-    leaving the PyCompilerFlags* argument set to NULL."""
-    raise NotImplementedError
-
 @cpython_api([rffi.CCHARP, PyCompilerFlags], rffi.INT_real, error=-1)
 def PyRun_SimpleStringFlags(space, command, flags):
     """Executes the Python source code from command in the __main__ module

File pypy/module/cpyext/test/test_eval.py

 
         assert space.int_w(w_res) == 10
 
+    def test_run_simple_string(self, space, api):
+        def run(code):
+            buf = rffi.str2charp(code)
+            try:
+                return api.PyRun_SimpleString(buf)
+            finally:
+                rffi.free_charp(buf)
+
+        assert 0 == run("42 * 43")
+        
+        assert -1 == run("4..3 * 43")
+        
+        assert api.PyErr_Occurred()
+        api.PyErr_Clear()
+        
     def test_run_string(self, space, api):
         def run(code, start, w_globals, w_locals):
             buf = rffi.str2charp(code)