[gnumeric] Parsing: make GnmConvensions ref-counted.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Parsing: make GnmConvensions ref-counted.
- Date: Tue, 21 Sep 2010 18:13:58 +0000 (UTC)
commit a014f7d666eb48813bb0a71f2a9873b5ca863c16
Author: Morten Welinder <terra gnome org>
Date: Tue Sep 21 14:13:27 2010 -0400
Parsing: make GnmConvensions ref-counted.
ChangeLog | 7 +++++++
NEWS | 3 ++-
plugins/applix/applix-read.c | 2 +-
plugins/excel/xlsx-utils.c | 2 +-
plugins/oleo/oleo.c | 2 +-
plugins/openoffice/openoffice-read.c | 2 +-
plugins/sc/sc.c | 2 +-
plugins/sylk/sylk-write.c | 2 +-
src/graph.c | 6 ++++--
src/parse-util.c | 26 ++++++++++++++++++++++----
src/parse-util.h | 7 ++++++-
src/xml-sax-read.c | 12 +++++++++---
src/xml-sax-write.c | 4 ++--
13 files changed, 58 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 94693a8..a473b47 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2010-09-21 Morten Welinder <terra gnome org>
+ * src/graph.c (set_pending_convs): Keep track of convs'
+ life-cycles.
+
+ * src/parse-util.c (gnm_conventions_unref): Renamed from
+ gnm_conventions_free. Change to handle ref-counting.
+ (gnm_conventions_ref): New function.
+
* src/xml-sax-read.c (xml_sax_cell_content): Handle empty values
in inter-process paste. Part of #629302.
diff --git a/NEWS b/NEWS
index fdc3023..101e231 100644
--- a/NEWS
+++ b/NEWS
@@ -20,7 +20,8 @@ J.H.M. Dassen (Ray):
Morten:
* Fix date entry problem. [#630177]
- * Fix problem with inter-process paste. [#629302]
+ * Fix problem with inter-process empty-value paste. [#629302]
+ * Fix problem with inter-process object paste. [#629302]
--------------------------------------------------------------------------
Gnumeric 1.10.10
diff --git a/plugins/applix/applix-read.c b/plugins/applix/applix-read.c
index 1cac5ed..a0241d0 100644
--- a/plugins/applix/applix-read.c
+++ b/plugins/applix/applix-read.c
@@ -1704,5 +1704,5 @@ applix_read (GOIOContext *io_context, WorkbookView *wb_view, GsfInput *src)
if (state.parse_error != NULL)
go_io_error_info_set (io_context, state.parse_error);
- gnm_conventions_free (state.convs);
+ gnm_conventions_unref (state.convs);
}
diff --git a/plugins/excel/xlsx-utils.c b/plugins/excel/xlsx-utils.c
index 44afb2a..f73fbd6 100644
--- a/plugins/excel/xlsx-utils.c
+++ b/plugins/excel/xlsx-utils.c
@@ -149,7 +149,7 @@ xlsx_conventions_free (GnmConventions *convs)
XLSXExprConventions *xconv = (XLSXExprConventions *)convs;
g_hash_table_destroy (xconv->extern_id_by_wb);
g_hash_table_destroy (xconv->extern_wb_by_id);
- gnm_conventions_free (convs);
+ gnm_conventions_unref (convs);
}
/**
diff --git a/plugins/oleo/oleo.c b/plugins/oleo/oleo.c
index 4272a0d..d3a0875 100644
--- a/plugins/oleo/oleo.c
+++ b/plugins/oleo/oleo.c
@@ -294,6 +294,6 @@ oleo_read (GOIOContext *io_context, Workbook *wb, GsfInput *input)
gnm_style_unref (style);
g_iconv_close (state.converter);
- gnm_conventions_free (state.convs);
+ gnm_conventions_unref (state.convs);
g_object_unref (G_OBJECT (state.textline));
}
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 25c04ea..6736e54 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -8537,7 +8537,7 @@ openoffice_file_open (GOFileOpener const *fo, GOIOContext *io_context,
for (i = 0; i < NUM_FORMULAE_SUPPORTED; i++)
if (state.convs[i] != NULL)
- gnm_conventions_free (state.convs[i]);
+ gnm_conventions_unref (state.convs[i]);
gnm_pop_C_locale (locale);
}
diff --git a/plugins/sc/sc.c b/plugins/sc/sc.c
index 2d867f7..2223922 100644
--- a/plugins/sc/sc.c
+++ b/plugins/sc/sc.c
@@ -621,7 +621,7 @@ sc_file_open (GOFileOpener const *fo, GOIOContext *io_context,
}
g_object_unref (G_OBJECT (state.textline));
g_iconv_close (state.converter);
- gnm_conventions_free (state.convs);
+ gnm_conventions_unref (state.convs);
}
diff --git a/plugins/sylk/sylk-write.c b/plugins/sylk/sylk-write.c
index 1388806..ca9a341 100644
--- a/plugins/sylk/sylk-write.c
+++ b/plugins/sylk/sylk-write.c
@@ -240,5 +240,5 @@ sylk_file_save (GOFileSaver const *fs, GOIOContext *io_context,
sylk_write_sheet (&state);
gsf_output_puts (output, "E\r\n");
gnm_pop_C_locale (locale);
- gnm_conventions_free (state.convs);
+ gnm_conventions_unref (state.convs);
}
diff --git a/src/graph.c b/src/graph.c
index df639a0..731d5f6 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -64,8 +64,10 @@ set_pending_str (const GOData *data, const char *str)
static void
set_pending_convs (GOData *data, const GnmConventions *convs)
{
- g_object_set_data (G_OBJECT (data),
- "unserialize-convs", (gpointer)convs);
+ g_object_set_data_full (G_OBJECT (data),
+ "unserialize-convs",
+ gnm_conventions_ref ((gpointer)convs),
+ (GDestroyNotify)gnm_conventions_unref);
}
/* ------------------------------------------------------------------------- */
diff --git a/src/parse-util.c b/src/parse-util.c
index c567062..8463ec2 100644
--- a/src/parse-util.c
+++ b/src/parse-util.c
@@ -1342,6 +1342,7 @@ gnm_conventions_new_full (unsigned size)
g_return_val_if_fail (size >= sizeof (GnmConventions), NULL);
convs = g_malloc0 (size);
+ convs->ref_count = 1;
convs->sheet_name_sep = '!';
convs->intersection_char = ' ';
@@ -1379,17 +1380,34 @@ gnm_conventions_new (void)
}
/**
- * gnm_conventions_free :
+ * gnm_conventions_unref :
* @c : #GnmConventions
*
* Release a convention
**/
void
-gnm_conventions_free (GnmConventions *c)
+gnm_conventions_unref (GnmConventions *c)
{
+ if (c == NULL)
+ return;
+
+ g_return_if_fail (c->ref_count > 0);
+
+ c->ref_count--;
+ if (c->ref_count > 0)
+ return;
+
g_free (c);
}
+GnmConventions *
+gnm_conventions_ref (GnmConventions *c)
+{
+ if (c)
+ c->ref_count++;
+ return c;
+}
+
/* ------------------------------------------------------------------------- */
GnmConventions const *gnm_conventions_default;
@@ -1414,9 +1432,9 @@ parse_util_init (void)
void
parse_util_shutdown (void)
{
- gnm_conventions_free ((GnmConventions *)gnm_conventions_default);
+ gnm_conventions_unref ((GnmConventions *)gnm_conventions_default);
gnm_conventions_default = NULL;
- gnm_conventions_free ((GnmConventions *)gnm_conventions_xls_r1c1);
+ gnm_conventions_unref ((GnmConventions *)gnm_conventions_xls_r1c1);
gnm_conventions_xls_r1c1 = NULL;
}
diff --git a/src/parse-util.h b/src/parse-util.h
index ed52b42..d37cbcb 100644
--- a/src/parse-util.h
+++ b/src/parse-util.h
@@ -95,6 +95,8 @@ typedef enum {
} GnmExprParseFlags;
struct _GnmConventions {
+ int ref_count;
+
#if 0
/* Not yet. */
gboolean force_absolute_col_references;
@@ -190,7 +192,10 @@ struct _GnmConventions {
};
GnmConventions *gnm_conventions_new (void);
GnmConventions *gnm_conventions_new_full (unsigned size);
-void gnm_conventions_free (GnmConventions *c);
+
+GnmConventions *gnm_conventions_ref (GnmConventions *c);
+void gnm_conventions_unref (GnmConventions *c);
+
GNM_VAR_DECL GnmConventions const *gnm_conventions_default;
GNM_VAR_DECL GnmConventions const *gnm_conventions_xls_r1c1;
diff --git a/src/xml-sax-read.c b/src/xml-sax-read.c
index 1092a0f..03a8c97 100644
--- a/src/xml-sax-read.c
+++ b/src/xml-sax-read.c
@@ -3095,14 +3095,20 @@ static void
read_file_free_state (XMLSaxParseState *state, gboolean self)
{
g_hash_table_destroy (state->expr_map);
+ state->expr_map = NULL;
- gnm_conventions_free (state->convs);
+ gnm_conventions_unref (state->convs);
+ state->convs = NULL;
- if (state->style)
+ if (state->style) {
gnm_style_unref (state->style);
+ state->style = NULL;
+ }
- if (state->style_handler_doc)
+ if (state->style_handler_doc) {
gsf_xml_in_doc_free (state->style_handler_doc);
+ state->style_handler_doc = NULL;
+ }
if (self)
g_free (state);
diff --git a/src/xml-sax-write.c b/src/xml-sax-write.c
index 5261274..8fd77ff 100644
--- a/src/xml-sax-write.c
+++ b/src/xml-sax-write.c
@@ -1395,7 +1395,7 @@ gnm_xml_file_save (GOFileSaver const *fs, GOIOContext *io_context,
g_hash_table_destroy (state.expr_map);
g_string_free (state.cell_str, TRUE);
- gnm_conventions_free (state.convs);
+ gnm_conventions_unref (state.convs);
g_object_unref (G_OBJECT (state.output));
if (gzout) {
@@ -1518,7 +1518,7 @@ gnm_cellregion_to_xml (GnmCellRegion const *cr)
g_hash_table_destroy (state.state.expr_map);
g_string_free (state.state.cell_str, TRUE);
- gnm_conventions_free (state.state.convs);
+ gnm_conventions_unref (state.state.convs);
g_object_unref (G_OBJECT (state.state.output));
gsf_output_close (buf);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]