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.
parent a450f40e
......@@ -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);
......
......@@ -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 *
......
......@@ -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
......
......@@ -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);
}
/*
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment