[CM] [PATCH] Fix R7RS newline escaping in string serialization

Da Shen da at liii.pro
Wed Sep 17 01:36:51 PDT 2025


------------------------------------------------------------------
From:jinser <aimer at purejs.icu>
Send Time:2025 Sep. 17 (Wed.) 16:34
To:"沈达"<da at liii.pro>
Subject:Fwd: [PATCH] Fix R7RS newline escaping in string serialization
---------- Forwarded message ---------
发件人: Jinser Kafka <aimer at purejs.icu>
Date: 2025年9月17日周三 14:42
Subject: [PATCH] Fix R7RS newline escaping in string serialization
To: <997460364 at qq.com <mailto:997460364 at qq.com >>
In R7RS mode, newlines in strings should be escaped as \n to ensure
 proper serialization and readback compatibility. This change:
 - Makes slashify_table escape newlines when WITH_R7RS is defined
 - Adds newline case to slashify_string_to_port for proper \n output
 This fixes issues where strings containing newlines would not serialize
 correctly in R7RS mode, breaking the round-trip property of write/read.
 ---
 s7.c | 6 ++++++
 1 file changed, 6 insertions(+)
 diff --git a/s7.c b/s7.c
 index 273f6d1..4534a01 100644
 --- a/s7.c
 +++ b/s7.c
 @@ -15584,7 +15584,12 @@ static void init_ctables(void)
 /* for (int32_t i = 127; i < 160; i++) slashify_table[i] = true; */ /* 6-Apr-24 for utf-8, but this has no effect on s7test?? */
 slashify_table[(uint8_t)'\\'] = true;
 slashify_table[(uint8_t)'"'] = true;
 +#if WITH_R7RS
 + /* In R7RS mode, newlines should be escaped to ensure proper serialization */
 + slashify_table[(uint8_t)'\n'] = true;
 +#else
 slashify_table[(uint8_t)'\n'] = false;
 +#endif
 for (int32_t i = 0; i < CTABLE_SIZE; i++)
 symbol_slashify_table[i] = ((slashify_table[i]) || (!char_ok_in_a_name[i])); /* force use of (symbol ...) for cases like '(ab) as symbol */
 @@ -33935,6 +33940,7 @@ static void slashify_string_to_port(s7_scheme *sc, s7_pointer port, const char *
 case '\'': port_write_character(port)(sc, '\'', port); break;
 case '\t': port_write_character(port)(sc, 't', port); break;
 case '\r': port_write_character(port)(sc, 'r', port); break;
 + case '\n': port_write_character(port)(sc, 'n', port); break;
 case '\b': port_write_character(port)(sc, 'b', port); break;
 case '\f': port_write_character(port)(sc, 'f', port); break;
 case '\?': port_write_character(port)(sc, '?', port); break;
 -- 
 2.51.0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20250917/3e95f284/attachment.html>


More information about the Cmdist mailing list