diff --git a/CHANGES.current b/CHANGES.current index bb4e85576..d06c0736b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,8 +7,13 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-08-28: wsfulton + [Octave] SWIG now marshalls a C/C++ NULL pointer into the null matrix, []. + SWIG has always marshalled the null matrix into a NULL pointer; this remains + and now we have consistency in representing a NULL pointer. + 2022-08-26: wsfulton - [Racket] SWIG now converts a C/C++ NULL pointer into a null value by calling + [Racket] SWIG now marshalls a C/C++ NULL pointer into a null value by calling scheme_make_null(), so that scheme's null? is true for a NULL C/C++ pointer value. 2022-08-18: wsfulton diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 151957cff..de39a1d96 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -363,6 +363,10 @@ octave:2> f=swigexample.fopen("not there", "r"); error: value on right hand side of assignment is undefined error: evaluating assignment expression near line 2, column 2 +

+NULL C/C++ pointers are represented by the Octave null matrix, []. +

+

30.3.6 Structures and C++ classes

diff --git a/Examples/test-suite/octave/null_pointer_runme.m b/Examples/test-suite/octave/null_pointer_runme.m index 72362f451..7a49d37f0 100644 --- a/Examples/test-suite/octave/null_pointer_runme.m +++ b/Examples/test-suite/octave/null_pointer_runme.m @@ -6,3 +6,13 @@ endif null_pointer; assert(funk([])); +null_ptr = getnull(); +assert(ismatrix(null_ptr)) +assert(size(null_ptr) == size([])) +assert(isequal([], null_ptr)) + +# Can't use isnull as a test due to null matrix not being copyable... +# n = [] +# isnull(n) # ans = 0 +# isnull([]) # ans = 1 +# isnull(getnull()) # ans = 0 diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 71a907f9b..2973318c4 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -1547,12 +1547,15 @@ octave_value_typeinfo::register_binary_op(octave_value::op_##name,tid1,tid2,swig SWIGRUNTIME octave_value SWIG_Octave_NewPointerObj(void *ptr, swig_type_info *type, int flags) { int own = (flags &SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; + if (ptr) { #ifdef SWIG_DIRECTORS - Swig::Director *d = Swig::get_rtdir(ptr); - if (d && Swig::swig_director_get_self(d)) - return Swig::swig_director_get_self(d)->as_value(); + Swig::Director *d = Swig::get_rtdir(ptr); + if (d && Swig::swig_director_get_self(d)) + return Swig::swig_director_get_self(d)->as_value(); #endif - return Swig::swig_value_ref(new octave_swig_type(ptr, type, own)); + return Swig::swig_value_ref(new octave_swig_type(ptr, type, own)); + } + return octave_value(Matrix()); // null matrix } SWIGRUNTIME int SWIG_Octave_ConvertPtrAndOwn(octave_value ov, void **ptr, swig_type_info *type, int flags, int *own) {