scilab: add pointer conversion builtin functions swig_this & swig_ptr

This commit is contained in:
Simon Marchetto 2014-03-28 15:01:01 +01:00
commit 675c4cee0f
5 changed files with 97 additions and 7 deletions

View file

@ -18,6 +18,7 @@ CPP_TEST_CASES += \
primitive_types \
inout \
scilab_li_matrix \
scilab_pointer_conversion_functions \
CPP_STD_TEST_CASES += \
li_std_container_typemaps \

View file

@ -0,0 +1,18 @@
exec("swigtest.start", -1);
// Test on NULL
null = getNull();
checkequal(swig_this(null), 0, "swig_this(null)");
null = swig_ptr(0);
checkequal(isNull(null), %T, "func(null)");
// Test on variable
expected_foo_addr = getFooAddress();
foo_addr = swig_this(pfoo_get());
checkequal(uint32(foo_addr), expected_foo_addr, "swig_this(pfoo_get())");
pfoo = swig_ptr(foo_addr);
checkequal(equalFooPointer(pfoo), %T, "equalFooPointer(pfoo)");
exec("swigtest.quit", -1);

View file

@ -0,0 +1,16 @@
%module scilab_pointer_conversion_functions
%inline %{
void* getNull() { return NULL; }
bool isNull(void *p) { return p == NULL; }
int foo = 3;
int *pfoo = &foo;
unsigned long getFooAddress() { return (unsigned long) pfoo; }
bool equalFooPointer(void *p) { return p == pfoo; }
%}