# HG changeset patch # User jwe # Date 1094144177 0 # Node ID 0ab18cbe8b5fa98b45bc9f81ccfe31910cdee561 # Parent 2acb248a653fb1793541dcd091eccfe0ae4e0083 [project @ 2004-09-02 16:56:17 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2004-09-02 John W. Eaton + + * 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 * version.h (OCTAVE_VERSION): Now 2.1.58. diff --git a/src/DLD-FUNCTIONS/quad.cc b/src/DLD-FUNCTIONS/quad.cc --- 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 = "); diff --git a/src/ov-fcn-inline.cc b/src/ov-fcn-inline.cc --- 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. diff --git a/src/variables.cc b/src/variables.cc --- a/src/variables.cc +++ b/src/variables.cc @@ -662,14 +662,28 @@ return retval; } +#define GET_IDX(LEN) \ + static_cast ((LEN-1) * static_cast (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, ,