Add test for null pointer handling ([] taken as null pointer).
Support automatic single cell dereferencing. Add test for it and pass-through cell arrays. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10379 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
dda6df974f
commit
e7894a104b
7 changed files with 52 additions and 6 deletions
|
|
@ -13,7 +13,9 @@ srcdir = @srcdir@
|
|||
top_srcdir = @top_srcdir@
|
||||
top_builddir = @top_builddir@
|
||||
|
||||
#CPP_TEST_CASES +=
|
||||
CPP_TEST_CASES += \
|
||||
null_pointer \
|
||||
cell_deref
|
||||
|
||||
CPP_TEST_BROKEN += \
|
||||
implicittest \
|
||||
|
|
|
|||
15
Examples/test-suite/octave/cell_deref.i
Normal file
15
Examples/test-suite/octave/cell_deref.i
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
%module cell_deref
|
||||
|
||||
%inline {
|
||||
bool func(const char* s) {
|
||||
return !strcmp("hello",s);
|
||||
}
|
||||
|
||||
Cell func2() {
|
||||
Cell c(1,2);
|
||||
c(0) = "hello";
|
||||
c(1) = 4;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
8
Examples/test-suite/octave/cell_deref_runme.m
Normal file
8
Examples/test-suite/octave/cell_deref_runme.m
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
cell_deref;
|
||||
|
||||
assert(func("hello"));
|
||||
assert(func({"hello"}));
|
||||
|
||||
c = func2();
|
||||
assert(strcmp(c{1}, "hello"));
|
||||
assert(c{2} == 4);
|
||||
10
Examples/test-suite/octave/null_pointer.i
Normal file
10
Examples/test-suite/octave/null_pointer.i
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
%module null_pointer
|
||||
|
||||
%inline {
|
||||
struct A {};
|
||||
|
||||
bool func(A* a) {
|
||||
return !a;
|
||||
}
|
||||
}
|
||||
|
||||
3
Examples/test-suite/octave/null_pointer_runme.m
Normal file
3
Examples/test-suite/octave/null_pointer_runme.m
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
null_pointer;
|
||||
|
||||
assert(func([]));
|
||||
|
|
@ -200,8 +200,10 @@ SWIG_AsVal_dec(bool)(const octave_value& ov, bool *val)
|
|||
|
||||
%fragment("SWIG_AsCharPtrAndSize","header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsCharPtrAndSize(const octave_value& ov, char** cptr, size_t* psize, int *alloc)
|
||||
SWIG_AsCharPtrAndSize(octave_value ov, char** cptr, size_t* psize, int *alloc)
|
||||
{
|
||||
if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1)
|
||||
ov = ov.cell_value()(0);
|
||||
if (!ov.is_string())
|
||||
return SWIG_TypeError;
|
||||
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ namespace Swig {
|
|||
SWIGRUNTIME void swig_director_set_self(Director *d, octave_swig_type *self);
|
||||
|
||||
SWIGRUNTIME octave_base_value *swig_value_ref(octave_swig_type *ost);
|
||||
SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_value &ov);
|
||||
SWIGRUNTIME octave_swig_type *swig_value_deref(octave_value ov);
|
||||
SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_base_value &ov);
|
||||
|
||||
typedef std::map < void *, Director * > rtdir_map;
|
||||
|
|
@ -1007,6 +1007,8 @@ namespace Swig {
|
|||
error("swig_typeinfo must be called with only a single object");
|
||||
return octave_value_list();
|
||||
}
|
||||
if (args(0).is_matrix_type() && args(0).rows() == 0 && args(0).columns() == 0)
|
||||
return octave_value(octave_uint64(0));
|
||||
octave_swig_type *ost = Swig::swig_value_deref(args(0));
|
||||
if (!ost) {
|
||||
error("object is not a swig_ref");
|
||||
|
|
@ -1106,7 +1108,9 @@ namespace Swig {
|
|||
return new octave_swig_ref(ost);
|
||||
}
|
||||
|
||||
SWIGRUNTIME octave_swig_type *swig_value_deref(const octave_value &ov) {
|
||||
SWIGRUNTIME octave_swig_type *swig_value_deref(octave_value ov) {
|
||||
if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1)
|
||||
ov = ov.cell_value()(0);
|
||||
return swig_value_deref(*ov.internal_rep());
|
||||
}
|
||||
|
||||
|
|
@ -1216,9 +1220,11 @@ SWIGRUNTIME octave_value SWIG_Octave_NewPointerObj(void *ptr, swig_type_info *ty
|
|||
return Swig::swig_value_ref(new octave_swig_type(ptr, type, own));
|
||||
}
|
||||
|
||||
SWIGRUNTIME int SWIG_Octave_ConvertPtrAndOwn(const octave_value &ov, void **ptr, swig_type_info *type, int flags, int *own) {
|
||||
SWIGRUNTIME int SWIG_Octave_ConvertPtrAndOwn(octave_value ov, void **ptr, swig_type_info *type, int flags, int *own) {
|
||||
if (ov.is_cell() && ov.rows() == 1 && ov.columns() == 1)
|
||||
ov = ov.cell_value()(0);
|
||||
if (!ov.is_defined() ||
|
||||
(ov.is_matrix_type() && ov.rows()==0 && ov.columns()==0) ) {
|
||||
(ov.is_matrix_type() && ov.rows() == 0 && ov.columns() == 0) ) {
|
||||
if (ptr)
|
||||
*ptr = 0;
|
||||
return SWIG_OK;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue