# HG changeset patch # User John W. Eaton # Date 1349974616 14400 # Node ID 814c4b0d5c4908443c2b857d7e78518706477f98 # Parent 96b7343b8a419fc727a30f9aca10b1bf7f66028f make numeric mapper functions throw error for char args (bug #37535) * ov-base.h (octave_base_value::get_umap_name): Now protected instead of private. * ov-ch-mat.cc (octave_char_matrix::map): Special cases for umap_abs, umap_ceil, umap_fix, umap_floor, umap_imag, umap_isinf, umap_isnan, umap_real, and umap_round. Error for all other mappers that expect numeric arguments. diff --git a/libinterp/octave-value/ov-base.h b/libinterp/octave-value/ov-base.h --- a/libinterp/octave-value/ov-base.h +++ b/libinterp/octave-value/ov-base.h @@ -802,9 +802,9 @@ // (think of an empty cell array with >2G elements). octave_refcount count; -private: + static const char *get_umap_name (unary_mapper_t); - static const char *get_umap_name (unary_mapper_t); +private: static int curr_print_indent_level; static bool beginning_of_line; diff --git a/libinterp/octave-value/ov-ch-mat.cc b/libinterp/octave-value/ov-ch-mat.cc --- a/libinterp/octave-value/ov-ch-mat.cc +++ b/libinterp/octave-value/ov-ch-mat.cc @@ -172,6 +172,8 @@ octave_value octave_char_matrix::map (unary_mapper_t umap) const { + octave_value retval; + switch (umap) { #define STRING_MAPPER(UMAP,FCN,TYPE) \ @@ -194,10 +196,26 @@ STRING_MAPPER (xtolower, std::tolower, char); STRING_MAPPER (xtoupper, std::toupper, char); - default: + // For Matlab compatibility, these should work on ASCII values + // without error or warning. + case umap_abs: + case umap_ceil: + case umap_fix: + case umap_floor: + case umap_imag: + case umap_isinf: + case umap_isnan: + case umap_real: + case umap_round: { octave_matrix m (array_value (true)); return m.map (umap); } + + default: + error ("%s: expecting numeric argument", get_umap_name (umap)); + break; } + + return retval; }