Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move error check right after making call to Z3 #373

Conversation

janvrany
Copy link
Collaborator

During debugging of weird failure in Z3CAPITest >> testEnum we
realized that the call to Z3 failed but did not fail in #errorCheck
as one would expect. Instead, the code failed trying to extract value
from output parameter (which was luckily NULL!).

This is because call to #errorCheck was made too late, after
extracting and freeing output parameters.

The correct thing is to call #errorCheck right after the call to Z3
API. However, this is not that simple! If there are array arguments,
we have to free them in ensure (otherwise we'd leak them). To make it
more complicated, some arrays are out or in/out parameters, so we have
to extract the value after # errorCheck but NOT in #ensure: block in
case call fails.

Yet another 'complication' comes from the fact, that few Z3 API do not
require error check (have no context) but use out and/or in/out
parameters.

This PR updates apigen.py so it generates ensure when needed
and updates code in class Z3 accordingly.

This commit introduces a simple helper class to write source code. It's
basically a string-like object to which more code can be added via +=
(as it was done before) but with some helpers to manage indentation.

This is merely a preparation for next commit which would generate more
complex code and managing indentation by hand (as it was done up to
now) becomes too much.

The changes in `Z3` class are all whitespace changes - the new code
does not output trailing tab and I did not care to complicate logic in
apigen.py to make write bit-to-bit output.
During debugging of weird failure in `Z3CAPITest >> testEnum` we
realized that the call to Z3 failed but did not fail in `#errorCheck`
as one would expect. Instead, the code failed trying to extract value
from output parameter (which was luckily NULL!).

This is because call to `#errorCheck` was made too late, after
extracting and freeing output parameters.

The correct thing is to call `#errorCheck` right after the call to Z3
API. However, this is not that simple! If there are array arguments,
we have to free them in ensure (otherwise we'd leak them). To make it
more complicated, some arrays are out or in/out parameters, so we have
to extract the value after # errorCheck but NOT in #ensure: block in
case call fails.

Yet another 'complication' comes from the fact, that few Z3 API do not
require error check (have no context) but use out and/or in/out
parameters.

This commit updates `apigen.py` so it generates ensure when needed
and updates code in class `Z3` accordingly.
@janvrany janvrany requested a review from shingarov October 22, 2024 13:01
@shingarov shingarov merged commit 5019fff into shingarov:pure-z3 Oct 22, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants