diff options
| author | Philipp Stephani | 2019-12-04 22:27:45 +0100 |
|---|---|---|
| committer | Philipp Stephani | 2019-12-04 22:27:45 +0100 |
| commit | 0e774d4f355b4f12a625da5ca9602d1ba876bcc1 (patch) | |
| tree | 207fd267295c00d407fa97bf91517131661e6c04 | |
| parent | d673f871f943a395720f7ceca8b3dcb7b44d50f3 (diff) | |
| download | emacs-0e774d4f355b4f12a625da5ca9602d1ba876bcc1.tar.gz emacs-0e774d4f355b4f12a625da5ca9602d1ba876bcc1.zip | |
Use new function encode_string_utf_8 for the module API, too
* src/emacs-module.c (module_encode): Remove.
(module_copy_string_contents): Use encode_string_utf_8.
(syms_of_module): Define symbol 'unicode-string-p'.
| -rw-r--r-- | src/emacs-module.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index 82c587fcbe9..2cd3fbd3df5 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -625,7 +625,21 @@ module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer, | |||
| 625 | Lisp_Object lisp_str = value_to_lisp (value); | 625 | Lisp_Object lisp_str = value_to_lisp (value); |
| 626 | CHECK_STRING (lisp_str); | 626 | CHECK_STRING (lisp_str); |
| 627 | 627 | ||
| 628 | Lisp_Object lisp_str_utf8 = module_encode (lisp_str); | 628 | /* We can set NOCOPY to true here because we only use the byte |
| 629 | sequence starting at SDATA and don't modify the original string | ||
| 630 | before copying out the data. | ||
| 631 | |||
| 632 | We set HANDLE-8-BIT and HANDLE-OVER-UNI to nil to signal an error | ||
| 633 | if the argument is not a valid Unicode string. While it isn't | ||
| 634 | documented how copy_string_contents behaves in this case, | ||
| 635 | signaling an error is the most defensive and obvious reaction. */ | ||
| 636 | Lisp_Object lisp_str_utf8 | ||
| 637 | = encode_string_utf_8 (lisp_str, Qnil, true, Qnil, Qnil); | ||
| 638 | |||
| 639 | /* Since we set HANDLE-8-BIT and HANDLE-OVER-UNI to nil, the return | ||
| 640 | value can be nil, and we have to check for that. */ | ||
| 641 | CHECK_TYPE (!NILP (lisp_str_utf8), Qunicode_string_p, lisp_str_utf8); | ||
| 642 | |||
| 629 | ptrdiff_t raw_size = SBYTES (lisp_str_utf8); | 643 | ptrdiff_t raw_size = SBYTES (lisp_str_utf8); |
| 630 | ptrdiff_t required_buf_size = raw_size + 1; | 644 | ptrdiff_t required_buf_size = raw_size + 1; |
| 631 | 645 | ||
| @@ -1136,12 +1150,6 @@ module_out_of_memory (emacs_env *env) | |||
| 1136 | XCDR (Vmemory_signal_data)); | 1150 | XCDR (Vmemory_signal_data)); |
| 1137 | } | 1151 | } |
| 1138 | 1152 | ||
| 1139 | static Lisp_Object | ||
| 1140 | module_encode (Lisp_Object string) | ||
| 1141 | { | ||
| 1142 | return code_convert_string (string, Qutf_8_unix, Qt, true, true, true); | ||
| 1143 | } | ||
| 1144 | |||
| 1145 | 1153 | ||
| 1146 | /* Value conversion. */ | 1154 | /* Value conversion. */ |
| 1147 | 1155 | ||
| @@ -1485,6 +1493,7 @@ syms_of_module (void) | |||
| 1485 | build_pure_c_string ("Invalid function arity")); | 1493 | build_pure_c_string ("Invalid function arity")); |
| 1486 | 1494 | ||
| 1487 | DEFSYM (Qmodule_function_p, "module-function-p"); | 1495 | DEFSYM (Qmodule_function_p, "module-function-p"); |
| 1496 | DEFSYM (Qunicode_string_p, "unicode-string-p"); | ||
| 1488 | 1497 | ||
| 1489 | defsubr (&Smodule_load); | 1498 | defsubr (&Smodule_load); |
| 1490 | } | 1499 | } |