From 9151ec709258273a555180696bdbae8bb0794658 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 28 Feb 2016 01:38:28 -0800 Subject: Eliminate narrow_string_rep_t This was used to cache a narrow string representation of commands, so that if certain system calls returned errors after fork, we could output error messages without allocating memory. But in practice these errors are very uncommon, as are commands that have wide characters. It is simpler to do a best-effort output of the wide string, instead of caching a narrow string unconditionally. --- src/common.h | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) (limited to 'src/common.h') diff --git a/src/common.h b/src/common.h index 2ba49854..d255ac62 100644 --- a/src/common.h +++ b/src/common.h @@ -396,6 +396,9 @@ void debug_safe(int level, const char *msg, const char *param1 = NULL, const cha void format_long_safe(char buff[64], long val); void format_long_safe(wchar_t buff[64], long val); +/** "Narrows" a wide character string. This just grabs any ASCII characters and trunactes. */ +void narrow_string_safe(char buff[64], const wchar_t *s); + template T from_string(const wcstring &x) @@ -526,36 +529,6 @@ public: /* Helper function to convert from a null_terminated_array_t to a null_terminated_array_t */ void convert_wide_array_to_narrow(const null_terminated_array_t &arr, null_terminated_array_t *output); -/* Helper class to cache a narrow version of a wcstring in a malloc'd buffer, so that we can read it after fork() */ -class narrow_string_rep_t -{ -private: - const char *str; - - /* No copying */ - narrow_string_rep_t &operator=(const narrow_string_rep_t &); - narrow_string_rep_t(const narrow_string_rep_t &x); - -public: - ~narrow_string_rep_t() - { - free((void *)str); - } - - narrow_string_rep_t() : str(NULL) {} - - void set(const wcstring &s) - { - free((void *)str); - str = wcs2str(s.c_str()); - } - - const char *get() const - { - return str; - } -}; - bool is_forked_child(); -- cgit v1.2.3