emacs-diffs
[Top][All Lists]
Advanced

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

scratch/comp-static-data 80ea23618da 06/16: Avoid directly accessing the


From: Vibhav Pant
Subject: scratch/comp-static-data 80ea23618da 06/16: Avoid directly accessing the size field in a Lisp String.
Date: Thu, 19 Jan 2023 12:44:35 -0500 (EST)

branch: scratch/comp-static-data
commit 80ea23618da0e06a70c6f1063327ff8781dc0fc4
Author: Vibhav Pant <vibhavp@gmail.com>
Commit: Vibhav Pant <vibhavp@gmail.com>

    Avoid directly accessing the size field in a Lisp String.
    
    * src/lisp.h (STRING_CHARS): New function.
    * src/casefiddle.c (case_character_impl): Use STRING_CHARS to get the
    number of characters for str.
---
 src/casefiddle.c |  2 +-
 src/lisp.h       | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/casefiddle.c b/src/casefiddle.c
index e8ae2e276fc..d3df3390f3f 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -140,7 +140,7 @@ case_character_impl (struct casing_str_buf *buf,
           struct Lisp_String *str = XSTRING (prop);
           if (STRING_BYTES (str) <= sizeof buf->data)
            {
-             buf->len_chars = str->u.s.size;
+             buf->len_chars = STRING_CHARS (str);
              buf->len_bytes = STRING_BYTES (str);
              memcpy (buf->data, str->u.s.data, buf->len_bytes);
              return 1;
diff --git a/src/lisp.h b/src/lisp.h
index 2ceffd47345..a0b42c3a6a3 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1740,6 +1740,17 @@ STRING_BYTES (struct Lisp_String *s)
   return nbytes;
 }
 
+INLINE ptrdiff_t
+STRING_CHARS (struct Lisp_String *s)
+{
+  ptrdiff_t nchars = s->u.s.size;
+#ifdef HAVE_STATIC_LISP_GLOBALS
+  nchars &= ~ARRAY_MARK_FLAG;
+#endif
+  eassume (0 <= nchars);
+  return nchars;
+}
+
 INLINE ptrdiff_t
 SBYTES (Lisp_Object string)
 {



reply via email to

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