Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixed libxml2 API usage by appropriately using 'const' and 'xmlChar*'

  • Loading branch information...
commit 290fdc52a30164a46f349dd6b7d2a94b45bdc15b 1 parent 5658b26
scoder scoder authored

Showing 29 changed files with 502 additions and 554 deletions. Show diff stats Hide diff stats

  1. +73 89 src/lxml/apihelpers.pxi
  2. +11 16 src/lxml/classlookup.pxi
  3. +13 14 src/lxml/extensions.pxi
  4. +2 2 src/lxml/includes/c14n.pxd
  5. +8 7 src/lxml/includes/etreepublic.pxd
  6. +2 2 src/lxml/includes/htmlparser.pxd
  7. +80 71 src/lxml/includes/tree.pxd
  8. +30 24 src/lxml/includes/xmlparser.pxd
  9. +22 19 src/lxml/includes/xpath.pxd
  10. +7 5 src/lxml/includes/xslt.pxd
  11. +10 9 src/lxml/iterparse.pxi
  12. +32 39 src/lxml/lxml.etree.pyx
  13. +39 61 src/lxml/lxml.objectify.pyx
  14. +2 3 src/lxml/nsclasses.pxi
  15. +19 40 src/lxml/objectpath.pxi
  16. +23 24 src/lxml/parser.pxi
  17. +3 3 src/lxml/proxy.pxi
  18. +10 10 src/lxml/public-api.pxi
  19. +2 1  src/lxml/python.pxd
  20. +5 6 src/lxml/readonlytree.pxi
  21. +2 3 src/lxml/relaxng.pxi
  22. +18 18 src/lxml/saxparser.pxi
  23. +36 35 src/lxml/serializer.pxi
  24. +1 1  src/lxml/xmlerror.pxi
  25. +3 3 src/lxml/xmlid.pxi
  26. +2 2 src/lxml/xmlschema.pxi
  27. +10 12 src/lxml/xpath.pxi
  28. +34 31 src/lxml/xslt.pxi
  29. +3 4 src/lxml/xsltext.pxi
162 src/lxml/apihelpers.pxi
@@ -231,13 +231,11 @@ cdef int _initNodeNamespaces(xmlNode* c_node, _Document doc,
231 231 This only works for a newly created node!
232 232 """
233 233 cdef xmlNs* c_ns
234   - cdef char* c_prefix
235   - cdef char* c_href
236 234 cdef list nsdefs
237 235 if not nsmap:
238 236 if node_ns_utf is not None:
239 237 _uriValidOrRaise(node_ns_utf)
240   - doc._setNodeNs(c_node, _cstr(node_ns_utf))
  238 + doc._setNodeNs(c_node, _xcstr(node_ns_utf))
241 239 return 0
242 240
243 241 nsdefs = list(nsmap.items())
@@ -255,25 +253,25 @@ cdef int _initNodeNamespaces(xmlNode* c_node, _Document doc,
255 253 for prefix, href in nsdefs:
256 254 href_utf = _utf8(href)
257 255 _uriValidOrRaise(href_utf)
258   - c_href = _cstr(href_utf)
  256 + c_href = _xcstr(href_utf)
259 257 if prefix is not None:
260 258 prefix_utf = _utf8(prefix)
261 259 _prefixValidOrRaise(prefix_utf)
262   - c_prefix = _cstr(prefix_utf)
  260 + c_prefix = _xcstr(prefix_utf)
263 261 else:
264   - c_prefix = NULL
  262 + c_prefix = <const_xmlChar*>NULL
265 263 # add namespace with prefix if it is not already known
266 264 c_ns = tree.xmlSearchNs(doc._c_doc, c_node, c_prefix)
267 265 if c_ns is NULL or \
268 266 c_ns.href is NULL or \
269   - cstring_h.strcmp(c_ns.href, c_href) != 0:
  267 + tree.xmlStrcmp(c_ns.href, c_href) != 0:
270 268 c_ns = tree.xmlNewNs(c_node, c_href, c_prefix)
271 269 if href_utf == node_ns_utf:
272 270 tree.xmlSetNs(c_node, c_ns)
273 271 node_ns_utf = None
274 272
275 273 if node_ns_utf is not None:
276   - doc._setNodeNs(c_node, _cstr(node_ns_utf))
  274 + doc._setNodeNs(c_node, _xcstr(node_ns_utf))
277 275 return 0
278 276
279 277 cdef _initNodeAttributes(xmlNode* c_node, _Document doc, attrib, extra):
@@ -298,12 +296,12 @@ cdef _initNodeAttributes(xmlNode* c_node, _Document doc, attrib, extra):
298 296 _attributeValidOrRaise(attr_name_utf)
299 297 value_utf = _utf8(value)
300 298 if attr_ns_utf is None:
301   - tree.xmlNewProp(c_node, _cstr(attr_name_utf), _cstr(value_utf))
  299 + tree.xmlNewProp(c_node, _xcstr(attr_name_utf), _xcstr(value_utf))
302 300 else:
303 301 _uriValidOrRaise(attr_ns_utf)
304   - c_ns = doc._findOrBuildNodeNs(c_node, _cstr(attr_ns_utf), NULL, 1)
  302 + c_ns = doc._findOrBuildNodeNs(c_node, _xcstr(attr_ns_utf), NULL, 1)
305 303 tree.xmlNewNsProp(c_node, c_ns,
306   - _cstr(attr_name_utf), _cstr(value_utf))
  304 + _xcstr(attr_name_utf), _xcstr(value_utf))
307 305
308 306 ctypedef struct _ns_node_ref:
309 307 xmlNs* ns
@@ -409,7 +407,7 @@ cdef int _removeUnusedNamespaceDeclarations(xmlNode* c_element) except -1:
409 407 stdlib.free(c_ns_list)
410 408 return 0
411 409
412   -cdef xmlNs* _searchNsByHref(xmlNode* c_node, char* c_href, bint is_attribute):
  410 +cdef xmlNs* _searchNsByHref(xmlNode* c_node, const_xmlChar* c_href, bint is_attribute):
413 411 u"""Search a namespace declaration that covers a node (element or
414 412 attribute).
415 413
@@ -422,7 +420,7 @@ cdef xmlNs* _searchNsByHref(xmlNode* c_node, char* c_href, bint is_attribute):
422 420 cdef xmlNode* c_element
423 421 if c_href is NULL or c_node is NULL or c_node.type == tree.XML_ENTITY_REF_NODE:
424 422 return NULL
425   - if cstring_h.strcmp(c_href, tree.XML_XML_NAMESPACE) == 0:
  423 + if tree.xmlStrcmp(c_href, tree.XML_XML_NAMESPACE) == 0:
426 424 # no special cases here, let libxml2 handle this
427 425 return tree.xmlSearchNsByHref(c_node.doc, c_node, c_href)
428 426 if c_node.type == tree.XML_ATTRIBUTE_NODE:
@@ -434,7 +432,7 @@ cdef xmlNs* _searchNsByHref(xmlNode* c_node, char* c_href, bint is_attribute):
434 432 if c_node.type == tree.XML_ELEMENT_NODE:
435 433 c_ns = c_node.nsDef
436 434 while c_ns is not NULL:
437   - if c_ns.href is not NULL and cstring_h.strcmp(c_href, c_ns.href) == 0:
  435 + if c_ns.href is not NULL and tree.xmlStrcmp(c_href, c_ns.href) == 0:
438 436 if c_ns.prefix is NULL and is_attribute:
439 437 # for attributes, continue searching a named
440 438 # prefix, but keep the first default namespace
@@ -449,7 +447,7 @@ cdef xmlNs* _searchNsByHref(xmlNode* c_node, char* c_href, bint is_attribute):
449 447 if c_node is not c_element and c_node.ns is not NULL:
450 448 # optimise: the node may have the namespace itself
451 449 c_ns = c_node.ns
452   - if c_ns.href is not NULL and cstring_h.strcmp(c_href, c_ns.href) == 0:
  450 + if c_ns.href is not NULL and tree.xmlStrcmp(c_href, c_ns.href) == 0:
453 451 if c_ns.prefix is NULL and is_attribute:
454 452 # for attributes, continue searching a named
455 453 # prefix, but keep the first default namespace
@@ -508,8 +506,6 @@ cdef int _replaceNodeByChildren(_Document doc, xmlNode* c_node) except -1:
508 506 return 0
509 507
510 508 cdef object _attributeValue(xmlNode* c_element, xmlAttr* c_attrib_node):
511   - cdef char* value
512   - cdef char* c_href
513 509 c_href = _getNs(<xmlNode*>c_attrib_node)
514 510 value = tree.xmlGetNsProp(c_element, c_attrib_node.name, c_href)
515 511 try:
@@ -519,8 +515,8 @@ cdef object _attributeValue(xmlNode* c_element, xmlAttr* c_attrib_node):
519 515 return result
520 516
521 517 cdef object _attributeValueFromNsName(xmlNode* c_element,
522   - char* c_href, char* c_name):
523   - cdef char* c_result = tree.xmlGetNsProp(c_element, c_name, c_href)
  518 + const_xmlChar* c_href, const_xmlChar* c_name):
  519 + c_result = tree.xmlGetNsProp(c_element, c_name, c_href)
