emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/sweeprolog 2f5dd9f13c 024/166: FIXED: Use more robust Prol


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog 2f5dd9f13c 024/166: FIXED: Use more robust Prolog to C string conversion
Date: Fri, 30 Sep 2022 04:59:22 -0400 (EDT)

branch: elpa/sweeprolog
commit 2f5dd9f13c23e5789f67188c907696e6458cda5f
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>

    FIXED: Use more robust Prolog to C string conversion
---
 sweep.c  |  4 +++-
 sweep.el | 10 ++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/sweep.c b/sweep.c
index ff148c71fb..bccb1ad40b 100644
--- a/sweep.c
+++ b/sweep.c
@@ -102,8 +102,10 @@ term_to_value_string(emacs_env *eenv, term_t t) {
   char * string = NULL;
   emacs_value v = NULL;
   size_t      l = -1;
-  if (PL_get_string_chars(t, &string, &l)) {
+  if (PL_get_nchars(t, &l, &string, CVT_STRING|REP_UTF8)) {
     v = eenv->make_string(eenv, string, l);
+  } else {
+    v = eenv->make_string(eenv, "sweep conversion error", 22);
   }
   return v;
 }
diff --git a/sweep.el b/sweep.el
index 88dfe1b0a2..ed8c7af17a 100644
--- a/sweep.el
+++ b/sweep.el
@@ -15,6 +15,10 @@
 
 ;;; Code:
 
+(defgroup sweep nil
+  "SWI-Prolog Embedded in Emacs."
+  :group 'prolog)
+
 (defvar sweep-install-buffer-name "*Install sweep*"
   "Name of the buffer used for compiling sweep-module.")
 
@@ -88,6 +92,7 @@
                       nil))))))
     (completing-read "Predicate: " col)))
 
+;;;###autoload
 (defun sweep-find-predicate (mfn)
   "Jump to the definiton of the Prolog predicate MFN.
 MFN must be a string of the form \"M:F/N\" where M is a Prolog
@@ -125,12 +130,13 @@ module name, F is a functor name and N is its arity."
                   (let* ((val (cdr (assoc-string key col)))
                          (pat (car val))
                          (des (cdr val)))
-                    (concat (make-string (- 32 (length key)) ? )
+                    (concat (make-string (max 0 (- 32 (length key))) ? )
                             (if des
-                                (concat pat (make-string (- 64 (length pat)) ? 
) des)
+                                (concat pat (make-string (max 0 (- 80 (length 
pat))) ? ) des)
                               pat)))))))
     (completing-read "Module: " col)))
 
+;;;###autoload
 (defun sweep-find-module (mod)
   "Jump to the source file of the Prolog module MOD."
   (interactive (list (sweep-read-module-name)))



reply via email to

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