mirror of
https://gitlab.gnome.org/GNOME/libxml2
synced 2025-03-28 21:33:13 +00:00
include: Use intptr_t to cast between pointers and ints
This commit is contained in:
parent
41c10c0cec
commit
ca81916023
@ -4916,7 +4916,7 @@ static int
|
||||
htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
|
||||
int ret = 0;
|
||||
htmlParserInputPtr in;
|
||||
ptrdiff_t avail = 0;
|
||||
size_t avail = 0;
|
||||
int cur;
|
||||
|
||||
htmlParserNodeInfo node_info;
|
||||
|
2
SAX2.c
2
SAX2.c
@ -2566,7 +2566,7 @@ xmlSAX2Text(xmlParserCtxtPtr ctxt, const xmlChar *ch, int len,
|
||||
else {
|
||||
lastChild->line = USHRT_MAX;
|
||||
if (ctxt->options & XML_PARSE_BIG_LINES)
|
||||
lastChild->psvi = (void *) (ptrdiff_t) ctxt->input->line;
|
||||
lastChild->psvi = XML_INT_TO_PTR(ctxt->input->line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
libxml.h
11
libxml.h
@ -41,6 +41,17 @@
|
||||
#define XML_INLINE
|
||||
#endif
|
||||
|
||||
#if __STDC_VERSION__ >= 199901L || (defined(_MSC_VER) && _MSC_VER >= 1900)
|
||||
#include <stdint.h>
|
||||
#define XML_INTPTR_T intptr_t
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#define XML_INTPTR_T ptrdiff_t
|
||||
#endif
|
||||
|
||||
#define XML_PTR_TO_INT(p) ((XML_INTPTR_T) (p))
|
||||
#define XML_INT_TO_PTR(i) ((void *) (XML_INTPTR_T) (i))
|
||||
|
||||
#if !defined(_WIN32) && \
|
||||
!defined(__CYGWIN__) && \
|
||||
(defined(__clang__) || \
|
||||
|
23
parser.c
23
parser.c
@ -1199,7 +1199,7 @@ xmlAddSpecialAttr(xmlParserCtxtPtr ctxt,
|
||||
}
|
||||
|
||||
if (xmlHashAdd2(ctxt->attsSpecial, fullname, fullattr,
|
||||
(void *) (ptrdiff_t) type) < 0)
|
||||
XML_INT_TO_PTR(type)) < 0)
|
||||
goto mem_error;
|
||||
return;
|
||||
|
||||
@ -1218,7 +1218,7 @@ xmlCleanSpecialAttrCallback(void *payload, void *data,
|
||||
const xmlChar *unused ATTRIBUTE_UNUSED) {
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) data;
|
||||
|
||||
if (((ptrdiff_t) payload) == XML_ATTRIBUTE_CDATA) {
|
||||
if (XML_PTR_TO_INT(payload) == XML_ATTRIBUTE_CDATA) {
|
||||
xmlHashRemoveEntry2(ctxt->attsSpecial, fullname, fullattr, NULL);
|
||||
}
|
||||
}
|
||||
@ -8908,9 +8908,8 @@ xmlParseAttribute2(xmlParserCtxtPtr ctxt,
|
||||
if (ctxt->attsSpecial != NULL) {
|
||||
int type;
|
||||
|
||||
type = (int) (ptrdiff_t) xmlHashQLookup2(ctxt->attsSpecial,
|
||||
pref, elem,
|
||||
prefix, name);
|
||||
type = XML_PTR_TO_INT(xmlHashQLookup2(ctxt->attsSpecial, pref, elem,
|
||||
prefix, name));
|
||||
if (type != 0)
|
||||
normalize = 1;
|
||||
}
|
||||
@ -9013,7 +9012,7 @@ xmlAttrHashInsert(xmlParserCtxtPtr ctxt, unsigned size, const xmlChar *name,
|
||||
const xmlChar **atts = &ctxt->atts[bucket->index];
|
||||
|
||||
if (name == atts[0]) {
|
||||
int nsIndex = (int) (ptrdiff_t) atts[2];
|
||||
int nsIndex = XML_PTR_TO_INT(atts[2]);
|
||||
|
||||
if ((nsIndex == NS_INDEX_EMPTY) ? (uri == NULL) :
|
||||
(nsIndex == NS_INDEX_XML) ? (uri == ctxt->str_xml_ns) :
|
||||
@ -9424,7 +9423,7 @@ next_attr:
|
||||
}
|
||||
}
|
||||
|
||||
atts[i+2] = (const xmlChar *) (ptrdiff_t) nsIndex;
|
||||
atts[i+2] = XML_INT_TO_PTR(nsIndex);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -9462,7 +9461,7 @@ next_attr:
|
||||
|
||||
attname = atts[i];
|
||||
aprefix = atts[i+1];
|
||||
nsIndex = (ptrdiff_t) atts[i+2];
|
||||
nsIndex = XML_PTR_TO_INT(atts[i+2]);
|
||||
/* Hash values always have bit 31 set, see dict.c */
|
||||
nameHashValue = ctxt->attallocs[j] | 0x80000000;
|
||||
|
||||
@ -9591,7 +9590,7 @@ next_attr:
|
||||
|
||||
atts[nbatts++] = attname;
|
||||
atts[nbatts++] = aprefix;
|
||||
atts[nbatts++] = (const xmlChar *) (ptrdiff_t) nsIndex;
|
||||
atts[nbatts++] = XML_INT_TO_PTR(nsIndex);
|
||||
atts[nbatts++] = attr->value.name;
|
||||
atts[nbatts++] = attr->valueEnd;
|
||||
if ((ctxt->standalone == 1) && (attr->external != 0)) {
|
||||
@ -9647,7 +9646,7 @@ next_attr:
|
||||
*/
|
||||
for (i = 0, j = 0; i < nbatts; i += 5, j++) {
|
||||
/* namespace URI */
|
||||
nsIndex = (ptrdiff_t) atts[i+2];
|
||||
nsIndex = XML_PTR_TO_INT(atts[i+2]);
|
||||
if (nsIndex == INT_MAX)
|
||||
atts[i+2] = NULL;
|
||||
else if (nsIndex == INT_MAX - 1)
|
||||
@ -9656,8 +9655,8 @@ next_attr:
|
||||
atts[i+2] = ctxt->nsTab[nsIndex * 2 + 1];
|
||||
|
||||
if ((j < nratts) && (ctxt->attallocs[j] & 0x80000000) == 0) {
|
||||
atts[i+3] = BASE_PTR + (ptrdiff_t) atts[i+3]; /* value */
|
||||
atts[i+4] = BASE_PTR + (ptrdiff_t) atts[i+4]; /* valuend */
|
||||
atts[i+3] = BASE_PTR + XML_PTR_TO_INT(atts[i+3]); /* value */
|
||||
atts[i+4] = BASE_PTR + XML_PTR_TO_INT(atts[i+4]); /* valuend */
|
||||
}
|
||||
}
|
||||
|
||||
|
12
relaxng.c
12
relaxng.c
@ -4326,7 +4326,7 @@ xmlRelaxNGComputeInterleaves(void *payload, void *data,
|
||||
if ((*tmp)->type == XML_RELAXNG_TEXT) {
|
||||
res = xmlHashAddEntry2(partitions->triage,
|
||||
BAD_CAST "#text", NULL,
|
||||
(void *) (ptrdiff_t) (i + 1));
|
||||
XML_INT_TO_PTR(i + 1));
|
||||
if (res != 0)
|
||||
is_determinist = -1;
|
||||
} else if (((*tmp)->type == XML_RELAXNG_ELEMENT) &&
|
||||
@ -4334,22 +4334,22 @@ xmlRelaxNGComputeInterleaves(void *payload, void *data,
|
||||
if (((*tmp)->ns == NULL) || ((*tmp)->ns[0] == 0))
|
||||
res = xmlHashAddEntry2(partitions->triage,
|
||||
(*tmp)->name, NULL,
|
||||
(void *) (ptrdiff_t) (i + 1));
|
||||
XML_INT_TO_PTR(i + 1));
|
||||
else
|
||||
res = xmlHashAddEntry2(partitions->triage,
|
||||
(*tmp)->name, (*tmp)->ns,
|
||||
(void *) (ptrdiff_t) (i + 1));
|
||||
XML_INT_TO_PTR(i + 1));
|
||||
if (res != 0)
|
||||
is_determinist = -1;
|
||||
} else if ((*tmp)->type == XML_RELAXNG_ELEMENT) {
|
||||
if (((*tmp)->ns == NULL) || ((*tmp)->ns[0] == 0))
|
||||
res = xmlHashAddEntry2(partitions->triage,
|
||||
BAD_CAST "#any", NULL,
|
||||
(void *) (ptrdiff_t) (i + 1));
|
||||
XML_INT_TO_PTR(i + 1));
|
||||
else
|
||||
res = xmlHashAddEntry2(partitions->triage,
|
||||
BAD_CAST "#any", (*tmp)->ns,
|
||||
(void *) (ptrdiff_t) (i + 1));
|
||||
XML_INT_TO_PTR(i + 1));
|
||||
if ((*tmp)->nameClass != NULL)
|
||||
is_determinist = 2;
|
||||
if (res != 0)
|
||||
@ -9232,7 +9232,7 @@ xmlRelaxNGValidateInterleave(xmlRelaxNGValidCtxtPtr ctxt,
|
||||
if (tmp == NULL) {
|
||||
i = nbgroups;
|
||||
} else {
|
||||
i = ((ptrdiff_t) tmp) - 1;
|
||||
i = XML_PTR_TO_INT(tmp) - 1;
|
||||
if (partitions->flags & IS_NEEDCHECK) {
|
||||
group = partitions->groups[i];
|
||||
if (!xmlRelaxNGNodeMatchesList(cur, group->defs))
|
||||
|
4
tree.c
4
tree.c
@ -4681,7 +4681,7 @@ xmlGetLineNoInternal(const xmlNode *node, int depth)
|
||||
(node->type == XML_PI_NODE)) {
|
||||
if (node->line == 65535) {
|
||||
if ((node->type == XML_TEXT_NODE) && (node->psvi != NULL))
|
||||
result = (long) (ptrdiff_t) node->psvi;
|
||||
result = XML_PTR_TO_INT(node->psvi);
|
||||
else if ((node->type == XML_ELEMENT_NODE) &&
|
||||
(node->children != NULL))
|
||||
result = xmlGetLineNoInternal(node->children, depth + 1);
|
||||
@ -4691,7 +4691,7 @@ xmlGetLineNoInternal(const xmlNode *node, int depth)
|
||||
result = xmlGetLineNoInternal(node->prev, depth + 1);
|
||||
}
|
||||
if ((result == -1) || (result == 65535))
|
||||
result = (long) node->line;
|
||||
result = node->line;
|
||||
} else if ((node->prev != NULL) &&
|
||||
((node->prev->type == XML_ELEMENT_NODE) ||
|
||||
(node->prev->type == XML_TEXT_NODE) ||
|
||||
|
58
xpath.c
58
xpath.c
@ -309,7 +309,10 @@ static const xmlNs *const xmlXPathXMLNamespace = &xmlXPathXMLNamespaceStruct;
|
||||
static void
|
||||
xmlXPathNodeSetClear(xmlNodeSetPtr set, int hasNsNodes);
|
||||
|
||||
#define XML_NODE_SORT_VALUE(n) XML_PTR_TO_INT((n)->content)
|
||||
|
||||
#ifdef XP_OPTIMIZED_NON_ELEM_COMPARISON
|
||||
|
||||
/**
|
||||
* xmlXPathCmpNodesExt:
|
||||
* @node1: the first node
|
||||
@ -327,7 +330,7 @@ xmlXPathCmpNodesExt(xmlNodePtr node1, xmlNodePtr node2) {
|
||||
int misc = 0, precedence1 = 0, precedence2 = 0;
|
||||
xmlNodePtr miscNode1 = NULL, miscNode2 = NULL;
|
||||
xmlNodePtr cur, root;
|
||||
ptrdiff_t l1, l2;
|
||||
XML_INTPTR_T l1, l2;
|
||||
|
||||
if ((node1 == NULL) || (node2 == NULL))
|
||||
return(-2);
|
||||
@ -341,12 +344,12 @@ xmlXPathCmpNodesExt(xmlNodePtr node1, xmlNodePtr node2) {
|
||||
switch (node1->type) {
|
||||
case XML_ELEMENT_NODE:
|
||||
if (node2->type == XML_ELEMENT_NODE) {
|
||||
if ((0 > (ptrdiff_t) node1->content) &&
|
||||
(0 > (ptrdiff_t) node2->content) &&
|
||||
if ((0 > XML_NODE_SORT_VALUE(node1)) &&
|
||||
(0 > XML_NODE_SORT_VALUE(node2)) &&
|
||||
(node1->doc == node2->doc))
|
||||
{
|
||||
l1 = -((ptrdiff_t) node1->content);
|
||||
l2 = -((ptrdiff_t) node2->content);
|
||||
l1 = -XML_NODE_SORT_VALUE(node1);
|
||||
l2 = -XML_NODE_SORT_VALUE(node2);
|
||||
if (l1 < l2)
|
||||
return(1);
|
||||
if (l1 > l2)
|
||||
@ -391,7 +394,7 @@ xmlXPathCmpNodesExt(xmlNodePtr node1, xmlNodePtr node2) {
|
||||
node1 = node1->parent;
|
||||
}
|
||||
if ((node1 == NULL) || (node1->type != XML_ELEMENT_NODE) ||
|
||||
(0 <= (ptrdiff_t) node1->content)) {
|
||||
(0 <= XML_NODE_SORT_VALUE(node1))) {
|
||||
/*
|
||||
* Fallback for whatever case.
|
||||
*/
|
||||
@ -441,7 +444,7 @@ xmlXPathCmpNodesExt(xmlNodePtr node1, xmlNodePtr node2) {
|
||||
node2 = node2->parent;
|
||||
}
|
||||
if ((node2 == NULL) || (node2->type != XML_ELEMENT_NODE) ||
|
||||
(0 <= (ptrdiff_t) node2->content))
|
||||
(0 <= XML_NODE_SORT_VALUE(node2)))
|
||||
{
|
||||
node2 = miscNode2;
|
||||
precedence2 = 0;
|
||||
@ -514,12 +517,12 @@ xmlXPathCmpNodesExt(xmlNodePtr node1, xmlNodePtr node2) {
|
||||
*/
|
||||
if ((node1->type == XML_ELEMENT_NODE) &&
|
||||
(node2->type == XML_ELEMENT_NODE) &&
|
||||
(0 > (ptrdiff_t) node1->content) &&
|
||||
(0 > (ptrdiff_t) node2->content) &&
|
||||
(0 > XML_NODE_SORT_VALUE(node1)) &&
|
||||
(0 > XML_NODE_SORT_VALUE(node2)) &&
|
||||
(node1->doc == node2->doc)) {
|
||||
|
||||
l1 = -((ptrdiff_t) node1->content);
|
||||
l2 = -((ptrdiff_t) node2->content);
|
||||
l1 = -XML_NODE_SORT_VALUE(node1);
|
||||
l2 = -XML_NODE_SORT_VALUE(node2);
|
||||
if (l1 < l2)
|
||||
return(1);
|
||||
if (l1 > l2)
|
||||
@ -582,12 +585,12 @@ turtle_comparison:
|
||||
*/
|
||||
if ((node1->type == XML_ELEMENT_NODE) &&
|
||||
(node2->type == XML_ELEMENT_NODE) &&
|
||||
(0 > (ptrdiff_t) node1->content) &&
|
||||
(0 > (ptrdiff_t) node2->content) &&
|
||||
(0 > XML_NODE_SORT_VALUE(node1)) &&
|
||||
(0 > XML_NODE_SORT_VALUE(node2)) &&
|
||||
(node1->doc == node2->doc)) {
|
||||
|
||||
l1 = -((ptrdiff_t) node1->content);
|
||||
l2 = -((ptrdiff_t) node2->content);
|
||||
l1 = -XML_NODE_SORT_VALUE(node1);
|
||||
l2 = -XML_NODE_SORT_VALUE(node2);
|
||||
if (l1 < l2)
|
||||
return(1);
|
||||
if (l1 > l2)
|
||||
@ -2417,7 +2420,7 @@ xmlXPathFormatNumber(double number, char buffer[], int buffersize)
|
||||
*/
|
||||
long
|
||||
xmlXPathOrderDocElems(xmlDocPtr doc) {
|
||||
ptrdiff_t count = 0;
|
||||
XML_INTPTR_T count = 0;
|
||||
xmlNodePtr cur;
|
||||
|
||||
if (doc == NULL)
|
||||
@ -2425,7 +2428,8 @@ xmlXPathOrderDocElems(xmlDocPtr doc) {
|
||||
cur = doc->children;
|
||||
while (cur != NULL) {
|
||||
if (cur->type == XML_ELEMENT_NODE) {
|
||||
cur->content = (void *) (-(++count));
|
||||
count += 1;
|
||||
cur->content = XML_INT_TO_PTR(-count);
|
||||
if (cur->children != NULL) {
|
||||
cur = cur->children;
|
||||
continue;
|
||||
@ -2517,13 +2521,13 @@ xmlXPathCmpNodes(xmlNodePtr node1, xmlNodePtr node2) {
|
||||
*/
|
||||
if ((node1->type == XML_ELEMENT_NODE) &&
|
||||
(node2->type == XML_ELEMENT_NODE) &&
|
||||
(0 > (ptrdiff_t) node1->content) &&
|
||||
(0 > (ptrdiff_t) node2->content) &&
|
||||
(0 > XML_NODE_SORT_VALUE(node1)) &&
|
||||
(0 > XML_NODE_SORT_VALUE(node2)) &&
|
||||
(node1->doc == node2->doc)) {
|
||||
ptrdiff_t l1, l2;
|
||||
XML_INTPTR_T l1, l2;
|
||||
|
||||
l1 = -((ptrdiff_t) node1->content);
|
||||
l2 = -((ptrdiff_t) node2->content);
|
||||
l1 = -XML_NODE_SORT_VALUE(node1);
|
||||
l2 = -XML_NODE_SORT_VALUE(node2);
|
||||
if (l1 < l2)
|
||||
return(1);
|
||||
if (l1 > l2)
|
||||
@ -2580,13 +2584,13 @@ xmlXPathCmpNodes(xmlNodePtr node1, xmlNodePtr node2) {
|
||||
*/
|
||||
if ((node1->type == XML_ELEMENT_NODE) &&
|
||||
(node2->type == XML_ELEMENT_NODE) &&
|
||||
(0 > (ptrdiff_t) node1->content) &&
|
||||
(0 > (ptrdiff_t) node2->content) &&
|
||||
(0 > XML_NODE_SORT_VALUE(node1)) &&
|
||||
(0 > XML_NODE_SORT_VALUE(node2)) &&
|
||||
(node1->doc == node2->doc)) {
|
||||
ptrdiff_t l1, l2;
|
||||
XML_INTPTR_T l1, l2;
|
||||
|
||||
l1 = -((ptrdiff_t) node1->content);
|
||||
l2 = -((ptrdiff_t) node2->content);
|
||||
l1 = -XML_NODE_SORT_VALUE(node1);
|
||||
l2 = -XML_NODE_SORT_VALUE(node2);
|
||||
if (l1 < l2)
|
||||
return(1);
|
||||
if (l1 > l2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user