-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Interpret C++ exceptions in C bindings (#955)
This PR amends the interface of the simplification routines in the C bindings to allow for error information to be safely returned to calling clients without crashing the host process. The changes are as follows: - Introduce a new opaque `kore_error` type to the C bindings, with appropriate bindings. - **Breaking change** to the interfaces of `kore_simplify`, `kore_simplify_bool` and `kore_simplify_binary` to take an optional additional `kore_error` parameter. If a C++ exception is thrown during these bindings, it will be caught and used to populate the error parameter's fields. The booster will need to be updated as part of its K release job down the line. - Add a test that catches an error that imitates the original reporting of this issue (invalid numeric value in the hooked arithmetic library). Closes #953
- Loading branch information
Showing
13 changed files
with
2,307 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "api.h" | ||
|
||
#include <assert.h> | ||
#include <stdio.h> | ||
|
||
int main(int argc, char **argv) { | ||
if (argc <= 2) { | ||
return 1; | ||
} | ||
|
||
struct kllvm_c_api api = load_c_api(argv[1]); | ||
|
||
api.kllvm_init(); | ||
|
||
kore_sort *sort_int = api.kore_composite_sort_new("SortInt"); | ||
|
||
kore_pattern *good_call = api.kore_pattern_parse( | ||
"Lblfoo{}(\\dv{SortInt{}}(\"2\"), \\dv{SortInt{}}(\"2\"))"); | ||
|
||
kore_pattern *bad_call = api.kore_pattern_parse( | ||
"Lblfoo{}(\\dv{SortInt{}}(\"2\"), \\dv{SortInt{}}(\"0\"))"); | ||
|
||
kore_error *err = api.kore_error_new(); | ||
|
||
char *data; | ||
size_t size; | ||
|
||
api.kore_simplify(err, good_call, sort_int, &data, &size); | ||
assert(api.kore_error_is_success(err)); | ||
|
||
FILE *f = fopen(argv[2], "wb"); | ||
if (!f) { | ||
return 4; | ||
} | ||
|
||
fwrite(data, size, 1, f); | ||
fclose(f); | ||
|
||
api.kore_simplify(err, bad_call, sort_int, &data, &size); | ||
assert(!api.kore_error_is_success(err)); | ||
|
||
printf("%s\n", api.kore_error_message(err)); | ||
|
||
api.kore_error_free(err); | ||
api.kore_pattern_free(good_call); | ||
api.kore_pattern_free(bad_call); | ||
api.kore_sort_free(sort_int); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.