1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-27 12:15:34 +03:00
Files
libxml2/include/private/io.h
Nick Wellnhofer 834b8123ef parser: Stream data when reading from memory
Don't create a copy of the whole input buffer. Read the data chunk by
chunk to save memory.

Historically, it was probably envisioned to read data from memory
without additional copying. This doesn't work reliably with the current
design of the XML parser which requires a terminating null byte at the
end of input buffers. This lead to xmlReadMemory interfaces, which
expect pointer and size arguments, being changed to make a
zero-terminated copy of the input buffer. Interfaces based on
xmlReadDoc, which actually expect a zero-terminated string and
would make zero-copy operation work, were then simplified to rely on
xmlReadMemoryi, resulting in an unnecessary copy.

To avoid copying (possibly gigabytes) of memory temporarily, we now
stream in-memory input just like content read from files in a
chunk-by-chunk fashion (using a somewhat outdated INPUT_CHUNK size of
250 bytes). As a side effect, we also avoid another copy of the whole
input when handling non-UTF-8 data which was made possible by some
earlier commits.

Interfaces expecting zero-terminated strings now make use of strnlen
which unfortunately isn't part of the standard C library and only
mandated since POSIX 2008.
2023-08-08 15:21:28 +02:00

23 lines
575 B
C

#ifndef XML_IO_H_PRIVATE__
#define XML_IO_H_PRIVATE__
#include <libxml/encoding.h>
#include <libxml/tree.h>
#include <libxml/xmlversion.h>
XML_HIDDEN void
__xmlIOErr(int domain, int code, const char *extra);
XML_HIDDEN void
__xmlLoaderErr(void *ctx, const char *msg,
const char *filename) LIBXML_ATTR_FORMAT(2,0);
xmlParserInputBufferPtr
xmlParserInputBufferCreateString(const xmlChar *str);
#ifdef LIBXML_OUTPUT_ENABLED
XML_HIDDEN xmlOutputBufferPtr
xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder);
#endif
#endif /* XML_IO_H_PRIVATE__ */