]> git.eshelyaron.com Git - emacs.git/commitdiff
* Sandbox syncronous libgccjit invocation on interactive sessions
authorAndrea Corallo <akrl@sdf.org>
Sat, 19 Sep 2020 08:27:41 +0000 (10:27 +0200)
committerAndrea Corallo <akrl@sdf.org>
Mon, 21 Sep 2020 19:46:07 +0000 (21:46 +0200)
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.

lisp/emacs-lisp/comp.el

index 25e2de9d5d239ec4afd5c55fb5dc28f91ad820df..4795d2fc07e81dc87e6d38b1a01de7d869dd5896 100644 (file)
@@ -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)))))))
+
 \f
 ;;; Compiler type hints.
 ;; Public entry points to be used by user code to give comp