Re: [xml] PATCH: implement xmlSaveToBuffer()



On Sun, Nov 06, 2005 at 07:33:19PM -0500, Rob Richards wrote:
Geert Jansen wrote: 
See the attached patch. I took your original suggestion and used the 
original prototype for xmlSaveToBuffer(). I now create an 
xmlOutputBuffer from the xmlBuffer. This is done by a new function in 
xmlIO.c: xmlOutputBufferCreateBuffer(). It uses xmlAllocOutputBuffer() 
to create a new output buffer and then replaces either .buffer or 
.conv by the user supplied buffer. This requires me to free one buffer 
that was just allocated. This isn't ideal but I thought this would be 
better than either duplicating xmlAllocOutputBuffer() or changing it 
signature to accept a flag indicating that it should not allocate 
buffers.

In order to ensure that xmlFreeSaveCtxt() does not free the user 
supplied buffer, I had to extend xmlSaveCtxt with two members: 
"user_buffer" and "user_conv" to indicate that buffer or conv 
respectively are allocated by the user and should not be freed. I 
didn't feel very confident about extending this structure but I could 
not come up with something else. Did you have something else in mind?
Any reason why this couldn't or shouldn't be done the same way 
xmlNewTextWriterMemory is done?
Would only require the addition of write and close callbacks and not 
require any of the other new stuff from the patch.

  Right, while Geert patch is correct, an approach where you reuse the
I/O callback to fill up a buffer looks cleaner to me.

Daniel

-- 
Daniel Veillard      | Red Hat http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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