[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 26b2ec7cb8 2/2: Simplify last change (bug#60311)
From: |
Eli Zaretskii |
Subject: |
emacs-29 26b2ec7cb8 2/2: Simplify last change (bug#60311) |
Date: |
Mon, 26 Dec 2022 08:27:42 -0500 (EST) |
branch: emacs-29
commit 26b2ec7cb8c81db7d8705cb87579b325901ed303
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>
Simplify last change (bug#60311)
* src/json.c (json_available_p): Use original code. Always return
true for !WINDOWSNT.
(ensure_json_available): Now defined only on WINDOWSNT.
(Fjson_serialize, Fjson_insert, Fjson_parse_string)
(Fjson_parse_buffer): Call ensure_json_available only on
WINDOWSNT.
* lisp/subr.el (json-available-p): Simplify.
---
lisp/subr.el | 7 ++-----
src/json.c | 40 ++++++++++++++++++++++++++--------------
2 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/lisp/subr.el b/lisp/subr.el
index 701c26f8cd..2fcdc7addf 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -6911,11 +6911,8 @@ sentence (see Info node `(elisp) Documentation Tips')."
(defun json-available-p ()
"Return non-nil if Emacs has libjansson support."
- (declare (side-effect-free error-free))
- (and (eval-when-compile (fboundp 'json-serialize))
- ;; If `json--available-p' is present, we need to call it at run-time.
- (or (not (eval-when-compile (fboundp 'json--available-p)))
- (json--available-p))))
+ (and (fboundp 'json--available-p)
+ (json--available-p)))
(defun ensure-list (object)
"Return OBJECT as a list.
diff --git a/src/json.c b/src/json.c
index d2105bc27b..621c7d7c15 100644
--- a/src/json.c
+++ b/src/json.c
@@ -555,37 +555,39 @@ json_parse_args (ptrdiff_t nargs,
}
}
-#ifdef WINDOWSNT
static bool
json_available_p (void)
{
- if (json_initialized)
- return true;
- json_initialized = init_json_functions ();
- Lisp_Object status = json_initialized ? Qt : Qnil;
- Vlibrary_cache = Fcons (Fcons (Qjson, status), Vlibrary_cache);
+#ifdef WINDOWSNT
+ if (!json_initialized)
+ {
+ Lisp_Object status;
+ json_initialized = init_json_functions ();
+ status = json_initialized ? Qt : Qnil;
+ Vlibrary_cache = Fcons (Fcons (Qjson, status), Vlibrary_cache);
+ }
return json_initialized;
-}
+#else /* !WINDOWSNT */
+ return true;
#endif
+}
+#ifdef WINDOWSNT
static void
ensure_json_available (void)
{
-#ifdef WINDOWSNT
if (!json_available_p ())
Fsignal (Qjson_unavailable,
list1 (build_unibyte_string ("jansson library not found")));
-#endif
}
+#endif
-#ifdef WINDOWSNT
DEFUN ("json--available-p", Fjson__available_p, Sjson__available_p, 0, 0, NULL,
- doc: /* Whether libjansson is available (internal). */)
+ doc: /* Return non-nil if libjansson is available (internal use only).
*/)
(void)
{
return json_available_p () ? Qt : Qnil;
}
-#endif
DEFUN ("json-serialize", Fjson_serialize, Sjson_serialize, 1, MANY,
NULL,
@@ -617,7 +619,10 @@ usage: (json-serialize OBJECT &rest ARGS) */)
(ptrdiff_t nargs, Lisp_Object *args)
{
specpdl_ref count = SPECPDL_INDEX ();
+
+#ifdef WINDOWSNT
ensure_json_available ();
+#endif
struct json_configuration conf =
{json_object_hashtable, json_array_array, QCnull, QCfalse};
@@ -714,7 +719,10 @@ usage: (json-insert OBJECT &rest ARGS) */)
(ptrdiff_t nargs, Lisp_Object *args)
{
specpdl_ref count = SPECPDL_INDEX ();
+
+#ifdef WINDOWSNT
ensure_json_available ();
+#endif
struct json_configuration conf =
{json_object_hashtable, json_array_array, QCnull, QCfalse};
@@ -959,7 +967,10 @@ usage: (json-parse-string STRING &rest ARGS) */)
(ptrdiff_t nargs, Lisp_Object *args)
{
specpdl_ref count = SPECPDL_INDEX ();
+
+#ifdef WINDOWSNT
ensure_json_available ();
+#endif
Lisp_Object string = args[0];
CHECK_STRING (string);
@@ -1044,7 +1055,10 @@ usage: (json-parse-buffer &rest args) */)
(ptrdiff_t nargs, Lisp_Object *args)
{
specpdl_ref count = SPECPDL_INDEX ();
+
+#ifdef WINDOWSNT
ensure_json_available ();
+#endif
struct json_configuration conf =
{json_object_hashtable, json_array_array, QCnull, QCfalse};
@@ -1121,9 +1135,7 @@ syms_of_json (void)
DEFSYM (Qplist, "plist");
DEFSYM (Qarray, "array");
-#ifdef WINDOWSNT
defsubr (&Sjson__available_p);
-#endif
defsubr (&Sjson_serialize);
defsubr (&Sjson_insert);
defsubr (&Sjson_parse_string);