diff options
author | Andy Wingo <wingo@pobox.com> | 2012-01-30 19:59:08 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2012-01-30 20:27:35 +0100 |
commit | dfadcf85cb3ae9133dece6bc39ed03dd25323d6e (patch) | |
tree | 93c918a793ee86c8406fd1bac521ea2b870361cf /libguile/macros.c | |
parent | 252acfe8e70ac4c7d325588ffea1905fcf6f86b2 (diff) | |
parent | e1fbe716e8596b7027af57623ebc72a0c6393187 (diff) |
Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
libguile/debug.h
module/ice-9/psyntax-pp.scm
module/ice-9/psyntax.scm
module/language/tree-il/peval.scm
module/language/tree-il/primitives.scm
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 7423e9758..34aa60c83 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); } /* |