emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master b929bdaeb6: Fix Fchar_syntax for non-ASCII in unibyte buffers


From: Mattias Engdegård
Subject: master b929bdaeb6: Fix Fchar_syntax for non-ASCII in unibyte buffers
Date: Thu, 20 Jan 2022 05:44:32 -0500 (EST)

branch: master
commit b929bdaeb6bcb919d4d1a5d02713cdcac3fc44d0
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Fix Fchar_syntax for non-ASCII in unibyte buffers
    
    Fchar_syntax did not convert unibyte characters to multibyte when the
    current buffer was unibyte, in contrast to `char-syntax` in
    byte-compiled code (bug#53260).
    
    * src/bytecode.c (exec_byte_code): Call out to Fchar_syntax;
    the dynamic frequency is too low to justify inlining here, and it
    did lead to implementations diverging.
    * src/syntax.c (Fchar_syntax): Convert non-ASCII unibyte values to
    multibyte.
    * test/src/syntax-tests.el (syntax-char-syntax): New test.
---
 src/bytecode.c           |  8 +-------
 src/syntax.c             |  5 +++--
 test/src/syntax-tests.el | 15 +++++++++++++++
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/bytecode.c b/src/bytecode.c
index 472992be18..b7e65d05ae 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -1167,13 +1167,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, 
Lisp_Object maxdepth,
          NEXT;
 
        CASE (Bchar_syntax):
-         {
-           CHECK_CHARACTER (TOP);
-           int c = XFIXNAT (TOP);
-           if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
-             c = make_char_multibyte (c);
-           XSETFASTINT (TOP, syntax_code_spec[SYNTAX (c)]);
-         }
+         TOP = Fchar_syntax (TOP);
          NEXT;
 
        CASE (Bbuffer_substring):
diff --git a/src/syntax.c b/src/syntax.c
index 9df878b8ed..13c36fdf3c 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -1101,10 +1101,11 @@ this is probably the wrong function to use, because it 
can't take
 `syntax-after' instead.  */)
   (Lisp_Object character)
 {
-  int char_int;
   CHECK_CHARACTER (character);
-  char_int = XFIXNUM (character);
+  int char_int = XFIXNAT (character);
   SETUP_BUFFER_SYNTAX_TABLE ();
+  if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
+    char_int = make_char_multibyte (char_int);
   return make_fixnum (syntax_code_spec[SYNTAX (char_int)]);
 }
 
diff --git a/test/src/syntax-tests.el b/test/src/syntax-tests.el
index 3b9f21cde3..751a900a23 100644
--- a/test/src/syntax-tests.el
+++ b/test/src/syntax-tests.el
@@ -506,4 +506,19 @@ the `parse-partial-sexp's are expected to stop.  See
     (should (parse-partial-sexp 1 1))
     (should-error (parse-partial-sexp 2 1))))
 
+(ert-deftest syntax-char-syntax ()
+  ;; Verify that char-syntax behaves identically in interpreted and
+  ;; byte-compiled code (bug#53260).
+  (let ((cs (byte-compile (lambda (x) (char-syntax x)))))
+    ;; Use a unibyte buffer with a syntax table using symbol syntax
+    ;; for raw byte 128.
+    (with-temp-buffer
+      (set-buffer-multibyte nil)
+      (let ((st (make-syntax-table)))
+        (modify-syntax-entry (unibyte-char-to-multibyte 128) "_" st)
+        (set-syntax-table st)
+        (should (equal (eval '(char-syntax 128) t) ?_))
+        (should (equal (funcall cs 128) ?_))))
+    (list (char-syntax 128) (funcall cs 128))))
+
 ;;; syntax-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]