From: Paul Eggert Date: Fri, 25 Jul 2025 02:41:01 +0000 (-0700) Subject: Refactor to allow nameless auto strings X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ec5301ac6be7817c55c55471400a861bab1bf0a4;p=emacs.git Refactor to allow nameless auto strings * src/lisp.h (AUTO_STR, AUTO_STR_WITH_LEN): New macros. Long ago this sort of thing would have been a no-no because we needed to GCPRO the strings. However, GCPRO went away a decade ago. (cherry picked from commit d7e818608027552aa084eb37e3bf39deedff4921) --- diff --git a/src/lisp.h b/src/lisp.h index 95dbe2b83c8..1312660faee 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -5811,20 +5811,32 @@ enum an expression that should not have side effects. STR's value is not necessarily copied. The resulting Lisp string should not be modified or given text properties or made visible to - user code. */ + user code, and its lifetime is that of the enclosing C block. */ #define AUTO_STRING(name, str) \ AUTO_STRING_WITH_LEN (name, str, strlen (str)) /* Declare NAME as an auto Lisp string if possible, a GC-based one if not. Take its unibyte value from the null-terminated string STR with length LEN. - STR may have side effects and may contain null bytes. + STR and LEN may have side effects and STR may contain null bytes. STR's value is not necessarily copied. The resulting Lisp string should not be modified or given text properties or made visible to - user code. */ + user code, and its lifetime is that of the enclosing C block. */ #define AUTO_STRING_WITH_LEN(name, str, len) \ Lisp_Object name = \ + AUTO_STR_WITH_LEN (str, len) + +/* Yield an auto Lisp string if possible, a GC-based one if not. + This is like AUTO_STRING, except without a name. */ + +#define AUTO_STR(str) \ + AUTO_STR_WITH_LEN (str, strlen (str)) + +/* Yield an auto Lisp string if possible, a GC-based one if not. + This is like AUTO_STRING_WITH_LEN, except without a name. */ + +#define AUTO_STR_WITH_LEN(str, len) \ (USE_STACK_STRING \ ? (make_lisp_ptr \ ((&(struct Lisp_String) {{{len, -1, 0, (unsigned char *) (str)}}}), \