From f9659e648cd06a9322b501168b1af8ede7d1ae16 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Mon, 22 Apr 2019 15:43:52 +0200 Subject: [PATCH] =?utf8?q?Module=20API:=20Don=E2=80=99t=20require=20null-t?= =?utf8?q?erminated=20strings=20in=20make=5Fstring.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * emacs-module.c (module_make_string): Use make_unibyte_string, which doesn’t require its argument to be null-terminated. Since it always returns a heap-allocated string, we don’t have to copy it any more while decoding. (module_decode): New helper function. --- src/emacs-module.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/emacs-module.c b/src/emacs-module.c index 8fd2a87cc23..20dcff2b67a 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -212,6 +212,7 @@ static void module_reset_handlerlist (struct handler **); static bool value_storage_contains_p (const struct emacs_value_storage *, emacs_value, ptrdiff_t *); static Lisp_Object module_encode (Lisp_Object); +static Lisp_Object module_decode (Lisp_Object); static Lisp_Object module_decode_copy (Lisp_Object); static bool module_assertions = false; @@ -629,10 +630,8 @@ module_make_string (emacs_env *env, const char *str, ptrdiff_t length) MODULE_FUNCTION_BEGIN (NULL); if (! (0 <= length && length <= STRING_BYTES_BOUND)) overflow_error (); - /* FIXME: AUTO_STRING_WITH_LEN requires STR to be NUL-terminated, - but we shouldn't require that. */ - AUTO_STRING_WITH_LEN (lstr, str, length); - return lisp_to_value (env, module_decode_copy (lstr)); + Lisp_Object lstr = make_unibyte_string (str, length); + return lisp_to_value (env, module_decode (lstr)); } static emacs_value @@ -946,6 +945,12 @@ module_encode (Lisp_Object string) return code_convert_string (string, Qutf_8_unix, Qt, true, true, true); } +static Lisp_Object +module_decode (Lisp_Object string) +{ + return code_convert_string (string, Qutf_8_unix, Qt, false, true, true); +} + static Lisp_Object module_decode_copy (Lisp_Object string) { -- 2.39.2