~ chicken-core (chicken-5) 4a41c90296858d6265f867a9f89becc102579b38
commit 4a41c90296858d6265f867a9f89becc102579b38
Author: Mario Domenech Goulart <mario@parenteses.org>
AuthorDate: Mon Jan 1 21:07:36 2024 +0100
Commit: felix <felix@call-with-current-continuation.org>
CommitDate: Wed Jan 3 13:56:05 2024 +0100
Drop memoization of envvars used by create-temporary-{file,directory}
Once cached, the directory used by create-temporary-file and
create-temporary-directory remains unchanged regardless of changes to
the environment variables they are supposed to respect (TMPDIR, TMP
and TEMP).
Example:
Without this patch:
#;1> (create-temporary-file)
"/tmp/tempcd92.182728.tmp"
#;2> (set-environment-variable! "TMPDIR" "/home/mario")
#;3> (create-temporary-file)
"/tmp/tempc6c.182728.tmp"
With this patch:
#;1> (create-temporary-file)
"/tmp/temp6bf0.186696.tmp"
#;2> (set-environment-variable! "TMPDIR" "/home/mario")
#;3> (create-temporary-file)
"/home/mario/temp639b.186696.tmp"
Fixes #1830
Signed-off-by: felix <felix@call-with-current-continuation.org>
diff --git a/NEWS b/NEWS
index cb565620..3fcbbdd4 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,8 @@
using it from there is deprecated.
- Added "export/rename" to (chicken module) for renaming identifiers on
export.
+ - The values of the TMPDIR, TMP and TEMP environment variables are no
+ longer memoized (fixes #1830).
- Tools
- The -R option for csi and csc now accepts list-notation like
diff --git a/file.scm b/file.scm
index 11b1bcc0..78d68a41 100644
--- a/file.scm
+++ b/file.scm
@@ -304,18 +304,13 @@ EOF
(define create-temporary-file)
(define create-temporary-directory)
-(let ((temp #f)
- (temp-prefix "temp")
+(let ((temp-prefix "temp")
(string-append string-append))
(define (tempdir)
- (or temp
- (let ((tmp
- (or (get-environment-variable "TMPDIR")
- (get-environment-variable "TEMP")
- (get-environment-variable "TMP")
- "/tmp")))
- (set! temp tmp)
- tmp)))
+ (or (get-environment-variable "TMPDIR")
+ (get-environment-variable "TEMP")
+ (get-environment-variable "TMP")
+ "/tmp"))
(set! create-temporary-file
(lambda (#!optional (ext "tmp"))
(##sys#check-string ext 'create-temporary-file)
diff --git a/manual/Module (chicken file) b/manual/Module (chicken file)
index e78fb91b..4dd96d08 100644
--- a/manual/Module (chicken file)
+++ b/manual/Module (chicken file)
@@ -129,22 +129,36 @@ write or execute permissions on the file named {{FILENAME}}.
<procedure>(create-temporary-file [EXTENSION])</procedure>
Creates an empty temporary file and returns its pathname. If
-{{EXTENSION}} is not given, then {{.tmp}} is used. If the
-environment variable {{TMPDIR, TEMP}} or {{TMP}} is set,
-then the pathname names a file in that directory. If none of
-the environment variables is given the location of the
-temporary file defaults to {{/tmp}} if it exists or the
-current-directory
+{{EXTENSION}} is not given, then {{.tmp}} is used. If the environment
+variable {{TMPDIR}}, {{TEMP}} or {{TMP}} is set, then the pathname
+names a file in that directory. If none of the environment variables
+is given, the location of the temporary file defaults to {{/tmp}}.
+Note that {{TMPDIR}}, {{TEMP}} and {{TMP}} are checked in this order.
+It means that, for example, if both {{TMPDIR}} and {{TEMP}} are set,
+the value of {{TMPDIR}} will be used.
+
+Changed in CHICKEN 5.4.0: the values of the {{TMPDIR}}, {{TEMP}} and
+{{TMP}} environment variables are no longer memoized (see
+[[#1830|https://bugs.call-cc.org/ticket/1830]]).
==== create-temporary-directory
<procedure>(create-temporary-directory)</procedure>
Creates an empty temporary directory and returns its pathname. If the
-environment variable {{TMPDIR, TEMP}} or {{TMP}} is set, then the
-temporary directory is created at that location.
-
+environment variable {{TMPDIR}}, {{TEMP}} or {{TMP}} is set, then the
+temporary directory is created at that location. If none of the
+environment variables is given, the location of the temporary
+directory defaults to {{/tmp}}.
+
+Note that {{TMPDIR}}, {{TEMP}} and {{TMP}} are checked in this order.
+It means that, for example, if both {{TMPDIR}} and {{TEMP}} are set,
+the value of {{TMPDIR}} will be used.
+
+Changed in CHICKEN 5.4.0: the values of the {{TMPDIR}}, {{TEMP}} and
+{{TMP}} environment variables are no longer memoized (see
+[[#1830|https://bugs.call-cc.org/ticket/1830]]).
=== Finding files
diff --git a/tests/runtests.bat b/tests/runtests.bat
index ab0bcc45..6f98aa37 100644
--- a/tests/runtests.bat
+++ b/tests/runtests.bat
@@ -479,7 +479,7 @@ del /f /q ec.so ec.import.*
if errorlevel 1 exit /b 1
%compile_s% ec.scm -emit-import-library ec -o ec.so
if errorlevel 1 exit /b 1
-%compile_s% ec.import.scm -o ec.import.so
+%compile_s% ec.import.scm -o ec.import.so
if errorlevel 1 exit /b 1
%interpret% -bnq ec.so ec-tests.scm
rem %compile% ec-tests.scm
@@ -586,7 +586,11 @@ echo ======================================== find-files tests ...
%interpret% -bnq test-find-files.scm
if errorlevel 1 exit /b 1
-echo "======================================== record-renaming tests ..."
+echo ======================================== create-temporary-file tests ...
+$interpret -bnq test-create-temporary-file.scm
+
+
+echo ======================================== record-renaming tests ...
%interpret% -bnq record-rename-test.scm
if errorlevel 1 exit /b 1
diff --git a/tests/runtests.sh b/tests/runtests.sh
index 4fba44b5..185db284 100755
--- a/tests/runtests.sh
+++ b/tests/runtests.sh
@@ -433,6 +433,9 @@ fi
echo "======================================== find-files tests ..."
$interpret -bnq test-find-files.scm
+echo "======================================== create-temporary-file tests ..."
+$interpret -bnq test-create-temporary-file.scm
+
echo "======================================== record-renaming tests ..."
$interpret -bnq record-rename-test.scm
Trap