Branch: Tag:

2013-06-28

2013-06-28 16:55:06 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Runtime: Improve robustness against outputting wide strings.

master()->handle_error() now survives if eg an object has
an _sprintf() that returns a wide string.

master()->compile_{error,warning}() now survive messages about
wide symbols.

Made a similar fix in Hilfe to survive compiler warnings and
errors about wide symbols.

Fixes [bug 6805].

1998:   }       + protected string narrowify_string(string s) + { +  if (Builtin.string_width(s) <= 8) return s; +  // Perform Unicode escaping. +  return map(s/"", +  lambda(string s) { +  if (Builtin.string_width(s) <= 8) return s; +  int c = s[0] & 0xffffffff; +  if (c <= 0xffff) return sprintf("\\u%04x", c); +  return sprintf("\\U%08x", c); +  }) * ""; + } +    //! This function is called when an error occurs that is not caught   //! with catch().   void handle_error(array|object trace)
2018:    if (catch {    string msg = [string]x[0];    array bt = [array]x[1]; -  werror("%s", msg); -  werror("%O\n", bt); +  werror("%s", narrowify_string(msg)); +  werror(narrowify_string(sprintf("%O\n", bt)));    }) { -  werror("%O\n", x); +  werror(narrowify_string(sprintf("%O\n", x)));    }    }; -  werror("Original error:\n" -  "%O\n", trace); +  werror(narrowify_string(sprintf("Original error:\n" +  "%O\n", trace)));    }) {    werror("sprintf() failed to write error.\n");    }
3965:    if(! (val = get_inhibit_compile_errors() ))    {    werror( "%s:%s:%s\n",trim_file_name(file), -  line?(string)line:"-",err ); +  line?(string)line:"-",narrowify_string(err) );    }    else if(objectp(val) ||    programp(val) ||
3991:    {    if(want_warnings)    werror( "%s:%s: Warning: %s\n",trim_file_name(file), -  line?(string)line:"-",err ); +  line?(string)line:"-",narrowify_string(err) );    }    else if (objectp(val) && val->compile_warning) {    ([function(string,int,string:void)]([object]val)
4196:    }    break;    } +  // Objects may have _sprintfs that output wide characters, +  // and function names may be wide, etc... +  res = narrowify_string(res);    if (stringp(ident[m]))    return ident[m] + "=" + res;    return res;
4894:    mixed _v__ = (val); \    werror (" returned %s\n", \    zero_type (_v__) ? "UNDEFINED" : \ -  sprintf ("%O", _v__)); \ +  narrowify_string(sprintf ("%O", _v__))); \    return _v__; \   } while (0)   #else
4908:    mixed _v__ = (val); \    werror (" returned %s\n", \    zero_type (_v__) ? "UNDEFINED" : \ -  sprintf ("%O", _v__)); \ +  narrowify_string(sprintf ("%O", _v__))); \    return _v__; \   } while (0)   #else