branch: externals/compat
commit f8a6172953ee6c88485c5fb6589caebd82f18822
Author: Philip Kaludercic <phil...@posteo.net>
Commit: Philip Kaludercic <phil...@posteo.net>

    Ensure that all prefixed functions do not use :cond
    
    As a prefixed function should always be defined (even if the real
    function exists and works), using conditions that might result in the
    function not being included is contradictory and should be avoided.
---
 compat-26.el   |  3 ---
 compat-27.el   |  4 ----
 compat-28.el   | 36 ------------------------------------
 compat-macs.el |  2 ++
 4 files changed, 2 insertions(+), 43 deletions(-)

diff --git a/compat-26.el b/compat-26.el
index e9d0d70354..f3e65b6318 100644
--- a/compat-26.el
+++ b/compat-26.el
@@ -112,9 +112,6 @@ Equality is defined by the function TESTFN, defaulting to
 ‘equal’.  TESTFN is called with 2 arguments: a car of an alist
 element and KEY.  With no optional argument, the function behaves
 just like `assoc'."
-  :cond (condition-case nil
-            (or (assoc nil nil #'ignore) t)
-          (wrong-number-of-arguments nil))
   :prefix t
   (if testfn
       (catch 'found
diff --git a/compat-27.el b/compat-27.el
index ade4ae9e13..6901870fcf 100644
--- a/compat-27.el
+++ b/compat-27.el
@@ -356,10 +356,6 @@ Compare keys with TEST.  Defaults to `equal'.
 Return the modified alist.
 Elements of ALIST that are not conses are ignored."
   :prefix t
-  :cond (condition-case nil
-            (or (assoc-delete-all nil nil #'ignore) t)
-          (wrong-number-of-arguments nil)
-          (void-function nil))
   (unless test (setq test #'equal))
   (while (and (consp (car alist))
              (funcall test (caar alist) key))
diff --git a/compat-28.el b/compat-28.el
index d5dbb336ff..2d6a55bf4e 100644
--- a/compat-28.el
+++ b/compat-28.el
@@ -170,15 +170,6 @@ If COUNT is non-nil and a natural number, the function will
 
 (compat-defun json-serialize (object &rest args)
   "Handle top-level JSON values."
-  :cond (condition-case err
-            ;; Use `random' to prevent byte compiler from optimising
-            ;; the "pure" `json-serialize' call.
-            (ignore (json-serialize (if (random) 0 0)))
-          (wrong-type-argument (eq (cadr err) 'json-value-p))
-          ;; `json-serialize' might be disabled at compile time, so we
-          ;; have to check if an error was raised that the function
-          ;; was not defined.
-          (void-function (eq (cadr err) 'json-serialize)))
   :prefix t
   :min-version "27"
   (if (or (listp object) (vectorp object))
@@ -187,15 +178,6 @@ If COUNT is non-nil and a natural number, the function will
 
 (compat-defun json-insert (object &rest args)
   "Handle top-level JSON values."
-  :cond (condition-case err
-            ;; Use `random' to prevent byte compiler from optimising
-            ;; the "pure" `json-serialize' call.
-            (ignore (json-serialize (if (random) 0 0)))
-          (wrong-type-argument (eq (cadr err) 'json-value-p))
-          ;; `json-serialize' might be disabled at compile time, so we
-          ;; have to check if an error was raised that the function
-          ;; was not defined.
-          (void-function (eq (cadr err) 'json-serialize)))
   :prefix t
   :min-version "27"
   (if (or (listp object) (vectorp object))
@@ -204,15 +186,6 @@ If COUNT is non-nil and a natural number, the function will
 
 (compat-defun json-parse-string (string &rest args)
   "Handle top-level JSON values."
-  :cond (condition-case err
-            ;; Use `random' to prevent byte compiler from optimising
-            ;; the "pure" `json-serialize' call.
-            (ignore (json-parse-string (if (random) "0" "0")))
-          (json-parse-error t)
-          ;; `json-parse-string' might be disabled at compile time, so
-          ;; we have to check if an error was raised that the function
-          ;; was not defined.
-          (void-function (eq (cadr err) 'json-parse-error)))
   :prefix t
   :min-version "27"
   (if (string-match-p "\\`[[:space:]]*[[{]" string)
@@ -224,15 +197,6 @@ If COUNT is non-nil and a natural number, the function will
 
 (compat-defun json-parse-buffer (&rest args)
   "Handle top-level JSON values."
-  :cond (condition-case err
-            ;; Use `random' to prevent byte compiler from optimising
-            ;; the "pure" `json-serialize' call.
-            (ignore (json-parse-string (if (random) "0" "0")))
-          (json-parse-error t)
-          ;; `json-parse-string' might be disabled at compile time, so
-          ;; we have to check if an error was raised that the function
-          ;; was not defined.
-          (void-function (eq (cadr err) 'json-parse-error)))
   :prefix t
   :min-version "27"
   (if (looking-at-p "[[:space:]]*[[{]")
diff --git a/compat-macs.el b/compat-macs.el
index 12c8c62965..f9506df189 100644
--- a/compat-macs.el
+++ b/compat-macs.el
@@ -202,6 +202,8 @@ DEF-FN, INSTALL-FN, CHECK-FN, ATTR and TYPE."
   "Common code for generating compatibility definitions.
 See `compat-generate-function' for details on the arguments NAME,
 DEF-FN, INSTALL-FN, CHECK-FN, ATTR and TYPE."
+  (when (and (plist-get attr :cond) (plist-get attr :prefix))
+    (error "A prefixed function %s cannot have a condition" name))
   (funcall compat--generate-function
            name def-fn install-fn check-fn attr type))
 

Reply via email to