diff options
author | Andy Wingo <wingo@pobox.com> | 2012-01-26 11:52:06 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2012-01-26 12:08:58 +0100 |
commit | f9685f437312ea790981373ddc375b2a26ba9c4f (patch) | |
tree | cca75600546c5ebb7b8b1bbb5994e55567bef67a /libguile/macros.c | |
parent | 4496c9c1e8c5620fd3b4eaacc7f1f8e35829b32d (diff) |
globally unique marks and labels using syntax-session-id
* libguile/macros.c (scm_init_macros): Add definition of new
syntax-session-id helper.
* module/ice-9/psyntax.scm: Capture a reference to syntax-session-id at
boot time. Uniquify marks and labels using the session id.
* module/ice-9/boot-9.scm: Shunt syntax-session-id off to (system
syntax) once we finished booting.
* module/ice-9/compile-psyntax.scm: Override syntax-session-id when
remaking psyntax to avoid spurious diffs.
* module/ice-9/psyntax-pp.scm: Regenerate.
Diffstat (limited to 'libguile/macros.c')
-rw-r--r-- | libguile/macros.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libguile/macros.c b/libguile/macros.c index 556e60f57..a0b140126 100644 --- a/libguile/macros.c +++ b/libguile/macros.c @@ -177,12 +177,46 @@ SCM_DEFINE (scm_macro_binding, "macro-binding", 1, 0, 0, #undef FUNC_NAME +static SCM syntax_session_id; + +#define SESSION_ID_LENGTH 22 /* bytes */ +#define BASE64_RADIX_BITS 6 +#define BASE64_RADIX (1 << (BASE64_RADIX_BITS)) +#define BASE64_MASK (BASE64_RADIX - 1) + +static SCM +fresh_syntax_session_id (void) +{ + static const char base64[BASE64_RADIX] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$@"; + + unsigned char digit_buf[SESSION_ID_LENGTH]; + char char_buf[SESSION_ID_LENGTH]; + size_t i; + + scm_i_random_bytes_from_platform (digit_buf, SESSION_ID_LENGTH); + for (i = 0; i < SESSION_ID_LENGTH; ++i) + char_buf[i] = base64[digit_buf[i] & BASE64_MASK]; + + return scm_from_latin1_stringn (char_buf, SESSION_ID_LENGTH); +} + +static SCM +scm_syntax_session_id (void) +{ + return syntax_session_id; +} + + void scm_init_macros () { scm_tc16_macro = scm_make_smob_type ("macro", 0); scm_set_smob_print (scm_tc16_macro, macro_print); #include "libguile/macros.x" + + syntax_session_id = fresh_syntax_session_id(); + scm_c_define_gsubr ("syntax-session-id", 0, 0, 0, scm_syntax_session_id); } /* |