>From 785903ca29d755a4660148dae5cca7c211f488ed Mon Sep 17 00:00:00 2001 From: Peter Bex
Date: Fri, 1 Mar 2013 20:41:49 +0100 Subject: [PATCH] Remove ##sys#get-argument and simplify get-environment-variable by using the FFI instead of hand-rolled C functions; deprecated these underlying C functions This should make the code easier to understand, more maintainable and reduce bloat. It is also a more structural approach of preventing security problems like those fixed by d9f2ad87b42f by using one vetted underlying system; the FFI conversion procedures. Signed-off-by: Christian Kellermann --- NEWS | 3 +++ chicken.h | 4 ++-- library.scm | 16 +++++++++++----- runtime.c | 16 ++++++++++------ 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index a5f9054..03df87c 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,9 @@ - Runtime system - Special events in poll() are now handled, avoiding hangs in threaded apps. +- C API + - Deprecated C_get_argument[_2] and C_get_environment_variable[_2] functions. + 4.8.1 - Security fixes diff --git a/chicken.h b/chicken.h index 566aad3..2b9030a 100644 --- a/chicken.h +++ b/chicken.h @@ -1782,14 +1782,14 @@ C_fctexport void C_ccall C_quotient(C_word c, C_word closure, C_word k, C_word n C_fctexport void C_ccall C_number_to_string(C_word c, C_word closure, C_word k, C_word num, ...) C_noret; C_fctexport void C_ccall C_fixnum_to_string(C_word c, C_word closure, C_word k, C_word num) C_noret; C_fctexport void C_ccall C_get_argv(C_word c, C_word closure, C_word k) C_noret; /* OBSOLETE */ -C_fctexport void C_ccall C_get_argument(C_word c, C_word closure, C_word k, C_word index) C_noret; +C_fctexport void C_ccall C_get_argument(C_word c, C_word closure, C_word k, C_word index) C_noret; /* OBSOLETE */ C_fctexport void C_ccall C_make_structure(C_word c, C_word closure, C_word k, C_word type, ...) C_noret; C_fctexport void C_ccall C_make_symbol(C_word c, C_word closure, C_word k, C_word name) C_noret; C_fctexport void C_ccall C_make_pointer(C_word c, C_word closure, C_word k) C_noret; C_fctexport void C_ccall C_make_tagged_pointer(C_word c, C_word closure, C_word k, C_word tag) C_noret; C_fctexport void C_ccall C_ensure_heap_reserve(C_word c, C_word closure, C_word k, C_word n) C_noret; C_fctexport void C_ccall C_return_to_host(C_word c, C_word closure, C_word k) C_noret; -C_fctexport void C_ccall C_get_environment_variable(C_word c, C_word closure, C_word k, C_word name) C_noret; +C_fctexport void C_ccall C_get_environment_variable(C_word c, C_word closure, C_word k, C_word name) C_noret; /* OBSOLETE */ C_fctexport void C_ccall C_get_symbol_table_info(C_word c, C_word closure, C_word k) C_noret; C_fctexport void C_ccall C_get_memory_info(C_word c, C_word closure, C_word k) C_noret; C_fctexport void C_ccall C_context_switch(C_word c, C_word closure, C_word k, C_word state) C_noret; diff --git a/library.scm b/library.scm index 31e1e0c..b1b1a78 100644 --- a/library.scm +++ b/library.scm @@ -202,7 +202,7 @@ EOF (define (current-milliseconds) (##core#inline_allocate ("C_a_i_current_milliseconds" 4) #f)) (define (current-gc-milliseconds) (##sys#fudge 31)) (define ##sys#decode-seconds (##core#primitive "C_decode_seconds")) -(define get-environment-variable (##core#primitive "C_get_environment_variable")) +(define get-environment-variable (foreign-lambda c-string "C_getenv" c-string)) (define (##sys#start-timer) (##sys#gc #t) @@ -4594,14 +4594,18 @@ EOF ;;; command-line handling -(define ##sys#get-argument (##core#primitive "C_get_argument")) (define argv ; includes program name - (let ((cache #f)) + (let* ((cache #f) + (fetch-arg (foreign-lambda* c-string ((int i)) + "C_return(C_main_argv[i]);")) + (get-argument (lambda (index) + (and (fx< index main_argc) + (fetch-arg index))))) (lambda () (or cache (let ((v (let loop ((i 0)) - (let ((arg (##sys#get-argument i))) + (let ((arg (get-argument i))) (if arg (cons arg (loop (fx+ i 1))) '()))))) @@ -4610,7 +4614,9 @@ EOF (define program-name (make-parameter - (or (##sys#get-argument 0) "