aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilipp Stephani2019-04-22 15:43:52 +0200
committerPhilipp Stephani2019-04-22 15:44:37 +0200
commitf9659e648cd06a9322b501168b1af8ede7d1ae16 (patch)
tree78d556c9123a6b16417df082351a0b2cdb9019d1 /src
parentca3ad9746da5ced05e8fd692731ffe4dcb52d7e8 (diff)
downloademacs-f9659e648cd06a9322b501168b1af8ede7d1ae16.tar.gz
emacs-f9659e648cd06a9322b501168b1af8ede7d1ae16.zip
Module API: Don’t require null-terminated strings in make_string.
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/emacs-module.c13
1 files 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 **);
212static bool value_storage_contains_p (const struct emacs_value_storage *, 212static bool value_storage_contains_p (const struct emacs_value_storage *,
213 emacs_value, ptrdiff_t *); 213 emacs_value, ptrdiff_t *);
214static Lisp_Object module_encode (Lisp_Object); 214static Lisp_Object module_encode (Lisp_Object);
215static Lisp_Object module_decode (Lisp_Object);
215static Lisp_Object module_decode_copy (Lisp_Object); 216static Lisp_Object module_decode_copy (Lisp_Object);
216 217
217static bool module_assertions = false; 218static bool module_assertions = false;
@@ -629,10 +630,8 @@ module_make_string (emacs_env *env, const char *str, ptrdiff_t length)
629 MODULE_FUNCTION_BEGIN (NULL); 630 MODULE_FUNCTION_BEGIN (NULL);
630 if (! (0 <= length && length <= STRING_BYTES_BOUND)) 631 if (! (0 <= length && length <= STRING_BYTES_BOUND))
631 overflow_error (); 632 overflow_error ();
632 /* FIXME: AUTO_STRING_WITH_LEN requires STR to be NUL-terminated, 633 Lisp_Object lstr = make_unibyte_string (str, length);
633 but we shouldn't require that. */ 634 return lisp_to_value (env, module_decode (lstr));
634 AUTO_STRING_WITH_LEN (lstr, str, length);
635 return lisp_to_value (env, module_decode_copy (lstr));
636} 635}
637 636
638static emacs_value 637static emacs_value
@@ -947,6 +946,12 @@ module_encode (Lisp_Object string)
947} 946}
948 947
949static Lisp_Object 948static Lisp_Object
949module_decode (Lisp_Object string)
950{
951 return code_convert_string (string, Qutf_8_unix, Qt, false, true, true);
952}
953
954static Lisp_Object
950module_decode_copy (Lisp_Object string) 955module_decode_copy (Lisp_Object string)
951{ 956{
952 return code_convert_string (string, Qutf_8_unix, Qt, false, false, true); 957 return code_convert_string (string, Qutf_8_unix, Qt, false, false, true);