summaryrefslogtreecommitdiff
path: root/src/lxml/includes
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2014-01-02 13:53:53 +0100
committerStefan Behnel <stefan_ml@behnel.de>2014-01-02 13:53:53 +0100
commit293302cb0c0278bb3ae52a8ed3dbfc877aab00cf (patch)
tree929bb6184602675ab76137f59a7185c3ea7151ae /src/lxml/includes
parent0c339d4277b6857a358c06f071bad6864cb84fef (diff)
downloadpython-lxml-293302cb0c0278bb3ae52a8ed3dbfc877aab00cf.tar.gz
optimise Unicode string parsing for PEP393 (Py3.3+)
Diffstat (limited to 'src/lxml/includes')
-rw-r--r--src/lxml/includes/etree_defs.h11
-rw-r--r--src/lxml/includes/htmlparser.pxd10
-rw-r--r--src/lxml/includes/xmlparser.pxd2
3 files changed, 18 insertions, 5 deletions
diff --git a/src/lxml/includes/etree_defs.h b/src/lxml/includes/etree_defs.h
index 1c6b5dfe..0d2ff7a9 100644
--- a/src/lxml/includes/etree_defs.h
+++ b/src/lxml/includes/etree_defs.h
@@ -78,6 +78,13 @@
#endif
#endif
+#if PY_VERSION_HEX <= 0x03030000 && !(defined(CYTHON_PEP393_ENABLED) && CYTHON_PEP393_ENABLED)
+ #define PyUnicode_READY(op) (0)
+ #define PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
+ #define PyUnicode_KIND(u) (sizeof(Py_UNICODE))
+ #define PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
+#endif
+
/* PySlice_GetIndicesEx() has wrong signature in Py<=3.1 */
#if PY_VERSION_HEX >= 0x03020000
# define _lx_PySlice_GetIndicesEx(o, l, b, e, s, sl) PySlice_GetIndicesEx(o, l, b, e, s, sl)
@@ -232,6 +239,10 @@ long _ftol2( double dblSource ) { return _ftol( dblSource ); }
#define _getNs(c_node) \
(((c_node)->ns == 0) ? 0 : ((c_node)->ns->href))
+#include <stdint.h>
+#define _lx__is_big_endian() \
+ (((union {uint32_t i; char c[4];}) {0x01020304}).c[0] == 1)
+
/* Macro pair implementation of a depth first tree walker
*
* Calls the code block between the BEGIN and END macros for all elements
diff --git a/src/lxml/includes/htmlparser.pxd b/src/lxml/includes/htmlparser.pxd
index 6ae00bba..2a0ad1e6 100644
--- a/src/lxml/includes/htmlparser.pxd
+++ b/src/lxml/includes/htmlparser.pxd
@@ -1,3 +1,5 @@
+from libc.string cimport const_char
+
from lxml.includes.tree cimport xmlDoc, xmlDict
from lxml.includes.tree cimport xmlInputReadCallback, xmlInputCloseCallback
from lxml.includes.xmlparser cimport xmlParserCtxt, xmlSAXHandler, xmlSAXHandlerV1
@@ -32,18 +34,18 @@ cdef extern from "libxml/HTMLparser.h":
char* chunk, int size, int terminate) nogil
cdef xmlDoc* htmlCtxtReadFile(xmlParserCtxt* ctxt,
- char* filename, char* encoding,
+ char* filename, const_char* encoding,
int options) nogil
cdef xmlDoc* htmlCtxtReadDoc(xmlParserCtxt* ctxt,
- char* buffer, char* URL, char* encoding,
+ char* buffer, char* URL, const_char* encoding,
int options) nogil
cdef xmlDoc* htmlCtxtReadIO(xmlParserCtxt* ctxt,
xmlInputReadCallback ioread,
xmlInputCloseCallback ioclose,
void* ioctx,
- char* URL, char* encoding,
+ char* URL, const_char* encoding,
int options) nogil
cdef xmlDoc* htmlCtxtReadMemory(xmlParserCtxt* ctxt,
char* buffer, int size,
- char* filename, char* encoding,
+ char* filename, const_char* encoding,
int options) nogil
diff --git a/src/lxml/includes/xmlparser.pxd b/src/lxml/includes/xmlparser.pxd
index 15bda0dd..de95da14 100644
--- a/src/lxml/includes/xmlparser.pxd
+++ b/src/lxml/includes/xmlparser.pxd
@@ -171,7 +171,7 @@ cdef extern from "libxml/parser.h":
int options) nogil
cdef xmlDoc* xmlCtxtReadMemory(xmlParserCtxt* ctxt,
char* buffer, int size,
- char* filename, char* encoding,
+ char* filename, const_char* encoding,
int options) nogil
# iterparse: