[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master ca3ad97 1/2: Use utf-8-unix for coding system conve
From: |
Philipp Stephani |
Subject: |
[Emacs-diffs] master ca3ad97 1/2: Use utf-8-unix for coding system conversions in the module API. |
Date: |
Mon, 22 Apr 2019 09:44:57 -0400 (EDT) |
branch: master
commit ca3ad9746da5ced05e8fd692731ffe4dcb52d7e8
Author: Philipp Stephani <address@hidden>
Commit: Philipp Stephani <address@hidden>
Use utf-8-unix for coding system conversions in the module API.
Factor out conversions into helper functions to provide a simpler
interface.
* src/emacs-module.c (module_encode, module_decode_copy): New helper
functions.
(module_make_function, module_copy_string_contents)
(module_make_string): Use them.
---
src/emacs-module.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/src/emacs-module.c b/src/emacs-module.c
index 68bee70..8fd2a87 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -211,6 +211,8 @@ static void module_out_of_memory (emacs_env *);
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_copy (Lisp_Object);
static bool module_assertions = false;
@@ -496,8 +498,7 @@ module_make_function (emacs_env *env, ptrdiff_t min_arity,
ptrdiff_t max_arity,
if (documentation)
{
AUTO_STRING (unibyte_doc, documentation);
- function->documentation =
- code_convert_string_norecord (unibyte_doc, Qutf_8, false);
+ function->documentation = module_decode_copy (unibyte_doc);
}
Lisp_Object result;
@@ -600,7 +601,7 @@ module_copy_string_contents (emacs_env *env, emacs_value
value, char *buffer,
Lisp_Object lisp_str = value_to_lisp (value);
CHECK_STRING (lisp_str);
- Lisp_Object lisp_str_utf8 = ENCODE_UTF_8 (lisp_str);
+ Lisp_Object lisp_str_utf8 = module_encode (lisp_str);
ptrdiff_t raw_size = SBYTES (lisp_str_utf8);
ptrdiff_t required_buf_size = raw_size + 1;
@@ -631,8 +632,7 @@ module_make_string (emacs_env *env, const char *str,
ptrdiff_t length)
/* 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,
- code_convert_string_norecord (lstr, Qutf_8, false));
+ return lisp_to_value (env, module_decode_copy (lstr));
}
static emacs_value
@@ -940,6 +940,18 @@ module_out_of_memory (emacs_env *env)
XCDR (Vmemory_signal_data));
}
+static Lisp_Object
+module_encode (Lisp_Object string)
+{
+ return code_convert_string (string, Qutf_8_unix, Qt, true, true, true);
+}
+
+static Lisp_Object
+module_decode_copy (Lisp_Object string)
+{
+ return code_convert_string (string, Qutf_8_unix, Qt, false, false, true);
+}
+
/* Value conversion. */