From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.devel Subject: Re: What's the right way to detect libxml2? Date: Wed, 25 Oct 2017 13:24:34 +0200 Message-ID: <873767fp1p.fsf@gmail.com> References: <7f80cde1944261b7ee29020ff953f14c.squirrel@cloud103.planethippo.com> <36e54d52-99b2-ae53-2b36-99d06eb53d15@gmail.com> <877evkfpe1.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1508930820 9114 195.159.176.226 (25 Oct 2017 11:27:00 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 25 Oct 2017 11:27:00 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) Cc: emacs-devel@gnu.org To: Andy Moreton Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 25 13:26:52 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e7JpX-0008Tg-RI for ged-emacs-devel@m.gmane.org; Wed, 25 Oct 2017 13:26:40 +0200 Original-Received: from localhost ([::1]:47702 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7Jpf-0002ZY-6i for ged-emacs-devel@m.gmane.org; Wed, 25 Oct 2017 07:26:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7JpI-0002X4-OT for emacs-devel@gnu.org; Wed, 25 Oct 2017 07:26:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7Jnb-0001AX-Ux for emacs-devel@gnu.org; Wed, 25 Oct 2017 07:26:24 -0400 Original-Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]:53903) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e7Jnb-00018q-Cc for emacs-devel@gnu.org; Wed, 25 Oct 2017 07:24:39 -0400 Original-Received: by mail-wr0-x232.google.com with SMTP id u40so17779797wrf.10 for ; Wed, 25 Oct 2017 04:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:gmane-reply-to-list:date:in-reply-to :message-id:user-agent:mime-version; bh=FrwM7rBzgbmfPLyYDj1K40dPpMOxdSnwlXXnPAakEF8=; b=B5u0St82sVjP8d3E7VQy9j+Qbzbjcib3Pb/oQzp1YNoey253whBbf9iR5j9vEHuft0 8CaJeV+iqbqz1aVr7eDpezVEVqCdH5MpbMcjQeOFSN1bFlLG0thp16aZ6BWn3by9GUma 704WYpJqNyVu/mLUaSm8SHYOc+Ztj55/ANtdtmiom+mkA2Uh9efrppuAF/nHDt/otHFM mwWn8wlaS+SoSlEswvQoQcG5EWdE7I2Y8+5jeRSdKyEFFAQV0A1KSo1dmR/TbojLtVKp kwVnDg/r1u4Jrcb6WiY3VdFaDL2dTm9jkm6y7QRhvx6h0EoCG6hlJM9x/7ZR2txWo66q Iwvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references :gmane-reply-to-list:date:in-reply-to:message-id:user-agent :mime-version; bh=FrwM7rBzgbmfPLyYDj1K40dPpMOxdSnwlXXnPAakEF8=; b=mL5f+Jt9G/6uTxSdjg7I29IQTkg098AH8gv8rrVKaq42Bslo0q1+bLOp/EZ83LSn3b 1LfIi/u1/66Lt2IUdUlcZcwPEaa2p3HU4wVfNnilAbbzvbb6s8OMRXkGuqeT5aHY2WPL GBN/xsW1fTZDRXZi9ID/hAmb7SzFKYIsVKb+251oRXcQyYxwCig+GNOZZ6wt5bA/0N3J vK1G8fjqE5wMBpdC398Afa7NAf9cwl8U1JL94umdsa+2awOxw2n5OMAdntNDAX6Cwd9K J6lUxx5FjG0Z7KpGy96E95wXBtAuHZUvvNmOSYwCNt1D/uG7ckLdls9t3F38C52urkGh S+aQ== X-Gm-Message-State: AMCzsaVMf/RhqC3DxPFeDnx1DX43f4ruOrEwD6+Qiy48GNbdTAwTRABr t2Tdhk5eRq4oNAAYh/qWHEKKC2zn X-Google-Smtp-Source: ABhQp+RSD5YNphnEovpM1h0eZGK71BaVY6NcM07dmInPGZ2ItKuPJo4bGQXimMZS0admeG5vMEr3yQ== X-Received: by 10.223.131.226 with SMTP id 89mr1946120wre.227.1508930677544; Wed, 25 Oct 2017 04:24:37 -0700 (PDT) Original-Received: from rpluim-ubuntu ([149.5.228.1]) by smtp.gmail.com with ESMTPSA id p4sm1924193wrf.36.2017.10.25.04.24.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Oct 2017 04:24:35 -0700 (PDT) Gmane-Reply-To-List: yes In-Reply-To: (Andy Moreton's message of "Tue, 24 Oct 2017 18:46:07 +0100") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::232 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:219747 Archived-At: --=-=-= Content-Type: text/plain Andy Moreton writes: > On Tue 24 Oct 2017, Robert Pluim wrote: >> Like thus? Very lightly tested on GNU/Linux only. Might need a NEWS >> entry. >> > Works for me on a 64bit MinGW64/MSYS2 build of emacs-26 on Windows 10. OK. > I don't think you need to remove the HAVE_LIBXML2 conditionals, as lisp > code can check (fboundp 'libxml-available-p) before calling it, and it > may break builds without libxml2 support. I'm following the gnutls model, where gnutls-available-p is always available, so you don't have to do (and (fboundp 'libxml-available-p) (libxml-available-p)) If a build without libxml2 support breaks, then we fix the code in emacs. Actually, my patch breaks --without-xml2 :-) > Also, the libxml-available-p doc string claims it returns a list of > capabilities (which is true for gnutls-available-p), but it only returns > nil or t. Ah yes, too much cut & paste. Revised version attached. Compile and run-tested with and without xml2 on GNU/Linux. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Provide-libxml-available-p.patch >From 10fe04edc5adf942c2bf9806eea5dd81edd2c9a5 Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Tue, 24 Oct 2017 19:01:28 +0200 Subject: [PATCH] Provide libxml-available-p * src/emacs.c (main): Call syms_of_xml unconditionally * src/lisp.h: Provide syms_of_xml prototype even when HAVE_LIBXML2 is not defined * src/xml.c (Flibxml_available_p): New function, cloned from Fgnutls_available_p (syms_of_xml): Provide Slibxml_available_p * doc/lispref/text.texi (Parsing HTML/XML): Document libxml-available-p --- doc/lispref/text.texi | 5 +++++ src/emacs.c | 2 -- src/lisp.h | 2 +- src/xml.c | 37 ++++++++++++++++++++++++++++++++----- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index baa3c708e9..565d098069 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi @@ -4723,6 +4723,11 @@ Parsing HTML/XML @section Parsing HTML and XML @cindex parsing html +@defun libxml-available-p +This function returns non-@code{nil} if built-in libxml2 support is +available. +@end defun + When Emacs is compiled with libxml2 support, the following functions are available to parse HTML or XML text into Lisp object trees. diff --git a/src/emacs.c b/src/emacs.c index 0fe7d9113b..808abcd9aa 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1542,9 +1542,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem #endif #endif /* HAVE_X_WINDOWS */ -#ifdef HAVE_LIBXML2 syms_of_xml (); -#endif #ifdef HAVE_LCMS2 syms_of_lcms2 (); diff --git a/src/lisp.h b/src/lisp.h index 266370333f..cc8d90cbf1 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4399,9 +4399,9 @@ extern void syms_of_xterm (void); extern char *x_get_keysym_name (int); #endif /* HAVE_WINDOW_SYSTEM */ -#ifdef HAVE_LIBXML2 /* Defined in xml.c. */ extern void syms_of_xml (void); +#ifdef HAVE_LIBXML2 extern void xml_cleanup_parser (void); #endif diff --git a/src/xml.c b/src/xml.c index d087a34a5e..7afaa63c42 100644 --- a/src/xml.c +++ b/src/xml.c @@ -18,15 +18,15 @@ along with GNU Emacs. If not, see . */ #include +#include "lisp.h" +#include "buffer.h" + #ifdef HAVE_LIBXML2 #include #include #include -#include "lisp.h" -#include "buffer.h" - #ifdef WINDOWSNT @@ -291,16 +291,43 @@ If DISCARD-COMMENTS is non-nil, all HTML comments are discarded. */) return parse_region (start, end, base_url, discard_comments, false); return Qnil; } +#endif /* HAVE_LIBXML2 */ + +DEFUN ("libxml-available-p", Flibxml_available_p, Slibxml_available_p, 0, 0, 0, + doc: /* Return t if libxml2 support is available in this instance of Emacs.*/) + (void) +{ +#ifdef HAVE_LIBXML2 +# ifdef WINDOWSNT + Lisp_Object found = Fassq (Qlibxml2, Vlibrary_cache); + if (CONSP (found)) + return XCDR (found); + else + { + Lisp_Object status; + status = init_libxml2_functions () ? Qt : Qnil; + Vlibrary_cache = Fcons (Fcons (Qlibxml2, status), Vlibrary_cache); + return status; + } +# else + return Qt; +# endif /* WINDOWSNT */ +#else + return Qnil; +#endif /* HAVE_LIBXML2 */ +} + /*********************************************************************** Initialization ***********************************************************************/ void syms_of_xml (void) { +#ifdef HAVE_LIBXML2 defsubr (&Slibxml_parse_html_region); defsubr (&Slibxml_parse_xml_region); +#endif + defsubr (&Slibxml_available_p); } - -#endif /* HAVE_LIBXML2 */ -- 2.15.0.rc1 --=-=-=--