[libxml2] Expose xmlBufShrink in the public tree API



commit 82cdfc4eb338f039024e1619aca8ff14b5c3dc71
Author: Daniel Veillard <veillard redhat com>
Date:   Wed Aug 22 11:05:09 2012 +0800

    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.

 buf.h                 |    2 +-
 doc/libxml2-api.xml   |    7 +++++++
 doc/libxml2-refs.xml  |   22 ++++++++++++++++++++++
 doc/symbols.xml       |    1 +
 include/libxml/tree.h |    1 +
 libxml2.syms          |    1 +
 testapi.c             |   13 ++++++++++++-
 7 files changed, 45 insertions(+), 2 deletions(-)
---
diff --git a/buf.h b/buf.h
index c58f8af..e8c7715 100644
--- a/buf.h
+++ b/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);
diff --git a/doc/libxml2-api.xml b/doc/libxml2-api.xml
index 16f7a63..5cd7efb 100644
--- a/doc/libxml2-api.xml
+++ b/doc/libxml2-api.xml
@@ -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'/>
diff --git a/doc/libxml2-refs.xml b/doc/libxml2-refs.xml
index c74811d..07194fe 100644
--- a/doc/libxml2-refs.xml
+++ b/doc/libxml2-refs.xml
@@ -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>
diff --git a/doc/symbols.xml b/doc/symbols.xml
index 7f6d692..9a04267 100644
--- a/doc/symbols.xml
+++ b/doc/symbols.xml
@@ -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>
diff --git a/include/libxml/tree.h b/include/libxml/tree.h
index 967748a..68f92f9 100644
--- a/include/libxml/tree.h
+++ b/include/libxml/tree.h
@@ -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:
diff --git a/libxml2.syms b/libxml2.syms
index 2013101..4436506 100644
--- a/libxml2.syms
+++ b/libxml2.syms
@@ -2252,6 +2252,7 @@ LIBXML2_2.9.0 {
   xmlBufEnd;
   xmlBufGetNodeContent;
   xmlBufNodeDump;
+  xmlBufShrink;
   xmlBufUse;
 
 # dict
diff --git a/testapi.c b/testapi.c
index ba68e2e..deb8cca 100644
--- a/testapi.c
+++ b/testapi.c
@@ -18531,6 +18531,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();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]