# HG changeset patch # User Rik # Date 1454095943 28800 # Node ID bfd5e48c41a192cef3204d9e3649c88826a6a307 # Parent f090661930ba14afdb346b6f6abf400a76a80776 Rename local error in mex I/F from invalid_type_error to err_invalid_type. Switch from using class method mxArray_base::error to error from error.h * mex.cc (mxArray_base::error, mxArray_matlab::invalid_type_error): Delete functions. * mex.cc (mxArray_matlab::err_invalid_type): New function declared with OCTAVE_NORETURN. * mex.cc: #include "error.h". Rename all invalid_type_error calls to err_invalid_type. Remove useless statements appearing after calls to err_invalid_type. * mxarray.in.h: #include "error.h". Rename all invalid_type_error calls to err_invalid_type. * mxarray.in.h (mxArray_base::err_invalid_type): New function declared with OCTAVE_NORETURN. * mxarray.in.h (mxArray_base::invalid_type_error): Add OCTAVE_DEPRECATED attribute to function. diff -r f090661930ba -r bfd5e48c41a1 libinterp/corefcn/mex.cc --- a/libinterp/corefcn/mex.cc Fri Jan 29 12:25:39 2016 -0500 +++ b/libinterp/corefcn/mex.cc Fri Jan 29 11:32:23 2016 -0800 @@ -36,6 +36,7 @@ #include "oct-locbuf.h" #include "Cell.h" +#include "error.h" // mxArray must be declared as a class before including mexproto.h. #include "mxarray.h" #include "mexproto.h" @@ -104,13 +105,6 @@ // ------------------------------------------------------------------ -void -mxArray_base::error (const char *msg) const -{ - // FIXME - ::error ("%s", msg); -} - static mwIndex calc_single_subscript_internal (mwSize ndims, const mwSize *dims, mwSize nsubs, const mwIndex *subs) @@ -792,109 +786,98 @@ mxArray *get_cell (mwIndex /*idx*/) const { - invalid_type_error (); - return 0; + err_invalid_type (); } void set_cell (mwIndex /*idx*/, mxArray */*val*/) { - invalid_type_error (); + err_invalid_type (); } double get_scalar (void) const { - invalid_type_error (); - return 0; + err_invalid_type (); } void *get_data (void) const { - invalid_type_error (); - return 0; + err_invalid_type (); } void *get_imag_data (void) const { - invalid_type_error (); - return 0; + err_invalid_type (); } void set_data (void */*pr*/) { - invalid_type_error (); + err_invalid_type (); } void set_imag_data (void */*pi*/) { - invalid_type_error (); + err_invalid_type (); } mwIndex *get_ir (void) const { - invalid_type_error (); - return 0; + err_invalid_type (); } mwIndex *get_jc (void) const { - invalid_type_error (); - return 0; + err_invalid_type (); } mwSize get_nzmax (void) const { - invalid_type_error (); - return 0; + err_invalid_type (); } void set_ir (mwIndex */*ir*/) { - invalid_type_error (); + err_invalid_type (); } void set_jc (mwIndex */*jc*/) { - invalid_type_error (); + err_invalid_type (); } void set_nzmax (mwSize /*nzmax*/) { - invalid_type_error (); + err_invalid_type (); } int add_field (const char */*key*/) { - invalid_type_error (); - return -1; + err_invalid_type (); } void remove_field (int /*key_num*/) { - invalid_type_error (); + err_invalid_type (); } mxArray *get_field_by_number (mwIndex /*index*/, int /*key_num*/) const { - invalid_type_error (); - return 0; + err_invalid_type (); } void set_field_by_number (mwIndex /*index*/, int /*key_num*/, mxArray */*val*/) { - invalid_type_error (); + err_invalid_type (); } int get_number_of_fields (void) const { - invalid_type_error (); - return 0; + err_invalid_type (); } const char *get_field_name_by_number (int /*key_num*/) const { - invalid_type_error (); - return 0; + err_invalid_type (); } int get_field_number (const char */*key*/) const @@ -904,14 +887,12 @@ int get_string (char */*buf*/, mwSize /*buflen*/) const { - invalid_type_error (); - return 0; + err_invalid_type (); } char *array_to_string (void) const { - invalid_type_error (); - return 0; + err_invalid_type (); } mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const @@ -978,13 +959,14 @@ mwSize ndims; mwSize *dims; - void invalid_type_error (void) const + OCTAVE_NORETURN void err_invalid_type (void) const { error ("invalid type for operation"); } - // No assignment! FIXME: should this be implemented? Note that we - // do have a copy constructor. + // No assignment! + // FIXME: should this be implemented? + // Note that we *do* have a copy constructor. mxArray_matlab& operator = (const mxArray_matlab&); }; @@ -1342,27 +1324,21 @@ octave_value int_to_ov (const dim_vector& dv) const { - octave_value retval; + if (pi) + error ("complex integer types are not supported"); mwSize nel = get_number_of_elements (); ELT_T *ppr = static_cast (pr); - if (pi) - error ("complex integer types are not supported"); - else - { - ARRAY_T val (dv); - - ARRAY_ELT_T *ptr = val.fortran_vec (); - - for (mwIndex i = 0; i < nel; i++) - ptr[i] = ppr[i]; - - retval = val; - } - - return retval; + ARRAY_T val (dv); + + ARRAY_ELT_T *ptr = val.fortran_vec (); + + for (mwIndex i = 0; i < nel; i++) + ptr[i] = ppr[i]; + + return octave_value (val); } mxArray_number (const mxArray_number& val) @@ -2064,7 +2040,6 @@ if (! ptr) { // FIXME: could use "octave_new_handler();" instead - error ("%s: failed to allocate %d bytes of memory", function_name (), n); } @@ -3078,6 +3053,8 @@ // continue to have memory leaks after Ctrl-C until proper exception // handling is implemented. + // FIXME: Proper exception handling has been implemented (Jan. 2016). + // Can this code be re-factored? args.resize (nargin); for (int i = 0; i < nargin; i++) diff -r f090661930ba -r bfd5e48c41a1 libinterp/corefcn/mxarray.in.h --- a/libinterp/corefcn/mxarray.in.h Fri Jan 29 12:25:39 2016 -0500 +++ b/libinterp/corefcn/mxarray.in.h Fri Jan 29 11:32:23 2016 -0800 @@ -93,6 +93,7 @@ #if ! defined (MXARRAY_TYPEDEFS_ONLY) #include +#include "error.h" class octave_value; @@ -116,10 +117,10 @@ rep->METHOD_CALL; \ } -// A class to provide the default implemenation of some of the virtual -// functions declared in the mxArray class. +class mxArray; -class mxArray; +// A class to provide the default implementation of some of the +// virtual functions declared in the mxArray class. class mxArray_base { @@ -216,10 +217,11 @@ virtual void set_class_name (const char *name_arg) = 0; + // FIXME: Why not just have this '= 0' as the others? + // Could then eliminate err_invalid_type function and #include "error.h". virtual mxArray *get_cell (mwIndex /*idx*/) const { - invalid_type_error (); - return 0; + err_invalid_type (); } virtual void set_cell (mwIndex idx, mxArray *val) = 0; @@ -279,12 +281,17 @@ mxArray_base (const mxArray_base&) { } + // FIXME: Deprecated in 4.2, remove in 4.6 + OCTAVE_DEPRECATED ("use 'err_invalid_type' instead") void invalid_type_error (void) const { error ("invalid type for operation"); } - void error (const char *msg) const; + OCTAVE_NORETURN void err_invalid_type (void) const + { + error ("invalid type for operation"); + } }; // The main interface class. The representation can be based on an