From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#60311: json-available-p: make dynamically correct for Windows Date: Sun, 25 Dec 2022 15:32:06 +0100 Message-ID: Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_B531C513-F760-47B3-9A16-FF7390E66714" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15224"; mail-complaints-to="usenet@ciao.gmane.io" To: 60311@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 25 15:33:31 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p9S49-0003me-Sb for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 25 Dec 2022 15:33:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p9S3m-0001lv-Fs; Sun, 25 Dec 2022 09:33:06 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p9S3j-0001la-7I for bug-gnu-emacs@gnu.org; Sun, 25 Dec 2022 09:33:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p9S3i-0004eH-Hk for bug-gnu-emacs@gnu.org; Sun, 25 Dec 2022 09:33:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p9S3h-0000n3-Su for bug-gnu-emacs@gnu.org; Sun, 25 Dec 2022 09:33:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 25 Dec 2022 14:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 60311 X-GNU-PR-Package: emacs X-Debbugs-Original-To: Emacs Bug Report Original-Received: via spool by submit@debbugs.gnu.org id=B.16719787352905 (code B ref -1); Sun, 25 Dec 2022 14:33:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 25 Dec 2022 14:32:15 +0000 Original-Received: from localhost ([127.0.0.1]:47722 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p9S2w-0000kl-HF for submit@debbugs.gnu.org; Sun, 25 Dec 2022 09:32:14 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:46654) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p9S2u-0000ka-8i for submit@debbugs.gnu.org; Sun, 25 Dec 2022 09:32:12 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p9S2u-0001hE-30 for bug-gnu-emacs@gnu.org; Sun, 25 Dec 2022 09:32:12 -0500 Original-Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p9S2s-0004WO-GC for bug-gnu-emacs@gnu.org; Sun, 25 Dec 2022 09:32:11 -0500 Original-Received: by mail-lf1-x134.google.com with SMTP id cf42so13178092lfb.1 for ; Sun, 25 Dec 2022 06:32:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:date:message-id:subject:mime-version:from:sender:from:to:cc :subject:date:message-id:reply-to; bh=BRP6FxmzbSX/EDOBOLIOaCyMAPlq6bgPPeWRjWiEq4c=; b=TAW8ScEjtgGVdyzRxOU2lPXRH/vlemR7XxhlADMw65FhMELNRUacdSlBv0y1gogso/ SH4IaN8sRq6MFSQDF+lD+LQNpdNDbn2zYS4ct55kJX8aSC0VpIr4jI9VU3LiXem7hW9i n/25NM+9OBwbzyHW8VaHtZxJdXBBd+qja5P+VSYSRPkNty+Zb31zGTdhVdo0ybPpM84O Z9Zm7/rIgLoTlnyYIminDAjUljFnipkcCMBX5aeV05bC65Vjjxd04DkqNJXJM/qchVX3 S19HNeLmyuhRCtltPmEfalGx/R6UWCh/1Zb5LwzvAhk+jkY/ZGr3l/OrBsjsFMViwtcF 6VPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:date:message-id:subject:mime-version:from:sender :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BRP6FxmzbSX/EDOBOLIOaCyMAPlq6bgPPeWRjWiEq4c=; b=EMfjPbjeRok/5kkJwn6DXB7SjzqFB2mjoigdgLZyHLglIcbHeSRpT424p3M/i3h7zi WPDMbmIDKcEGhCdZ5YbA/bz4fFJ597U09Z+aQyjRexQJpVXphSldGzZ4ZGNG0ZKaC7rP 8BPMIUk/qcM5w3u9DImwoj05Mrqbv3atzf4UNSJ4ryA0EUX6LBHZrphFJx3XdnftLvfA UaVthdfke6VuEJXy8Tk06dTeEaLohmzIiHyXZhjuhWeL9TNAFQ4cc3KtyF3Nx1FeFQNF l3AXut7mYW82AHxT/tElWxTYkoWww87RGfq6oEzKrLYb4mOedNlRQSqZnH4vM12xBHfd lhXA== X-Gm-Message-State: AFqh2koHOISiWRxuphqVkmYDrnYZTwNF3G3FJ8JAD3lrs59kqYiQumSM rijcwXI9dJ8qAyezGJc0vhsN805qP/U= X-Google-Smtp-Source: AMrXdXu4BLNc3CuLv0EqNYAX8Xs+O9Oy3KpD4N0OuI02TqzAqaLFNnoCwqlMosq1EPU8Pw57EoHrfw== X-Received: by 2002:ac2:5982:0:b0:4b5:892:3987 with SMTP id w2-20020ac25982000000b004b508923987mr5480343lfn.9.1671978727726; Sun, 25 Dec 2022 06:32:07 -0800 (PST) Original-Received: from smtpclient.apple (c188-150-171-209.bredband.tele2.se. [188.150.171.209]) by smtp.gmail.com with ESMTPSA id z11-20020a056512370b00b0049c29389b98sm1346864lfr.151.2022.12.25.06.32.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Dec 2022 06:32:07 -0800 (PST) X-Mailer: Apple Mail (2.3654.120.0.1.13) Received-SPF: pass client-ip=2a00:1450:4864:20::134; envelope-from=mattias.engdegard@gmail.com; helo=mail-lf1-x134.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:251850 Archived-At: --Apple-Mail=_B531C513-F760-47B3-9A16-FF7390E66714 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii The implementation of `json-available-p`, (and (fboundp 'json-serialize) (condition-case nil (json-serialize t) (:success t) (json-unavailable nil)))) probably isn't quite right on Windows: `json-serialize` is pure so it = will be called at compile time and the result, "true", used in the code = (actually not even that since the result is never used). Thus, if = libjansson could not be loaded during actual Emacs use (as opposed to = when Emacs was built), this would never be detected and json-available-p = would still return t. The patch below should take care of this. Would someone please help = testing it on Windows? --Apple-Mail=_B531C513-F760-47B3-9A16-FF7390E66714 Content-Disposition: attachment; filename=json-available-p.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="json-available-p.diff" Content-Transfer-Encoding: 7bit diff --git a/lisp/subr.el b/lisp/subr.el index fff4c88ccf..ce5ac14f5f 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -6905,11 +6905,11 @@ internal--format-docstring-line (defun json-available-p () "Return non-nil if Emacs has libjansson support." - (and (fboundp 'json-serialize) - (condition-case nil - (json-serialize t) - (:success t) - (json-unavailable nil)))) + (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)))) (defun ensure-list (object) "Return OBJECT as a list. diff --git a/src/json.c b/src/json.c index cdcc11358e..d2105bc27b 100644 --- a/src/json.c +++ b/src/json.c @@ -555,6 +555,38 @@ 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); + return json_initialized; +} +#endif + +static void +ensure_json_available (void) +{ +#ifdef WINDOWSNT + if (!json_available_p ()) + Fsignal (Qjson_unavailable, + list1 (build_unibyte_string ("jansson library not found"))); +#endif +} + +#ifdef WINDOWSNT +DEFUN ("json--available-p", Fjson__available_p, Sjson__available_p, 0, 0, NULL, + doc: /* Whether libjansson is available (internal). */) + (void) +{ + return json_available_p () ? Qt : Qnil; +} +#endif + DEFUN ("json-serialize", Fjson_serialize, Sjson_serialize, 1, MANY, NULL, doc: /* Return the JSON representation of OBJECT as a string. @@ -585,19 +617,7 @@ DEFUN ("json-serialize", Fjson_serialize, Sjson_serialize, 1, MANY, (ptrdiff_t nargs, Lisp_Object *args) { specpdl_ref count = SPECPDL_INDEX (); - -#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); - } - if (!json_initialized) - Fsignal (Qjson_unavailable, - list1 (build_unibyte_string ("jansson library not found"))); -#endif + ensure_json_available (); struct json_configuration conf = {json_object_hashtable, json_array_array, QCnull, QCfalse}; @@ -694,19 +714,7 @@ DEFUN ("json-insert", Fjson_insert, Sjson_insert, 1, MANY, (ptrdiff_t nargs, Lisp_Object *args) { specpdl_ref count = SPECPDL_INDEX (); - -#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); - } - if (!json_initialized) - Fsignal (Qjson_unavailable, - list1 (build_unibyte_string ("jansson library not found"))); -#endif + ensure_json_available (); struct json_configuration conf = {json_object_hashtable, json_array_array, QCnull, QCfalse}; @@ -951,19 +959,7 @@ DEFUN ("json-parse-string", Fjson_parse_string, Sjson_parse_string, 1, MANY, (ptrdiff_t nargs, Lisp_Object *args) { specpdl_ref count = SPECPDL_INDEX (); - -#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); - } - if (!json_initialized) - Fsignal (Qjson_unavailable, - list1 (build_unibyte_string ("jansson library not found"))); -#endif + ensure_json_available (); Lisp_Object string = args[0]; CHECK_STRING (string); @@ -1048,19 +1044,7 @@ DEFUN ("json-parse-buffer", Fjson_parse_buffer, Sjson_parse_buffer, (ptrdiff_t nargs, Lisp_Object *args) { specpdl_ref count = SPECPDL_INDEX (); - -#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); - } - if (!json_initialized) - Fsignal (Qjson_unavailable, - list1 (build_unibyte_string ("jansson library not found"))); -#endif + ensure_json_available (); struct json_configuration conf = {json_object_hashtable, json_array_array, QCnull, QCfalse}; @@ -1137,6 +1121,9 @@ 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); --Apple-Mail=_B531C513-F760-47B3-9A16-FF7390E66714--