[R] Run destructors of local C++ objects on SWIG_fail
Arrange that destructors of local C++ objects in the wrapper function get run on SWIG_fail (which calls Rf_error() which calls longjmp()). We achieve this by putting almost everything in the function in its own block, and end that right before Rf_error() at which point those destructors will get called.
This commit is contained in:
parent
fefb231bd8
commit
5f96d15943
3 changed files with 25 additions and 1 deletions
|
|
@ -14,7 +14,7 @@ unittest(Foo_get_count(), 2);
|
|||
invisible(trigger_internal_swig_exception("no problem", a));
|
||||
unittest(Foo_get_count(), 2);
|
||||
unittest(Foo_get_freearg_count(), 1);
|
||||
# SWIG exception introduced
|
||||
# SWIG exception introduced (return new object case).
|
||||
result <- tryCatch({
|
||||
trigger_internal_swig_exception("null", b);
|
||||
}, warning = function(w) {
|
||||
|
|
@ -26,3 +26,14 @@ result <- tryCatch({
|
|||
})
|
||||
unittest(Foo_get_count(), 2);
|
||||
unittest(Foo_get_freearg_count(), 2);
|
||||
# SWIG exception introduced (return by value case).
|
||||
result <- tryCatch({
|
||||
trigger_internal_swig_exception("null");
|
||||
}, warning = function(w) {
|
||||
# print(" Hum... We received a warning, but this should be an error");
|
||||
unittest(1,0);
|
||||
}, error = function(e) {
|
||||
# print(" Gotcha!");
|
||||
unittest(1,1);
|
||||
})
|
||||
unittest(Foo_get_count(), 2);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue