Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ cmake_dependent_option(
"LIBXML2_WITH_REGEXPS;LIBXML2_WITH_SCHEMAS" OFF)

if(LIBXML2_WITH_PYTHON)
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
#find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
#set(LIBXML2_PYTHON_INSTALL_DIR ${Python3_SITEARCH} CACHE PATH "Python bindings install directory")
set(LIBXML2_PYTHON_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/python"
set(LIBXML2_PYTHON_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib"
CACHE PATH "Python bindings install directory")
endif()

Expand Down Expand Up @@ -307,9 +307,15 @@ endif()
add_library(LibXml2 ${LIBXML2_HDRS} ${LIBXML2_SRCS})
add_library(LibXml2::LibXml2 ALIAS LibXml2)

# for nice looking
target_compile_options(LibXml2 PRIVATE -Wno-shorten-64-to-32)
target_compile_options(LibXml2 PRIVATE -Wno-cast-align)

target_include_directories(
LibXml2
PUBLIC
${PYTHON_INCLUDE_DIRS}
${LZMA_INCLUDE_DIRS}
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/libxml2>
Expand Down Expand Up @@ -522,8 +528,8 @@ if(LIBXML2_WITH_PYTHON)
Doxygen
)

Python3_add_library(
LibXml2Mod MODULE WITH_SOABI
add_library(
LibXml2Mod
libxml2-py.c
libxml2-py.h
python/libxml.c
Expand All @@ -533,16 +539,22 @@ if(LIBXML2_WITH_PYTHON)
target_include_directories(
LibXml2Mod
PRIVATE
${PYTHON_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/python>
)
target_link_libraries(LibXml2Mod PRIVATE LibXml2)
# target_link_libraries(LibXml2Mod PRIVATE LibXml2)
set_target_properties(
LibXml2Mod
PROPERTIES
IMPORT_PREFIX lib
OUTPUT_NAME xml2mod
PREFIX lib
)
# for nice looking
target_compile_options(LibXml2Mod PRIVATE -Wno-shorten-64-to-32)

install(
TARGETS LibXml2Mod
ARCHIVE DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT development
Expand Down
21 changes: 12 additions & 9 deletions HTMLparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#include "private/parser.h"
#include "private/tree.h"

#include "juno_vars.h"

#define HTML_MAX_NAMELEN 1000
#define HTML_MAX_ATTRS 100000000 /* 100 million */
#define HTML_PARSER_BIG_BUFFER_SIZE 1000
Expand All @@ -68,36 +70,37 @@ typedef enum {

typedef const unsigned htmlAsciiMask[2];

static htmlAsciiMask MASK_DQ = {
static htmlAsciiMask MASK_DQ = { /* juno_skip */
0,
1u << ('"' - 32),
};
static htmlAsciiMask MASK_SQ = {
static htmlAsciiMask MASK_SQ = { /* juno_skip */
0,
1u << ('\'' - 32),
};
static htmlAsciiMask MASK_GT = {
static htmlAsciiMask MASK_GT = { /* juno_skip */
0,
1u << ('>' - 32),
};
static htmlAsciiMask MASK_DASH = {
static htmlAsciiMask MASK_DASH = { /* juno_skip */
0,
1u << ('-' - 32),
};
static htmlAsciiMask MASK_WS_GT = {
static htmlAsciiMask MASK_WS_GT = { /* juno_skip */
1u << 0x09 | 1u << 0x0A | 1u << 0x0C | 1u << 0x0D,
1u << (' ' - 32) | 1u << ('>' - 32),
};
static htmlAsciiMask MASK_DQ_GT = {
static htmlAsciiMask MASK_DQ_GT = { /* juno_skip */
0,
1u << ('"' - 32) | 1u << ('>' - 32),
};
static htmlAsciiMask MASK_SQ_GT = {
static htmlAsciiMask MASK_SQ_GT = { /* juno_skip */
0,
1u << ('\'' - 32) | 1u << ('>' - 32),
};

static int htmlOmittedDefaultValue = 1;
JUNO_DECLARE_STATIC_VAR(int, htmlOmittedDefaultValue, 1)
#define htmlOmittedDefaultValue JUNO_VAR(htmlOmittedDefaultValue)

static int
htmlParseElementInternal(htmlParserCtxtPtr ctxt);
Expand Down Expand Up @@ -500,7 +503,7 @@ htmlSkipBlankChars(xmlParserCtxtPtr ctxt) {
*/

static const htmlElemDesc
html40ElementTable[] = {
html40ElementTable[] = { /* juno_skip */
{ "a", 0, 0, 0, 0, 0, 0, 1, "anchor ",
NULL, NULL, NULL, NULL, NULL,
0
Expand Down
7 changes: 7 additions & 0 deletions HTMLtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,9 @@ htmlNodeDumpInternal(xmlOutputBuffer *buf, xmlNode *cur,
root = cur;
parent = cur->parent;
while (1) {
if (cur == NULL) {
break;
}
switch (cur->type) {
case XML_HTML_DOCUMENT_NODE:
case XML_DOCUMENT_NODE:
Expand Down Expand Up @@ -1069,6 +1072,10 @@ htmlNodeDumpInternal(xmlOutputBuffer *buf, xmlNode *cur,

isRaw = 0;

if (cur == NULL) {
break;
}

cur = parent;
/* cur->parent was validated when descending. */
parent = cur->parent;
Expand Down
37 changes: 24 additions & 13 deletions catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include "private/memory.h"
#include "private/threads.h"

#include "juno_vars.h"

#define MAX_DELEGATE 50
#define MAX_CATAL_DEPTH 50

Expand All @@ -55,12 +57,12 @@
#define XML_URN_PUBID "urn:publicid:"
#define XML_CATAL_BREAK ((xmlChar *) -1)
#ifndef XML_XML_DEFAULT_CATALOG
#define XML_XML_DEFAULT_CATALOG "file://" XML_SYSCONFDIR "/xml/catalog"
#define XML_XML_DEFAULT_CATALOG "file://" XML_SYSCONFDIR "/xml/catalog" /* juno_skip */
#endif

#ifdef LIBXML_SGML_CATALOG_ENABLED
#ifndef XML_SGML_DEFAULT_CATALOG
#define XML_SGML_DEFAULT_CATALOG "file://" XML_SYSCONFDIR "/sgml/catalog"
#define XML_SGML_DEFAULT_CATALOG "file://" XML_SYSCONFDIR "/sgml/catalog" /* juno_skip */
#endif
#endif

Expand Down Expand Up @@ -163,33 +165,42 @@ struct _xmlCatalog {
/*
* Those are preferences
*/
static int xmlDebugCatalogs = 0; /* used for debugging */
static xmlCatalogAllow xmlCatalogDefaultAllow = XML_CATA_ALLOW_ALL;
static xmlCatalogPrefer xmlCatalogDefaultPrefer = XML_CATA_PREFER_PUBLIC;

JUNO_DECLARE_STATIC_VAR(int, xmlDebugCatalogs, 0) /* used for debugging */
#define xmlDebugCatalogs JUNO_VAR(xmlDebugCatalogs)
JUNO_DECLARE_STATIC_VAR(xmlCatalogAllow, xmlCatalogDefaultAllow, XML_CATA_ALLOW_ALL)
#define xmlCatalogDefaultAllow JUNO_VAR(xmlCatalogDefaultAllow)
JUNO_DECLARE_STATIC_VAR(xmlCatalogPrefer, xmlCatalogDefaultPrefer, XML_CATA_PREFER_PUBLIC)
#define xmlCatalogDefaultPrefer JUNO_VAR(xmlCatalogDefaultPrefer)

/*
* Hash table containing all the trees of XML catalogs parsed by
* the application.
*/
static xmlHashTablePtr xmlCatalogXMLFiles = NULL;
JUNO_DECLARE_STATIC_VAR(xmlHashTablePtr, xmlCatalogXMLFiles, NULL)
#define xmlCatalogXMLFiles JUNO_VAR(xmlCatalogXMLFiles)

/*
* The default catalog in use by the application
*/
static xmlCatalogPtr xmlDefaultCatalog = NULL;
JUNO_DECLARE_STATIC_VAR(xmlCatalogPtr, xmlDefaultCatalog, NULL)
#define xmlDefaultCatalog JUNO_VAR(xmlDefaultCatalog)

/*
* A mutex for modifying the shared global catalog(s)
* xmlDefaultCatalog tree.
* It also protects xmlCatalogXMLFiles
* The core of this readers/writer scheme is in #xmlFetchXMLCatalogFile
*/
static xmlRMutex xmlCatalogMutex;

JUNO_DECLARE_STATIC_VAR(xmlRMutex, xmlCatalogMutex, {0})
#define xmlCatalogMutex JUNO_VAR(xmlCatalogMutex)

/*
* Whether the default system catalog was initialized.
*/
static int xmlCatalogInitialized = 0;
JUNO_DECLARE_STATIC_VAR(int, xmlCatalogInitialized, 0)
#define xmlCatalogInitialized JUNO_VAR(xmlCatalogInitialized)

/************************************************************************
* *
Expand Down Expand Up @@ -3637,8 +3648,8 @@ xmlCatalogLocalResolveURI(void *catalogs, const xmlChar *URI) {
const xmlChar *
xmlCatalogGetSystem(const xmlChar *sysID) {
xmlChar *ret;
static xmlChar result[1000];
static int msg = 0;
static xmlChar result[1000]; /* juno_skip */
static int msg = 0; /* juno_skip */

if (!xmlCatalogInitialized)
xmlInitializeCatalog();
Expand Down Expand Up @@ -3682,8 +3693,8 @@ xmlCatalogGetSystem(const xmlChar *sysID) {
const xmlChar *
xmlCatalogGetPublic(const xmlChar *pubID) {
xmlChar *ret;
static xmlChar result[1000];
static int msg = 0;
static xmlChar result[1000]; /* juno_skip */
static int msg = 0; /* juno_skip */

if (!xmlCatalogInitialized)
xmlInitializeCatalog();
Expand Down
11 changes: 8 additions & 3 deletions dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <libxml/xmlmemory.h>
#include <libxml/xmlstring.h>

#include "juno_vars.h"

#ifndef SIZE_MAX
#define SIZE_MAX ((size_t) -1)
#endif
Expand Down Expand Up @@ -78,7 +80,8 @@ struct _xmlDict {
* A mutex for modifying the reference counter for shared
* dictionaries.
*/
static xmlMutex xmlDictMutex;
JUNO_DECLARE_STATIC_VAR(xmlMutex, xmlDictMutex, {0})
#define xmlDictMutex JUNO_VAR(xmlDictMutex)

/**
* @deprecated Alias for #xmlInitParser.
Expand Down Expand Up @@ -902,9 +905,11 @@ xmlDictQLookup(xmlDict *dict, const xmlChar *prefix, const xmlChar *name) {
#include <time.h>
#endif

static xmlMutex xmlRngMutex;
JUNO_DECLARE_STATIC_VAR(xmlMutex, xmlRngMutex, {0})
#define xmlRngMutex JUNO_VAR(xmlRngMutex)

static unsigned globalRngState[2];
JUNO_DECLARE_STATIC_ARRAY(unsigned, 2, globalRngState, {0})
#define globalRngState JUNO_ARRAY(globalRngState)

/*
*
Expand Down
21 changes: 15 additions & 6 deletions encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#include <unicode/ucnv.h>
#endif

#include "juno_vars.h"

#define XML_HANDLER_STATIC (1 << 0)
#define XML_HANDLER_LEGACY (1 << 1)

Expand All @@ -60,11 +62,15 @@ struct _xmlCharEncodingAlias {
const char *alias;
};

static xmlCharEncodingAliasPtr xmlCharEncodingAliases = NULL;
static int xmlCharEncodingAliasesNb = 0;
static int xmlCharEncodingAliasesMax = 0;
JUNO_DECLARE_STATIC_VAR(xmlCharEncodingAliasPtr, xmlCharEncodingAliases, NULL)
#define xmlCharEncodingAliases JUNO_VAR(xmlCharEncodingAliases)
JUNO_DECLARE_STATIC_VAR(int, xmlCharEncodingAliasesNb, 0)
#define xmlCharEncodingAliasesNb JUNO_VAR(xmlCharEncodingAliasesNb)
JUNO_DECLARE_STATIC_VAR(int, xmlCharEncodingAliasesMax, 0)
#define xmlCharEncodingAliasesMax JUNO_VAR(xmlCharEncodingAliasesMax)

static int xmlLittleEndian = 1;
JUNO_DECLARE_STATIC_VAR(int, xmlLittleEndian, 1)
#define xmlLittleEndian JUNO_VAR(xmlLittleEndian)

typedef struct {
const char *name;
Expand Down Expand Up @@ -356,8 +362,11 @@ static const xmlCharEncodingHandler defaultHandlers[32] = {

/* the size should be growable, but it's not a big deal ... */
#define MAX_ENCODING_HANDLERS 50
static xmlCharEncodingHandlerPtr *globalHandlers = NULL;
static int nbCharEncodingHandler = 0;
JUNO_DECLARE_STATIC_VAR(xmlCharEncodingHandlerPtr *,globalHandlers, NULL)
#define globalHandlers JUNO_VAR(globalHandlers)
JUNO_DECLARE_STATIC_VAR(int, nbCharEncodingHandler, 0)
#define nbCharEncodingHandler JUNO_VAR(nbCharEncodingHandler)


#ifdef LIBXML_ICONV_ENABLED
static xmlParserErrors
Expand Down
27 changes: 17 additions & 10 deletions entities.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "private/error.h"
#include "private/io.h"

#include "juno_vars.h"

#ifndef SIZE_MAX
#define SIZE_MAX ((size_t) -1)
#endif
Expand All @@ -38,41 +40,46 @@
* The XML predefined entities.
*/

static xmlEntity xmlEntityLt = {
JUNO_DECLARE_STATIC_VAR(xmlEntity, xmlEntityLt, JUNO_VAR_INITIALIZER({
NULL, XML_ENTITY_DECL, BAD_CAST "lt",
NULL, NULL, NULL, NULL, NULL, NULL,
BAD_CAST "<", BAD_CAST "<", 1,
XML_INTERNAL_PREDEFINED_ENTITY,
NULL, NULL, NULL, NULL, 0, 0, 0
};
static xmlEntity xmlEntityGt = {
}))
#define xmlEntityLt JUNO_VAR(xmlEntityLt)
JUNO_DECLARE_STATIC_VAR(xmlEntity, xmlEntityGt, JUNO_VAR_INITIALIZER({
NULL, XML_ENTITY_DECL, BAD_CAST "gt",
NULL, NULL, NULL, NULL, NULL, NULL,
BAD_CAST ">", BAD_CAST ">", 1,
XML_INTERNAL_PREDEFINED_ENTITY,
NULL, NULL, NULL, NULL, 0, 0, 0
};
static xmlEntity xmlEntityAmp = {
}))
#define xmlEntityGt JUNO_VAR(xmlEntityGt)
JUNO_DECLARE_STATIC_VAR(xmlEntity, xmlEntityAmp, JUNO_VAR_INITIALIZER({
NULL, XML_ENTITY_DECL, BAD_CAST "amp",
NULL, NULL, NULL, NULL, NULL, NULL,
BAD_CAST "&", BAD_CAST "&", 1,
XML_INTERNAL_PREDEFINED_ENTITY,
NULL, NULL, NULL, NULL, 0, 0, 0
};
static xmlEntity xmlEntityQuot = {
}))
#define xmlEntityAmp JUNO_VAR(xmlEntityAmp)
JUNO_DECLARE_STATIC_VAR(xmlEntity, xmlEntityQuot, JUNO_VAR_INITIALIZER({
NULL, XML_ENTITY_DECL, BAD_CAST "quot",
NULL, NULL, NULL, NULL, NULL, NULL,
BAD_CAST "\"", BAD_CAST "\"", 1,
XML_INTERNAL_PREDEFINED_ENTITY,
NULL, NULL, NULL, NULL, 0, 0, 0
};
static xmlEntity xmlEntityApos = {
}))
#define xmlEntityQuot JUNO_VAR(xmlEntityQuot)
JUNO_DECLARE_STATIC_VAR(xmlEntity, xmlEntityApos, JUNO_VAR_INITIALIZER({
NULL, XML_ENTITY_DECL, BAD_CAST "apos",
NULL, NULL, NULL, NULL, NULL, NULL,
BAD_CAST "'", BAD_CAST "'", 1,
XML_INTERNAL_PREDEFINED_ENTITY,
NULL, NULL, NULL, NULL, 0, 0, 0
};
}))
#define xmlEntityApos JUNO_VAR(xmlEntityApos)

/**
* Frees the entity.
Expand Down
1 change: 1 addition & 0 deletions example/io1.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#error juno_skip
/**
* section: InputOutput
* synopsis: Example of custom Input/Output
Expand Down
1 change: 1 addition & 0 deletions example/parse4.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#error juno_skip
/**
* section: Parsing
* synopsis: Parse an XML document chunk by chunk to a tree and free it
Expand Down
Loading