aboutsummaryrefslogtreecommitdiffstats
path: root/src/xml.c
diff options
context:
space:
mode:
authorPaul Eggert2014-12-26 09:32:06 -0800
committerPaul Eggert2014-12-28 00:33:27 -0800
commite092accb6bb8aea08dab1796d707b3adce55a38c (patch)
treef3f2bad267ce9f3f2ec61441a03447027ae3a3ea /src/xml.c
parent1505643bb70ce66e86d6c72902fe7e9199e93606 (diff)
downloademacs-e092accb6bb8aea08dab1796d707b3adce55a38c.tar.gz
emacs-e092accb6bb8aea08dab1796d707b3adce55a38c.zip
Wrap dll functions more simply
* decompress.c, gnutls.c, image.c, xml.c: If WINDOWSNT, use '#define FOO fn_FOO' to wrap dll functions, rather than the inverse when not WINDOWSNT. This isolates the fn_* business into the WINDOWSNT-specific section of the code, which makes it easier to maintain the generic code. * decompress.c (DEF_ZLIB_FN, LOAD_ZLIB_FN): * gnutls.c (DEF_GNUTLS_FN, LOAD_GNUTLS_FN): * image.c (DEF_IMGLIB_FN, LOAD_IMGLIB_FN): * xml.c (DEF_XML2_FN, LOAD_XML2_FN): Remove. All uses replaced by DEF_DLL_FN. * w32.h (DEF_DLL_FN, LOAD_DLL_FN): New macros.
Diffstat (limited to 'src/xml.c')
-rw-r--r--src/xml.c94
1 files changed, 49 insertions, 45 deletions
diff --git a/src/xml.c b/src/xml.c
index d418202182b..6be3bc74e97 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -33,26 +33,17 @@ static Lisp_Object Qlibxml2_dll;
33 33
34#ifdef WINDOWSNT 34#ifdef WINDOWSNT
35 35
36#include <windows.h> 36# include <windows.h>
37#include "w32.h" 37# include "w32.h"
38 38
39/* Macro for defining functions that will be loaded from the libxml2 DLL. */ 39DEF_DLL_FN (htmlDocPtr, htmlReadMemory,
40#define DEF_XML2_FN(rettype,func,args) static rettype (FAR CDECL *fn_##func)args
41
42/* Macro for loading libxml2 functions from the library. */
43#define LOAD_XML2_FN(lib,func) { \
44 fn_##func = (void *) GetProcAddress (lib, #func); \
45 if (!fn_##func) goto bad_library; \
46 }
47
48DEF_XML2_FN (htmlDocPtr, htmlReadMemory,
49 (const char *, int, const char *, const char *, int)); 40 (const char *, int, const char *, const char *, int));
50DEF_XML2_FN (xmlDocPtr, xmlReadMemory, 41DEF_DLL_FN (xmlDocPtr, xmlReadMemory,
51 (const char *, int, const char *, const char *, int)); 42 (const char *, int, const char *, const char *, int));
52DEF_XML2_FN (xmlNodePtr, xmlDocGetRootElement, (xmlDocPtr)); 43DEF_DLL_FN (xmlNodePtr, xmlDocGetRootElement, (xmlDocPtr));
53DEF_XML2_FN (void, xmlFreeDoc, (xmlDocPtr)); 44DEF_DLL_FN (void, xmlFreeDoc, (xmlDocPtr));
54DEF_XML2_FN (void, xmlCleanupParser, (void)); 45DEF_DLL_FN (void, xmlCleanupParser, (void));
55DEF_XML2_FN (void, xmlCheckVersion, (int)); 46DEF_DLL_FN (void, xmlCheckVersion, (int));
56 47
57static int 48static int
58libxml2_loaded_p (void) 49libxml2_loaded_p (void)
@@ -64,14 +55,33 @@ libxml2_loaded_p (void)
64 return 0; 55 return 0;
65} 56}
66 57
67#else /* !WINDOWSNT */ 58# undef htmlReadMemory
59# undef xmlCheckVersion
60# undef xmlCleanupParser
61# undef xmlDocGetRootElement
62# undef xmlFreeDoc
63# undef xmlReadMemory
64
65# define htmlReadMemory fn_htmlReadMemory
66# define xmlCheckVersion fn_xmlCheckVersion
67# define xmlCleanupParser fn_xmlCleanupParser
68# define xmlDocGetRootElement fn_xmlDocGetRootElement
69# define xmlFreeDoc fn_xmlFreeDoc
70# define xmlReadMemory fn_xmlReadMemory
71
72static bool
73load_dll_functions (HMODULE library)
74{
75 LOAD_DLL_FN (library, htmlReadMemory);
76 LOAD_DLL_FN (library, xmlReadMemory);
77 LOAD_DLL_FN (library, xmlDocGetRootElement);
78 LOAD_DLL_FN (library, xmlFreeDoc);
79 LOAD_DLL_FN (library, xmlCleanupParser);
80 LOAD_DLL_FN (library, xmlCheckVersion);
81 return true;
82}
68 83
69#define fn_htmlReadMemory htmlReadMemory 84#else /* !WINDOWSNT */
70#define fn_xmlReadMemory xmlReadMemory
71#define fn_xmlDocGetRootElement xmlDocGetRootElement
72#define fn_xmlFreeDoc xmlFreeDoc
73#define fn_xmlCleanupParser xmlCleanupParser
74#define fn_xmlCheckVersion xmlCheckVersion
75 85
76static int 86static int
77libxml2_loaded_p (void) 87libxml2_loaded_p (void)
@@ -97,14 +107,8 @@ init_libxml2_functions (void)
97 return 0; 107 return 0;
98 } 108 }
99 109
100 /* LOAD_XML2_FN jumps to bad_library if it fails to find the 110 if (! load_dll_functions (library))
101 named function. */ 111 goto bad_library;
102 LOAD_XML2_FN (library, htmlReadMemory);
103 LOAD_XML2_FN (library, xmlReadMemory);
104 LOAD_XML2_FN (library, xmlDocGetRootElement);
105 LOAD_XML2_FN (library, xmlFreeDoc);
106 LOAD_XML2_FN (library, xmlCleanupParser);
107 LOAD_XML2_FN (library, xmlCheckVersion);
108 112
109 Vlibrary_cache = Fcons (Fcons (Qlibxml2_dll, Qt), Vlibrary_cache); 113 Vlibrary_cache = Fcons (Fcons (Qlibxml2_dll, Qt), Vlibrary_cache);
110 return 1; 114 return 1;
@@ -182,7 +186,7 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, Lisp_Obj
182 const char *burl = ""; 186 const char *burl = "";
183 ptrdiff_t istart, iend, istart_byte, iend_byte; 187 ptrdiff_t istart, iend, istart_byte, iend_byte;
184 188
185 fn_xmlCheckVersion (LIBXML_VERSION); 189 xmlCheckVersion (LIBXML_VERSION);
186 190
187 validate_region (&start, &end); 191 validate_region (&start, &end);
188 192
@@ -201,16 +205,16 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, Lisp_Obj
201 } 205 }
202 206
203 if (htmlp) 207 if (htmlp)
204 doc = fn_htmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte), 208 doc = htmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte),
205 iend_byte - istart_byte, burl, "utf-8", 209 iend_byte - istart_byte, burl, "utf-8",
206 HTML_PARSE_RECOVER|HTML_PARSE_NONET| 210 HTML_PARSE_RECOVER|HTML_PARSE_NONET|
207 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR| 211 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR|
208 HTML_PARSE_NOBLANKS); 212 HTML_PARSE_NOBLANKS);
209 else 213 else
210 doc = fn_xmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte), 214 doc = xmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte),
211 iend_byte - istart_byte, burl, "utf-8", 215 iend_byte - istart_byte, burl, "utf-8",
212 XML_PARSE_NONET|XML_PARSE_NOWARNING| 216 XML_PARSE_NONET|XML_PARSE_NOWARNING|
213 XML_PARSE_NOBLANKS |XML_PARSE_NOERROR); 217 XML_PARSE_NOBLANKS |XML_PARSE_NOERROR);
214 218
215 if (doc != NULL) 219 if (doc != NULL)
216 { 220 {
@@ -232,14 +236,14 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, Lisp_Obj
232 if (NILP (result)) { 236 if (NILP (result)) {
233 /* The document doesn't have toplevel comments or we discarded 237 /* The document doesn't have toplevel comments or we discarded
234 them. Get the tree the proper way. */ 238 them. Get the tree the proper way. */
235 xmlNode *node = fn_xmlDocGetRootElement (doc); 239 xmlNode *node = xmlDocGetRootElement (doc);
236 if (node != NULL) 240 if (node != NULL)
237 result = make_dom (node); 241 result = make_dom (node);
238 } else 242 } else
239 result = Fcons (intern ("top"), 243 result = Fcons (intern ("top"),
240 Fcons (Qnil, Fnreverse (Fcons (r, result)))); 244 Fcons (Qnil, Fnreverse (Fcons (r, result))));
241 245
242 fn_xmlFreeDoc (doc); 246 xmlFreeDoc (doc);
243 } 247 }
244 248
245 return result; 249 return result;
@@ -249,7 +253,7 @@ void
249xml_cleanup_parser (void) 253xml_cleanup_parser (void)
250{ 254{
251 if (libxml2_loaded_p ()) 255 if (libxml2_loaded_p ())
252 fn_xmlCleanupParser (); 256 xmlCleanupParser ();
253} 257}
254 258
255DEFUN ("libxml-parse-html-region", Flibxml_parse_html_region, 259DEFUN ("libxml-parse-html-region", Flibxml_parse_html_region,