[lasem] dom: use gsize type for data size parameter



commit 098724b8902698ed51390dedf055a4892d313baa
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Mon May 19 10:51:28 2014 +0200

    dom: use gsize type for data size parameter

 src/lasemrender.c  |    4 +-
 src/lsmdomparser.c |   82 +++++++++++++++++++++++++++++++++++++++++++++------
 src/lsmdomparser.h |   14 ++++----
 tests/lsmtest.c    |    4 +-
 4 files changed, 83 insertions(+), 21 deletions(-)
---
diff --git a/src/lasemrender.c b/src/lasemrender.c
index ec9a41f..7c6e7fa 100644
--- a/src/lasemrender.c
+++ b/src/lasemrender.c
@@ -186,12 +186,12 @@ int main(int argc, char **argv)
        if (document != NULL) {
                if (lsm_debug_check (&lsm_debug_category_dom, LSM_DEBUG_LEVEL_LOG)) {
                        void *buffer;
-                       int size;
+                       gsize size;
 
                        lsm_dom_document_save_to_memory (document, &buffer, &size, NULL);
 
                        if (buffer != NULL) {
-                               g_printf ("%*s\n", size, (char *) buffer);
+                               g_printf ("%*s\n", (int) size, (char *) buffer);
                                g_free (buffer);
                        }
                }
diff --git a/src/lsmdomparser.c b/src/lsmdomparser.c
index a1af8f7..bb342f2 100644
--- a/src/lsmdomparser.c
+++ b/src/lsmdomparser.c
@@ -259,7 +259,7 @@ typedef enum {
 
 static LsmDomDocument *
 _parse_memory (LsmDomDocument *document, LsmDomNode *node,
-              const void *buffer, int size, GError **error)
+              const void *buffer, gsize size, GError **error)
 {
        static LsmDomSaxParserState state;
 
@@ -269,7 +269,7 @@ _parse_memory (LsmDomDocument *document, LsmDomNode *node,
        else
                state.current_node = LSM_DOM_NODE (document);
 
-       if (size < 0)
+       if (size < 1)
                size = strlen (buffer);
 
        if (xmlSAXUserParseMemory (&sax_handler, &state, buffer, size) < 0) {
@@ -293,18 +293,18 @@ _parse_memory (LsmDomDocument *document, LsmDomNode *node,
  * @document: a #LsmDomDocument
  * @node: a #LsmDomNode
  * @buffer: a memory buffer holding xml data
- * @size: size of the xml data, in bytes
+ * @size: size of the xml data, in bytes, 0 if unknown
  * @error: an error placeholder
  *
  * Append a chunk of xml tree to an existing document. The resulting nodes will be appended to
  * @node, or to @document if @node == NULL.
  *
- * Size set to a negative value indicated an unknow xml data size.
+ * Size set to 0 indicates an unknow xml data size.
  */
 
 void
 lsm_dom_document_append_from_memory (LsmDomDocument *document, LsmDomNode *node,
-                                    const void *buffer, int size, GError **error)
+                                    const void *buffer, gsize size, GError **error)
 {
        g_return_if_fail (LSM_IS_DOM_DOCUMENT (document));
        g_return_if_fail (LSM_IS_DOM_NODE (node) || node == NULL);
@@ -313,14 +313,30 @@ lsm_dom_document_append_from_memory (LsmDomDocument *document, LsmDomNode *node,
        _parse_memory (document, node, buffer, size, error);
 }
 
+/**
+ * lsm_dom_document_new_from_memory:
+ * @buffer: xml data
+ * @size: size of the data, in bytes, 0 if unknown
+ * @error: an error placeholder
+ *
+ * Create a new document from a memory data buffer.
+ */
+
 LsmDomDocument *
-lsm_dom_document_new_from_memory (const void *buffer, int size, GError **error)
+lsm_dom_document_new_from_memory (const void *buffer, gsize size, GError **error)
 {
        g_return_val_if_fail (buffer != NULL, NULL);
 
        return _parse_memory (NULL, NULL, buffer, size, error); 
 }
 
+/**
+ * lsm_dom_document_new_from_file:
+ * @file: a #GFile
+ * @error: an error placeholder
+ *
+ * Create a new document from a #GFile.
+ */
 
 static LsmDomDocument *
 lsm_dom_document_new_from_file (GFile *file, GError **error)
@@ -339,6 +355,14 @@ lsm_dom_document_new_from_file (GFile *file, GError **error)
        return document;
 }
 
+/**
+ * lsm_dom_document_new_from_path:
+ * @path: a file path
+ * @error: an error placeholder
+ *
+ * Create a new document from the data stored in @path.
+ */
+
 LsmDomDocument *
 lsm_dom_document_new_from_path (const char *path, GError **error)
 {
@@ -359,6 +383,14 @@ lsm_dom_document_new_from_path (const char *path, GError **error)
        return document;
 }
 
+/**
+ * lsm_dom_document_new_from_url:
+ * @url: a file url
+ * @error: an error placeholder
+ *
+ * Create a new document from the data stored at @url.
+ */
+
 LsmDomDocument *
 lsm_dom_document_new_from_url (const char *url, GError **error)
 {
@@ -384,6 +416,8 @@ lsm_dom_document_new_from_url (const char *url, GError **error)
  * @document: a #LsmDomDocument
  * @stream: stream to save to
  * @error: an error placeholder
+ *
+ * Save @document as an xml representation into @stream.
  */
 
 void
@@ -395,8 +429,18 @@ lsm_dom_document_save_to_stream (LsmDomDocument *document, GOutputStream *stream
        lsm_dom_node_write_to_stream (LSM_DOM_NODE (document), stream, error);
 }
 
+/**
+ * lsm_dom_document_save_to_memory:
+ * @document: a #LsmDomDocument
+ * @buffer: placeholder for a pointer to the resulting data buffer
+ * @size: placeholder for the data size
+ * @error: placeholder for a #GError
+ *
+ * Save @document as an xml representation into @buffer.
+ */
+
 void
-lsm_dom_document_save_to_memory        (LsmDomDocument *document, void **buffer, int *size, GError **error)
+lsm_dom_document_save_to_memory        (LsmDomDocument *document, void **buffer, gsize *size, GError **error)
 {
        GOutputStream *stream;
 
@@ -426,6 +470,15 @@ lsm_dom_document_save_to_memory    (LsmDomDocument *document, void **buffer, int *s
        g_object_unref (stream);
 }
 
+/**
+ * lsm_dom_document_save_to_path:
+ * @document: a #LsmDomDocument
+ * @path: a file path
+ * @error: placeholder for a #GError
+ *
+ * Save @document as an xml representation to a file, replacing the already existing file if needed.
+ */
+
 void
 lsm_dom_document_save_to_path (LsmDomDocument *document, const char *path, GError **error)
 {
@@ -443,15 +496,24 @@ lsm_dom_document_save_to_path (LsmDomDocument *document, const char *path, GErro
        g_object_unref (file);
 }
 
+/**
+ * lsm_dom_document_save_to_url:
+ * @document: a #LsmDomDocument
+ * @url: an url
+ * @error: placeholder for a #GError
+ *
+ * Save @document as an xml representation to @url, replacing the already existing file if needed.
+ */
+
 void
-lsm_dom_document_save_to_url (LsmDomDocument *document, const char *path, GError **error)
+lsm_dom_document_save_to_url (LsmDomDocument *document, const char *url, GError **error)
 {
        GFile *file;
        GFileOutputStream *stream;
 
-       g_return_if_fail (path != NULL);
+       g_return_if_fail (url != NULL);
 
-       file = g_file_new_for_uri (path);
+       file = g_file_new_for_uri (url);
        stream = g_file_create (file, G_FILE_CREATE_REPLACE_DESTINATION, NULL, error);
        if (stream != NULL) {
                lsm_dom_document_save_to_stream (document, G_OUTPUT_STREAM (stream), error);
diff --git a/src/lsmdomparser.h b/src/lsmdomparser.h
index b47a4d5..8e89331 100644
--- a/src/lsmdomparser.h
+++ b/src/lsmdomparser.h
@@ -30,23 +30,23 @@
 G_BEGIN_DECLS
 
 void                   lsm_dom_document_append_from_memory     (LsmDomDocument *document, LsmDomNode *node,
-                                                                const void *buffer, int size, GError 
**error);
-LsmDomDocument *       lsm_dom_document_new_from_memory        (const void *buffer, int size, GError 
**error);
+                                                                const void *buffer, gsize size, GError 
**error);
+LsmDomDocument *       lsm_dom_document_new_from_memory        (const void *buffer, gsize size, GError 
**error);
 LsmDomDocument *       lsm_dom_document_new_from_path          (const char *path, GError **error);
 LsmDomDocument *       lsm_dom_document_new_from_url           (const char *url, GError **error);
 
 void                   lsm_dom_document_save_to_stream         (LsmDomDocument *document,
                                                                 GOutputStream *stream,
                                                                 GError **error);
-void                   lsm_dom_document_save_to_memory         (LsmDomDocument *documennt,
+void                   lsm_dom_document_save_to_memory         (LsmDomDocument *document,
                                                                 void **buffer,
-                                                                int *size,
+                                                                gsize *size,
                                                                 GError **error);
-void                   lsm_dom_document_save_to_path           (LsmDomDocument *documennt,
+void                   lsm_dom_document_save_to_path           (LsmDomDocument *document,
                                                                 const char *path,
                                                                 GError **error);
-void                   lsm_dom_document_save_to_url            (LsmDomDocument *documennt,
-                                                                const char *path,
+void                   lsm_dom_document_save_to_url            (LsmDomDocument *document,
+                                                                const char *url,
                                                                 GError **error);
 
 G_END_DECLS
diff --git a/tests/lsmtest.c b/tests/lsmtest.c
index 960a9c5..1fdaf56 100644
--- a/tests/lsmtest.c
+++ b/tests/lsmtest.c
@@ -254,7 +254,7 @@ lasem_test_render (char const *filename, gboolean compare, gboolean dry_run, Sta
        cairo_t *cairo;
        cairo_surface_t *surface;
        char *buffer = NULL;
-       size_t size;
+       gsize size;
        char *png_filename;
        char *reference_png_filename;
        char *test_name;
@@ -300,7 +300,7 @@ lasem_test_render (char const *filename, gboolean compare, gboolean dry_run, Sta
                        xml = buffer;
                else {
                        xml = itex2MML_parse (buffer, size);
-                       size = -1;
+                       size = 0;
                }
 
                timer = g_timer_new ();


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