diff options
| author | Philipp Stephani | 2020-01-13 00:07:07 +0100 |
|---|---|---|
| committer | Philipp Stephani | 2020-01-13 00:08:32 +0100 |
| commit | 3252f3149673bbd6919d5d9a5a672e2f3730741d (patch) | |
| tree | d3f77ec7ecf0595590f1f1f304fd6ea33ab9a1b7 /src | |
| parent | 41d9d51cf5ac5b76c09802388e1691cf489d9d9d (diff) | |
| download | emacs-3252f3149673bbd6919d5d9a5a672e2f3730741d.tar.gz emacs-3252f3149673bbd6919d5d9a5a672e2f3730741d.zip | |
Use decode_string_utf_8 in emacs-module.c.
Now that decode_string_utf_8 is available, we can use it to signal
errors on invalid input.
* src/coding.c (syms_of_coding): Move Qutf_8_string_p from json.c
since it’s now used outside json.c.
* src/emacs-module.c (module_decode_utf_8): New helper function.
(module_make_function, module_copy_string_contents): Use it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/coding.c | 2 | ||||
| -rw-r--r-- | src/emacs-module.c | 24 | ||||
| -rw-r--r-- | src/json.c | 1 |
3 files changed, 24 insertions, 3 deletions
diff --git a/src/coding.c b/src/coding.c index ed755b1afcf..8b54281c0bf 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -11745,6 +11745,8 @@ syms_of_coding (void) | |||
| 11745 | 11745 | ||
| 11746 | DEFSYM (Qignored, "ignored"); | 11746 | DEFSYM (Qignored, "ignored"); |
| 11747 | 11747 | ||
| 11748 | DEFSYM (Qutf_8_string_p, "utf-8-string-p"); | ||
| 11749 | |||
| 11748 | defsubr (&Scoding_system_p); | 11750 | defsubr (&Scoding_system_p); |
| 11749 | defsubr (&Sread_coding_system); | 11751 | defsubr (&Sread_coding_system); |
| 11750 | defsubr (&Sread_non_nil_coding_system); | 11752 | defsubr (&Sread_non_nil_coding_system); |
diff --git a/src/emacs-module.c b/src/emacs-module.c index f40ca931fa9..60f16418efa 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -213,6 +213,25 @@ static bool value_storage_contains_p (const struct emacs_value_storage *, | |||
| 213 | 213 | ||
| 214 | static bool module_assertions = false; | 214 | static bool module_assertions = false; |
| 215 | 215 | ||
| 216 | |||
| 217 | /* Small helper functions. */ | ||
| 218 | |||
| 219 | /* Interprets the string at STR with length LEN as UTF-8 string. | ||
| 220 | Signals an error if it's not a valid UTF-8 string. */ | ||
| 221 | |||
| 222 | static Lisp_Object | ||
| 223 | module_decode_utf_8 (const char *str, ptrdiff_t len) | ||
| 224 | { | ||
| 225 | /* We set HANDLE-8-BIT and HANDLE-OVER-UNI to nil to signal an error | ||
| 226 | if the argument is not a valid UTF-8 string. While it isn't | ||
| 227 | documented how make_string and make_function behave in this case, | ||
| 228 | signaling an error is the most defensive and obvious reaction. */ | ||
| 229 | Lisp_Object s = decode_string_utf_8 (Qnil, str, len, Qnil, false, Qnil, Qnil); | ||
| 230 | CHECK_TYPE (!NILP (s), Qutf_8_string_p, make_string_from_utf8 (str, len)); | ||
| 231 | return s; | ||
| 232 | } | ||
| 233 | |||
| 234 | |||
| 216 | /* Convenience macros for non-local exit handling. */ | 235 | /* Convenience macros for non-local exit handling. */ |
| 217 | 236 | ||
| 218 | /* FIXME: The following implementation for non-local exit handling | 237 | /* FIXME: The following implementation for non-local exit handling |
| @@ -521,7 +540,8 @@ module_make_function (emacs_env *env, ptrdiff_t min_arity, ptrdiff_t max_arity, | |||
| 521 | function->finalizer = NULL; | 540 | function->finalizer = NULL; |
| 522 | 541 | ||
| 523 | if (docstring) | 542 | if (docstring) |
| 524 | function->documentation = build_string_from_utf8 (docstring); | 543 | function->documentation |
| 544 | = module_decode_utf_8 (docstring, strlen (docstring)); | ||
| 525 | 545 | ||
| 526 | Lisp_Object result; | 546 | Lisp_Object result; |
| 527 | XSET_MODULE_FUNCTION (result, function); | 547 | XSET_MODULE_FUNCTION (result, function); |
| @@ -694,7 +714,7 @@ module_make_string (emacs_env *env, const char *str, ptrdiff_t len) | |||
| 694 | MODULE_FUNCTION_BEGIN (NULL); | 714 | MODULE_FUNCTION_BEGIN (NULL); |
| 695 | if (! (0 <= len && len <= STRING_BYTES_BOUND)) | 715 | if (! (0 <= len && len <= STRING_BYTES_BOUND)) |
| 696 | overflow_error (); | 716 | overflow_error (); |
| 697 | Lisp_Object lstr = make_string_from_utf8 (str, len); | 717 | Lisp_Object lstr = module_decode_utf_8 (str, len); |
| 698 | return lisp_to_value (env, lstr); | 718 | return lisp_to_value (env, lstr); |
| 699 | } | 719 | } |
| 700 | 720 | ||
diff --git a/src/json.c b/src/json.c index 2e50ce514fd..30027675580 100644 --- a/src/json.c +++ b/src/json.c | |||
| @@ -1121,7 +1121,6 @@ syms_of_json (void) | |||
| 1121 | 1121 | ||
| 1122 | DEFSYM (Qstring_without_embedded_nulls_p, "string-without-embedded-nulls-p"); | 1122 | DEFSYM (Qstring_without_embedded_nulls_p, "string-without-embedded-nulls-p"); |
| 1123 | DEFSYM (Qjson_value_p, "json-value-p"); | 1123 | DEFSYM (Qjson_value_p, "json-value-p"); |
| 1124 | DEFSYM (Qutf_8_string_p, "utf-8-string-p"); | ||
| 1125 | 1124 | ||
| 1126 | DEFSYM (Qjson_error, "json-error"); | 1125 | DEFSYM (Qjson_error, "json-error"); |
| 1127 | DEFSYM (Qjson_out_of_memory, "json-out-of-memory"); | 1126 | DEFSYM (Qjson_out_of_memory, "json-out-of-memory"); |