Mercurial > hg > octave-nkf
changeset 4962:0ab18cbe8b5f
[project @ 2004-09-02 16:56:17 by jwe]
author | jwe |
---|---|
date | Thu, 02 Sep 2004 16:56:17 +0000 |
parents | 2acb248a653f |
children | 573d23f9c9cf |
files | src/ChangeLog src/DLD-FUNCTIONS/quad.cc src/ov-fcn-inline.cc src/variables.cc |
diffstat | 4 files changed, 31 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2004-09-02 John W. Eaton <jwe@octave.org> + + * DLD-FUNCTIONS/quad.cc (Fquad): Pass "__quad_fcn_" instead of + "__quad_fcn__" to unique_symbol_name. + + * ov-fcn-inline.cc (octave_fcn_inline): Pass "__inline_" instead + of "__inline__" to unique_symbol_name. + + * variables.cc (unique_symbol_name): Make better random symbol name. + 2004-09-01 John W. Eaton <jwe@octave.org> * version.h (OCTAVE_VERSION): Now 2.1.58.
--- a/src/DLD-FUNCTIONS/quad.cc +++ b/src/DLD-FUNCTIONS/quad.cc @@ -188,7 +188,7 @@ quad_fcn = args(0).function_value (); else { - fcn_name = unique_symbol_name ("__quad__fcn__"); + fcn_name = unique_symbol_name ("__quad_fcn_"); std::string fname = "function y = "; fname.append (fcn_name); fname.append ("(x) y = ");
--- a/src/ov-fcn-inline.cc +++ b/src/ov-fcn-inline.cc @@ -55,7 +55,7 @@ : octave_fcn_handle (0, n), iftext (f), ifargs (a) { // Find a function name that isn't already in the symbol table. - std::string fname = unique_symbol_name ("__inline__"); + std::string fname = unique_symbol_name ("__inline_"); // Form a string representing the function.
--- a/src/variables.cc +++ b/src/variables.cc @@ -662,14 +662,28 @@ return retval; } +#define GET_IDX(LEN) \ + static_cast<int> ((LEN-1) * static_cast<double> (rand ()) / RAND_MAX) + std::string unique_symbol_name (const std::string& basename) { - // XXX FIXME XXX Can we be smarter than just adding characters? - std::string name = basename; - while (symbol_exist (name, "any")) - name.append ("X"); - return name; + static const std::string alpha + = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + static size_t len = alpha.length (); + + std::string nm = basename + alpha[GET_IDX (len)]; + + size_t pos = nm.length (); + + if (nm.substr (0, 2) == "__") + nm.append ("__"); + + while (symbol_exist (nm, "any")) + nm.insert (pos++, 1, alpha[GET_IDX (len)]); + + return nm; } DEFUN (exist, args, ,