emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/native-comp 69c32e0 2/3: * Sandbox syncronous libgccjit invocati


From: Andrea Corallo
Subject: feature/native-comp 69c32e0 2/3: * Sandbox syncronous libgccjit invocation on interactive sessions
Date: Mon, 21 Sep 2020 16:05:56 -0400 (EDT)

branch: feature/native-comp
commit 69c32e01875f33ba1cc4ad37d0940375cd0c6e27
Author: Andrea Corallo <akrl@sdf.org>
Commit: Andrea Corallo <akrl@sdf.org>

    * 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.
---
 lisp/emacs-lisp/comp.el | 42 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 25e2de9..4795d2f 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]