mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-26 00:37:43 +03:00
Expose xmlBufShrink in the public tree API
As suggested by Andrew W. Nosenko: Proposal: expose the new xmlBufShrink() to the "public" API for compatibility with xmlBufUse(). Reason: the following scenario: 1. Read something into xmlParserInputBuffer (e.g. using xmlParserInputBufferRead()) 2. Extract content through xmlBufContent() 3. Extract content length through xmlBufUse(). Result have type 'size_t'. 4. Use this content 5. Now, you need to shrink the buffer. How to do it? Doing that through legacy xmlBufferShrink() is unsafe because it uses 'unsigned int' and the whole point of introducing the new API was handling the cases, when 'unsigned int' is not enough. Therefore, need to use the new xmlBufShrink(). But it is "private". Therefore, I propose to expose the new xmlBufShrink() in the same way, as xmlBufContent() and xmlBufUse() are exposed.
This commit is contained in:
2
buf.h
2
buf.h
@@ -30,7 +30,7 @@ int xmlBufGetAllocationScheme(xmlBufPtr buf);
|
||||
void xmlBufFree(xmlBufPtr buf);
|
||||
void xmlBufEmpty(xmlBufPtr buf);
|
||||
|
||||
size_t xmlBufShrink(xmlBufPtr buf, size_t len);
|
||||
/* size_t xmlBufShrink(xmlBufPtr buf, size_t len); */
|
||||
int xmlBufGrow(xmlBufPtr buf, int len);
|
||||
int xmlBufInflate(xmlBufPtr buf, size_t len);
|
||||
int xmlBufResize(xmlBufPtr buf, size_t len);
|
||||
|
||||
@@ -1702,6 +1702,7 @@
|
||||
<exports symbol='xmlFreeDtd' type='function'/>
|
||||
<exports symbol='xmlFreeNodeList' type='function'/>
|
||||
<exports symbol='xmlFreeDoc' type='function'/>
|
||||
<exports symbol='xmlBufShrink' type='function'/>
|
||||
<exports symbol='xmlNewDocNode' type='function'/>
|
||||
<exports symbol='xmlSaveFileEnc' type='function'/>
|
||||
<exports symbol='xmlSetNsProp' type='function'/>
|
||||
@@ -8573,6 +8574,12 @@ Could we use @subtypes for this?'/>
|
||||
<arg name='level' type='int' info='the imbrication level for indenting'/>
|
||||
<arg name='format' type='int' info='is formatting allowed'/>
|
||||
</function>
|
||||
<function name='xmlBufShrink' file='tree' module='buf'>
|
||||
<info>Remove the beginning of an XML buffer. NOTE that this routine behaviour differs from xmlBufferShrink() as it will return 0 on error instead of -1 due to size_t being used as the return type.</info>
|
||||
<return type='size_t' info='the number of byte removed or 0 in case of failure'/>
|
||||
<arg name='buf' type='xmlBufPtr' info='the buffer to dump'/>
|
||||
<arg name='len' type='size_t' info='the number of xmlChar to remove'/>
|
||||
</function>
|
||||
<function name='xmlBufUse' file='tree' module='buf'>
|
||||
<info>Function to get the length of a buffer</info>
|
||||
<return type='size_t' info='the length of data in the internal content'/>
|
||||
|
||||
@@ -1768,6 +1768,7 @@
|
||||
<reference name='xmlBufGetNodeContent' href='html/libxml-tree.html#xmlBufGetNodeContent'/>
|
||||
<reference name='xmlBufNodeDump' href='html/libxml-tree.html#xmlBufNodeDump'/>
|
||||
<reference name='xmlBufPtr' href='html/libxml-tree.html#xmlBufPtr'/>
|
||||
<reference name='xmlBufShrink' href='html/libxml-tree.html#xmlBufShrink'/>
|
||||
<reference name='xmlBufUse' href='html/libxml-tree.html#xmlBufUse'/>
|
||||
<reference name='xmlBuffer' href='html/libxml-tree.html#xmlBuffer'/>
|
||||
<reference name='xmlBufferAdd' href='html/libxml-tree.html#xmlBufferAdd'/>
|
||||
@@ -5398,6 +5399,7 @@
|
||||
<ref name='xmlBufGetNodeContent'/>
|
||||
<ref name='xmlBufNodeDump'/>
|
||||
<ref name='xmlBufPtr'/>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlBufUse'/>
|
||||
<ref name='xmlBuffer'/>
|
||||
<ref name='xmlBufferAdd'/>
|
||||
@@ -7314,6 +7316,7 @@
|
||||
</type>
|
||||
<type name='size_t'>
|
||||
<ref name='xmlBufNodeDump'/>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlBufUse'/>
|
||||
<ref name='xmlDictGetUsage'/>
|
||||
<ref name='xmlDictSetLimit'/>
|
||||
@@ -8639,6 +8642,7 @@
|
||||
<ref name='xmlMemDisplayLast'/>
|
||||
</type>
|
||||
<type name='size_t'>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlBufferCreateSize'/>
|
||||
<ref name='xmlBufferCreateStatic'/>
|
||||
<ref name='xmlDictSetLimit'/>
|
||||
@@ -9043,6 +9047,7 @@
|
||||
<type name='xmlBufPtr'>
|
||||
<ref name='xmlBufGetNodeContent'/>
|
||||
<ref name='xmlBufNodeDump'/>
|
||||
<ref name='xmlBufShrink'/>
|
||||
</type>
|
||||
<type name='xmlBufferAllocationScheme'>
|
||||
<ref name='xmlBufferSetAllocationScheme'/>
|
||||
@@ -12151,6 +12156,7 @@
|
||||
<ref name='xmlBufGetNodeContent'/>
|
||||
<ref name='xmlBufNodeDump'/>
|
||||
<ref name='xmlBufPtr'/>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlBufUse'/>
|
||||
<ref name='xmlBuffer'/>
|
||||
<ref name='xmlBufferAdd'/>
|
||||
@@ -16675,6 +16681,7 @@
|
||||
<ref name='xmlValidateDtdFinal'/>
|
||||
</word>
|
||||
<word name='NOTE'>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlCtxtReadFd'/>
|
||||
<ref name='xmlParseExternalID'/>
|
||||
<ref name='xmlParseNotationDecl'/>
|
||||
@@ -17482,6 +17489,7 @@
|
||||
</word>
|
||||
<word name='Remove'>
|
||||
<ref name='xmlACatalogRemove'/>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlBufferDetach'/>
|
||||
<ref name='xmlBufferShrink'/>
|
||||
<ref name='xmlCatalogRemove'/>
|
||||
@@ -19745,6 +19753,7 @@
|
||||
<ref name='xmlXPathStringFunction'/>
|
||||
</word>
|
||||
<word name='beginning'>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlBufferAddHead'/>
|
||||
<ref name='xmlBufferShrink'/>
|
||||
<ref name='xmlByteConsumed'/>
|
||||
@@ -19776,6 +19785,7 @@
|
||||
<ref name='resolveEntity'/>
|
||||
<ref name='resolveEntitySAXFunc'/>
|
||||
<ref name='xmlBufNodeDump'/>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlElemDump'/>
|
||||
<ref name='xmlFreeNode'/>
|
||||
<ref name='xmlFreeNodeList'/>
|
||||
@@ -21832,6 +21842,7 @@
|
||||
<ref name='xmlTextReaderGetRemainder'/>
|
||||
</word>
|
||||
<word name='differs'>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlNewEntity'/>
|
||||
</word>
|
||||
<word name='digit'>
|
||||
@@ -22101,10 +22112,12 @@
|
||||
<ref name='xmlValidateDtdFinal'/>
|
||||
</word>
|
||||
<word name='due'>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlModuleOpen'/>
|
||||
<ref name='xmlModuleSymbol'/>
|
||||
</word>
|
||||
<word name='dump'>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlBufferAdd'/>
|
||||
<ref name='xmlBufferCCat'/>
|
||||
<ref name='xmlBufferDump'/>
|
||||
@@ -24385,6 +24398,7 @@
|
||||
<ref name='xmlAddChild'/>
|
||||
<ref name='xmlAddNextSibling'/>
|
||||
<ref name='xmlAddPrevSibling'/>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlCopyElementContent'/>
|
||||
<ref name='xmlDocSetRootElement'/>
|
||||
<ref name='xmlFreeElementContent'/>
|
||||
@@ -27779,6 +27793,7 @@
|
||||
</word>
|
||||
<word name='remove'>
|
||||
<ref name='xmlACatalogRemove'/>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlBufferShrink'/>
|
||||
<ref name='xmlCatalogRemove'/>
|
||||
<ref name='xmlDecodeEntities'/>
|
||||
@@ -27798,6 +27813,7 @@
|
||||
<ref name='nodePop'/>
|
||||
<ref name='valuePop'/>
|
||||
<ref name='xmlACatalogRemove'/>
|
||||
<ref name='xmlBufShrink'/>
|
||||
<ref name='xmlBufferShrink'/>
|
||||
<ref name='xmlCatalogRemove'/>
|
||||
<ref name='xmlCheckLanguageID'/>
|
||||
@@ -28759,6 +28775,9 @@
|
||||
<word name='site2'>
|
||||
<ref name='xmlBuildRelativeURI'/>
|
||||
</word>
|
||||
<word name='size_t'>
|
||||
<ref name='xmlBufShrink'/>
|
||||
</word>
|
||||
<word name='sizes'>
|
||||
<ref name='xmlGetBufferAllocationScheme'/>
|
||||
<ref name='xmlSetBufferAllocationScheme'/>
|
||||
@@ -31128,6 +31147,9 @@
|
||||
<ref name='xmlNewTextWriterMemory'/>
|
||||
<ref name='xmlOutputBufferCreateBuffer'/>
|
||||
</word>
|
||||
<word name='xmlBufferShrink'>
|
||||
<ref name='xmlBufShrink'/>
|
||||
</word>
|
||||
<word name='xmlBuildURI'>
|
||||
<ref name='xmlBuildRelativeURI'/>
|
||||
</word>
|
||||
|
||||
@@ -1751,6 +1751,7 @@
|
||||
<symbol file="tree">xmlBufEnd</symbol>
|
||||
<symbol file="tree">xmlBufGetNodeContent</symbol>
|
||||
<symbol file="tree">xmlBufNodeDump</symbol>
|
||||
<symbol file="tree">xmlBufShrink</symbol>
|
||||
<symbol file="tree">xmlBufUse</symbol>
|
||||
<symbol file="dict">xmlDictGetUsage</symbol>
|
||||
<symbol file="dict">xmlDictSetLimit</symbol>
|
||||
|
||||
@@ -119,6 +119,7 @@ typedef xmlBuf *xmlBufPtr;
|
||||
XMLPUBFUN xmlChar* XMLCALL xmlBufContent (const xmlBufPtr buf);
|
||||
XMLPUBFUN xmlChar* XMLCALL xmlBufEnd (const xmlBufPtr buf);
|
||||
XMLPUBFUN size_t XMLCALL xmlBufUse (xmlBufPtr buf);
|
||||
XMLPUBFUN size_t XMLCALL xmlBufShrink (xmlBufPtr buf, size_t len);
|
||||
|
||||
/*
|
||||
* LIBXML2_NEW_BUFFER:
|
||||
|
||||
@@ -2252,6 +2252,7 @@ LIBXML2_2.9.0 {
|
||||
xmlBufEnd;
|
||||
xmlBufGetNodeContent;
|
||||
xmlBufNodeDump;
|
||||
xmlBufShrink;
|
||||
xmlBufUse;
|
||||
|
||||
# dict
|
||||
|
||||
13
testapi.c
13
testapi.c
@@ -18530,6 +18530,16 @@ test_xmlBufNodeDump(void) {
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
test_xmlBufShrink(void) {
|
||||
int test_ret = 0;
|
||||
|
||||
|
||||
/* missing type support */
|
||||
return(test_ret);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
test_xmlBufUse(void) {
|
||||
int test_ret = 0;
|
||||
@@ -24170,7 +24180,7 @@ static int
|
||||
test_tree(void) {
|
||||
int test_ret = 0;
|
||||
|
||||
if (quiet == 0) printf("Testing tree : 142 of 163 functions ...\n");
|
||||
if (quiet == 0) printf("Testing tree : 142 of 164 functions ...\n");
|
||||
test_ret += test_xmlAddChild();
|
||||
test_ret += test_xmlAddChildList();
|
||||
test_ret += test_xmlAddNextSibling();
|
||||
@@ -24181,6 +24191,7 @@ test_tree(void) {
|
||||
test_ret += test_xmlBufEnd();
|
||||
test_ret += test_xmlBufGetNodeContent();
|
||||
test_ret += test_xmlBufNodeDump();
|
||||
test_ret += test_xmlBufShrink();
|
||||
test_ret += test_xmlBufUse();
|
||||
test_ret += test_xmlBufferAdd();
|
||||
test_ret += test_xmlBufferAddHead();
|
||||
|
||||
Reference in New Issue
Block a user