Fix issues with exception_memory_leak testcase

The out typemap uses a function name which doesn't match the name of the
function we want it to apply to, so this testcase wasn't actually
triggering an exception so wasn't actually testing anything!

With that fixed, the testcase fails to compile for PHP due to use of
SWIG_exception_fail() (which not all target languages implement), and
with that fixed, the _runme.php needs a try ... catch adding to handle
the raised exception.
This commit is contained in:
Olly Betts 2022-10-14 09:36:03 +13:00 committed by Olly Betts
commit 3dd7e93c77
2 changed files with 13 additions and 4 deletions

View file

@ -1,6 +1,7 @@
%module exception_memory_leak
%include <std_string.i>
%include <exception.i>
%typemap(in) Foo* foo
{
@ -11,10 +12,14 @@
Foo::inc_freearg_count();
delete $1;
}
%typemap(out) Foo* verify_no_memory_leak
%typemap(out) Foo* trigger_internal_swig_exception
{
if ($1 == NULL)
SWIG_exception_fail(SWIG_RuntimeError, "Let's see how the bindings manage this exception!");
if ($1 == NULL) {
SWIG_exception(SWIG_RuntimeError, "Let's see how the bindings manage this exception!");
#ifdef SWIG_fail
SWIG_fail;
#endif
}
$1 = NULL;
}

View file

@ -18,6 +18,10 @@ check::equal(Foo::get_count(), 2, "Should have 2 Foo objects");
check::equal(Foo::get_freearg_count(), 1, "freearg should have been used once");
// SWIG exception triggered and handled.
trigger_internal_swig_exception("null", $b);
try {
trigger_internal_swig_exception("null", $b);
check::fail("Expected exception not thrown");
} catch (Exception $e) {
}
check::equal(Foo::get_count(), 2, "Should have 2 Foo objects");
check::equal(Foo::get_freearg_count(), 2, "freearg should have been used twice");