[PATCH] Add memory buffer length param to SaveToMemory*
Blair Zajac <[email protected]> Sat, 15 Mar 2003 12:19:03 -0800
| Newsgroups | gmane.comp.gnome.gdome |
|---|---|
| Message-ID | <[email protected]> |
Hello, Right now the gdome2 saveDocToMemory and saveDocToMemoryEnc functions only return to the caller the memory buffer created by libxml2, even though libxml2 returns the length of that buffer. I'm using gmetadom Ocaml bindings (gmetadom uses gdome2) and need to copy an XSLT generated file from the gmetadom/gdome2 to Ocaml string. Right now the Ocaml bindings scan the buffer to find the \0 and then make another pass to copy the buffer, which is a waste of CPU time. The attached patch modifies gdome2 to add an additional int * parameter to the *saveDocToMemory* calls. This patch is against CVS HEAD and passes make check. Best, Blair -- Blair Zajac <[email protected]> Plots of your system's performance - http://www.orcaware.com/orca/
gdome2-add-mem-length-param-patch.txt
(text/plain, 15.9 KB)
Index: ChangeLog =================================================================== RCS file: /cvs/gnome/gdome2/ChangeLog,v retrieving revision 1.104 diff -u -r1.104 ChangeLog --- ChangeLog 10 Mar 2003 10:42:07 -0000 1.104 +++ ChangeLog 15 Mar 2003 20:13:22 -0000 @@ -1,4 +1,39 @@ -2003-04-10 Paolo Casarini <[email protected]> +2003-03-15 Blair Zajac <[email protected]> + * libgdome/gdome.[ch] + (gdome_di_saveDocToMemory) add a int *men_length pointer to get + the length of the newly created memory buffer + (gdome_di_saveDocToMemoryEnc) add a int *men_length pointer to get + the length of the newly created memory buffer + + * test/apigen/core.xml + (saveDocToMemory) add a int *men_length pointer to get the length + of the newly created memory buffer + (saveDocToMemoryEnc) add a int *men_length pointer to get the + length of the newly created memory buffer + + * libgdome/gdomecore/gdome-xml-domimpl.[ch] + (gdome_xml_di_saveDocToMemory) add a int *men_length pointer to + get the length of the newly created memory buffer + (gdome_xml_di_saveDocToMemoryEnc) add a int *men_length pointer to + get the length of the newly created memory buffer + + * test/test-loadsave.c + Modified to test gdome_di_saveDocToMemmory and + gdome_di_saveDocToMemoryEnc with the new function arguments + + * gtk-doc/gdome2-decl.txt + (gdome_xml_di_saveDocToMemory) add a int *men_length pointer to + get the length of the newly created memory buffer + (gdome_xml_di_saveDocToMemoryEnc) add a int *men_length pointer to + get the length of the newly created memory buffer + + * test/apigen/core.xml + (saveDocToMemory) add a int *men_length pointer to get the length + of the newly created memory buffer + (saveDocToMemoryEnc) add a int *men_length pointer to get the + length of the newly created memory buffer + +2003-03-10 Paolo Casarini <[email protected]> * configure.in, README Updated for 0.7.4 release @@ -3277,5 +3312,3 @@ * ifgen.pl, DOM* : remove. * gdome2/Makefile.am : cleanups. Remove code autogeneration. - - Index: gtk-doc/gdome2-decl.txt =================================================================== RCS file: /cvs/gnome/gdome2/gtk-doc/gdome2-decl.txt,v retrieving revision 1.10 diff -u -r1.10 gdome2-decl.txt --- gtk-doc/gdome2-decl.txt 10 Mar 2003 10:42:10 -0000 1.10 +++ gtk-doc/gdome2-decl.txt 15 Mar 2003 20:13:32 -0000 @@ -1935,12 +1935,12 @@ <FUNCTION> <NAME>gdome_di_saveDocToMemory</NAME> <RETURNS>GdomeBoolean </RETURNS> -GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, GdomeSavingCode mode, GdomeException *exc +GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, int *mem_length, GdomeSavingCode mode, GdomeException *exc </FUNCTION> <FUNCTION> <NAME>gdome_di_saveDocToMemoryEnc</NAME> <RETURNS>GdomeBoolean </RETURNS> -GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, const char *encoding, GdomeSavingCode mode, GdomeException *exc +GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, int *mem_length, const char *encoding, GdomeSavingCode mode, GdomeException *exc </FUNCTION> <FUNCTION> <NAME>gdome_doc_doctype</NAME> Index: libgdome/gdome.c =================================================================== RCS file: /cvs/gnome/gdome2/libgdome/gdome.c,v retrieving revision 1.38 diff -u -r1.38 gdome.c --- libgdome/gdome.c 23 May 2002 15:46:17 -0000 1.38 +++ libgdome/gdome.c 15 Mar 2003 20:14:21 -0000 @@ -558,46 +558,49 @@ * @self: DOMImplementation Object ref * @doc: the Document of which the tree is wanted to be saved * @mem: the memory pointer where the saved document is returned + * @mem_length: the length buffer pointed to by the memory pointer * @mode: the indentation mode wanted * @exc: Exception Object ref * * Save the DOM tree of the Document specified to a new allocated memory and - * return it in the @mem pointer. + * return it in the @mem pointer along with the length of the buffer in + * @mem_length. * Returns: %FALSE in case of failure, %TRUE otherwise. */ GdomeBoolean -gdome_di_saveDocToMemory (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, GdomeSavingCode mode, GdomeException *exc) +gdome_di_saveDocToMemory (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, int *mem_length, GdomeSavingCode mode, GdomeException *exc) { if (self == NULL) { *exc = GDOME_NULL_POINTER_ERR; return FALSE; } *exc = 0; - return ((Gdome_xml_DOMImplementation *)self)->vtab->saveDocToMemory (self, doc, mem, mode, exc); + return ((Gdome_xml_DOMImplementation *)self)->vtab->saveDocToMemory (self, doc, mem, mem_length, mode, exc); } /** * gdome_di_saveDocToMemoryEnc: * @self: DOMImplementation Object ref * @doc: the Document of which the tree is wanted to be saved * @mem: the memory pointer where the saved document is returned + * @mem_length: the length buffer pointed to by the memory pointer * @encoding: character encoding to use when generating XML text * @mode: the indentation mode wanted * @exc: Exception Object ref * * Save the DOM tree of the Document specified using the specified character * encoding standard to a new allocated memory and return it in the @mem - * pointer. + * pointer along with the length of the buffer in @mem_length. * Returns: %FALSE in case of failure, %TRUE otherwise. */ GdomeBoolean -gdome_di_saveDocToMemoryEnc (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, const char *encoding, GdomeSavingCode mode, GdomeException *exc) +gdome_di_saveDocToMemoryEnc (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, int *mem_length, const char *encoding, GdomeSavingCode mode, GdomeException *exc) { if (self == NULL) { *exc = GDOME_NULL_POINTER_ERR; return FALSE; } *exc = 0; - return ((Gdome_xml_DOMImplementation *)self)->vtab->saveDocToMemoryEnc (self, doc, mem, encoding, mode, exc); + return ((Gdome_xml_DOMImplementation *)self)->vtab->saveDocToMemoryEnc (self, doc, mem, mem_length, encoding, mode, exc); } /****************************************************************************** Index: libgdome/gdome.h =================================================================== RCS file: /cvs/gnome/gdome2/libgdome/gdome.h,v retrieving revision 1.52 diff -u -r1.52 gdome.h --- libgdome/gdome.h 23 May 2002 15:46:18 -0000 1.52 +++ libgdome/gdome.h 15 Mar 2003 20:14:28 -0000 @@ -808,8 +808,8 @@ GdomeDocument *gdome_di_createDocFromMemoryWithEntitiesTable (GdomeDOMImplementation *self, char *buffer, const GdomeEntitiesTableEntry entityTable[], unsigned int mode, GdomeException *exc); GdomeBoolean gdome_di_saveDocToFile (GdomeDOMImplementation *self, GdomeDocument *doc, const char *filename, GdomeSavingCode mode, GdomeException *exc); GdomeBoolean gdome_di_saveDocToFileEnc (GdomeDOMImplementation *self, GdomeDocument *doc, const char *filename, const char *encoding, GdomeSavingCode mode, GdomeException *exc); -GdomeBoolean gdome_di_saveDocToMemory (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, GdomeSavingCode mode, GdomeException *exc); -GdomeBoolean gdome_di_saveDocToMemoryEnc (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, const char *encoding, GdomeSavingCode mode, GdomeException *exc); +GdomeBoolean gdome_di_saveDocToMemory (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, int *mem_length, GdomeSavingCode mode, GdomeException *exc); +GdomeBoolean gdome_di_saveDocToMemoryEnc (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, int *mem_length, const char *encoding, GdomeSavingCode mode, GdomeException *exc); GdomeDocumentType *gdome_doc_doctype (GdomeDocument *self, GdomeException *exc); Index: libgdome/gdomecore/gdome-xml-domimpl.c =================================================================== RCS file: /cvs/gnome/gdome2/libgdome/gdomecore/gdome-xml-domimpl.c,v retrieving revision 1.37 diff -u -r1.37 gdome-xml-domimpl.c --- libgdome/gdomecore/gdome-xml-domimpl.c 23 May 2002 15:46:20 -0000 1.37 +++ libgdome/gdomecore/gdome-xml-domimpl.c 15 Mar 2003 20:14:32 -0000 @@ -781,29 +781,31 @@ * @self: DOMImplementation Object ref * @doc: the Document of which the tree is wanted to be saved * @mem: the memory pointer where the saved document is returned + * @mem_length: the length buffer pointed to by the memory pointer * @mode: the indentation mode wanted * @exc: Exception Object ref * * Save the DOM tree of the Document specified to a new allocated memory and - * return it in the @mem pointer. + * return it in the @mem pointer along with the length of the buffer in + * @mem_length. * Returns: %FALSE in case of failure, %TRUE otherwise. */ GdomeBoolean gdome_xml_di_saveDocToMemory (GdomeDOMImplementation *self, GdomeDocument *doc, - char **mem, GdomeSavingCode mode, - GdomeException *exc) + char **mem, int *mem_length, + GdomeSavingCode mode, GdomeException *exc) { Gdome_xml_Document *priv_doc = (Gdome_xml_Document *)doc; - int size = 0; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (doc != NULL, FALSE); g_return_val_if_fail (mem != NULL, FALSE); + g_return_val_if_fail (mem_length != NULL, FALSE); g_return_val_if_fail (exc != NULL, FALSE); g_assert(self == (GdomeDOMImplementation *)gdome_xml_DOMImplementation); - xmlDocDumpFormatMemory(priv_doc->n, (xmlChar **)mem, &size, mode); - if ((mem == NULL) && (size > 0)) + xmlDocDumpFormatMemory(priv_doc->n, (xmlChar **)mem, mem_length, mode); + if ((mem == NULL) && (*mem_length > 0)) return FALSE; else return TRUE; @@ -814,32 +816,36 @@ * @self: DOMImplementation Object ref * @doc: the Document of which the tree is wanted to be saved * @mem: the memory pointer where the saved document is returned + * @mem_length: the length buffer pointed to by the memory pointer * @encoding: character encoding to use when generating XML text * @mode: the indentation mode wanted * @exc: Exception Object ref * * Save the DOM tree of the Document specified using the specified character * encoding standard to a new allocated memory and return it in the @mem - * pointer. + * pointer along with the length of the buffer in @mem_length. * Returns: %FALSE in case of failure, %TRUE otherwise. */ GdomeBoolean -gdome_xml_di_saveDocToMemoryEnc (GdomeDOMImplementation *self, GdomeDocument *doc, - char **mem, const char *encoding, +gdome_xml_di_saveDocToMemoryEnc (GdomeDOMImplementation *self, + GdomeDocument *doc, + char **mem, int *mem_length, + const char *encoding, GdomeSavingCode mode, GdomeException *exc) { Gdome_xml_Document *priv_doc = (Gdome_xml_Document *)doc; - int size = 0; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (doc != NULL, FALSE); g_return_val_if_fail (mem != NULL, FALSE); + g_return_val_if_fail (mem_length != NULL, FALSE); g_return_val_if_fail (encoding != NULL, FALSE); g_return_val_if_fail (exc != NULL, FALSE); g_assert(self == (GdomeDOMImplementation *)gdome_xml_DOMImplementation); - xmlDocDumpFormatMemoryEnc(priv_doc->n, (xmlChar **)mem, &size, encoding, mode); - if ((mem == NULL) && (size > 0)) + xmlDocDumpFormatMemoryEnc(priv_doc->n, (xmlChar **)mem, mem_length, + encoding, mode); + if ((mem == NULL) && (*mem_length > 0)) return FALSE; else return TRUE; Index: libgdome/gdomecore/gdome-xml-domimpl.h =================================================================== RCS file: /cvs/gnome/gdome2/libgdome/gdomecore/gdome-xml-domimpl.h,v retrieving revision 1.21 diff -u -r1.21 gdome-xml-domimpl.h --- libgdome/gdomecore/gdome-xml-domimpl.h 23 May 2002 15:46:20 -0000 1.21 +++ libgdome/gdomecore/gdome-xml-domimpl.h 15 Mar 2003 20:14:33 -0000 @@ -41,9 +41,9 @@ GdomeDocument *(*createDocFromURIWithEntitiesTable) (GdomeDOMImplementation *self, const char *uri, const GdomeEntitiesTableEntry entityTable[], unsigned int mode, GdomeException *exc); GdomeDocument *(*createDocFromMemoryWithEntitiesTable) (GdomeDOMImplementation *self, char *buffer, const GdomeEntitiesTableEntry entityTable[], unsigned int mode, GdomeException *exc); GdomeBoolean (*saveDocToFile) (GdomeDOMImplementation *self, GdomeDocument *doc, const char *filename, GdomeSavingCode mode, GdomeException *exc); - GdomeBoolean (*saveDocToMemory) (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, GdomeSavingCode mode, GdomeException *exc); + GdomeBoolean (*saveDocToMemory) (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, int *mem_length, GdomeSavingCode mode, GdomeException *exc); GdomeBoolean (*saveDocToFileEnc) (GdomeDOMImplementation *self, GdomeDocument *doc, const char *filename, const char *encoding, GdomeSavingCode mode, GdomeException *exc); - GdomeBoolean (*saveDocToMemoryEnc) (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, const char *encoding, GdomeSavingCode mode, GdomeException *exc); + GdomeBoolean (*saveDocToMemoryEnc) (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, int *mem_length, const char *encoding, GdomeSavingCode mode, GdomeException *exc); }; typedef struct _Gdome_xml_DOMImplementation Gdome_xml_DOMImplementation; @@ -115,11 +115,13 @@ GdomeBoolean gdome_xml_di_saveDocToMemory (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, + int *mem_length, GdomeSavingCode mode, GdomeException *exc); GdomeBoolean gdome_xml_di_saveDocToMemoryEnc (GdomeDOMImplementation *self, GdomeDocument *doc, char **mem, + int *mem_length, const char *encoding, GdomeSavingCode mode, GdomeException *exc); Index: test/test-loadsave.c =================================================================== RCS file: /cvs/gnome/gdome2/test/test-loadsave.c,v retrieving revision 1.6 diff -u -r1.6 test-loadsave.c --- test/test-loadsave.c 23 May 2002 15:46:22 -0000 1.6 +++ test/test-loadsave.c 15 Mar 2003 20:14:34 -0000 @@ -101,6 +101,7 @@ GdomeDocument *domdoc = NULL; GdomeException exc = 0; char *mem; + int mem_length; domImpl = gdome_di_mkref(); @@ -133,12 +134,12 @@ fprintf (stderr, "DOMImplementation.createDocFromMemory: parsing failed\n"); return -1; } - if (!gdome_di_saveDocToMemory (domImpl, domdoc, &mem, 0, &exc)) { + if (!gdome_di_saveDocToMemory (domImpl, domdoc, &mem, &mem_length, 0, &exc)) { fprintf (stderr, "DOMImplementation.saveDocToMemory: failed\n"); return -1; } free (mem); - if (!gdome_di_saveDocToMemoryEnc (domImpl, domdoc, &mem, "ISO-8859-1", 0, &exc)) { + if (!gdome_di_saveDocToMemoryEnc (domImpl, domdoc, &mem, &mem_length, "ISO-8859-1", 0, &exc)) { fprintf (stderr, "DOMImplementation.saveDocToMemory: failed\n"); return -1; } Index: test/apigen/core.xml =================================================================== RCS file: /cvs/gnome/gdome2/test/apigen/core.xml,v retrieving revision 1.19 diff -u -r1.19 core.xml --- test/apigen/core.xml 23 May 2002 15:46:23 -0000 1.19 +++ test/apigen/core.xml 15 Mar 2003 20:14:38 -0000 @@ -180,12 +180,14 @@ <EXCEPTION TYPE="NULL_POINTER_ERR" ON="self == NULL"/> <PARAM TYPE="GdomeDocument *" NAME="doc"/> <PARAM TYPE="char **" NAME="mem"/> + <PARAM TYPE="int *" NAME="mem_length"/> <PARAM TYPE="GdomeSavingCode" NAME="mode"/> </METHOD> <METHOD TYPE="GdomeBoolean" NAME="saveDocToMemoryEnc" STANDARD="NO"> <EXCEPTION TYPE="NULL_POINTER_ERR" ON="self == NULL"/> <PARAM TYPE="GdomeDocument *" NAME="doc"/> <PARAM TYPE="char **" NAME="mem"/> + <PARAM TYPE="int *" NAME="mem_length"/> <PARAM TYPE="const char *" NAME="encoding"/> <PARAM TYPE="GdomeSavingCode" NAME="mode"/> </METHOD>