524 520 if c_result is NULL:
525 521 return None
526 522 try:
@@ -530,11 +526,9 @@ cdef object _attributeValueFromNsName(xmlNode* c_element,
530 526 return result
531 527
532 528 cdef object _getNodeAttributeValue(xmlNode* c_node, key, default):
533   - cdef char* c_result
534   - cdef char* c_href
535 529 ns, tag = _getNsTag(key)
536   - c_href = NULL if ns is None else _cstr(ns)
537   - c_result = tree.xmlGetNsProp(c_node, _cstr(tag), c_href)
  530 + c_href = <const_xmlChar*>NULL if ns is None else _xcstr(ns)
  531 + c_result = tree.xmlGetNsProp(c_node, _xcstr(tag), c_href)
538 532 if c_result is NULL:
539 533 # XXX free namespace that is not in use..?
540 534 return default
@@ -549,35 +543,30 @@ cdef inline object _getAttributeValue(_Element element, key, default):
549 543
550 544 cdef int _setAttributeValue(_Element element, key, value) except -1:
551 545 cdef xmlNs* c_ns
552   - cdef char* c_value
553   - cdef char* c_tag
554 546 ns, tag = _getNsTag(key)
555 547 if not element._doc._parser._for_html:
556 548 _attributeValidOrRaise(tag)
557   - c_tag = _cstr(tag)
  549 + c_tag = _xcstr(tag)
558 550 if isinstance(value, QName):
559 551 value = _resolveQNameText(element, value)
560 552 else:
561 553 value = _utf8(value)
562   - c_value = _cstr(value)
  554 + c_value = _xcstr(value)
563 555 if ns is None:
564 556 c_ns = NULL
565 557 else:
566   - c_ns = element._doc._findOrBuildNodeNs(element._c_node,
567   - _cstr(ns), NULL, 1)
  558 + c_ns = element._doc._findOrBuildNodeNs(element._c_node, _xcstr(ns), NULL, 1)
568 559 tree.xmlSetNsProp(element._c_node, c_ns, c_tag, c_value)
569 560 return 0
570 561
571 562 cdef int _delAttribute(_Element element, key) except -1:
572   - cdef char* c_href
573 563 ns, tag = _getNsTag(key)
574   - c_href = NULL if ns is None else _cstr(ns)
575   - if _delAttributeFromNsName(element._c_node, c_href, _cstr(tag)):
  564 + c_href = <const_xmlChar*>NULL if ns is None else _xcstr(ns)
  565 + if _delAttributeFromNsName(element._c_node, c_href, _xcstr(tag)):
576 566 raise KeyError, key
577 567 return 0
578 568
579   -cdef int _delAttributeFromNsName(xmlNode* c_node, char* c_href, char* c_name):
580   - cdef xmlAttr* c_attr
  569 +cdef int _delAttributeFromNsName(xmlNode* c_node, const_xmlChar* c_href, const_xmlChar* c_name):
581 570 c_attr = tree.xmlHasNsProp(c_node, c_name, c_href)
582 571 if c_attr is NULL:
583 572 # XXX free namespace that is not in use..?
@@ -590,15 +579,14 @@ cdef list _collectAttributes(xmlNode* c_node, int collecttype):
590 579 it collects either the name (1), the value (2) or the name-value tuples.
591 580 """
592 581 cdef Py_ssize_t count
593   - cdef xmlAttr* c_attr
594 582 c_attr = c_node.properties
595 583 count = 0
596 584 while c_attr is not NULL:
597 585 if c_attr.type == tree.XML_ATTRIBUTE_NODE:
598   - count = count + 1
  586 + count += 1
599 587 c_attr = c_attr.next
600 588
601   - if count == 0:
  589 + if not count:
602 590 return []
603 591
604 592 attributes = python.PyList_New(count)
@@ -616,7 +604,7 @@ cdef list _collectAttributes(xmlNode* c_node, int collecttype):
616 604
617 605 python.Py_INCREF(item)
618 606 python.PyList_SET_ITEM(attributes, count, item)
619   - count = count + 1
  607 + count += 1
620 608 c_attr = c_attr.next
621 609 return attributes
622 610
@@ -664,7 +652,7 @@ cdef _collectText(xmlNode* c_node):
664 652 If there was no text to collect, return None
665 653 """
666 654 cdef Py_ssize_t scount
667   - cdef char* c_text
  655 + cdef xmlChar* c_text
668 656 cdef xmlNode* c_node_cur
669 657 # check for multiple text nodes
670 658 scount = 0
@@ -685,9 +673,9 @@ cdef _collectText(xmlNode* c_node):
685 673 # the rest is not performance critical anymore
686 674 result = b''
687 675 while c_node is not NULL:
688   - result = result + c_node.content
  676 + result += <unsigned char*>c_node.content
689 677 c_node = _textNodeOrSkip(c_node.next)
690   - return funicode(result)
  678 + return funicode(<const_xmlChar*><unsigned char*>result)
691 679
692 680 cdef void _removeText(xmlNode* c_node):
693 681 u"""Remove all text nodes.
@@ -711,10 +699,10 @@ cdef int _setNodeText(xmlNode* c_node, value) except -1:
711 699 # now add new text node with value at start
712 700 if python._isString(value):
713 701 text = _utf8(value)
714   - c_text_node = tree.xmlNewDocText(c_node.doc, _cstr(text))
  702 + c_text_node = tree.xmlNewDocText(c_node.doc, _xcstr(text))
715 703 elif isinstance(value, CDATA):
716 704 c_text_node = tree.xmlNewCDataBlock(
717   - c_node.doc, _cstr((<CDATA>value)._utf8_data),
  705 + c_node.doc, _xcstr((<CDATA>value)._utf8_data),
718 706 python.PyBytes_GET_SIZE((<CDATA>value)._utf8_data))
719 707 else:
720 708 # this will raise the right error
@@ -733,7 +721,7 @@ cdef int _setTailText(xmlNode* c_node, value) except -1:
733 721 if value is None:
734 722 return 0
735 723 text = _utf8(value)
736   - c_text_node = tree.xmlNewDocText(c_node.doc, _cstr(text))
  724 + c_text_node = tree.xmlNewDocText(c_node.doc, _xcstr(text))
737 725 # XXX what if we're the top element?
738 726 tree.xmlAddNextSibling(c_node, c_text_node)
739 727 return 0
@@ -745,7 +733,7 @@ cdef bytes _resolveQNameText(_Element element, value):
745 733 return tag
746 734 else:
747 735 c_ns = element._doc._findOrBuildNodeNs(
748   - element._c_node, _cstr(ns), NULL, 0)
  736 + element._c_node, _xcstr(ns), NULL, 0)
749 737 return python.PyBytes_FromFormat('%s:%s', c_ns.prefix, _cstr(tag))
750 738
751 739 cdef inline bint _hasChild(xmlNode* c_node):
@@ -757,7 +745,7 @@ cdef inline Py_ssize_t _countElements(xmlNode* c_node):
757 745 count = 0
758 746 while c_node is not NULL:
759 747 if _isElement(c_node):
760   - count = count + 1
  748 + count += 1
761 749 c_node = c_node.next
762 750 return count
763 751
@@ -903,7 +891,7 @@ cdef inline xmlNode* _parentElement(xmlNode* c_node):
903 891 return NULL
904 892 return c_node
905 893
906   -cdef inline bint _tagMatches(xmlNode* c_node, char* c_href, char* c_name):
  894 +cdef inline bint _tagMatches(xmlNode* c_node, const_xmlChar* c_href, const_xmlChar* c_name):
907 895 u"""Tests if the node matches namespace URI and tag name.
908 896
909 897 A node matches if it matches both c_href and c_name.
@@ -917,7 +905,6 @@ cdef inline bint _tagMatches(xmlNode* c_node, char* c_href, char* c_name):
917 905 * c_name is NULL
918 906 * its name string equals the c_name string
919 907 """
920   - cdef char* c_node_href
921 908 if c_node is NULL:
922 909 return 0
923 910 if c_node.type != tree.XML_ELEMENT_NODE:
@@ -932,17 +919,17 @@ cdef inline bint _tagMatches(xmlNode* c_node, char* c_href, char* c_name):
932 919 if c_node_href is NULL:
933 920 return c_href[0] == c'\0'
934 921 else:
935   - return cstring_h.strcmp(c_node_href, c_href) == 0
  922 + return tree.xmlStrcmp(c_node_href, c_href) == 0
936 923 elif c_href is NULL:
937 924 if _getNs(c_node) is not NULL:
938 925 return 0
939   - return c_node.name == c_name or cstring_h.strcmp(c_node.name, c_name) == 0
940   - elif c_node.name == c_name or cstring_h.strcmp(c_node.name, c_name) == 0:
  926 + return c_node.name == c_name or tree.xmlStrcmp(c_node.name, c_name) == 0
  927 + elif c_node.name == c_name or tree.xmlStrcmp(c_node.name, c_name) == 0:
941 928 c_node_href = _getNs(c_node)
942 929 if c_node_href is NULL:
943 930 return c_href[0] == c'\0'
944 931 else:
945   - return cstring_h.strcmp(c_node_href, c_href) == 0
  932 + return tree.xmlStrcmp(c_node_href, c_href) == 0
946 933 else:
947 934 return 0
948 935
@@ -964,7 +951,6 @@ cdef inline bint _tagMatchesExactly(xmlNode* c_node, qname* c_qname):
964 951 * c_name is NULL
965 952 * its name string points to the same address (!) as c_name
966 953 """
967   - cdef char* c_node_href
968 954 if c_qname.c_name is not NULL and c_qname.c_name is not c_node.name:
969 955 return 0
970 956 c_node_href = _getNs(c_node)
@@ -973,7 +959,7 @@ cdef inline bint _tagMatchesExactly(xmlNode* c_node, qname* c_qname):
973 959 elif c_node_href is NULL:
974 960 return 0
975 961 else:
976   - return cstring_h.strcmp(python.__cstr(c_qname.href), c_node_href) == 0
  962 + return tree.xmlStrcmp(<const_xmlChar*>python.__cstr(c_qname.href), c_node_href) == 0
977 963
978 964 cdef size_t _mapTagsToQnameMatchArray(xmlDoc* c_doc, list ns_tags,
979 965 qname* c_ns_tags, bint force_into_dict) except -1:
@@ -984,20 +970,19 @@ cdef size_t _mapTagsToQnameMatchArray(xmlDoc* c_doc, list ns_tags,
984 970 if it is not NULL.
985 971 """
986 972 cdef size_t count = 0, i
987   - cdef char* c_tag
988 973 cdef bytes ns, tag
989 974 for ns, tag in ns_tags:
990 975 if tag is None:
991   - c_tag = NULL
  976 + c_tag = <const_xmlChar*>NULL
992 977 elif force_into_dict:
993   - c_tag = tree.xmlDictLookup(c_doc.dict, _cstr(tag), len(tag))
  978 + c_tag = tree.xmlDictLookup(c_doc.dict, _xcstr(tag), len(tag))
994 979 if c_tag is NULL:
995 980 # clean up before raising the error
996 981 for i in xrange(count):
997 982 cpython.ref.Py_XDECREF(c_ns_tags[i].href)
998 983 raise MemoryError()
999 984 else:
1000   - c_tag = tree.xmlDictExists(c_doc.dict, _cstr(tag), len(tag))
  985 + c_tag = tree.xmlDictExists(c_doc.dict, _xcstr(tag), len(tag))
1001 986 if c_tag is NULL:
1002 987 # not in the dict => not in the document
1003 988 continue
@@ -1322,12 +1307,12 @@ cdef int _prependSibling(_Element element, _Element sibling) except -1:
1322 1307 # parent element has moved; change them too..
1323 1308 moveNodeToDocument(element._doc, c_source_doc, c_node)
1324 1309
1325   -cdef inline int isutf8(char* s):
1326   - cdef char c = s[0]
  1310 +cdef inline int isutf8(const_xmlChar* s):
  1311 + cdef xmlChar c = s[0]
1327 1312 while c != c'\0':
1328 1313 if c & 0x80:
1329 1314 return 1
1330   - s = s + 1
  1315 + s += 1
1331 1316 c = s[0]
1332 1317 return 0
1333 1318
@@ -1336,8 +1321,8 @@ cdef int check_string_utf8(bytes pystring):
1336 1321 for ASCII, 1 for UTF-8 and -1 in the case of errors, such as NULL
1337 1322 bytes or ASCII control characters.
1338 1323 """
1339   - cdef char* s = _cstr(pystring)
1340   - cdef char* c_end = s + len(pystring)
  1324 + cdef const_xmlChar* s = _xcstr(pystring)
  1325 + cdef const_xmlChar* c_end = s + len(pystring)
1341 1326 cdef bint is_non_ascii = 0
1342 1327 while s < c_end:
1343 1328 if s[0] & 0x80:
@@ -1350,19 +1335,18 @@ cdef int check_string_utf8(bytes pystring):
1350 1335 s += 1
1351 1336 return is_non_ascii
1352 1337
1353   -cdef inline object funicodeOrNone(char* s):
  1338 +cdef inline object funicodeOrNone(const_xmlChar* s):
1354 1339 return funicode(s) if s is not NULL else None
1355 1340
1356   -cdef inline object funicodeOrEmpty(char* s):
  1341 +cdef inline object funicodeOrEmpty(const_xmlChar* s):
1357 1342 return funicode(s) if s is not NULL else ''
1358 1343
1359   -cdef object funicode(char* s):
  1344 +cdef object funicode(const_xmlChar* s):
1360 1345 cdef Py_ssize_t slen
1361   - cdef char* spos
  1346 + cdef const_xmlChar* spos
1362 1347 cdef bint is_non_ascii
1363 1348 if python.IS_PYTHON3:
1364   - slen = cstring_h.strlen(s)
1365   - return s[:slen].decode('UTF-8')
  1349 + return s.decode('UTF-8')
1366 1350 spos = s
1367 1351 is_non_ascii = 0
1368 1352 while spos[0] != c'\0':
@@ -1370,9 +1354,9 @@ cdef object funicode(char* s):
1370 1354 is_non_ascii = 1
1371 1355 break
1372 1356 spos += 1
1373   - while spos[0] != c'\0':
1374   - spos += 1
1375 1357 slen = spos - s
  1358 + if spos[0] != c'\0':
  1359 + slen += tree.xmlStrlen(spos)
1376 1360 if is_non_ascii:
1377 1361 return s[:slen].decode('UTF-8')
1378 1362 return <bytes>s[:slen]
@@ -1400,9 +1384,9 @@ cdef bytes _utf8(object s):
1400 1384 u"All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters"
1401 1385 return utf8_string
1402 1386
1403   -cdef bint _isFilePath(char* c_path):
  1387 +cdef bint _isFilePath(const_xmlChar* c_path):
1404 1388 u"simple heuristic to see if a path is a filename"
1405   - cdef char c
  1389 + cdef xmlChar c
1406 1390 # test if it looks like an absolute Unix path or a Windows network path
1407 1391 if c_path[0] == c'/':
1408 1392 return 1
@@ -1433,7 +1417,7 @@ cdef object _encodeFilename(object filename):
1433 1417 elif python.PyUnicode_Check(filename):
1434 1418 filename8 = python.PyUnicode_AsEncodedString(
1435 1419 filename, 'UTF-8', NULL)
1436   - if _isFilePath(filename8):
  1420 + if _isFilePath(<unsigned char*>filename8):
1437 1421 try:
1438 1422 return python.PyUnicode_AsEncodedString(
1439 1423 filename, _C_FILENAME_ENCODING, NULL)
@@ -1443,21 +1427,21 @@ cdef object _encodeFilename(object filename):
1443 1427 else:
1444 1428 raise TypeError, u"Argument must be string or unicode."
1445 1429
1446   -cdef object _decodeFilename(char* c_path):
  1430 +cdef object _decodeFilename(const_xmlChar* c_path):
1447 1431 u"""Make the filename a unicode string if we are in Py3.
1448 1432 """
1449   - cdef Py_ssize_t c_len = cstring_h.strlen(c_path)
  1433 + c_len = tree.xmlStrlen(c_path)
1450 1434 if _isFilePath(c_path):
1451 1435 try:
1452 1436 return python.PyUnicode_Decode(
1453   - c_path, c_len, _C_FILENAME_ENCODING, NULL)
  1437 + <const_char*>c_path, c_len, _C_FILENAME_ENCODING, NULL)
1454 1438 except UnicodeDecodeError:
1455 1439 pass
1456 1440 try:
1457   - return c_path[:c_len].decode('UTF-8')
  1441 + return (<unsigned char*>c_path)[:c_len].decode('UTF-8')
1458 1442 except UnicodeDecodeError:
1459 1443 # this is a stupid fallback, but it might still work...
1460   - return c_path[:c_len].decode('latin-1', 'replace')
  1444 + return (<unsigned char*>c_path)[:c_len].decode('latin-1', 'replace')
1461 1445
1462 1446 cdef object _encodeFilenameUTF8(object filename):
1463 1447 u"""Recode filename as UTF-8. Tries ASCII, local filesystem encoding and
@@ -1531,16 +1515,16 @@ cdef tuple __getNsTag(tag, bint empty_ns):
1531 1515 return ns, tag
1532 1516
1533 1517 cdef inline int _pyXmlNameIsValid(name_utf8):
1534   - return _xmlNameIsValid(_cstr(name_utf8))
  1518 + return _xmlNameIsValid(_xcstr(name_utf8))
1535 1519
1536 1520 cdef inline int _pyHtmlNameIsValid(name_utf8):
1537   - return _htmlNameIsValid(_cstr(name_utf8))
  1521 + return _htmlNameIsValid(_xcstr(name_utf8))
1538 1522
1539   -cdef inline int _xmlNameIsValid(char* c_name):
  1523 +cdef inline int _xmlNameIsValid(const_xmlChar* c_name):
1540 1524 return tree.xmlValidateNCName(c_name, 0) == 0
1541 1525
1542   -cdef int _htmlNameIsValid(char* c_name):
1543   - cdef char c
  1526 +cdef int _htmlNameIsValid(const_xmlChar* c_name):
  1527 + cdef xmlChar c
1544 1528 if c_name is NULL or c_name[0] == c'\0':
1545 1529 return 0
1546 1530 while c_name[0] != c'\0':
@@ -1548,10 +1532,10 @@ cdef int _htmlNameIsValid(char* c_name):
1548 1532 if c in (c'&', c'<', c'>', c'/', c'"', c"'",
1549 1533 c'\t', c'\n', c'\x0B', c'\x0C', c'\r', c' '):
1550 1534 return 0
1551   - c_name = c_name + 1
  1535 + c_name += 1
1552 1536 return 1
1553 1537
1554   -cdef bint _characterReferenceIsValid(char* c_name):
  1538 +cdef bint _characterReferenceIsValid(const_xmlChar* c_name):
1555 1539 cdef bint is_hex
1556 1540 if c_name[0] == c'x':
1557 1541 c_name += 1
@@ -1564,8 +1548,8 @@ cdef bint _characterReferenceIsValid(char* c_name):
1564 1548 if c_name[0] < c'0' or c_name[0] > c'9':
1565 1549 if not is_hex:
1566 1550 return 0
1567   - if not (c_name[0] >= c'a' and c_name[0] <= c'f'):
1568   - if not (c_name[0] >= c'A' and c_name[0] <= c'F'):
  1551 + if not (c'a' <= c_name[0] <= c'f'):
  1552 + if not (c'A' <= c_name[0] <= c'F'):
1569 1553 return 0
1570 1554 c_name += 1
1571 1555 return 1
@@ -1605,7 +1589,7 @@ cdef int _uriValidOrRaise(uri_utf) except -1:
1605 1589 cdef inline object _namespacedName(xmlNode* c_node):
1606 1590 return _namespacedNameFromNsName(_getNs(c_node), c_node.name)
1607 1591
1608   -cdef object _namespacedNameFromNsName(char* href, char* name):
  1592 +cdef object _namespacedNameFromNsName(const_xmlChar* href, const_xmlChar* name):
1609 1593 if href is NULL:
1610 1594 return funicode(name)
1611 1595 elif python.IS_PYTHON3:
27 src/lxml/classlookup.pxi
@@ -116,7 +116,7 @@ cdef class CommentBase(_Comment):
116 116 text = _utf8(text)
117 117 c_doc = _newXMLDoc()
118 118 doc = _documentFactory(c_doc, None)
119   - self._c_node = _createComment(c_doc, _cstr(text))
  119 + self._c_node = _createComment(c_doc, _xcstr(text))
120 120 tree.xmlAddChild(<xmlNode*>c_doc, self._c_node)
121 121
122 122 cdef class PIBase(_ProcessingInstruction):
@@ -143,7 +143,7 @@ cdef class PIBase(_ProcessingInstruction):
143 143 text = _utf8(text)
144 144 c_doc = _newXMLDoc()
145 145 doc = _documentFactory(c_doc, None)
146   - self._c_node = _createPI(c_doc, _cstr(target), _cstr(text))
  146 + self._c_node = _createPI(c_doc, _xcstr(target), _xcstr(text))
147 147 tree.xmlAddChild(<xmlNode*>c_doc, self._c_node)
148 148
149 149 cdef class EntityBase(_Entity):
@@ -161,9 +161,8 @@ cdef class EntityBase(_Entity):
161 161 def __init__(self, name):
162 162 cdef _Document doc
163 163 cdef xmlDoc* c_doc
164   - cdef char* c_name
165 164 name_utf = _utf8(name)
166   - c_name = _cstr(name_utf)
  165 + c_name = _xcstr(name_utf)
167 166 if c_name[0] == c'#':
168 167 if not _characterReferenceIsValid(c_name + 1):
169 168 raise ValueError, u"Invalid character reference: '%s'" % name
@@ -296,9 +295,9 @@ cdef object _lookupDefaultElementClass(state, _Document _doc, xmlNode* c_node):
296 295 if state is None or (<ElementDefaultClassLookup>state).pi_class is None:
297 296 # special case XSLT-PI
298 297 if c_node.name is not NULL and c_node.content is not NULL:
299   - if cstring_h.strcmp(c_node.name, "xml-stylesheet") == 0:
300   - if cstring_h.strstr(c_node.content, "text/xsl") is not NULL or \
301   - cstring_h.strstr(c_node.content, "text/xml") is not NULL:
  298 + if tree.xmlStrcmp(c_node.name, <unsigned char*>"xml-stylesheet") == 0:
  299 + if tree.xmlStrstr(c_node.content, <unsigned char*>"text/xsl") is not NULL or \
  300 + tree.xmlStrstr(c_node.content, <unsigned char*>"text/xml") is not NULL:
302 301 return _XSLTProcessingInstruction
303 302 return _ProcessingInstruction
304 303 else:
@@ -325,8 +324,8 @@ cdef class AttributeBasedElementClassLookup(FallbackElementClassLookup):
325 324 """
326 325 cdef object _class_mapping
327 326 cdef object _pytag
328   - cdef char* _c_ns
329   - cdef char* _c_name
  327 + cdef const_xmlChar* _c_ns
  328 + cdef const_xmlChar* _c_name
330 329 def __cinit__(self):
331 330 self._lookup_function = _attribute_class_lookup
332 331
@@ -337,8 +336,8 @@ cdef class AttributeBasedElementClassLookup(FallbackElementClassLookup):
337 336 if ns is None:
338 337 self._c_ns = NULL
339 338 else:
340   - self._c_ns = _cstr(ns)
341   - self._c_name = _cstr(name)
  339 + self._c_ns = _xcstr(ns)
  340 + self._c_name = _xcstr(name)
342 341 self._class_mapping = dict(class_mapping)
343 342
344 343 FallbackElementClassLookup.__init__(self, fallback)
@@ -402,7 +401,6 @@ cdef class CustomElementClassLookup(FallbackElementClassLookup):
402 401
403 402 cdef object _custom_class_lookup(state, _Document doc, xmlNode* c_node):
404 403 cdef CustomElementClassLookup lookup
405   - cdef char* c_str
406 404
407 405 lookup = <CustomElementClassLookup>state
408 406
@@ -421,10 +419,7 @@ cdef object _custom_class_lookup(state, _Document doc, xmlNode* c_node):
421 419 else:
422 420 name = funicode(c_node.name)
423 421 c_str = tree._getNs(c_node)
424   - if c_str is NULL:
425   - ns = None
426   - else:
427   - ns = funicode(c_str)
  422 + ns = funicode(c_str) if c_str is not NULL else None
428 423
429 424 cls = lookup.lookup(element_type, doc, ns, name)
430 425 if cls is not None:
27 src/lxml/extensions.pxi
@@ -183,7 +183,7 @@ cdef class _BaseContext:
183 183 self._namespaces = namespaces
184 184 if self._xpathCtxt is not NULL:
185 185 xpath.xmlXPathRegisterNs(
186   - self._xpathCtxt, _cstr(prefix_utf), _cstr(ns_uri_utf))
  186 + self._xpathCtxt, _xcstr(prefix_utf), _xcstr(ns_uri_utf))
