mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-28 16:00:22 +02:00
don't truncate .go files, do an atomic rename to prevent SIGBUS
* module/system/base/compile.scm (call-with-output-file/atomic): New proc, outputs to a tempfile then does an atomic rename. Prevents SIGBUS if a compiled file is truncated and rewritten, as the file's objcode is mmap'd in. (compile-file): Use the new helper.
This commit is contained in:
parent
fbea69ad42
commit
e6d4e05cbd
1 changed files with 13 additions and 1 deletions
|
@ -58,6 +58,18 @@
|
|||
|
||||
(define (scheme) (lookup-language 'scheme))
|
||||
|
||||
(define (call-with-output-file/atomic filename proc)
|
||||
(let* ((template (string-append filename ".XXXXXX"))
|
||||
(tmp (mkstemp! template)))
|
||||
(catch #t
|
||||
(lambda ()
|
||||
(with-output-to-port tmp
|
||||
(lambda () (proc (current-output-port))))
|
||||
(rename-file template filename))
|
||||
(lambda args
|
||||
(delete-file template)
|
||||
(apply throw args)))))
|
||||
|
||||
(define (compile-file file . opts)
|
||||
(let ((comp (compiled-file-name file))
|
||||
(scheme (scheme)))
|
||||
|
@ -65,7 +77,7 @@
|
|||
(lambda ()
|
||||
(call-with-compile-error-catch
|
||||
(lambda ()
|
||||
(call-with-output-file comp
|
||||
(call-with-output-file/atomic comp
|
||||
(lambda (port)
|
||||
(let* ((source (read-file-in file scheme))
|
||||
(objcode (apply compile-in source (current-module)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue