Author: Matti Picus <matti.pi...@gmail.com>
Branch: 
Changeset: r92121:9ddefd44f80d
Date: 2017-08-11 12:37 +0300
http://bitbucket.org/pypy/pypy/changeset/9ddefd44f80d/

Log:    do not change preexisting error when calling c-api functions

        unsuccessfully tried to write a test, since testing does not go
        through this path

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1575,6 +1575,7 @@
         assert cpyext_glob_tid_ptr[0] == 0
         cpyext_glob_tid_ptr[0] = tid
 
+        preexist_error = PyErr_Occurred(space) is not None
         try:
             # Call the function
             result = call_external_function(func, *boxed_args)
@@ -1598,15 +1599,15 @@
             # Check for exception consistency
             has_error = PyErr_Occurred(space) is not None
             has_result = ret is not None
-            if has_error and has_result:
-                raise oefmt(space.w_SystemError,
-                            "An exception was set, but function returned a "
-                            "value")
-            elif not expect_null and not has_error and not has_result:
-                raise oefmt(space.w_SystemError,
-                            "Function returned a NULL result without setting "
-                            "an exception")
-
+            if not preexist_error:
+                if has_error and has_result:
+                    raise oefmt(space.w_SystemError,
+                                "An exception was set, but function returned a 
"
+                                "value")
+                elif not expect_null and not has_error and not has_result:
+                    raise oefmt(space.w_SystemError,
+                                "Function returned a NULL result without 
setting "
+                                "an exception")
             if has_error:
                 state = space.fromcache(State)
                 state.check_and_raise_exception()
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to