Re: [xml] PATCH: implement xmlSaveToBuffer()



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.

Rob




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