diff --git a/Examples/test-suite/octave/Makefile.in b/Examples/test-suite/octave/Makefile.in index eecedf041..746a27010 100644 --- a/Examples/test-suite/octave/Makefile.in +++ b/Examples/test-suite/octave/Makefile.in @@ -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 \ diff --git a/Examples/test-suite/octave/cell_deref.i b/Examples/test-suite/octave/cell_deref.i new file mode 100644 index 000000000..fddcd80ec --- /dev/null +++ b/Examples/test-suite/octave/cell_deref.i @@ -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; + } +} + diff --git a/Examples/test-suite/octave/cell_deref_runme.m b/Examples/test-suite/octave/cell_deref_runme.m new file mode 100644 index 000000000..1c370fe85 --- /dev/null +++ b/Examples/test-suite/octave/cell_deref_runme.m @@ -0,0 +1,8 @@ +cell_deref; + +assert(func("hello")); +assert(func({"hello"})); + +c = func2(); +assert(strcmp(c{1}, "hello")); +assert(c{2} == 4); diff --git a/Examples/test-suite/octave/null_pointer.i b/Examples/test-suite/octave/null_pointer.i new file mode 100644 index 000000000..59d554c2b --- /dev/null +++ b/Examples/test-suite/octave/null_pointer.i @@ -0,0 +1,10 @@ +%module null_pointer + +%inline { + struct A {}; + + bool func(A* a) { + return !a; + } +} + diff --git a/Examples/test-suite/octave/null_pointer_runme.m b/Examples/test-suite/octave/null_pointer_runme.m new file mode 100644 index 000000000..51b6eaf91 --- /dev/null +++ b/Examples/test-suite/octave/null_pointer_runme.m @@ -0,0 +1,3 @@ +null_pointer; + +assert(func([])); diff --git a/Lib/octave/octprimtypes.swg b/Lib/octave/octprimtypes.swg index 5e1b7bdfe..6f43f21b0 100644 --- a/Lib/octave/octprimtypes.swg +++ b/Lib/octave/octprimtypes.swg @@ -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; diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 9bf7bd22e..34076e90e 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -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;