# HG changeset patch # User Jaroslav Hajek # Date 1274164442 -7200 # Node ID 5c594472f75e77f3e275f0a40c1be86e0a747392 # Parent a52cc4f6ebfcaf2280caf051837b9abf166fe3ef determine string enum length by trailing null rather than sizeof diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2010-05-18 Jaroslav Hajek + + * 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 * variables.cc (set_internal_variable (int&, ..., const char **, int)): diff --git a/src/DLD-FUNCTIONS/svd.cc b/src/DLD-FUNCTIONS/svd.cc --- 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); } diff --git a/src/variables.cc b/src/variables.cc --- 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); diff --git a/src/variables.h b/src/variables.h --- 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&);