Commit eaf62e4c authored by Jon K Hellan's avatar Jon K Hellan Committed by Jon Kåre Hellan

Free Value after it has been cloned.

2002-03-26  Jon K Hellan  <hellan@acm.org>

	* plugins/guile/plugin.c (scm_gnumeric_funcall): Free Value
	after it has been cloned.

	* plugins/guile/smob-value.c (make_new_smob): Make the Value
	inside the smob a clone of v.
	(get_value_from_smob): Also clone when returning Value from smob.
parent ecad73aa
2002-03-26 Jon K Hellan <hellan@acm.org>
* plugin.c (scm_gnumeric_funcall): Free Value after it has been
cloned.
* smob-value.c (make_new_smob): Make the Value inside the smob a
clone of v.
(get_value_from_smob): Also clone when returning Value from smob.
2002-03-24 Jon K Hellan <hellan@acm.org>
* plugin.c (scm_register_function) constify help.
......
......@@ -114,24 +114,26 @@ static SCM
scm_gnumeric_funcall (SCM funcname, SCM arglist)
{
int i, num_args;
Value **values;
Value **argvals;
Value *retval;
SCM retsmob;
CellRef cell_ref = { 0, 0, 0, 0 };
SCM_ASSERT (SCM_NIMP (funcname) && SCM_STRINGP (funcname), funcname, SCM_ARG1, "gnumeric-funcall");
SCM_ASSERT (SCM_NFALSEP (scm_list_p (arglist)), arglist, SCM_ARG2, "gnumeric-funcall");
num_args = scm_ilength (arglist);
values = g_new (Value *, num_args);
argvals = g_new (Value *, num_args);
for (i = 0; i < num_args; ++i) {
values[i] = scm_to_value (SCM_CAR (arglist));
argvals[i] = scm_to_value (SCM_CAR (arglist));
arglist = SCM_CDR (arglist);
}
return value_to_scm (function_call_with_values (eval_pos,
SCM_CHARS (funcname),
num_args,
values),
cell_ref);
retval = function_call_with_values (eval_pos, SCM_CHARS (funcname),
num_args,argvals);
retsmob = value_to_scm (retval, cell_ref);
value_release (retval);
return retsmob;
}
static Value*
......
......@@ -40,30 +40,34 @@ typedef struct _SCM_Value
SCM update_func;
} SCM_Value;
/**
* The Value in the smob has to be a clone of v, since the original may be
* released in C-land, and there is no way to tell the Guile garbage
* collector.
*/
SCM
make_new_smob (Value *v)
{
SCM_Value *value;
value = (SCM_Value *) scm_must_malloc (sizeof (SCM_Value), "value");
value->v = v;
value->v = value_duplicate (v);
value->update_func = SCM_BOOL_F;
SCM_RETURN_NEWSMOB (value_tag, value);
}
/**
* We also have to clone the value in the smob before returning it to
* C-land, since the returned value may be released. There may be leaks, but
* freing memory twice is worse.
*/
Value *
get_value_from_smob (SCM value_smob)
{
Value *value;
SCM_Value *v = (SCM_Value *) SCM_CDR (value_smob);
value = g_new (Value, 1);
value = v->v;
return value;
return value_duplicate (v->v);
}
int
......
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