Mercurial > octave
changeset 25445:97e64c23fd07 stable
treat NULL as [] for mxSetFieldByNumber and mxSetCell (bug #54096)
* mex.cc (make_empty_matrix): New static function.
(mxArray_struct::set_field_by_number, mxArray_cell::set_cell):
If value is NULL, store empty double matrix.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 11 Jun 2018 12:55:59 -0400 |
parents | 2b3c3c8c8360 |
children | 1eedd589fb3e 66b72fbf2845 |
files | libinterp/corefcn/mex.cc |
diffstat | 1 files changed, 11 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/mex.cc Mon Jun 04 23:15:50 2018 +0200 +++ b/libinterp/corefcn/mex.cc Mon Jun 11 12:55:59 2018 -0400 @@ -2469,18 +2469,27 @@ return ptr; } +static mxArray * +make_empty_matrix (void) +{ + static const mwSize zero = 0; + + return new mxArray (mxDOUBLE_CLASS, zero, zero, mxREAL); +} + void mxArray_struct::set_field_by_number (mwIndex index, int key_num, mxArray *val) { if (key_num >= 0 && key_num < nfields) - data[nfields * index + key_num] = maybe_unmark_array (val); + data[nfields * index + key_num] + = val ? maybe_unmark_array (val) : make_empty_matrix (); } void mxArray_cell::set_cell (mwIndex idx, mxArray *val) { if (idx >= 0 && idx < get_number_of_elements ()) - data[idx] = maybe_unmark_array (val); + data[idx] = val ? maybe_unmark_array (val) : make_empty_matrix (); } // ------------------------------------------------------------------