diff options
| author | Paul Eggert | 2025-07-24 19:41:01 -0700 |
|---|---|---|
| committer | Paul Eggert | 2025-07-24 22:13:47 -0700 |
| commit | d7e818608027552aa084eb37e3bf39deedff4921 (patch) | |
| tree | 1e22eaa5f9249959a187f8a0d7400a57ce38e103 /src | |
| parent | b01b521717bed33323142aa791a22d46b8af11ad (diff) | |
| download | emacs-d7e818608027552aa084eb37e3bf39deedff4921.tar.gz emacs-d7e818608027552aa084eb37e3bf39deedff4921.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lisp.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/lisp.h b/src/lisp.h index b89a4647725..fd3ff7c6b76 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -5811,20 +5811,32 @@ enum | |||
| 5811 | an expression that should not have side effects. | 5811 | an expression that should not have side effects. |
| 5812 | STR's value is not necessarily copied. The resulting Lisp string | 5812 | STR's value is not necessarily copied. The resulting Lisp string |
| 5813 | should not be modified or given text properties or made visible to | 5813 | should not be modified or given text properties or made visible to |
| 5814 | user code. */ | 5814 | user code, and its lifetime is that of the enclosing C block. */ |
| 5815 | 5815 | ||
| 5816 | #define AUTO_STRING(name, str) \ | 5816 | #define AUTO_STRING(name, str) \ |
| 5817 | AUTO_STRING_WITH_LEN (name, str, strlen (str)) | 5817 | AUTO_STRING_WITH_LEN (name, str, strlen (str)) |
| 5818 | 5818 | ||
| 5819 | /* Declare NAME as an auto Lisp string if possible, a GC-based one if not. | 5819 | /* Declare NAME as an auto Lisp string if possible, a GC-based one if not. |
| 5820 | Take its unibyte value from the null-terminated string STR with length LEN. | 5820 | Take its unibyte value from the null-terminated string STR with length LEN. |
| 5821 | STR may have side effects and may contain null bytes. | 5821 | STR and LEN may have side effects and STR may contain null bytes. |
| 5822 | STR's value is not necessarily copied. The resulting Lisp string | 5822 | STR's value is not necessarily copied. The resulting Lisp string |
| 5823 | should not be modified or given text properties or made visible to | 5823 | should not be modified or given text properties or made visible to |
| 5824 | user code. */ | 5824 | user code, and its lifetime is that of the enclosing C block. */ |
| 5825 | 5825 | ||
| 5826 | #define AUTO_STRING_WITH_LEN(name, str, len) \ | 5826 | #define AUTO_STRING_WITH_LEN(name, str, len) \ |
| 5827 | Lisp_Object name = \ | 5827 | Lisp_Object name = \ |
| 5828 | AUTO_STR_WITH_LEN (str, len) | ||
| 5829 | |||
| 5830 | /* Yield an auto Lisp string if possible, a GC-based one if not. | ||
| 5831 | This is like AUTO_STRING, except without a name. */ | ||
| 5832 | |||
| 5833 | #define AUTO_STR(str) \ | ||
| 5834 | AUTO_STR_WITH_LEN (str, strlen (str)) | ||
| 5835 | |||
| 5836 | /* Yield an auto Lisp string if possible, a GC-based one if not. | ||
| 5837 | This is like AUTO_STRING_WITH_LEN, except without a name. */ | ||
| 5838 | |||
| 5839 | #define AUTO_STR_WITH_LEN(str, len) \ | ||
| 5828 | (USE_STACK_STRING \ | 5840 | (USE_STACK_STRING \ |
| 5829 | ? (make_lisp_ptr \ | 5841 | ? (make_lisp_ptr \ |
| 5830 | ((&(struct Lisp_String) {{{len, -1, 0, (unsigned char *) (str)}}}), \ | 5842 | ((&(struct Lisp_String) {{{len, -1, 0, (unsigned char *) (str)}}}), \ |