diff options
| author | Eli Zaretskii | 2015-11-23 20:08:01 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2015-11-23 20:08:01 +0200 |
| commit | 345bc61796b4f0712fa45d47ed14692c0de628ea (patch) | |
| tree | 370518e8bd89d08c46411d607eba3c6a1cd48831 | |
| parent | 33223605144c61709a6d3c2a3c96f0b7451512c6 (diff) | |
| download | emacs-345bc61796b4f0712fa45d47ed14692c0de628ea.tar.gz emacs-345bc61796b4f0712fa45d47ed14692c0de628ea.zip | |
Improve how non-ASCII strings are accepted from modules
* src/emacs-module.c (module_make_function, module_make_string):
Build a unibyte Lisp string and then decode it by UTF-8, instead
of building a multibyte string without decoding. This is more
tolerant to deviations from UTF-8.
| -rw-r--r-- | src/emacs-module.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index 643633935ca..a24d85537bd 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -393,10 +393,8 @@ module_make_function (emacs_env *env, ptrdiff_t min_arity, ptrdiff_t max_arity, | |||
| 393 | else | 393 | else |
| 394 | { | 394 | { |
| 395 | ptrdiff_t nbytes = strlen (documentation); | 395 | ptrdiff_t nbytes = strlen (documentation); |
| 396 | ptrdiff_t nchars, ignored_nbytes; | 396 | doc = make_unibyte_string (documentation, nbytes); |
| 397 | parse_str_as_multibyte ((unsigned char const *) documentation, nbytes, | 397 | doc = code_convert_string_norecord (doc, Qutf_8, false); |
| 398 | &nchars, &ignored_nbytes); | ||
| 399 | doc = make_multibyte_string (documentation, nchars, nbytes); | ||
| 400 | } | 398 | } |
| 401 | 399 | ||
| 402 | Lisp_Object ret = list4 (Qlambda, | 400 | Lisp_Object ret = list4 (Qlambda, |
| @@ -555,8 +553,7 @@ module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer, | |||
| 555 | } | 553 | } |
| 556 | 554 | ||
| 557 | *length = required_buf_size; | 555 | *length = required_buf_size; |
| 558 | memcpy (buffer, SDATA (lisp_str_utf8), raw_size); | 556 | memcpy (buffer, SDATA (lisp_str_utf8), raw_size + 1); |
| 559 | buffer[raw_size] = 0; | ||
| 560 | 557 | ||
| 561 | return true; | 558 | return true; |
| 562 | } | 559 | } |
| @@ -572,10 +569,9 @@ module_make_string (emacs_env *env, const char *str, ptrdiff_t length) | |||
| 572 | module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil); | 569 | module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil); |
| 573 | return NULL; | 570 | return NULL; |
| 574 | } | 571 | } |
| 575 | ptrdiff_t nchars, ignored_nbytes; | 572 | Lisp_Object lstr = make_unibyte_string (str, length); |
| 576 | parse_str_as_multibyte ((unsigned char const *) str, length, | 573 | return lisp_to_value (env, |
| 577 | &nchars, &ignored_nbytes); | 574 | code_convert_string_norecord (lstr, Qutf_8, false)); |
| 578 | return lisp_to_value (env, make_multibyte_string (str, nchars, length)); | ||
| 579 | } | 575 | } |
| 580 | 576 | ||
| 581 | static emacs_value | 577 | static emacs_value |