static bool
regression_trns_free (void *t_)
{
- bool result = true;
struct reg_trns *t = t_;
if (t->trns_id == t->n_trns)
{
- result = linreg_free (t->c);
+ linreg_unref (t->c);
}
free (t);
- return result;
+ return true;
}
static void
{
if ((*lc)->depvar != NULL)
{
+ (*lc)->refcnt++;
if (cmd->resid)
{
reg_save_var (cmd->ds, "RES", regression_trns_resid_proc, *lc,
}
if (regression.pred || regression.resid )
- subcommand_save (®ression);
+ {
+ subcommand_save (®ression);
+ }
for (k = 0; k < regression.n_dep_vars; k++)
- linreg_free (regression.models[k]);
+ linreg_unref (regression.models[k]);
free (regression.models);
free (regression.vars);
free (regression.dep_vars);
error:
for (k = 0; k < regression.n_dep_vars; k++)
- linreg_free (regression.models[k]);
+ linreg_unref (regression.models[k]);
free (regression.models);
free (regression.vars);
free (regression.dep_vars);
{
msg (SE,
_("No valid data found. This command was skipped."));
- linreg_free (models[k]);
+ linreg_unref (models[k]);
models[k] = NULL;
}
gsl_matrix_free (this_cm);
c->pred = NULL;
c->resid = NULL;
+ c->refcnt = 1;
return c;
}
-bool
-linreg_free (void *m)
+void
+linreg_ref (linreg *c)
+{
+ c->refcnt++;
+}
+
+void
+linreg_unref (linreg *c)
{
- linreg *c = m;
- if (c != NULL)
+ if (c && --c->refcnt == 0)
{
gsl_vector_free (c->indep_means);
gsl_vector_free (c->indep_std);
free (c->coeff);
free (c);
}
- return true;
}
static void
struct linreg_struct
{
+ int refcnt;
double n_obs; /* Number of observations. */
int n_indeps; /* Number of independent variables. */
int n_coeffs; /* The intercept is not considered a
linreg *linreg_alloc (const struct variable *, const struct variable **,
double, size_t);
-bool linreg_free (void *);
+void linreg_unref (linreg *);
+void linreg_ref (linreg *c);
/*
Fit the linear model via least squares. All pointers passed to pspp_linreg