187 187
188 188 cdef registerNamespace(self, prefix, ns_uri):
189 189 if prefix is None:
@@ -192,14 +192,14 @@ cdef class _BaseContext:
192 192 ns_uri_utf = self._to_utf(ns_uri)
193 193 self._global_namespaces.append(prefix_utf)
194 194 xpath.xmlXPathRegisterNs(self._xpathCtxt,
195   - _cstr(prefix_utf), _cstr(ns_uri_utf))
  195 + _xcstr(prefix_utf), _xcstr(ns_uri_utf))
196 196
197 197 cdef registerLocalNamespaces(self):
198 198 if self._namespaces is None:
199 199 return
200 200 for prefix_utf, ns_uri_utf in self._namespaces:
201 201 xpath.xmlXPathRegisterNs(
202   - self._xpathCtxt, _cstr(prefix_utf), _cstr(ns_uri_utf))
  202 + self._xpathCtxt, _xcstr(prefix_utf), _xcstr(ns_uri_utf))
203 203
204 204 cdef registerGlobalNamespaces(self):
205 205 cdef list ns_prefixes = _find_all_extension_prefixes()
@@ -207,18 +207,18 @@ cdef class _BaseContext:
207 207 for prefix_utf, ns_uri_utf in ns_prefixes:
208 208 self._global_namespaces.append(prefix_utf)
209 209 xpath.xmlXPathRegisterNs(
210   - self._xpathCtxt, _cstr(prefix_utf), _cstr(ns_uri_utf))
  210 + self._xpathCtxt, _xcstr(prefix_utf), _xcstr(ns_uri_utf))
