diff --git a/collects/racket/private/misc.rkt b/collects/racket/private/misc.rkt index c8dc905395..76e2a6f6d0 100644 --- a/collects/racket/private/misc.rkt +++ b/collects/racket/private/misc.rkt @@ -203,7 +203,7 @@ (define (getenv s) (unless (string-environment-variable-name? s) (raise-argument-error 'getenv "string-environment-variable-name?" s)) - (let ([v (environment-variables-get (current-environment-variables) + (let ([v (environment-variables-ref (current-environment-variables) (string->bytes/locale s (char->integer #\?)))]) (and v (bytes->string/locale v #\?)))) diff --git a/collects/scribblings/reference/envvars.scrbl b/collects/scribblings/reference/envvars.scrbl index 2a60c813fa..c3b22bb561 100644 --- a/collects/scribblings/reference/envvars.scrbl +++ b/collects/scribblings/reference/envvars.scrbl @@ -51,7 +51,7 @@ Creates a fresh @tech{environment variable set} that is initialized with the given @racket[name] to @racket[val] mappings.} -@defproc[(environment-variables-get [env environment-variables?] +@defproc[(environment-variables-ref [env environment-variables?] [name bytes-environment-variable-name?]) (or/c #f (and/c bytes-no-nuls? immutable?))]{ @@ -93,7 +93,7 @@ in which case @racket[fail] is called in tail position with respect to the an exception.} -@defproc[(environment-variables-keys [env environment-variables?]) +@defproc[(environment-variables-names [env environment-variables?]) (listof (and/c bytes-environment-variable-name? immutable?))]{ Returns a list of byte strings that corresponds to names mapped by @@ -114,7 +114,7 @@ the same mappings as @racket[env].} [value string-no-nuls?]) boolean?] )]{ -Convenience wrappers for @racket[environment-variables-get] and +Convenience wrappers for @racket[environment-variables-ref] and @racket[environment-variables-set!] that convert between strings and byte strings using the current @tech{locale}'s default encoding (using @racket[#\?] as the replacement character for encoding errors) and diff --git a/collects/tests/racket/file.rktl b/collects/tests/racket/file.rktl index 574ab18a39..3a07fd4674 100644 --- a/collects/tests/racket/file.rktl +++ b/collects/tests/racket/file.rktl @@ -1263,11 +1263,11 @@ (test #t environment-variables? (environment-variables-copy (current-environment-variables))) (test #t environment-variables? (make-environment-variables)) (test #t environment-variables? (make-environment-variables #"A" #"1")) -(test #t list? (environment-variables-keys (current-environment-variables))) -(test #t andmap bytes? (environment-variables-keys (current-environment-variables))) +(test #t list? (environment-variables-names (current-environment-variables))) +(test #t andmap bytes? (environment-variables-names (current-environment-variables))) (test #t = - (length (environment-variables-keys (current-environment-variables))) - (length (environment-variables-keys (environment-variables-copy (current-environment-variables))))) + (length (environment-variables-names (current-environment-variables))) + (length (environment-variables-names (environment-variables-copy (current-environment-variables))))) (test #f bytes-environment-variable-name? #"x=") (test #f bytes-environment-variable-name? #"x\0") (test (not (eq? 'windows (system-type))) bytes-environment-variable-name? #"") @@ -1276,10 +1276,10 @@ (test #f string-environment-variable-name? "x\0") (test (not (eq? 'windows (system-type))) string-environment-variable-name? "") -(test #"1" environment-variables-get (make-environment-variables #"a" #"1" #"b" #"two") #"a") -(test #"two" environment-variables-get (make-environment-variables #"a" #"1" #"b" #"two") #"b") -(test #f environment-variables-get (make-environment-variables #"a" #"1" #"b" #"two") #"c") -(test #f environment-variables-get (make-environment-variables) #"a") +(test #"1" environment-variables-ref (make-environment-variables #"a" #"1" #"b" #"two") #"a") +(test #"two" environment-variables-ref (make-environment-variables #"a" #"1" #"b" #"two") #"b") +(test #f environment-variables-ref (make-environment-variables #"a" #"1" #"b" #"two") #"c") +(test #f environment-variables-ref (make-environment-variables) #"a") (define (env-var-tests) (define success-1? (putenv "APPLE" "AnApple")) @@ -1298,21 +1298,21 @@ (test #f getenv "AnUndefinedEnvironmentVariable") (define env (current-environment-variables)) - (test #"AnApple" environment-variables-get env #"APPLE") - (err/rt-test (environment-variables-get env #"=AP=PLE=")) + (test #"AnApple" environment-variables-ref env #"APPLE") + (err/rt-test (environment-variables-ref env #"=AP=PLE=")) (test (void) environment-variables-set! env #"APPLE" #"=x=") - (test #"=x=" environment-variables-get env #"APPLE") - (test #"AnotherApple" environment-variables-get env #"BANANA") + (test #"=x=" environment-variables-ref env #"APPLE") + (test #"AnotherApple" environment-variables-ref env #"BANANA") (test (void) environment-variables-set! env #"BANANA" #f) - (test #f environment-variables-get env #"BANANA") + (test #f environment-variables-ref env #"BANANA") (test #f getenv "BANANA") (let ([apple (if (eq? 'windows (system-type)) #"apple" #"APPLE")]) - (test apple car (member apple (environment-variables-keys env)))) - (test #f member #"BANANA" (environment-variables-keys env)) - (test #f member #"banana" (environment-variables-keys env))) + (test apple car (member apple (environment-variables-names env)))) + (test #f member #"BANANA" (environment-variables-names env)) + (test #f member #"banana" (environment-variables-names env))) (parameterize ([current-environment-variables (environment-variables-copy diff --git a/doc/release-notes/racket/HISTORY.txt b/doc/release-notes/racket/HISTORY.txt index b0a88231e1..6062e02e99 100644 --- a/doc/release-notes/racket/HISTORY.txt +++ b/doc/release-notes/racket/HISTORY.txt @@ -2,8 +2,8 @@ Version 5.3.4.3 Added make-environment-variables Version 5.3.4.2 -Added current-environment-variables, environment-variables-get, - environment-variables-set!, environment-variables-keys, +Added current-environment-variables, environment-variables-ref, + environment-variables-set!, environment-variables-names, environment-variables-copy, bytes-environment-variables-name?, string-environment-variables-name?, and environment-variables? racket/sadnox: added sandbox-make-environment-variables diff --git a/src/get-libs.rkt b/src/get-libs.rkt index d6879c2845..d2c27dd882 100644 --- a/src/get-libs.rkt +++ b/src/get-libs.rkt @@ -104,7 +104,7 @@ ["libpangocairo-1.0-0.dll" 94625] ["libpangowin32-1.0-0.dll" 143647] ["libpangoft2-1.0-0.dll" 679322]] - (if (environment-variables-get (current-environment-variables) + (if (environment-variables-ref (current-environment-variables) #"PLT_WIN_GTK") '(["libatk-1.0-0.dll" 153763] ["libgtk-win32-2.0-0.dll" 4740156] @@ -196,7 +196,7 @@ (define-values (path-size/show) (lambda (path) (let-values ([(sz) (path-size path)]) - (if (environment-variables-get (current-environment-variables) + (if (environment-variables-ref (current-environment-variables) #"PLT_SHOW_PATH_SIZES") (printf "~s ~s\n" path sz) (void)) diff --git a/src/racket/src/string.c b/src/racket/src/string.c index 237e9aa5f2..63b589842a 100644 --- a/src/racket/src/string.c +++ b/src/racket/src/string.c @@ -868,9 +868,9 @@ scheme_init_string (Scheme_Env *env) MZCONFIG_CURRENT_ENV_VARS), env); - scheme_add_global_constant("environment-variables-get", + scheme_add_global_constant("environment-variables-ref", scheme_make_immed_prim(sch_getenv, - "environment-variables-get", + "environment-variables-ref", 2, 2), env); @@ -880,9 +880,9 @@ scheme_init_string (Scheme_Env *env) 3, 4), env); - scheme_add_global_constant("environment-variables-keys", + scheme_add_global_constant("environment-variables-names", scheme_make_immed_prim(sch_getenv_names, - "environment-variables-keys", + "environment-variables-names", 1, 1), env); @@ -2265,12 +2265,12 @@ static Scheme_Object *sch_getenv(int argc, Scheme_Object *argv[]) Scheme_Hash_Tree *ht; if (!SAME_TYPE(SCHEME_TYPE(argv[0]), scheme_environment_variables_type)) - scheme_wrong_contract("environment-variables-get", "environment-variables?", 0, argc, argv); + scheme_wrong_contract("environment-variables-ref", "environment-variables?", 0, argc, argv); bs = argv[1]; if (!SCHEME_BYTE_STRINGP(bs) || !byte_string_ok_name(bs)) - scheme_wrong_contract("environment-variables-get", "bytes-environment-variable-name?", 1, argc, argv); + scheme_wrong_contract("environment-variables-ref", "bytes-environment-variable-name?", 1, argc, argv); ev = argv[0]; ht = SCHEME_ENVVARS_TABLE(ev); @@ -2329,9 +2329,12 @@ static int sch_unix_putenv(const char *var, const char *val, const intptr_t varl if (buffer) return putenv(buffer); - else - return unsetenv(var); -} + else { + /* on some platforms, unsetenv() returns void */ + unsetenv(var); + return 0; + } +} #endif static Scheme_Object *sch_putenv(int argc, Scheme_Object *argv[]) @@ -2518,7 +2521,7 @@ static Scheme_Object *sch_getenv_names(int argc, Scheme_Object *argv[]) ev = argv[0]; if (!SAME_TYPE(SCHEME_TYPE(ev), scheme_environment_variables_type)) - scheme_wrong_contract("environment-variables-keys", "environment-variables?", 0, argc, argv); + scheme_wrong_contract("environment-variables-names", "environment-variables?", 0, argc, argv); ht = SCHEME_ENVVARS_TABLE(ev); if (!ht) {