mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-11 14:01:43 -08:00
With static functions, modern compilers inline pretty well by themselves; advice from programmers often hurts as much as it helps. On my host (x86-64, Fedora 17, GCC 4.7.2, default 'configure'), this change shrinks the text size of the Emacs executable by 1.1% without affecting CPU significantly in my benchmark. * alloc.c (mem_find, live_string_p, live_cons_p, live_symbol_p) (live_float_p, live_misc_p, live_vector_p, live_buffer_p) (mark_maybe_object, mark_maybe_pointer, bounded_number): * buffer.c (bset_abbrev_mode, bset_abbrev_table) (bset_auto_fill_function, bset_auto_save_file_format) (bset_auto_save_file_name, bset_backed_up, bset_begv_marker) (bset_bidi_display_reordering, bset_buffer_file_coding_system) (bset_cache_long_line_scans, bset_case_fold_search) (bset_ctl_arrow, bset_cursor_in_non_selected_windows) (bset_cursor_type, bset_display_table, bset_extra_line_spacing) (bset_file_format, bset_file_truename, bset_fringe_cursor_alist) (bset_fringe_indicator_alist, bset_fringes_outside_margins) (bset_header_line_format, bset_indicate_buffer_boundaries) (bset_indicate_empty_lines, bset_invisibility_spec) (bset_left_fringe_width, bset_major_mode, bset_mark) (bset_minor_modes, bset_mode_line_format, bset_mode_name) (bset_name, bset_overwrite_mode, bset_pt_marker) (bset_right_fringe_width, bset_save_length) (bset_scroll_bar_width, bset_scroll_down_aggressively) (bset_scroll_up_aggressively, bset_selective_display) (bset_selective_display_ellipses, bset_vertical_scroll_bar_type) (bset_word_wrap, bset_zv_marker, set_buffer_overlays_before) (set_buffer_overlays_after): * category.c (bset_category_table): * charset.c (read_hex): * coding.c (produce_composition, produce_charset) (handle_composition_annotation, handle_charset_annotation) (char_encodable_p): * dispnew.c (swap_glyph_pointers, copy_row_except_pointers) (assign_row, set_frame_matrix_frame, make_current) (add_row_entry): * eval.c (set_specpdl_symbol, set_specpdl_old_value): * fns.c (maybe_resize_hash_table): * frame.c (fset_buffer_predicate, fset_minibuffer_window): * gmalloc.c (register_heapinfo): * image.c (lookup_image_type): * intervals.c (set_interval_object, set_interval_left) (set_interval_right, copy_interval_parent, rotate_right) (rotate_left, balance_possible_root_interval): * keyboard.c (kset_echo_string, kset_kbd_queue) (kset_keyboard_translate_table, kset_last_prefix_arg) (kset_last_repeatable_command, kset_local_function_key_map) (kset_overriding_terminal_local_map, kset_real_last_command) (kset_system_key_syms, clear_event, set_prop): * lread.c (digit_to_number): * marker.c (attach_marker, live_buffer, set_marker_internal): * nsterm.m (ns_compute_glyph_string_overhangs): * process.c (pset_buffer, pset_command) (pset_decode_coding_system, pset_decoding_buf) (pset_encode_coding_system, pset_encoding_buf, pset_filter) (pset_log, pset_mark, pset_name, pset_plist, pset_sentinel) (pset_status, pset_tty_name, pset_type, pset_write_queue): * syntax.c (bset_syntax_table, dec_bytepos): * terminal.c (tset_param_alist): * textprop.c (interval_has_some_properties) (interval_has_some_properties_list): * window.c (wset_combination_limit, wset_dedicated) (wset_display_table, wset_hchild, wset_left_fringe_width) (wset_left_margin_cols, wset_new_normal, wset_new_total) (wset_normal_cols, wset_normal_lines, wset_parent, wset_pointm) (wset_right_fringe_width, wset_right_margin_cols) (wset_scroll_bar_width, wset_start, wset_temslot, wset_vchild) (wset_vertical_scroll_bar_type, wset_window_parameters): * xdisp.c (wset_base_line_number, wset_base_line_pos) (wset_column_number_displayed, wset_region_showing) (window_box_edges, run_window_scroll_functions) (append_glyph_string_lists, prepend_glyph_string_lists) (append_glyph_string, set_glyph_string_background_width) (append_glyph, append_composite_glyph) (take_vertical_position_into_account): * xfaces.c (x_create_gc, x_free_gc, merge_face_vectors) (face_attr_equal_p, lface_equal_p, hash_string_case_insensitive) (lface_hash, lface_same_font_attributes_p, lookup_face): * xml.c (libxml2_loaded_p): * xterm.c (x_set_mode_line_face_gc, x_set_glyph_string_gc) (x_set_glyph_string_clipping, x_clear_glyph_string_rect): Now 'static', not 'static inline'. Fixes: debbugs:12541
290 lines
7.3 KiB
C
290 lines
7.3 KiB
C
/* Interface to libxml2.
|
||
Copyright (C) 2010-2012 Free Software Foundation, Inc.
|
||
|
||
This file is part of GNU Emacs.
|
||
|
||
GNU Emacs is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation, either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
GNU Emacs is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
|
||
|
||
#include <config.h>
|
||
|
||
#ifdef HAVE_LIBXML2
|
||
|
||
#include <libxml/tree.h>
|
||
#include <libxml/parser.h>
|
||
#include <libxml/HTMLparser.h>
|
||
|
||
#include "lisp.h"
|
||
#include "character.h"
|
||
#include "buffer.h"
|
||
|
||
|
||
static Lisp_Object Qlibxml2_dll;
|
||
|
||
#ifdef WINDOWSNT
|
||
|
||
#include <windows.h>
|
||
#include "w32.h"
|
||
|
||
/* Macro for defining functions that will be loaded from the libxml2 DLL. */
|
||
#define DEF_XML2_FN(rettype,func,args) static rettype (FAR CDECL *fn_##func)args
|
||
|
||
/* Macro for loading libxml2 functions from the library. */
|
||
#define LOAD_XML2_FN(lib,func) { \
|
||
fn_##func = (void *) GetProcAddress (lib, #func); \
|
||
if (!fn_##func) goto bad_library; \
|
||
}
|
||
|
||
DEF_XML2_FN (htmlDocPtr, htmlReadMemory,
|
||
(const char *, int, const char *, const char *, int));
|
||
DEF_XML2_FN (xmlDocPtr, xmlReadMemory,
|
||
(const char *, int, const char *, const char *, int));
|
||
DEF_XML2_FN (xmlNodePtr, xmlDocGetRootElement, (xmlDocPtr));
|
||
DEF_XML2_FN (void, xmlFreeDoc, (xmlDocPtr));
|
||
DEF_XML2_FN (void, xmlCleanupParser, (void));
|
||
DEF_XML2_FN (void, xmlCheckVersion, (int));
|
||
|
||
static int
|
||
libxml2_loaded_p (void)
|
||
{
|
||
Lisp_Object found = Fassq (Qlibxml2_dll, Vlibrary_cache);
|
||
|
||
if (CONSP (found))
|
||
return EQ (XCDR (found), Qt) ? 1 : 0;
|
||
return 0;
|
||
}
|
||
|
||
#else /* !WINDOWSNT */
|
||
|
||
#define fn_htmlReadMemory htmlReadMemory
|
||
#define fn_xmlReadMemory xmlReadMemory
|
||
#define fn_xmlDocGetRootElement xmlDocGetRootElement
|
||
#define fn_xmlFreeDoc xmlFreeDoc
|
||
#define fn_xmlCleanupParser xmlCleanupParser
|
||
#define fn_xmlCheckVersion xmlCheckVersion
|
||
|
||
static int
|
||
libxml2_loaded_p (void)
|
||
{
|
||
return 1;
|
||
}
|
||
|
||
#endif /* !WINDOWSNT */
|
||
|
||
static int
|
||
init_libxml2_functions (void)
|
||
{
|
||
#ifdef WINDOWSNT
|
||
if (libxml2_loaded_p ())
|
||
return 1;
|
||
else
|
||
{
|
||
HMODULE library;
|
||
|
||
if (!(library = w32_delayed_load (Qlibxml2_dll)))
|
||
{
|
||
message ("%s", "libxml2 library not found");
|
||
return 0;
|
||
}
|
||
|
||
/* LOAD_XML2_FN jumps to bad_library if it fails to find the
|
||
named function. */
|
||
LOAD_XML2_FN (library, htmlReadMemory);
|
||
LOAD_XML2_FN (library, xmlReadMemory);
|
||
LOAD_XML2_FN (library, xmlDocGetRootElement);
|
||
LOAD_XML2_FN (library, xmlFreeDoc);
|
||
LOAD_XML2_FN (library, xmlCleanupParser);
|
||
LOAD_XML2_FN (library, xmlCheckVersion);
|
||
|
||
Vlibrary_cache = Fcons (Fcons (Qlibxml2_dll, Qt), Vlibrary_cache);
|
||
return 1;
|
||
}
|
||
|
||
bad_library:
|
||
Vlibrary_cache = Fcons (Fcons (Qlibxml2_dll, Qnil), Vlibrary_cache);
|
||
|
||
return 0;
|
||
#else /* !WINDOWSNT */
|
||
return 1;
|
||
#endif /* !WINDOWSNT */
|
||
}
|
||
|
||
static Lisp_Object
|
||
make_dom (xmlNode *node)
|
||
{
|
||
if (node->type == XML_ELEMENT_NODE)
|
||
{
|
||
Lisp_Object result = Fcons (intern ((char *) node->name), Qnil);
|
||
xmlNode *child;
|
||
xmlAttr *property;
|
||
Lisp_Object plist = Qnil;
|
||
|
||
/* First add the attributes. */
|
||
property = node->properties;
|
||
while (property != NULL)
|
||
{
|
||
if (property->children &&
|
||
property->children->content)
|
||
{
|
||
char *content = (char *) property->children->content;
|
||
plist = Fcons (Fcons (intern ((char *) property->name),
|
||
build_string (content)),
|
||
plist);
|
||
}
|
||
property = property->next;
|
||
}
|
||
result = Fcons (Fnreverse (plist), result);
|
||
|
||
/* Then add the children of the node. */
|
||
child = node->children;
|
||
while (child != NULL)
|
||
{
|
||
result = Fcons (make_dom (child), result);
|
||
child = child->next;
|
||
}
|
||
|
||
return Fnreverse (result);
|
||
}
|
||
else if (node->type == XML_TEXT_NODE || node->type == XML_CDATA_SECTION_NODE)
|
||
{
|
||
if (node->content)
|
||
return build_string ((char *) node->content);
|
||
else
|
||
return Qnil;
|
||
}
|
||
else if (node->type == XML_COMMENT_NODE)
|
||
{
|
||
if (node->content)
|
||
return list3 (intern ("comment"), Qnil,
|
||
build_string ((char *) node->content));
|
||
else
|
||
return Qnil;
|
||
}
|
||
else
|
||
return Qnil;
|
||
}
|
||
|
||
static Lisp_Object
|
||
parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int htmlp)
|
||
{
|
||
xmlDoc *doc;
|
||
Lisp_Object result = Qnil;
|
||
const char *burl = "";
|
||
ptrdiff_t bytes;
|
||
ptrdiff_t istart, iend;
|
||
|
||
fn_xmlCheckVersion (LIBXML_VERSION);
|
||
|
||
validate_region (&start, &end);
|
||
|
||
istart = XINT (start);
|
||
iend = XINT (end);
|
||
|
||
if (istart < GPT && GPT < iend)
|
||
move_gap (iend);
|
||
|
||
if (! NILP (base_url))
|
||
{
|
||
CHECK_STRING (base_url);
|
||
burl = SSDATA (base_url);
|
||
}
|
||
|
||
bytes = CHAR_TO_BYTE (iend) - CHAR_TO_BYTE (istart);
|
||
|
||
if (htmlp)
|
||
doc = fn_htmlReadMemory ((char *) BYTE_POS_ADDR (CHAR_TO_BYTE (istart)),
|
||
bytes, burl, "utf-8",
|
||
HTML_PARSE_RECOVER|HTML_PARSE_NONET|
|
||
HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR|
|
||
HTML_PARSE_NOBLANKS);
|
||
else
|
||
doc = fn_xmlReadMemory ((char *) BYTE_POS_ADDR (CHAR_TO_BYTE (istart)),
|
||
bytes, burl, "utf-8",
|
||
XML_PARSE_NONET|XML_PARSE_NOWARNING|
|
||
XML_PARSE_NOBLANKS |XML_PARSE_NOERROR);
|
||
|
||
if (doc != NULL)
|
||
{
|
||
/* If the document is just comments, then this should get us the
|
||
nodes anyway. */
|
||
xmlNode *n = doc->children->next;
|
||
Lisp_Object r = Qnil;
|
||
|
||
while (n) {
|
||
if (!NILP (r))
|
||
result = Fcons (r, result);
|
||
r = make_dom (n);
|
||
n = n->next;
|
||
}
|
||
|
||
if (NILP (result)) {
|
||
/* The document isn't just comments, so get the tree the
|
||
proper way. */
|
||
xmlNode *node = fn_xmlDocGetRootElement (doc);
|
||
if (node != NULL)
|
||
result = make_dom (node);
|
||
} else
|
||
result = Fcons (intern ("top"),
|
||
Fcons (Qnil, Fnreverse (Fcons (r, result))));
|
||
|
||
fn_xmlFreeDoc (doc);
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
void
|
||
xml_cleanup_parser (void)
|
||
{
|
||
if (libxml2_loaded_p ())
|
||
fn_xmlCleanupParser ();
|
||
}
|
||
|
||
DEFUN ("libxml-parse-html-region", Flibxml_parse_html_region,
|
||
Slibxml_parse_html_region,
|
||
2, 3, 0,
|
||
doc: /* Parse the region as an HTML document and return the parse tree.
|
||
If BASE-URL is non-nil, it is used to expand relative URLs. */)
|
||
(Lisp_Object start, Lisp_Object end, Lisp_Object base_url)
|
||
{
|
||
if (init_libxml2_functions ())
|
||
return parse_region (start, end, base_url, 1);
|
||
return Qnil;
|
||
}
|
||
|
||
DEFUN ("libxml-parse-xml-region", Flibxml_parse_xml_region,
|
||
Slibxml_parse_xml_region,
|
||
2, 3, 0,
|
||
doc: /* Parse the region as an XML document and return the parse tree.
|
||
If BASE-URL is non-nil, it is used to expand relative URLs. */)
|
||
(Lisp_Object start, Lisp_Object end, Lisp_Object base_url)
|
||
{
|
||
if (init_libxml2_functions ())
|
||
return parse_region (start, end, base_url, 0);
|
||
return Qnil;
|
||
}
|
||
|
||
|
||
/***********************************************************************
|
||
Initialization
|
||
***********************************************************************/
|
||
void
|
||
syms_of_xml (void)
|
||
{
|
||
defsubr (&Slibxml_parse_html_region);
|
||
defsubr (&Slibxml_parse_xml_region);
|
||
|
||
DEFSYM (Qlibxml2_dll, "libxml2");
|
||
}
|
||
|
||
#endif /* HAVE_LIBXML2 */
|