From: Andrea Corallo Date: Sat, 19 Sep 2020 08:27:41 +0000 (+0200) Subject: * Sandbox syncronous libgccjit invocation on interactive sessions X-Git-Tag: emacs-28.0.90~2727^2~433 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=69c32e01875f33ba1cc4ad37d0940375cd0c6e27;p=emacs.git * Sandbox syncronous libgccjit invocation on interactive sessions Avoid unnecessary memory fragmentation/leakeage * lisp/emacs-lisp/comp.el (comp-final1): New function. (comp-final): Invoke `comp-final1' in a child process if in an interactive session or directly otherwhise. --- diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 25e2de9d5d2..4795d2fc07e 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -2475,8 +2475,7 @@ Prepare every function for final compilation and drive the C back-end." (unless comp-dry-run (comp--compile-ctxt-to-file name)))) -(defun comp-final (_) - "Final pass driving the C back-end for code emission." +(defun comp-final1 () (let (compile-result) (comp--init-ctxt) (unwind-protect @@ -2485,6 +2484,45 @@ Prepare every function for final compilation and drive the C back-end." (and (comp--release-ctxt) compile-result)))) +(defun comp-final (_) + "Final pass driving the C back-end for code emission." + (if noninteractive + (comp-final1) + ;; Call comp-final1 in a child process. + (let* ((output (comp-ctxt-output comp-ctxt)) + (print-escape-newlines t) + (print-length nil) + (print-level nil) + (print-quoted t) + (print-gensym t) + (print-circle t) + (expr `(progn + (require 'comp) + (setf comp-speed ,comp-speed + comp-debug ,comp-debug + comp-verbose ,comp-verbose + comp-ctxt ,comp-ctxt + comp-eln-load-path ',comp-eln-load-path + comp-native-driver-options + ',comp-native-driver-options + load-path ',load-path) + ,comp-async-env-modifier-form + (message "Compiling %s..." ',output) + (comp-final1))) + (temp-file (make-temp-file + (concat "emacs-int-comp-" + (file-name-base output) "-") + nil ".el"))) + (with-temp-file temp-file + (insert (prin1-to-string expr))) + (with-temp-buffer + (if (zerop + (call-process (expand-file-name invocation-name + invocation-directory) + nil t t "--batch" "-l" temp-file)) + output + (signal 'native-compiler-error (buffer-string))))))) + ;;; Compiler type hints. ;; Public entry points to be used by user code to give comp