swig/Examples/test-suite/r/exception_memory_leak_runme.R
Olly Betts 1707d6b89b [PHP] Fix cleanup code handling issues
Fix to call cleanup code in exception situations and not to invoke
the freearg typemap twice in certain situations.

Fixes https://sourceforge.net/p/swig/bugs/1211/
2022-02-17 13:52:44 +13:00

28 lines
799 B
R

clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("exception_memory_leak", .Platform$dynlib.ext, sep=""))
source("exception_memory_leak.R")
cacheMetaData(1)
a <- Foo();
unittest(Foo_get_count(), 1);
b <- Foo();
unittest(Foo_get_count(), 2);
# Normal behaviour
invisible(trigger_internal_swig_exception("no problem", a));
unittest(Foo_get_count(), 2);
unittest(Foo_get_freearg_count(), 1);
# SWIG exception introduced
result <- tryCatch({
trigger_internal_swig_exception("null", b);
}, 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);
unittest(Foo_get_freearg_count(), 2);