Mercurial > hg > octave-lojdl
changeset 15501:814c4b0d5c49
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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 11 Oct 2012 12:56:56 -0400 |
parents | 96b7343b8a41 |
children | 312d544de165 |
files | libinterp/octave-value/ov-base.h libinterp/octave-value/ov-ch-mat.cc |
diffstat | 2 files changed, 21 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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<octave_idx_type> 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;
--- 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; }