3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-12 20:18:18 +00:00

Fixed error handlers in Python API.

This commit is contained in:
Christoph M. Wintersteiger 2017-11-08 20:09:09 +00:00
parent bec6c3f9e2
commit 17bcb37cf1
2 changed files with 20 additions and 15 deletions

View file

@ -330,8 +330,10 @@ class Elementaries:
raise self.Exception(self.get_error_message(ctx, err)) raise self.Exception(self.get_error_message(ctx, err))
def Z3_set_error_handler(ctx, hndlr, _elems=Elementaries(_lib.Z3_set_error_handler)): def Z3_set_error_handler(ctx, hndlr, _elems=Elementaries(_lib.Z3_set_error_handler)):
_elems.f(ctx, ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_uint)(hndlr)) ceh = _error_handler_type(hndlr)
_elems.f(ctx, ceh)
_elems.Check(ctx) _elems.Check(ctx)
return ceh
""") """)
@ -1710,8 +1712,10 @@ else:
else: else:
return "" return ""
_error_handler_type = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_uint)
_lib.Z3_set_error_handler.restype = None _lib.Z3_set_error_handler.restype = None
_lib.Z3_set_error_handler.argtypes = [ContextObj, ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_uint)] _lib.Z3_set_error_handler.argtypes = [ContextObj, _error_handler_type]
""" """
) )

View file

@ -125,11 +125,6 @@ def _get_args(args):
except: # len is not necessarily defined when args is not a sequence (use reflection?) except: # len is not necessarily defined when args is not a sequence (use reflection?)
return args return args
def z3_error_handler(c, e):
# Do nothing error handler, just avoid exit(0)
# The wrappers in z3core.py will raise a Z3Exception if an error is detected
return
def _to_param_value(val): def _to_param_value(val):
if isinstance(val, bool): if isinstance(val, bool):
if val == True: if val == True:
@ -139,6 +134,11 @@ def _to_param_value(val):
else: else:
return str(val) return str(val)
def z3_error_handler(c, e):
# Do nothing error handler, just avoid exit(0)
# The wrappers in z3core.py will raise a Z3Exception if an error is detected
return
class Context: class Context:
"""A Context manages all other Z3 objects, global configuration options, etc. """A Context manages all other Z3 objects, global configuration options, etc.
@ -165,13 +165,14 @@ class Context:
Z3_set_param_value(conf, str(prev), _to_param_value(a)) Z3_set_param_value(conf, str(prev), _to_param_value(a))
prev = None prev = None
self.ctx = Z3_mk_context_rc(conf) self.ctx = Z3_mk_context_rc(conf)
self.eh = Z3_set_error_handler(self.ctx, z3_error_handler)
Z3_set_ast_print_mode(self.ctx, Z3_PRINT_SMTLIB2_COMPLIANT) Z3_set_ast_print_mode(self.ctx, Z3_PRINT_SMTLIB2_COMPLIANT)
Z3_set_error_handler(self.ctx, z3_error_handler)
Z3_del_config(conf) Z3_del_config(conf)
def __del__(self): def __del__(self):
Z3_del_context(self.ctx) Z3_del_context(self.ctx)
self.ctx = None self.ctx = None
self.eh = None
def ref(self): def ref(self):
"""Return a reference to the actual C pointer to the Z3 context.""" """Return a reference to the actual C pointer to the Z3 context."""