DEFSYM (Qignored, "ignored");
+ DEFSYM (Qutf_8_string_p, "utf-8-string-p");
+
defsubr (&Scoding_system_p);
defsubr (&Sread_coding_system);
defsubr (&Sread_non_nil_coding_system);
emacs_value, ptrdiff_t *);
static bool module_assertions = false;
+\f
+
+/* Small helper functions. */
+
+/* Interprets the string at STR with length LEN as UTF-8 string.
+ Signals an error if it's not a valid UTF-8 string. */
+
+static Lisp_Object
+module_decode_utf_8 (const char *str, ptrdiff_t len)
+{
+ /* We set HANDLE-8-BIT and HANDLE-OVER-UNI to nil to signal an error
+ if the argument is not a valid UTF-8 string. While it isn't
+ documented how make_string and make_function behave in this case,
+ signaling an error is the most defensive and obvious reaction. */
+ Lisp_Object s = decode_string_utf_8 (Qnil, str, len, Qnil, false, Qnil, Qnil);
+ CHECK_TYPE (!NILP (s), Qutf_8_string_p, make_string_from_utf8 (str, len));
+ return s;
+}
+
\f
/* Convenience macros for non-local exit handling. */
function->finalizer = NULL;
if (docstring)
- function->documentation = build_string_from_utf8 (docstring);
+ function->documentation
+ = module_decode_utf_8 (docstring, strlen (docstring));
Lisp_Object result;
XSET_MODULE_FUNCTION (result, function);
MODULE_FUNCTION_BEGIN (NULL);
if (! (0 <= len && len <= STRING_BYTES_BOUND))
overflow_error ();
- Lisp_Object lstr = make_string_from_utf8 (str, len);
+ Lisp_Object lstr = module_decode_utf_8 (str, len);
return lisp_to_value (env, lstr);
}
DEFSYM (Qstring_without_embedded_nulls_p, "string-without-embedded-nulls-p");
DEFSYM (Qjson_value_p, "json-value-p");
- DEFSYM (Qutf_8_string_p, "utf-8-string-p");
DEFSYM (Qjson_error, "json-error");
DEFSYM (Qjson_out_of_memory, "json-out-of-memory");