[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [warnings 5/7] Fix some constness problems that led to warnings.
From: |
John Darrington |
Subject: |
Re: [warnings 5/7] Fix some constness problems that led to warnings. |
Date: |
Sat, 18 Sep 2010 07:06:32 +0000 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
Do you mind if we leave this one for now? These warnings are a
reminder to me that there are some ownership semantics which need
to be formalised between covariance/categoricals and the the
procedures which use then. I'm intending to do this at the same
time as implementing interactions.
Right now, the oneway command is leaking memory. These warnings
remind me to fix it.
On Fri, Sep 17, 2010 at 09:36:30PM -0700, Ben Pfaff wrote:
---
src/language/stats/oneway.c | 5 +++--
src/language/stats/regression.q | 4 ++--
src/math/categoricals.c | 26 ++++++++++++++------------
src/math/categoricals.h | 4 ++--
src/math/covariance.c | 30 +++++++++++++-----------------
src/math/covariance.h | 6 +++---
6 files changed, 37 insertions(+), 38 deletions(-)
diff --git a/src/language/stats/oneway.c b/src/language/stats/oneway.c
index aa8a255..9a69500 100644
--- a/src/language/stats/oneway.c
+++ b/src/language/stats/oneway.c
@@ -418,7 +418,8 @@ run_oneway (const struct oneway_spec *cmd,
cmd->wv, cmd->exclude,
makeit,
updateit,
- cmd->vars[v],
ws.dd_total[v]);
+ CONST_CAST (struct
variable *, cmd->vars[v]),
+ ws.dd_total[v]);
ws.vws[v].cov = covariance_2pass_create (1, &cmd->vars[v],
cats,
@@ -580,7 +581,7 @@ run_oneway (const struct oneway_spec *cmd,
for (v = 0; v < cmd->n_vars; ++v)
{
- struct categoricals *cats = covariance_get_categoricals
(ws.vws[v].cov);
+ const struct categoricals *cats = covariance_get_categoricals
(ws.vws[v].cov);
categoricals_done (cats);
diff --git a/src/language/stats/regression.q
b/src/language/stats/regression.q
index 8f9979a..668804d 100644
--- a/src/language/stats/regression.q
+++ b/src/language/stats/regression.q
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2005, 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -810,10 +810,10 @@ fill_covariance (gsl_matrix *cov, struct covariance
*all_cov,
size_t dep_subscript;
size_t *rows;
const gsl_matrix *ssizes;
- const gsl_matrix *cm;
const gsl_matrix *mean_matrix;
const gsl_matrix *ssize_matrix;
double result = 0.0;
+ gsl_matrix *cm;
cm = covariance_calculate_unnormalized (all_cov);
rows = xnmalloc (cov->size1 - 1, sizeof (*rows));
diff --git a/src/math/categoricals.c b/src/math/categoricals.c
index c8b337e..29c1e0f 100644
--- a/src/math/categoricals.c
+++ b/src/math/categoricals.c
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -16,19 +16,20 @@
#include <config.h>
-#include <stdio.h>
+#include "math/categoricals.h"
-#include "categoricals.h"
+#include <stdio.h>
-#include <gl/xalloc.h>
-#include <data/variable.h>
-#include <data/case.h>
-#include <data/value.h>
-#include <libpspp/hmap.h>
-#include <libpspp/pool.h>
-#include <libpspp/array.h>
+#include "data/case.h"
+#include "data/value.h"
+#include "data/variable.h"
+#include "libpspp/array.h"
+#include "libpspp/cast.h"
+#include "libpspp/hmap.h"
+#include "libpspp/pool.h"
+#include "libpspp/str.h"
-#include <libpspp/str.h>
+#include "gl/xalloc.h"
struct value_node
{
@@ -311,7 +312,7 @@ categoricals_total (const struct categoricals *cat)
/* This function must be called *before* any call to
categoricals_get_*_by subscript an
*after* all calls to categoricals_update */
void
-categoricals_done (struct categoricals *cat)
+categoricals_done (const struct categoricals *cat_)
{
/* Implementation Note: Whilst this function is O(n) in
cat->n_cats_total, in most
uses it will be more efficient that using a tree based structure,
since it
@@ -319,6 +320,7 @@ categoricals_done (struct categoricals *cat)
1 call of O(n) + 10^9 calls of O(1) is better than 10^9 calls of
O(log n).
*/
+ struct categoricals *cat = CONST_CAST (struct categoricals *, cat_);
int v;
int idx = 0;
cat->reverse_variable_map = pool_calloc (cat->pool,
diff --git a/src/math/categoricals.h b/src/math/categoricals.h
index 09ced7d..85fcc1a 100644
--- a/src/math/categoricals.h
+++ b/src/math/categoricals.h
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -61,7 +61,7 @@ size_t categoricals_total (const struct categoricals
*cat);
*/
size_t categoricals_get_n_variables (const struct categoricals *cat);
-void categoricals_done (struct categoricals *cat);
+void categoricals_done (const struct categoricals *);
const struct variable * categoricals_get_variable_by_subscript (const
struct categoricals *cat, int subscript);
diff --git a/src/math/covariance.c b/src/math/covariance.c
index aa7f417..cf486de 100644
--- a/src/math/covariance.c
+++ b/src/math/covariance.c
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -529,7 +529,7 @@ cm_to_gsl (struct covariance *cov)
}
-static const gsl_matrix *
+static gsl_matrix *
covariance_calculate_double_pass (struct covariance *cov)
{
size_t i, j;
@@ -553,7 +553,7 @@ covariance_calculate_double_pass (struct covariance
*cov)
return cm_to_gsl (cov);
}
-static const gsl_matrix *
+static gsl_matrix *
covariance_calculate_single_pass (struct covariance *cov)
{
size_t i, j;
@@ -598,12 +598,10 @@ covariance_calculate_single_pass (struct covariance
*cov)
}
-/*
- Return a pointer to gsl_matrix containing the pairwise covariances.
- The matrix remains owned by the COV object, and must not be freed.
- Call this function only after all data have been accumulated.
-*/
-const gsl_matrix *
+/* Return a pointer to a newly allocated gsl_matrix containing the
pairwise
+ covariances. The caller takes ownership of the returned matrix. Call
this
+ function only after all data have been accumulated. */
+gsl_matrix *
covariance_calculate (struct covariance *cov)
{
if ( cov->state <= 0 )
@@ -625,7 +623,7 @@ covariance_calculate (struct covariance *cov)
/*
Covariance computed without dividing by the sample size.
*/
-static const gsl_matrix *
+static gsl_matrix *
covariance_calculate_double_pass_unnormalized (struct covariance *cov)
{
size_t i, j;
@@ -647,7 +645,7 @@ covariance_calculate_double_pass_unnormalized (struct
covariance *cov)
return cm_to_gsl (cov);
}
-static const gsl_matrix *
+static gsl_matrix *
covariance_calculate_single_pass_unnormalized (struct covariance *cov)
{
size_t i, j;
@@ -679,12 +677,10 @@ covariance_calculate_single_pass_unnormalized
(struct covariance *cov)
}
-/*
- Return a pointer to gsl_matrix containing the pairwise covariances.
- The matrix remains owned by the COV object, and must not be freed.
- Call this function only after all data have been accumulated.
-*/
-const gsl_matrix *
+/* Return a pointer to a newly allocated gsl_matrix containing the
pairwise
+ covariances. The caller takes ownership of the returned matrix. Call
this
+ function only after all data have been accumulated. */
+gsl_matrix *
covariance_calculate_unnormalized (struct covariance *cov)
{
if ( cov->state <= 0 )
diff --git a/src/math/covariance.h b/src/math/covariance.h
index cb83e15..3605ba8 100644
--- a/src/math/covariance.h
+++ b/src/math/covariance.h
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -40,8 +40,8 @@ void covariance_accumulate (struct covariance *, const
struct ccase *);
void covariance_accumulate_pass1 (struct covariance *, const struct ccase
*);
void covariance_accumulate_pass2 (struct covariance *, const struct ccase
*);
-const gsl_matrix * covariance_calculate (struct covariance *cov);
-const gsl_matrix * covariance_calculate_unnormalized (struct covariance
*);
+gsl_matrix *covariance_calculate (struct covariance *cov);
+gsl_matrix * covariance_calculate_unnormalized (struct covariance *);
void covariance_destroy (struct covariance *cov);
--
1.7.1
_______________________________________________
pspp-dev mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/pspp-dev
--
PGP Public key ID: 1024D/2DE827B3
fingerprint = 8797 A26D 0854 2EAB 0285 A290 8A67 719C 2DE8 27B3
See http://pgp.mit.edu or any PGP keyserver for public key.
signature.asc
Description: Digital signature
- Re: [warnings 7/7] GLM: Fix compiler warnings., (continued)
- [warnings 1/7] build-aux: Add generated files to .gitignore., Ben Pfaff, 2010/09/18
- [warnings 3/7] Suppress warnings about conversions between char * and unsigned char *., Ben Pfaff, 2010/09/18
- [warnings 5/7] Fix some constness problems that led to warnings., Ben Pfaff, 2010/09/18
- Re: [warnings 5/7] Fix some constness problems that led to warnings.,
John Darrington <=
- [warnings 2/7] recode: Fix a warning in recode_trns_proc()., Ben Pfaff, 2010/09/18
- [warnings 4/7] ONEWAY: Fix declaration-after-statement warning., Ben Pfaff, 2010/09/18