Replies: 7 comments 13 replies
-
From my understanding, |
Beta Was this translation helpful? Give feedback.
-
You are right that "assert" is misused. For parameter validation an API function should really throw an exception. |
Beta Was this translation helpful? Give feedback.
-
Not everybody uses exception, as there's a price to pay. Visual Studio still builds C++ programs with exceptions turned off by default. Not that I care about Z3's C++ API, but if I did, I would be against using exceptions there. |
Beta Was this translation helpful? Give feedback.
-
There have been asks not to have exception behavior in the API. Hence the Z3_THROW macro. |
Beta Was this translation helpful? Give feedback.
-
How about: #define Z3_PARAM(x) { if (ctx().enable_exception() && !(x)) Z3_THROW(exception(#x)); assert(x); } The argument that assertions don't get lost is more the onus of the consumer: |
Beta Was this translation helpful? Give feedback.
-
If we want these checks enabled, which I suppose is something worth asking itself (personally I think we should as the relative overhead of the check vs z3 internal computations should be tiny), I think they should be done so in a way that doesn't just crash all threads of the program / send a signal.
|
Beta Was this translation helpful? Give feedback.
-
You have a real use case where assert crashes your program but want to recover? My thought was that the code above Z3 should be fixed to not create mal-formed arguments to the functions that assert. |
Beta Was this translation helpful? Give feedback.
-
In the C++ API, the
assert
function is frequently used; I propose replacing most all invocations of it with C++ exceptions. For example, take the function below. If the user passes in one FPA and one BV,assert
will be called, terminating the program without raising an exception. For this reason, users of the API must read how this function is implemented then wrap it with the very same logic that the API is meant to obscure to decide wether or not it is 'safe' to call the function without fear of the program being terminated.This is particularly troublesome in multi-threaded program. On failure assert failures invoke
std::abort
. Best case, the user installed a custom sigabrt handler and now has to deal with trying to fix up the stack frame before resuming that thread causing, which is difficult and slow since it requires signals. More likely, however, the signal will terminate the program and thus all threads.I propose we change this behavior. A custom failure function is possible, but I believe C++ exceptions provide the best answer here. If nothing else, we could replace
assert(false);
with something similar to:Function mentioned above:
Beta Was this translation helpful? Give feedback.
All reactions