211 211
212 212 cdef unregisterGlobalNamespaces(self):
213 213 if python.PyList_GET_SIZE(self._global_namespaces) > 0:
214 214 for prefix_utf in self._global_namespaces:
215 215 xpath.xmlXPathRegisterNs(self._xpathCtxt,
216   - _cstr(prefix_utf), NULL)
  216 + _xcstr(prefix_utf), NULL)
217 217 del self._global_namespaces[:]
218 218
219 219 cdef void _unregisterNamespace(self, prefix_utf):
220 220 xpath.xmlXPathRegisterNs(self._xpathCtxt,
221   - _cstr(prefix_utf), NULL)
  221 + _xcstr(prefix_utf), NULL)
222 222
223 223 # extension functions
224 224
@@ -279,7 +279,7 @@ cdef class _BaseContext:
279 279 unreg_func(ctxt, name_utf, ns_utf)
280 280
281 281 @cython.final
282   - cdef _find_cached_function(self, char* c_ns_uri, char* c_name):
  282 + cdef _find_cached_function(self, const_xmlChar* c_ns_uri, const_xmlChar* c_name):
283 283 u"""Lookup an extension function in the cache and return it.
284 284
285 285 Parameters: c_ns_uri may be NULL, c_name must not be NULL
@@ -290,7 +290,7 @@ cdef class _BaseContext:
290 290 self._function_cache, None if c_ns_uri is NULL else c_ns_uri)
291 291 if c_dict is not NULL:
292 292 dict_result = python.PyDict_GetItem(
293   - <object>c_dict, c_name)
  293 + <object>c_dict, <unsigned char*>c_name)
294 294 if dict_result is not NULL:
295 295 return <object>dict_result
296 296 return None
@@ -458,7 +458,6 @@ cdef class _ExsltRegExp:
458 458 self._compile_map = {}
459 459
460 460 cdef _make_string(self, value):
461   - cdef char* c_text
462 461 if _isString(value):
463 462 return value
464 463 elif python.PyList_Check(value):
@@ -592,12 +591,12 @@ cdef xpath.xmlXPathObject* _wrapXPathObject(object obj, _Document doc,
592 591 context._hold(fake_node)
593 592 else:
594 593 # append a comment node to keep the text nodes separate
595   - c_node = tree.xmlNewDocComment(doc._c_doc, "")
  594 + c_node = tree.xmlNewDocComment(doc._c_doc, <unsigned char*>"")
596 595 if c_node is NULL:
597 596 raise MemoryError()
598 597 tree.xmlAddChild(fake_node._c_node, c_node)
599 598 context._hold(value)
600   - c_node = tree.xmlNewDocText(doc._c_doc, _cstr(value))
  599 + c_node = tree.xmlNewDocText(doc._c_doc, _xcstr(value))
601 600 if c_node is NULL:
602 601 raise MemoryError()
603 602 tree.xmlAddChild(fake_node._c_node, c_node)
@@ -767,7 +766,6 @@ cdef object _buildElementStringResult(_Document doc, xmlNode* c_node,
767 766 cdef _Element parent = None
768 767 cdef object attrname = None
769 768 cdef xmlNode* c_element
770   - cdef char* s
771 769 cdef bint is_tail
772 770
773 771 if c_node.type == tree.XML_ATTRIBUTE_NODE:
@@ -843,9 +841,10 @@ cdef void _xpath_function_call(xpath.xmlXPathParserContext* ctxt,
843 841 _extension_function_call(context, function, ctxt, nargs)
844 842 else:
845 843 if rctxt.functionURI is not NULL:
846   - fref = u"{%s}%s" % (rctxt.functionURI, rctxt.function)
  844 + fref = u"{%s}%s" % ((<unsigned char*>rctxt.functionURI).decode('UTF-8'),
  845 + (<unsigned char*>rctxt.function).decode('UTF-8'))
847 846 else:
848   - fref = rctxt.function
  847 + fref = (<unsigned char*>rctxt.function).decode('UTF-8')
849 848 xpath.xmlXPathErr(ctxt, xpath.XPATH_UNKNOWN_FUNC_ERROR)
850 849 context._exc._store_exception(
851 850 XPathFunctionError(u"XPath function '%s' not found" % fref))
4 src/lxml/includes/c14n.pxd
... ... @@ -1,4 +1,4 @@
1   -from tree cimport xmlDoc, xmlOutputBuffer
  1 +from tree cimport xmlDoc, xmlOutputBuffer, xmlChar
2 2 from xpath cimport xmlNodeSet
3 3
4 4 cdef extern from "libxml/c14n.h":
@@ -7,7 +7,7 @@ cdef extern from "libxml/c14n.h":
7 7 int exclusive,
8 8 char** inclusive_ns_prefixes,
9 9 int with_comments,
10   - char** doc_txt_ptr) nogil
  10 + xmlChar** doc_txt_ptr) nogil
11 11
12 12 cdef int xmlC14NDocSave(xmlDoc* doc,
13 13 xmlNodeSet* nodes,
15 src/lxml/includes/etreepublic.pxd
... ... @@ -1,6 +1,7 @@
1 1 # public Cython/C interface to lxml.etree
2 2
3 3 cimport tree
  4 +from tree cimport const_xmlChar
4 5
5 6 cdef extern from "lxml-version.h":
6 7 cdef char* LXML_VERSION_STRING
@@ -10,7 +11,7 @@ cdef extern from "etree_defs.h":
10 11 cdef bint _isElement(tree.xmlNode* c_node) nogil
11 12
12 13 # return the namespace URI of the node or NULL
13   - cdef char* _getNs(tree.xmlNode* node) nogil
  14 + cdef const_xmlChar* _getNs(tree.xmlNode* node) nogil
14 15
15 16 # pair of macros for tree traversal
16 17 cdef void BEGIN_FOR_EACH_ELEMENT_FROM(tree.xmlNode* tree_top,
@@ -102,7 +103,7 @@ cdef extern from "lxml.etree_api.h":
102 103
103 104 # return the value of the attribute with 'ns' and 'name' (or None)
104 105 cdef object attributeValueFromNsName(tree.xmlNode* c_element,
105   - char* c_ns, char* c_name)
  106 + const_xmlChar* c_ns, const_xmlChar* c_name)
106 107
107 108 # return the value of attribute "{ns}name", or the default value
108 109 cdef object getAttributeValue(_Element element, key, default)
@@ -125,7 +126,7 @@ cdef extern from "lxml.etree_api.h":
125 126 # delete an attribute based on name and namespace URI
126 127 # returns -1 if the attribute was not found (no exception)
127 128 cdef int delAttributeFromNsName(tree.xmlNode* c_element,
128   - char* c_href, char* c_name)
  129 + const_xmlChar* c_href, const_xmlChar* c_name)
129 130
130 131 ##########################################################################
131 132 # XML node helper functions
@@ -175,10 +176,10 @@ cdef extern from "lxml.etree_api.h":
175 176
176 177 # check if a C node matches a tag name and namespace
177 178 # (NULL allowed for each => always matches)
178   - cdef int tagMatches(tree.xmlNode* c_node, char* c_href, char* c_name)
  179 + cdef int tagMatches(tree.xmlNode* c_node, const_xmlChar* c_href, const_xmlChar* c_name)
179 180
180 181 # convert a UTF-8 char* to a Python string or unicode string
181   - cdef object pyunicode(char* s)
  182 + cdef object pyunicode(const_xmlChar* s)
182 183
183 184 # convert the string to UTF-8 using the normal lxml.etree semantics
184 185 cdef bytes utf8(object s)
@@ -193,7 +194,7 @@ cdef extern from "lxml.etree_api.h":
193 194 cdef object namespacedName(tree.xmlNode* c_node)
194 195
195 196 # get the "{ns}tag" string for a href/tagname pair (c_ns may be NULL)
196   - cdef object namespacedNameFromNsName(char* c_ns, char* c_tag)
  197 + cdef object namespacedNameFromNsName(const_xmlChar* c_ns, const_xmlChar* c_tag)
197 198
198 199 # check if the node has a text value (which may be '')
199 200 cdef bint hasText(tree.xmlNode* c_node) nogil
@@ -218,7 +219,7 @@ cdef extern from "lxml.etree_api.h":
218 219
219 220 # recursively lookup a namespace in element or ancestors, or create it
220 221 cdef tree.xmlNs* findOrBuildNodeNsPrefix(
221   - _Document doc, tree.xmlNode* c_node, char* href, char* prefix)
  222 + _Document doc, tree.xmlNode* c_node, const_xmlChar* href, const_xmlChar* prefix)
222 223
223 224 # find the Document of an Element, ElementTree or Document (itself!)
224 225 cdef _Document documentOrRaise(object input)
4 src/lxml/includes/htmlparser.pxd
... ... @@ -1,6 +1,6 @@
1 1 from tree cimport xmlDoc, xmlDict
2 2 from tree cimport xmlInputReadCallback, xmlInputCloseCallback
3   -from xmlparser cimport xmlParserCtxt, xmlSAXHandler
  3 +from xmlparser cimport xmlParserCtxt, xmlSAXHandler, xmlSAXHandlerV1
4 4 from xmlerror cimport xmlError
5 5
6 6 cdef extern from "libxml/HTMLparser.h":
@@ -14,7 +14,7 @@ cdef extern from "libxml/HTMLparser.h":
14 14 HTML_PARSE_RECOVER # Relaxed parsing
15 15 HTML_PARSE_COMPACT # compact small text nodes
16 16
17   - xmlSAXHandler htmlDefaultSAXHandler
  17 + xmlSAXHandlerV1 htmlDefaultSAXHandler
18 18
19 19 cdef xmlParserCtxt* htmlCreateMemoryParserCtxt(
20 20 char* buffer, int size) nogil
151 src/lxml/includes/tree.pxd
... ... @@ -1,13 +1,25 @@
1 1 from libc cimport stdio
  2 +from libc.string cimport const_char
2 3
3 4 cdef extern from "lxml-version.h":
4 5 # deprecated declaration, use etreepublic.pxd instead
5 6 cdef char* LXML_VERSION_STRING
6 7
7 8 cdef extern from "libxml/xmlversion.h":
8   - cdef char* xmlParserVersion
  9 + cdef const_char* xmlParserVersion
9 10 cdef int LIBXML_VERSION
10 11
  12 +cdef extern from "libxml/xmlstring.h":
  13 + ctypedef unsigned char xmlChar
  14 + ctypedef unsigned char const_xmlChar "const xmlChar"
  15 + cdef int xmlStrlen(const_xmlChar* str) nogil
  16 + cdef xmlChar* xmlStrdup(const_xmlChar* cur) nogil
  17 + cdef int xmlStrncmp(const_xmlChar* str1, const_xmlChar* str2, int length) nogil
  18 + cdef int xmlStrcmp(const_xmlChar* str1, const_xmlChar* str2) nogil
  19 + cdef const_xmlChar* xmlStrstr(const_xmlChar* str1, const_xmlChar* str2) nogil
  20 + cdef const_xmlChar* xmlStrchr(const_xmlChar* str1, xmlChar ch) nogil
  21 + cdef const_xmlChar* _xcstr "(const xmlChar*)PyBytes_AS_STRING" (object s)
  22 +
11 23 cdef extern from "libxml/encoding.h":
12 24 ctypedef enum xmlCharEncoding:
13 25 XML_CHAR_ENCODING_ERROR = -1 # No char encoding detected
@@ -41,7 +53,7 @@ cdef extern from "libxml/encoding.h":
41 53 xmlCharEncoding enc) nogil
42 54 cdef int xmlCharEncCloseFunc(xmlCharEncodingHandler* handler) nogil
43 55 cdef xmlCharEncoding xmlDetectCharEncoding(char* text, int len) nogil
44   - cdef char* xmlGetCharEncodingName(xmlCharEncoding enc) nogil
  56 + cdef const_char* xmlGetCharEncodingName(xmlCharEncoding enc) nogil
45 57 cdef xmlCharEncoding xmlParseCharEncoding(char* name) nogil
46 58
47 59 cdef extern from "libxml/chvalid.h":
@@ -56,9 +68,9 @@ cdef extern from "libxml/hash.h":
56 68 cdef extern from *: # actually "libxml/dict.h"
57 69 # libxml/dict.h appears to be broken to include in C
58 70 ctypedef struct xmlDict
59   - cdef char* xmlDictLookup(xmlDict* dict, char* name, int len) nogil
60   - cdef char* xmlDictExists(xmlDict* dict, char* name, int len) nogil
61   - cdef int xmlDictOwns(xmlDict* dict, char* name) nogil
  71 + cdef const_xmlChar* xmlDictLookup(xmlDict* dict, const_xmlChar* name, int len) nogil
  72 + cdef const_xmlChar* xmlDictExists(xmlDict* dict, const_xmlChar* name, int len) nogil
  73 + cdef int xmlDictOwns(xmlDict* dict, const_xmlChar* name) nogil
62 74 cdef int xmlDictSize(xmlDict* dict) nogil
63 75
64 76 cdef extern from "libxml/tree.h":
@@ -134,21 +146,21 @@ cdef extern from "libxml/tree.h":
134 146 XML_INTERNAL_PREDEFINED_ENTITY= 6
135 147
136 148 ctypedef struct xmlNs:
137   - char* href
138   - char* prefix
  149 + const_xmlChar* href
  150 + const_xmlChar* prefix
139 151 xmlNs* next
140 152
141 153 ctypedef struct xmlNode:
142 154 void* _private
143 155 xmlElementType type
144   - char* name
  156 + const_xmlChar* name
145 157 xmlNode* children
146 158 xmlNode* last
147 159 xmlNode* parent
148 160 xmlNode* next
149 161 xmlNode* prev
150 162 xmlDoc* doc
151   - char* content
  163 + xmlChar* content
152 164 xmlAttr* properties
153 165 xmlNs* ns
154 166 xmlNs* nsDef
@@ -157,20 +169,20 @@ cdef extern from "libxml/tree.h":
157 169 ctypedef struct xmlElementContent:
158 170 xmlElementContentType type
159 171 xmlElementContentOccur ocur
160   - char *name
  172 + const_xmlChar *name
161 173 xmlElementContent *c1
162 174 xmlElementContent *c2
163 175 xmlElementContent *parent
164   - char *prefix
  176 + const_xmlChar *prefix
165 177
166 178 ctypedef struct xmlEnumeration:
167 179 xmlEnumeration *next
168   - char *name
  180 + const_xmlChar *name
169 181
170 182 ctypedef struct xmlAttribute:
171 183 void* _private
172 184 xmlElementType type
173   - char* name
  185 + const_xmlChar* name
174 186 xmlNode* children
175 187 xmlNode* last
176 188 xmlDtd* parent
@@ -180,15 +192,15 @@ cdef extern from "libxml/tree.h":
180 192 xmlAttribute* nexth
181 193 xmlAttributeType atype
182 194 xmlAttributeDefault def_ "def"
183   - char* defaultValue
  195 + const_xmlChar* defaultValue
184 196 xmlEnumeration* tree
185   - char* prefix
186   - char* elem
  197 + const_xmlChar* prefix
  198 + const_xmlChar* elem
187 199
188 200 ctypedef struct xmlElement:
189 201 void* _private
190 202 xmlElementType type
191   - char* name
  203 + const_xmlChar* name
192 204 xmlNode* children
193 205 xmlNode* last
194 206 xmlNode* parent
@@ -198,34 +210,34 @@ cdef extern from "libxml/tree.h":
198 210 xmlElementTypeVal etype
199 211 xmlElementContent* content
200 212 xmlAttribute* attributes
201   - char *prefix
  213 + const_xmlChar* prefix
202 214 void *contModel
203 215
204 216 ctypedef struct xmlEntity:
205 217 void* _private
206 218 xmlElementType type
207   - char* name
  219 + const_xmlChar* name
208 220 xmlNode* children
209 221 xmlNode* last
210 222 xmlDtd* parent
211 223 xmlNode* next
212 224 xmlNode* prev
213 225 xmlDoc* doc
214   - char* orig
215   - char* content
  226 + xmlChar* orig
  227 + xmlChar* content
216 228 int length
217 229 xmlEntityType etype
218   - char* ExternalID
219   - char* SystemID
  230 + const_xmlChar* ExternalID
  231 + const_xmlChar* SystemID
220 232 xmlEntity* nexte
221   - char* URI
  233 + const_xmlChar* URI
222 234 int owner
223 235 int checked
224 236
225 237 ctypedef struct xmlDtd:
226   - char* name
227   - char* ExternalID
228   - char* SystemID
  238 + const_xmlChar* name
  239 + const_xmlChar* ExternalID
  240 + const_xmlChar* SystemID
229 241 void* notations
230 242 void* entities
231 243 void* pentities
@@ -247,9 +259,9 @@ cdef extern from "libxml/tree.h":
247 259 xmlDict* dict
248 260 xmlHashTable* ids
249 261 int standalone
250   - char* version
251   - char* encoding
252   - char* URL
  262 + const_xmlChar* version
  263 + const_xmlChar* encoding
  264 + const_xmlChar* URL
253 265 void* _private
254 266 xmlDtd* intSubset
255 267 xmlDtd* extSubset
@@ -257,7 +269,7 @@ cdef extern from "libxml/tree.h":
257 269 ctypedef struct xmlAttr:
258 270 void* _private
259 271 xmlElementType type
260   - char* name
  272 + const_xmlChar* name
261 273 xmlNode* children
262 274 xmlNode* last
263 275 xmlNode* parent
@@ -267,7 +279,7 @@ cdef extern from "libxml/tree.h":
267 279 xmlNs* ns
268 280
269 281 ctypedef struct xmlID:
270   - char* value
  282 + const_xmlChar* value
271 283 xmlAttr* attr
272 284 xmlDoc* doc
273 285
@@ -278,40 +290,40 @@ cdef extern from "libxml/tree.h":
278 290 xmlBuffer* conv
279 291 int error
280 292
281   - char* XML_XML_NAMESPACE
  293 + const_xmlChar* XML_XML_NAMESPACE
282 294
283 295 cdef void xmlFreeDoc(xmlDoc* cur) nogil
284 296 cdef void xmlFreeDtd(xmlDtd* cur) nogil
285 297 cdef void xmlFreeNode(xmlNode* cur) nogil
286 298 cdef void xmlFreeNsList(xmlNs* ns) nogil
287 299 cdef void xmlFreeNs(xmlNs* ns) nogil
288   - cdef void xmlFree(char* buf) nogil
  300 + cdef void xmlFree(void* buf) nogil
289 301
290   - cdef xmlNode* xmlNewNode(xmlNs* ns, char* name) nogil
291   - cdef xmlNode* xmlNewDocText(xmlDoc* doc, char* content) nogil
292   - cdef xmlNode* xmlNewDocComment(xmlDoc* doc, char* content) nogil
293   - cdef xmlNode* xmlNewDocPI(xmlDoc* doc, char* name, char* content) nogil
294   - cdef xmlNode* xmlNewReference(xmlDoc* doc, char* name) nogil
295   - cdef xmlNode* xmlNewCDataBlock(xmlDoc* doc, char* text, int len) nogil
296   - cdef xmlNs* xmlNewNs(xmlNode* node, char* href, char* prefix) nogil
  302 + cdef xmlNode* xmlNewNode(xmlNs* ns, const_xmlChar* name) nogil
  303 + cdef xmlNode* xmlNewDocText(xmlDoc* doc, const_xmlChar* content) nogil
  304 + cdef xmlNode* xmlNewDocComment(xmlDoc* doc, const_xmlChar* content) nogil
  305 + cdef xmlNode* xmlNewDocPI(xmlDoc* doc, const_xmlChar* name, const_xmlChar* content) nogil
  306 + cdef xmlNode* xmlNewReference(xmlDoc* doc, const_xmlChar* name) nogil
  307 + cdef xmlNode* xmlNewCDataBlock(xmlDoc* doc, const_xmlChar* text, int len) nogil
  308 + cdef xmlNs* xmlNewNs(xmlNode* node, const_xmlChar* href, const_xmlChar* prefix) nogil
297 309 cdef xmlNode* xmlAddChild(xmlNode* parent, xmlNode* cur) nogil
298 310 cdef xmlNode* xmlReplaceNode(xmlNode* old, xmlNode* cur) nogil
299 311 cdef xmlNode* xmlAddPrevSibling(xmlNode* cur, xmlNode* elem) nogil
300 312 cdef xmlNode* xmlAddNextSibling(xmlNode* cur, xmlNode* elem) nogil
301 313 cdef xmlNode* xmlNewDocNode(xmlDoc* doc, xmlNs* ns,
302   - char* name, char* content) nogil
303   - cdef xmlDoc* xmlNewDoc(char* version) nogil
304   - cdef xmlAttr* xmlNewProp(xmlNode* node, char* name, char* value) nogil
  314 + const_xmlChar* name, const_xmlChar* content) nogil
  315 + cdef xmlDoc* xmlNewDoc(const_xmlChar* version) nogil
  316 + cdef xmlAttr* xmlNewProp(xmlNode* node, const_xmlChar* name, const_xmlChar* value) nogil
305 317 cdef xmlAttr* xmlNewNsProp(xmlNode* node, xmlNs* ns,
306   - char* name, char* value) nogil
307   - cdef char* xmlGetNoNsProp(xmlNode* node, char* name) nogil
308   - cdef char* xmlGetNsProp(xmlNode* node, char* name, char* nameSpace) nogil
  318 + const_xmlChar* name, const_xmlChar* value) nogil
  319 + cdef xmlChar* xmlGetNoNsProp(xmlNode* node, const_xmlChar* name) nogil
  320 + cdef xmlChar* xmlGetNsProp(xmlNode* node, const_xmlChar* name, const_xmlChar* nameSpace) nogil
309 321 cdef void xmlSetNs(xmlNode* node, xmlNs* ns) nogil
310   - cdef xmlAttr* xmlSetProp(xmlNode* node, char* name, char* value) nogil
  322 + cdef xmlAttr* xmlSetProp(xmlNode* node, const_xmlChar* name, const_xmlChar* value) nogil
311 323 cdef xmlAttr* xmlSetNsProp(xmlNode* node, xmlNs* ns,
312   - char* name, char* value) nogil
  324 + const_xmlChar* name, const_xmlChar* value) nogil
313 325 cdef int xmlRemoveProp(xmlAttr* cur) nogil
314   - cdef char* xmlGetNodePath(xmlNode* node) nogil
  326 + cdef xmlChar* xmlGetNodePath(xmlNode* node) nogil
315 327 cdef void xmlDocDumpMemory(xmlDoc* cur, char** mem, int* size) nogil
316 328 cdef void xmlDocDumpMemoryEnc(xmlDoc* cur, char** mem, int* size,
317 329 char* encoding) nogil
@@ -322,20 +334,20 @@ cdef extern from "libxml/tree.h":
322 334 cdef xmlNode* xmlDocSetRootElement(xmlDoc* doc, xmlNode* root) nogil
323 335 cdef xmlNode* xmlDocGetRootElement(xmlDoc* doc) nogil
324 336 cdef void xmlSetTreeDoc(xmlNode* tree, xmlDoc* doc) nogil
325   - cdef xmlAttr* xmlHasProp(xmlNode* node, char* name) nogil
326   - cdef xmlAttr* xmlHasNsProp(xmlNode* node, char* name, char* nameSpace) nogil
327   - cdef char* xmlNodeGetContent(xmlNode* cur) nogil
  337 + cdef xmlAttr* xmlHasProp(xmlNode* node, const_xmlChar* name) nogil
  338 + cdef xmlAttr* xmlHasNsProp(xmlNode* node, const_xmlChar* name, const_xmlChar* nameSpace) nogil
  339 + cdef xmlChar* xmlNodeGetContent(xmlNode* cur) nogil
328 340 cdef int xmlNodeBufGetContent(xmlBuffer* buffer, xmlNode* cur) nogil
329   - cdef xmlNs* xmlSearchNs(xmlDoc* doc, xmlNode* node, char* prefix) nogil
330   - cdef xmlNs* xmlSearchNsByHref(xmlDoc* doc, xmlNode* node, char* href) nogil
  341 + cdef xmlNs* xmlSearchNs(xmlDoc* doc, xmlNode* node, const_xmlChar* prefix) nogil
  342 + cdef xmlNs* xmlSearchNsByHref(xmlDoc* doc, xmlNode* node, const_xmlChar* href) nogil
331 343 cdef int xmlIsBlankNode(xmlNode* node) nogil
332 344 cdef long xmlGetLineNo(xmlNode* node) nogil
333 345 cdef void xmlElemDump(stdio.FILE* f, xmlDoc* doc, xmlNode* cur) nogil
334 346 cdef void xmlNodeDumpOutput(xmlOutputBuffer* buf,
335 347 xmlDoc* doc, xmlNode* cur, int level,
336   - int format, char* encoding) nogil
337   - cdef void xmlNodeSetName(xmlNode* cur, char* name) nogil
338   - cdef void xmlNodeSetContent(xmlNode* cur, char* content) nogil
  348 + int format, const_char* encoding) nogil
  349 + cdef void xmlNodeSetName(xmlNode* cur, const_xmlChar* name) nogil
  350 + cdef void xmlNodeSetContent(xmlNode* cur, const_xmlChar* content) nogil
339 351 cdef xmlDtd* xmlCopyDtd(xmlDtd* dtd) nogil
340 352 cdef xmlDoc* xmlCopyDoc(xmlDoc* doc, int recursive) nogil
341 353 cdef xmlNode* xmlCopyNode(xmlNode* node, int extended) nogil
@@ -345,31 +357,31 @@ cdef extern from "libxml/tree.h":
345 357 cdef xmlBuffer* xmlBufferCreate() nogil
346 358 cdef void xmlBufferWriteChar(xmlBuffer* buf, char* string) nogil
347 359 cdef void xmlBufferFree(xmlBuffer* buf) nogil
348   - cdef char* xmlBufferContent(xmlBuffer* buf) nogil
  360 + cdef const_xmlChar* xmlBufferContent(xmlBuffer* buf) nogil
349 361 cdef int xmlBufferLength(xmlBuffer* buf) nogil
350 362 cdef int xmlKeepBlanksDefault(int val) nogil
351   - cdef char* xmlNodeGetBase(xmlDoc* doc, xmlNode* node) nogil
352   - cdef void xmlNodeSetBase(xmlNode* node, char* uri) nogil
353   - cdef int xmlValidateNCName(char* value, int space) nogil
  363 + cdef xmlChar* xmlNodeGetBase(xmlDoc* doc, xmlNode* node) nogil
  364 + cdef void xmlNodeSetBase(xmlNode* node, const_xmlChar* uri) nogil
  365 + cdef int xmlValidateNCName(const_xmlChar* value, int space) nogil
354 366
355 367 cdef extern from "libxml/uri.h":
356   - cdef char* xmlBuildURI(char* href, char* base) nogil
  368 + cdef const_xmlChar* xmlBuildURI(const_xmlChar* href, const_xmlChar* base) nogil
357 369
358 370 cdef extern from "libxml/HTMLtree.h":
359 371 cdef void htmlNodeDumpFormatOutput(xmlOutputBuffer* buf,
360 372 xmlDoc* doc, xmlNode* cur,
361 373 char* encoding, int format) nogil
362   - cdef xmlDoc* htmlNewDoc(char* uri, char* externalID) nogil
  374 + cdef xmlDoc* htmlNewDoc(const_xmlChar* uri, const_xmlChar* externalID) nogil
363 375
364 376 cdef extern from "libxml/valid.h":
365   - cdef xmlAttr* xmlGetID(xmlDoc* doc, char* ID) nogil
  377 + cdef xmlAttr* xmlGetID(xmlDoc* doc, const_xmlChar* ID) nogil
366 378 cdef void xmlDumpNotationTable(xmlBuffer* buffer,
367 379 xmlNotationTable* table) nogil
368 380
369 381 cdef extern from "libxml/xmlIO.h":
370   - cdef int xmlOutputBufferWriteString(xmlOutputBuffer* out, char* str) nogil
  382 + cdef int xmlOutputBufferWriteString(xmlOutputBuffer* out, const_char* str) nogil
371 383 cdef int xmlOutputBufferWrite(xmlOutputBuffer* out,
372   - int len, char* str) nogil
  384 + int len, const_char* str) nogil
373 385 cdef int xmlOutputBufferFlush(xmlOutputBuffer* out) nogil
374 386 cdef int xmlOutputBufferClose(xmlOutputBuffer* out) nogil
375 387
@@ -421,9 +433,6 @@ cdef extern from "libxml/globals.h":
421 433 cdef int xmlThrDefLineNumbersDefaultValue(int onoff) nogil
422 434 cdef int xmlThrDefIndentTreeOutput(int onoff) nogil
423 435
424   -cdef extern from "libxml/xmlstring.h":
425   - cdef char* xmlStrdup(char* cur) nogil
426   -
427 436 cdef extern from "libxml/xmlmemory.h":
428 437 cdef void* xmlMalloc(size_t size) nogil
429 438 cdef int xmlMemBlocks() nogil
@@ -431,7 +440,7 @@ cdef extern from "libxml/xmlmemory.h":
431 440 cdef extern from "etree_defs.h":
432 441 cdef bint _isElement(xmlNode* node) nogil