------------------------------------------------------------------
From:jinser <[email protected]>
Send Time:2025 Sep. 17 (Wed.) 16:34
To:"沈达"<[email protected]>
Subject:Fwd: [PATCH] Fix R7RS newline escaping in string serialization
---------- Forwarded message ---------
发件人: Jinser Kafka <[email protected]>
Date: 2025年9月17日周三 14:42
Subject: [PATCH] Fix R7RS newline escaping in string serialization
To: <[email protected] <mailto:[email protected] >>
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
_______________________________________________
Cmdist mailing list
[email protected]
https://cm-mail.stanford.edu/mailman/listinfo/cmdist

Reply via email to