]> git.eshelyaron.com Git - sweep.git/commitdiff
Workaround issue with Xwidgets and XPCE in older SWI-Prolog
authorEshel Yaron <me@eshelyaron.com>
Mon, 14 Aug 2023 17:54:50 +0000 (19:54 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 14 Aug 2023 18:00:27 +0000 (20:00 +0200)
* sweeprolog.el (sweeprolog-init-args): Disable XPCE if Emacs is built
with Xwidgets and SWI-Prolog version is earlier then 9.1.14.

* README.org (Prolog Initialization and Cleanup): Reword
'sweeprolog-init-args' documentation.

README.org
sweeprolog.el

index d48badc631e318d0cdbba2ea5d210c690e22750a..09ef6b1bcd505dd750aed0652f6bcebffbfe98ab 100644 (file)
@@ -268,27 +268,32 @@ its customization options in Sweep:
 #+FINDEX: sweeprolog-restart
 - Command: sweeprolog-restart :: Restart the embedded Prolog runtime.
 
-In Sweep, Prolog initialization is done via
-the C-implemented =sweeprolog-initialize= Elisp function defined in
-=sweep-module=.  =sweeprolog-initialize= takes one or more arguments, which
-must all be strings, and initializes the embedded Prolog as if it were
-invoked externally in a command line with the given strings as command
-line arguments, where the first argument to =sweeprolog-initialize=
-corresponds to =argv[0]=.
+In Sweep, Prolog initialization is done via the C-implemented
+~sweeprolog-initialize~ Elisp function defined in ~sweep-module~.
+~sweeprolog-initialize~ takes one or more string arguments and
+initializes the embedded Prolog as if it were invoked externally in a
+command line with the given strings as command line arguments, where
+the first argument to ~sweeprolog-initialize~ corresponds to
+~argv[0]~.
 
 Sweep loads and initializes Prolog on-demand at the first invocation
-of a command that requires the embedded Prolog.  The arguments used to
-initialize Prolog are then determined by the value of the user-option
-~sweeprolog-init-args~ which the user is free to extend with e.g.:
+of a command that requires the embedded Prolog.  The user option
+~sweeprolog-init-args~ says which arguments to pass to Prolog
+initialization.  Its value is a list of strings that you can extend if
+you want to pass specific command line flags SWI-Prolog.  For example,
+to limit the embedded Prolog stack to 512 MB, add the following to
+your Emacs configuration:
 
 #+begin_src emacs-lisp
-  (add-to-list 'sweeprolog-init-args "--stack-limit=512m")
+  (with-eval-after-load 'sweeprolog
+    (push "--stack-limit=512m" sweeprolog-init-args))
 #+end_src
 
 #+CINDEX: sweep Prolog flag
 The default value of ~sweeprolog-init-args~ is set to load the Prolog
-helper library =sweep.pl= and to create a boolean Prolog flag Sweep, set
-to ~true~, which indicates to SWI-Prolog that it is running under Sweep.
+helper library =sweep.pl= and to create a boolean Prolog flag called
+~sweep~ with value ~true~.  You can check for this flag in Prolog code
+to detect at runtime that you're running under Sweep.
 
 #+CINDEX: command line arguments
 It is also possible to specify initialization arguments to SWI-Prolog
index 579e0bc48bbb27ea9d73d8dea9429eee3a666726..1a445235d8b781ee9ee9bf458ebf560924545493 100644 (file)
@@ -284,16 +284,35 @@ inserted to the input history in `sweeprolog-top-level-mode' buffers."
                          " regardless of the value of this option.")
                         "sweeprolog version 0.7.2")
 
-(defcustom sweeprolog-init-args (list "-q"
-                                      "--no-signals"
-                                      "-g"
-                                      "create_prolog_flag(sweep,true,[access(read_only),type(boolean)])"
-                                      "-l"
-                                      (expand-file-name
-                                       "sweep.pl"
-                                       sweeprolog--directory))
+(defcustom sweeprolog-init-args
+  (append
+   (when (and (featurep 'xwidget-internal)
+              (when-let (swipl (or sweeprolog-swipl-path
+                                   (executable-find "swipl")))
+                (<= 90114               ; first SWI-Prolog version to
+                                        ; hide XPCE private symbols
+                    (string-to-number
+                     (with-output-to-string
+                       (with-current-buffer standard-output
+                         (call-process swipl
+                                       nil '(t nil) nil
+                                       "-g"
+                                       "current_prolog_flag(version, V), writeln(V)"
+                                       "-t" "halt")))))))
+     ;; Disable XPCE if Emacs has been built with Xwidgets to
+     ;; workaround a potential crash due to symbol collision
+     ;; (see https://github.com/SWI-Prolog/swipl-devel/issues/1188).
+     '("--pce=false"))
+   (list "-q"
+         "--no-signals"
+         "-g"
+         "create_prolog_flag(sweep,true,[access(read_only),type(boolean)])"
+         "-l"
+         (expand-file-name
+          "sweep.pl"
+          sweeprolog--directory)))
   "List of strings used as initialization arguments for Prolog."
-  :package-version '((sweeprolog "0.5.2"))
+  :package-version '((sweeprolog "0.22.2"))
   :type '(repeat string)
   :group 'sweeprolog)