[librsvg/rustification] Make rsvg_state_new() / rsvg_state_free() the only way of getting new states
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustification] Make rsvg_state_new() / rsvg_state_free() the only way of getting new states
- Date: Wed, 9 Nov 2016 23:44:09 +0000 (UTC)
commit 468f9251782b7aed6f9ff5e34e404a6da161e880
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Nov 9 15:37:27 2016 -0600
Make rsvg_state_new() / rsvg_state_free() the only way of getting new states
Previously they were allocated on the stack, allocated by hand on the
heap, allocated with g_slice by rsvg_state_push()...
Make all of that consistent; rsvg_state_new() is the only way to get
a new state now.
rsvg-image.c | 4 +-
rsvg-paint-server.c | 15 ++++---
rsvg-structure.c | 11 +++--
rsvg-styles.c | 125 ++++++++++++++++++++++++++++++---------------------
rsvg-styles.h | 5 +-
5 files changed, 91 insertions(+), 69 deletions(-)
---
diff --git a/rsvg-image.c b/rsvg-image.c
index 700aa79..69127e3 100644
--- a/rsvg-image.c
+++ b/rsvg-image.c
@@ -155,9 +155,7 @@ static void
rsvg_node_image_free (RsvgNode * self)
{
RsvgNodeImage *z = (RsvgNodeImage *) self;
- rsvg_state_finalize (z->super.state);
- g_free (z->super.state);
- z->super.state = NULL;
+
if (z->surface)
cairo_surface_destroy (z->surface);
_rsvg_node_free(self);
diff --git a/rsvg-paint-server.c b/rsvg-paint-server.c
index 1bbb4cb..ebf24bb 100644
--- a/rsvg-paint-server.c
+++ b/rsvg-paint-server.c
@@ -153,7 +153,7 @@ rsvg_stop_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
gboolean is_current_color = FALSE;
const char *value;
RsvgGradientStop *stop;
- RsvgState state;
+ RsvgState *state;
stop = (RsvgGradientStop *) self;
@@ -179,12 +179,15 @@ rsvg_stop_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
rsvg_parse_style_pairs (ctx, self->state, atts);
}
self->parent = ctx->priv->currentnode;
- rsvg_state_init (&state);
- rsvg_state_reconstruct (&state, self);
+
+ state = rsvg_state_new ();
+ rsvg_state_reconstruct (state, self);
+
if (is_current_color)
- state.stop_color = state.current_color;
- stop->rgba = (state.stop_color << 8) | state.stop_opacity;
- rsvg_state_finalize (&state);
+ state->stop_color = state->current_color;
+ stop->rgba = (state->stop_color << 8) | state->stop_opacity;
+
+ rsvg_state_free (state);
}
RsvgNode *
diff --git a/rsvg-structure.c b/rsvg-structure.c
index c494cf5..cf9e9c5 100644
--- a/rsvg-structure.c
+++ b/rsvg-structure.c
@@ -92,8 +92,7 @@ _rsvg_node_init (RsvgNode * self,
self->type = type;
self->parent = NULL;
self->children = g_ptr_array_new ();
- self->state = g_new (RsvgState, 1);
- rsvg_state_init (self->state);
+ self->state = rsvg_state_new ();
self->free = _rsvg_node_free;
self->draw = _rsvg_node_draw_nothing;
self->set_atts = _rsvg_node_dont_set_atts;
@@ -103,11 +102,13 @@ void
_rsvg_node_finalize (RsvgNode * self)
{
if (self->state != NULL) {
- rsvg_state_finalize (self->state);
- g_free (self->state);
+ rsvg_state_free (self->state);
+ self->state = NULL;
}
- if (self->children != NULL)
+ if (self->children != NULL) {
g_ptr_array_free (self->children, TRUE);
+ self->children = NULL;
+ }
}
void
diff --git a/rsvg-styles.c b/rsvg-styles.c
index 6e91981..ee302f0 100644
--- a/rsvg-styles.c
+++ b/rsvg-styles.c
@@ -114,7 +114,7 @@ rsvg_dpi_percentage (RsvgHandle * ctx)
return sqrt (ctx->priv->dpi_x * ctx->priv->dpi_y);
}
-void
+static void
rsvg_state_init (RsvgState * state)
{
memset (state, 0, sizeof (RsvgState));
@@ -211,6 +211,71 @@ rsvg_state_init (RsvgState * state)
g_free, (GDestroyNotify) style_value_data_free);
}
+RsvgState *
+rsvg_state_new (void)
+{
+ RsvgState *state;
+
+ state = g_slice_new (RsvgState);
+ rsvg_state_init (state);
+
+ return state;
+}
+
+static void
+rsvg_state_finalize (RsvgState * state)
+{
+ g_free (state->filter);
+ state->filter = NULL;
+
+ g_free (state->mask);
+ state->mask = NULL;
+
+ g_free (state->clip_path);
+ state->clip_path = NULL;
+
+ g_free (state->font_family);
+ state->font_family = NULL;
+
+ g_free (state->lang);
+ state->lang = NULL;
+
+ g_free (state->startMarker);
+ state->startMarker = NULL;
+
+ g_free (state->middleMarker);
+ state->middleMarker = NULL;
+
+ g_free (state->endMarker);
+ state->endMarker = NULL;
+
+ rsvg_paint_server_unref (state->fill);
+ state->fill = NULL;
+
+ rsvg_paint_server_unref (state->stroke);
+ state->stroke = NULL;
+
+ if (state->dash.n_dash != 0) {
+ g_free (state->dash.dash);
+ state->dash.n_dash = 0;
+ state->dash.dash = NULL;
+ }
+
+ if (state->styles) {
+ g_hash_table_unref (state->styles);
+ state->styles = NULL;
+ }
+}
+
+void
+rsvg_state_free (RsvgState *state)
+{
+ g_assert (state != NULL);
+
+ rsvg_state_finalize (state);
+ g_slice_free (RsvgState, state);
+}
+
void
rsvg_state_reinit (RsvgState * state)
{
@@ -468,51 +533,6 @@ rsvg_state_inherit (RsvgState * dst, const RsvgState * src)
rsvg_state_inherit_run (dst, src, inheritfunction, 1);
}
-void
-rsvg_state_finalize (RsvgState * state)
-{
- g_free (state->filter);
- state->filter = NULL;
-
- g_free (state->mask);
- state->mask = NULL;
-
- g_free (state->clip_path);
- state->clip_path = NULL;
-
- g_free (state->font_family);
- state->font_family = NULL;
-
- g_free (state->lang);
- state->lang = NULL;
-
- g_free (state->startMarker);
- state->startMarker = NULL;
-
- g_free (state->middleMarker);
- state->middleMarker = NULL;
-
- g_free (state->endMarker);
- state->endMarker = NULL;
-
- rsvg_paint_server_unref (state->fill);
- state->fill = NULL;
-
- rsvg_paint_server_unref (state->stroke);
- state->stroke = NULL;
-
- if (state->dash.n_dash != 0) {
- g_free (state->dash.dash);
- state->dash.n_dash = 0;
- state->dash.dash = NULL;
- }
-
- if (state->styles) {
- g_hash_table_unref (state->styles);
- state->styles = NULL;
- }
-}
-
/* Parse a CSS2 style argument, setting the SVG context attributes. */
static void
rsvg_parse_style_pair (RsvgHandle * ctx,
@@ -1560,8 +1580,9 @@ rsvg_state_free_all (RsvgState * state)
{
while (state) {
RsvgState *parent = state->parent;
- rsvg_state_finalize (state);
- g_slice_free (RsvgState, state);
+
+ rsvg_state_free (state);
+
state = parent;
}
}
@@ -1650,8 +1671,7 @@ rsvg_state_push (RsvgDrawingCtx * ctx)
RsvgState *baseon;
baseon = ctx->state;
- data = g_slice_new (RsvgState);
- rsvg_state_init (data);
+ data = rsvg_state_new ();
if (baseon) {
rsvg_state_reinherit (data, baseon);
@@ -1666,9 +1686,10 @@ void
rsvg_state_pop (RsvgDrawingCtx * ctx)
{
RsvgState *dead_state = ctx->state;
+
ctx->state = dead_state->parent;
- rsvg_state_finalize (dead_state);
- g_slice_free (RsvgState, dead_state);
+
+ rsvg_state_free (dead_state);
}
/*
diff --git a/rsvg-styles.h b/rsvg-styles.h
index a044d3f..bad0425 100644
--- a/rsvg-styles.h
+++ b/rsvg-styles.h
@@ -191,7 +191,8 @@ G_GNUC_INTERNAL
RsvgState *rsvg_state_new (void);
G_GNUC_INTERNAL
-void rsvg_state_init (RsvgState * state);
+void rsvg_state_free (RsvgState *state);
+
G_GNUC_INTERNAL
void rsvg_state_reinit (RsvgState * state);
G_GNUC_INTERNAL
@@ -205,8 +206,6 @@ void rsvg_state_dominate (RsvgState * dst, const RsvgState * src);
G_GNUC_INTERNAL
void rsvg_state_override (RsvgState * dst, const RsvgState * src);
G_GNUC_INTERNAL
-void rsvg_state_finalize (RsvgState * state);
-G_GNUC_INTERNAL
void rsvg_state_free_all (RsvgState * state);
G_GNUC_INTERNAL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]