[pypy-commit] pypy multiphase: fix exception consistency checks
rlamy
pypy.commits at gmail.com
Fri Sep 1 11:00:52 EDT 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: multiphase
Changeset: r92294:1a20a8077e2e
Date: 2017-09-01 16:00 +0100
http://bitbucket.org/pypy/pypy/changeset/1a20a8077e2e/
Log: fix exception consistency checks
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
@@ -1559,8 +1559,7 @@
initfunc = rffi.cast(initfunctype, initptr)
initret = generic_cpy_call_dont_convert_result(space, initfunc)
if not initret:
- if state.operror:
- state.check_and_raise_exception()
+ state.check_and_raise_exception()
raise oefmt(space.w_SystemError,
"initialization of %s failed without raising an exception",
name)
@@ -1615,7 +1614,7 @@
@specialize.ll()
def generic_cpy_call_dont_convert_result(space, func, *args):
FT = lltype.typeOf(func).TO
- return make_generic_cpy_call(FT, True, False)(space, func, *args)
+ return make_generic_cpy_call(FT, False, False)(space, func, *args)
@specialize.memo()
def make_generic_cpy_call(FT, expect_null, convert_result):
@@ -1671,10 +1670,9 @@
cpyext_glob_tid_ptr[0] = 0
keepalive_until_here(*keepalives)
- if is_PyObject(RESULT_TYPE):
- if not convert_result or not is_pyobj(result):
+ if convert_result and is_PyObject(RESULT_TYPE):
+ if not is_pyobj(result):
ret = result
- has_result = bool(ret)
else:
# The object reference returned from a C function
# that is called from Python must be an owned reference
@@ -1683,13 +1681,13 @@
ret = get_w_obj_and_decref(space, result)
else:
ret = None
- has_result = ret is not None
# Check for exception consistency
# XXX best attempt, will miss preexisting error that is
# overwritten with a new error of the same type
error = PyErr_Occurred(space)
has_new_error = (error is not None) and (error is not preexist_error)
+ has_result = ret is not None
if not expect_null and has_new_error and has_result:
raise oefmt(space.w_SystemError,
"An exception was set, but function returned a "
diff --git a/pypy/module/cpyext/modsupport.py b/pypy/module/cpyext/modsupport.py
--- a/pypy/module/cpyext/modsupport.py
+++ b/pypy/module/cpyext/modsupport.py
@@ -1,7 +1,8 @@
from rpython.rtyper.lltypesystem import rffi, lltype
from pypy.module.cpyext.api import (
cpython_api, METH_STATIC, METH_CLASS, METH_COEXIST, CANNOT_FAIL, cts,
- parse_dir, bootstrap_function, generic_cpy_call, slot_function)
+ parse_dir, bootstrap_function, generic_cpy_call,
+ generic_cpy_call_dont_convert_result, slot_function)
from pypy.module.cpyext.pyobject import PyObject, as_pyobj, make_typedescr
from pypy.interpreter.module import Module
from pypy.module.cpyext.methodobject import (
@@ -150,21 +151,18 @@
while cur_slot and rffi.cast(lltype.Signed, cur_slot[0].c_slot):
if rffi.cast(lltype.Signed, cur_slot[0].c_slot) == 2:
execf = rffi.cast(execfunctype, cur_slot[0].c_value)
- res = generic_cpy_call(space, execf, w_mod)
- has_error = PyErr_Occurred(space) is not None
+ res = generic_cpy_call_dont_convert_result(space, execf, w_mod)
state = space.fromcache(State)
- if rffi.cast(lltype.Signed, res):
- if has_error:
- state.check_and_raise_exception()
- else:
+ if res:
+ state.check_and_raise_exception()
+ raise oefmt(space.w_SystemError,
+ "execution of module %S failed without "
+ "setting an exception", w_mod.w_name)
+ else:
+ if state.clear_exception():
raise oefmt(space.w_SystemError,
- "execution of module %S failed without "
- "setting an exception", w_mod.w_name)
- if has_error:
- state.clear_exception()
- raise oefmt(space.w_SystemError,
- "execution of module %S raised unreported "
- "exception", w_mod.w_name)
+ "execution of module %S raised unreported "
+ "exception", w_mod.w_name)
cur_slot = rffi.ptradd(cur_slot, 1)
More information about the pypy-commit
mailing list