From b97cbf16884532dd501c4f0fdb346e19a4c54783 Mon Sep 17 00:00:00 2001 From: Abdulaziz Ghuloum Date: Mon, 6 Apr 2009 09:59:07 +0300 Subject: [PATCH] Fixed environ. The procedure environ takes no arguments and returns an association list where both keys and values and strings found in the posix environment. --- scheme/ikarus.posix.ss | 28 ++++++++++++++-------------- scheme/last-revision | 2 +- scheme/makefile.ss | 1 + src/ikarus-runtime.c | 15 +++++++++------ 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/scheme/ikarus.posix.ss b/scheme/ikarus.posix.ss index db8fd04..15d93d4 100644 --- a/scheme/ikarus.posix.ss +++ b/scheme/ikarus.posix.ss @@ -371,22 +371,22 @@ busted)) - (define environ (lambda args (die 'environ "busted!"))) - (define environ^ + (define environ (lambda () (map - (lambda (s) - (define (loc= s i n) - (cond - [(fx= i n) i] - [(char=? (string-ref s i) #\=) i] - [else (loc= s (fx+ i 1) n)])) - (let ([n (string-length s)]) - (let ([i (loc= s 0 n)]) - (cons (substring s 0 i) - (if (fx< (fxadd1 i) n) - (substring s (fxadd1 i) n) - ""))))) + (lambda (bv) + (let ([s (utf8->string bv)]) + (define (loc= s i n) + (cond + [(fx= i n) i] + [(char=? (string-ref s i) #\=) i] + [else (loc= s (fx+ i 1) n)])) + (let ([n (string-length s)]) + (let ([i (loc= s 0 n)]) + (cons (substring s 0 i) + (if (fx< (fxadd1 i) n) + (substring s (fxadd1 i) n) + "")))))) (foreign-call "ikrt_environ")))) (define (nanosleep secs nsecs) diff --git a/scheme/last-revision b/scheme/last-revision index 2a81cfe..461033f 100644 --- a/scheme/last-revision +++ b/scheme/last-revision @@ -1 +1 @@ -1746 +1748 diff --git a/scheme/makefile.ss b/scheme/makefile.ss index af7370a..dc27460 100755 --- a/scheme/makefile.ss +++ b/scheme/makefile.ss @@ -1357,6 +1357,7 @@ [getenv i] [setenv i] [unsetenv i] + [environ i] [nanosleep i] [char-ready? ] [load i] diff --git a/src/ikarus-runtime.c b/src/ikarus-runtime.c index f6bffe9..7ad8202 100644 --- a/src/ikarus-runtime.c +++ b/src/ikarus-runtime.c @@ -972,21 +972,24 @@ ikrt_unsetenv(ikptr key){ ikptr ikrt_environ(ikpcb* pcb){ - fprintf(stderr, "environ busted!\n"); - exit(-1); char** es = environ; int i; char* e; ikptr ac = null_object; + pcb->root0 = ∾ for(i=0; (e=es[i]); i++){ long int n = strlen(e); - ikptr s = ik_unsafe_alloc(pcb, align(n+disp_string_data+1)) + string_tag; - ref(s, -string_tag) = fix(n); - memcpy((char*)(long)(s+off_string_data), e, n+1); - ikptr p = ik_unsafe_alloc(pcb, pair_size) + pair_tag; + ikptr s = ik_safe_alloc(pcb, align(n+disp_bytevector_data+1)) + + bytevector_tag; + ref(s, -bytevector_tag) = fix(n); + memcpy((char*)(long)(s+off_bytevector_data), e, n+1); + pcb->root1 = &s; + ikptr p = ik_safe_alloc(pcb, pair_size) + pair_tag; + pcb->root1 = 0; ref(p, off_cdr) = ac; ref(p, off_car) = s; ac = p; } + pcb->root0 = 0; return ac; }