Mercurial > hg > octave-lojdl
changeset 10640:5c594472f75e
determine string enum length by trailing null rather than sizeof
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 18 May 2010 08:34:02 +0200 |
parents | a52cc4f6ebfc |
children | ed6969880316 |
files | src/ChangeLog src/DLD-FUNCTIONS/svd.cc src/variables.cc src/variables.h |
diffstat | 4 files changed, 15 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2010-05-18 Jaroslav Hajek <highegg@gmail.com> + + * variables.cc (set_internal_variable (int&, ..., const char **)): + Drop nchoices argument. Instead determine nchoices by trailing NULL. + * variables.h (SET_INTERNAL_VARIABLE_CHOICES): Update. + * DLD-FUNCTIONS/svd.cc (Fsvd_driver): Update. + 2010-05-17 Jaroslav Hajek <highegg@gmail.com> * variables.cc (set_internal_variable (int&, ..., const char **, int)):
--- a/src/DLD-FUNCTIONS/svd.cc +++ b/src/DLD-FUNCTIONS/svd.cc @@ -411,7 +411,7 @@ @seealso{svd}\n\ @end deftypefn") { - static const char *driver_names[] = { "gesvd", "gesdd" }; + static const char *driver_names[] = { "gesvd", "gesdd", 0 }; return SET_INTERNAL_VARIABLE_CHOICES (svd_driver, driver_names); }
--- a/src/variables.cc +++ b/src/variables.cc @@ -873,10 +873,12 @@ octave_value set_internal_variable (int& var, const octave_value_list& args, - int nargout, const char *nm, const char **choices, - int nchoices) + int nargout, const char *nm, const char **choices) { octave_value retval; + int nchoices = 0; + while (choices[nchoices] != 0) + nchoices++; int nargin = args.length (); assert (var < nchoices);
--- a/src/variables.h +++ b/src/variables.h @@ -111,8 +111,7 @@ extern OCTINTERP_API octave_value set_internal_variable (int& var, const octave_value_list& args, - int nargout, const char *nm, const char **choices, - int nchoices); + int nargout, const char *nm, const char **choices); #define SET_INTERNAL_VARIABLE(NM) \ set_internal_variable (V ## NM, args, nargout, #NM) @@ -123,10 +122,9 @@ #define SET_INTERNAL_VARIABLE_WITH_LIMITS(NM, MINVAL, MAXVAL) \ set_internal_variable (V ## NM, args, nargout, #NM, MINVAL, MAXVAL) -// in the following, CHOICES must be a static C string array. +// in the following, CHOICES must be a C string array terminated by null. #define SET_INTERNAL_VARIABLE_CHOICES(NM, CHOICES) \ - set_internal_variable (V ## NM, args, nargout, #NM, CHOICES, \ - sizeof (CHOICES) / sizeof (const char *)) + set_internal_variable (V ## NM, args, nargout, #NM, CHOICES) extern OCTINTERP_API std::string builtin_string_variable (const std::string&); extern OCTINTERP_API int builtin_real_scalar_variable (const std::string&, double&);