pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] pspp/src data/ChangeLog data/variable.c data/va...


From: John Darrington
Subject: [Pspp-cvs] pspp/src data/ChangeLog data/variable.c data/va...
Date: Thu, 07 Dec 2006 06:31:04 +0000

CVSROOT:        /sources/pspp
Module name:    pspp
Changes by:     John Darrington <jmd>   06/12/07 06:31:04

Modified files:
        src/data       : ChangeLog variable.c variable.h 
        src/language/stats: ChangeLog examine.q 
        src/math       : ChangeLog factor-stats.c factor-stats.h sort.c 

Log message:
        Changed factors' independent variables to be copies on the heap.
        Fixes part of bug #15911.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/ChangeLog?cvsroot=pspp&r1=1.78&r2=1.79
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/variable.c?cvsroot=pspp&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/variable.h?cvsroot=pspp&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/stats/ChangeLog?cvsroot=pspp&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/stats/examine.q?cvsroot=pspp&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/pspp/src/math/ChangeLog?cvsroot=pspp&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/pspp/src/math/factor-stats.c?cvsroot=pspp&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/pspp/src/math/factor-stats.h?cvsroot=pspp&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/pspp/src/math/sort.c?cvsroot=pspp&r1=1.18&r2=1.19

Patches:
Index: data/ChangeLog
===================================================================
RCS file: /sources/pspp/pspp/src/data/ChangeLog,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -b -r1.78 -r1.79
--- data/ChangeLog      5 Dec 2006 15:10:21 -0000       1.78
+++ data/ChangeLog      7 Dec 2006 06:31:04 -0000       1.79
@@ -1,3 +1,7 @@
+Thu Dec  7 15:22:38 WST 2006 John Darrington <address@hidden>
+
+       * variable.c variable.h (value_dup): New function.
+
 Mon Dec  4 22:20:17 2006  Ben Pfaff  <address@hidden>
 
        Start converting struct variable to an opaque.  In this phase, we

Index: data/variable.c
===================================================================
RCS file: /sources/pspp/pspp/src/data/variable.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- data/variable.c     5 Dec 2006 15:10:21 -0000       1.14
+++ data/variable.c     7 Dec 2006 06:31:04 -0000       1.15
@@ -123,6 +123,21 @@
   free (v->aux);
 }
 
+/* Duplicate a value.
+   The caller is responsible for freeing the returned value
+*/
+union value *
+value_dup (const union value *val, int width)
+{
+  size_t bytes = MAX(width, sizeof *val);
+
+  union value *v = xmalloc (bytes);
+  memcpy (v, val, bytes);
+  return v;
+}
+
+
+
 /* Compares A and B, which both have the given WIDTH, and returns
    a strcmp()-type result. */
 int

Index: data/variable.h
===================================================================
RCS file: /sources/pspp/pspp/src/data/variable.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- data/variable.h     5 Dec 2006 15:10:21 -0000       1.14
+++ data/variable.h     7 Dec 2006 06:31:04 -0000       1.15
@@ -221,5 +221,7 @@
 
 int width_to_bytes(int width);
 
+union value * value_dup (const union value *val, int width);
+
 
 #endif /* !variable.h */

Index: language/stats/ChangeLog
===================================================================
RCS file: /sources/pspp/pspp/src/language/stats/ChangeLog,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- language/stats/ChangeLog    7 Dec 2006 05:16:33 -0000       1.33
+++ language/stats/ChangeLog    7 Dec 2006 06:31:04 -0000       1.34
@@ -1,3 +1,8 @@
+Thu Dec  7 15:26:25 WST 2006 John Darrington <address@hidden>
+
+       * examine.q: Allocated the categorical values for the dependent and 
+       independent variables, on the heap.  Hence they can be of any width.
+
 Wed Dec  6 21:14:26 2006  Ben Pfaff  <address@hidden>
 
        * regression.q (reg_inserted): Compare variable pointers instead

Index: language/stats/examine.q
===================================================================
RCS file: /sources/pspp/pspp/src/language/stats/examine.q,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- language/stats/examine.q    5 Dec 2006 15:10:21 -0000       1.18
+++ language/stats/examine.q    7 Dec 2006 06:31:04 -0000       1.19
@@ -1,7 +1,7 @@
 /* PSPP - EXAMINE data for normality . -*-c-*-
 
 Copyright (C) 2004 Free Software Foundation, Inc.
-Author: John Darrington 2004
+Author: John Darrington 2004, 2006
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as
@@ -107,9 +107,9 @@
 };
 
 /* Linked list of factors */
-static struct factor *factors=0;
+static struct factor *factors = 0;
 
-static struct metrics *totals=0;
+static struct metrics *totals = 0;
 
 /* Parse the clause specifying the factors */
 static int examine_parse_independent_vars (struct lexer *lexer, const struct 
dictionary *dict, struct cmd_examine *cmd);
@@ -159,14 +159,14 @@
 static void output_examine (void);
 
 
-void factor_calc (struct ccase *c, int case_no, 
+void factor_calc (const struct ccase *c, int case_no,
                 double weight, int case_missing);
 
 
 /* Represent a factor as a string, so it can be
    printed in a human readable fashion */
 const char * factor_to_string (const struct factor *fctr, 
-                             struct factor_statistics *fs,
+                              const struct factor_statistics *fs,
                              const struct variable *var);
 
 
@@ -637,7 +637,8 @@
 
 /* Perform calculations for the sub factors */
 void
-factor_calc (struct ccase *c, int case_no, double weight, int case_missing)
+factor_calc (const struct ccase *c, int case_no, double weight,
+            int case_missing)
 {
   size_t v;
   struct factor *fctr = factors;
@@ -645,14 +646,23 @@
   while ( fctr) 
     {
       struct factor_statistics **foo ;
-      union value indep_vals[2] ;
+      union value *indep_vals[2] ;
 
-      indep_vals[0] = * case_data (c, fctr->indep_var[0]->fv);
+      indep_vals[0] = value_dup (
+                                case_data (c, fctr->indep_var[0]->fv),
+                                var_get_width (fctr->indep_var[0])
+                                );
 
       if ( fctr->indep_var[1] ) 
-       indep_vals[1] = * case_data (c, fctr->indep_var[1]->fv);
+       indep_vals[1] = value_dup (
+                                  case_data (c, fctr->indep_var[1]->fv),
+                                  var_get_width (fctr->indep_var[1])
+                                  );
       else
-       indep_vals[1].f = SYSMIS;
+       {
+         const union value sm = {SYSMIS};
+         indep_vals[1] = value_dup (&sm, 0);
+       }
 
       assert (fctr->fstats);
 
@@ -663,8 +673,8 @@
        {
 
          *foo = create_factor_statistics (n_dependent_vars, 
-                                         &indep_vals[0],
-                                         &indep_vals[1]);
+                                         indep_vals[0],
+                                         indep_vals[1]);
 
          for ( v =  0 ; v  < n_dependent_vars ; ++v ) 
            {
@@ -672,23 +682,33 @@
            }
 
        }
+      else
+       {
+         free (indep_vals[0]);
+         free (indep_vals[1]);
+       }
 
       for ( v =  0 ; v  < n_dependent_vars ; ++v ) 
        {
          const struct variable *var = dependent_vars[v];
-         const union value *val = case_data (c, var->fv);
+         union value *val = value_dup (
+                                       case_data (c, var->fv),
+                                       var_get_width (var)
+                                       );
 
          if ( value_is_missing (var, val) || case_missing ) 
-           val = 0;
+           {
+             free (val);
+             continue;
+           }
          
          metrics_calc ( & (*foo)->m[v], val, weight, case_no);
          
+         free (val);
        }
 
       fctr = fctr->next;
     }
-
-
 }
 
 static bool 
@@ -738,31 +758,40 @@
          for ( v = 0 ; v < n_dependent_vars ; ++v ) 
            {
              const struct variable *var = dependent_vars[v];
-             const union value *val = case_data (&c, var->fv);
+             union value *val = value_dup (
+                                                 case_data (&c, var->fv),
+                                                 var_get_width (var)
+                                                 );
 
              if ( value_is_missing (var, val))
                case_missing = 1;
                   
+             free (val);
            }
        }
 
       for ( v = 0 ; v < n_dependent_vars ; ++v ) 
        {
          const struct variable *var = dependent_vars[v];
-         const union value *val = case_data (&c, var->fv);
+         union value *val = value_dup (
+                                       case_data (&c, var->fv),
+                                       var_get_width (var)
+                                       );
 
          if ( value_is_missing (var, val) || case_missing ) 
-           val = 0;
+           {
+             free (val) ;
+             continue ;
+           }
 
          metrics_calc (&totals[v], val, weight, case_no);
     
+         free (val);
        }
 
       factor_calc (&c, case_no, weight, case_missing);
-
     }
 
-
   for ( v = 0 ; v < n_dependent_vars ; ++v)
     {
       fctr = factors;
@@ -1017,12 +1046,12 @@
        {
          struct factor_statistics **fs = fctr->fs;
          int count = 0 ;
+         const union value *prev = NULL;
 
          while (*fs) 
            {
-             static union value prev;
-             
-             if ( 0 != compare_values (&prev, & (*fs)->id[0], 
+             if ( !prev ||
+                  0 != compare_values (prev, (*fs)->id[0],
                                         var_get_width (fctr->indep_var[0])))
                {
                  tab_text (tbl, 
@@ -1030,7 +1059,8 @@
                            (i * n_factors ) + count + 
                            heading_rows,
                            TAB_LEFT | TAT_TITLE, 
-                           value_to_string (& (*fs)->id[0], fctr->indep_var[0])
+                           value_to_string ((*fs)->id[0],
+                                            fctr->indep_var[0])
                            );
 
                  if (fctr->indep_var[1] && count > 0 ) 
@@ -1048,7 +1078,7 @@
                          (i * n_factors ) + count + 
                          heading_rows,
                          TAB_LEFT | TAT_TITLE, 
-                         value_to_string (& (*fs)->id[1], fctr->indep_var[1])
+                         value_to_string ((*fs)->id[1], fctr->indep_var[1])
                          );
 
              populate_summary (tbl, heading_columns, 
@@ -1186,16 +1216,15 @@
        {
          struct factor_statistics **fs = fctr->fs;
          int count = 0 ;
+         const union value *prev  = NULL;
 
          while (*fs) 
            {
-             static union value prev ;
-
              const int row = heading_rows + ( 2 * n_extremities )  * 
                 ( ( i  * n_factors  ) +  count );
 
 
-             if ( 0 != compare_values (&prev, & (*fs)->id[0], 
+             if ( !prev || 0 != compare_values (prev, (*fs)->id[0],
                                         var_get_width (fctr->indep_var[0])))
                {
                  
@@ -1205,7 +1234,7 @@
                  tab_text (tbl, 
                            1, row,
                            TAB_LEFT | TAT_TITLE, 
-                           value_to_string (& (*fs)->id[0], fctr->indep_var[0])
+                           value_to_string ((*fs)->id[0], fctr->indep_var[0])
                            );
                }
 
@@ -1217,7 +1246,7 @@
              if ( fctr->indep_var[1]) 
                tab_text (tbl, 2, row,
                          TAB_LEFT | TAT_TITLE, 
-                         value_to_string (& (*fs)->id[1], fctr->indep_var[1])
+                         value_to_string ((*fs)->id[1], fctr->indep_var[1])
                          );
 
              populate_extremes (tbl, heading_columns - 2, 
@@ -1413,6 +1442,8 @@
 
       if ( fctr  )
        {
+         const union value *prev = NULL;
+
          struct factor_statistics **fs = fctr->fs;
          int count = 0;
 
@@ -1426,14 +1457,11 @@
 
          while ( *fs ) 
            {
-
-             static union value prev ;
-
              const int row = heading_rows + n_stat_rows  * 
                 ( ( i  * n_factors  ) +  count );
 
 
-             if ( 0 != compare_values (&prev, & (*fs)->id[0], 
+             if ( !prev || 0 != compare_values (prev, (*fs)->id[0],
                                         var_get_width (fctr->indep_var[0])))
                {
                  
@@ -1443,7 +1471,7 @@
                  tab_text (tbl, 
                            1, row,
                            TAB_LEFT | TAT_TITLE, 
-                           value_to_string (& (*fs)->id[0], fctr->indep_var[0])
+                           value_to_string ((*fs)->id[0], fctr->indep_var[0])
                            );
                }
 
@@ -1455,7 +1483,7 @@
              if ( fctr->indep_var[1]) 
                tab_text (tbl, 2, row,
                          TAB_LEFT | TAT_TITLE, 
-                         value_to_string (& (*fs)->id[1], fctr->indep_var[1])
+                         value_to_string ((*fs)->id[1], fctr->indep_var[1])
                          );
 
              populate_descriptives (tbl, heading_columns - 2, 
@@ -2040,6 +2068,7 @@
 
       if ( fctr  )
        {
+         const union value *prev  = NULL ;
          struct factor_statistics **fs = fctr->fs;
          int count = 0;
 
@@ -2054,14 +2083,11 @@
 
          while ( *fs ) 
            {
-
-             static union value prev ;
-
              const int row = n_heading_rows + n_stat_rows  * 
                 ( ( i  * n_factors  ) +  count );
 
 
-             if ( 0 != compare_values (&prev, & (*fs)->id[0], 
+             if ( !prev || 0 != compare_values (prev, (*fs)->id[0],
                                         var_get_width (fctr->indep_var[0])))
                {
                  
@@ -2071,7 +2097,7 @@
                  tab_text (tbl, 
                            1, row,
                            TAB_LEFT | TAT_TITLE, 
-                           value_to_string (& (*fs)->id[0], fctr->indep_var[0])
+                           value_to_string ((*fs)->id[0], fctr->indep_var[0])
                            );
 
 
@@ -2085,7 +2111,7 @@
              if ( fctr->indep_var[1]) 
                tab_text (tbl, 2, row,
                          TAB_LEFT | TAT_TITLE, 
-                         value_to_string (& (*fs)->id[1], fctr->indep_var[1])
+                         value_to_string ((*fs)->id[1], fctr->indep_var[1])
                          );
 
 
@@ -2172,7 +2198,7 @@
 
 const char *
 factor_to_string (const struct factor *fctr, 
-                struct factor_statistics *fs,
+                 const struct factor_statistics *fs,
                 const struct variable *var)
 {
 
@@ -2187,7 +2213,7 @@
                      
   snprintf (buf2, 100, "%s = %s",
           var_to_string (fctr->indep_var[0]),
-          value_to_string (&fs->id[0],fctr->indep_var[0]));
+          value_to_string (fs->id[0], fctr->indep_var[0]));
                      
   strcat (buf1, buf2);
                      
@@ -2195,7 +2221,7 @@
     {
       sprintf (buf2, "; %s = %s)",
              var_to_string (fctr->indep_var[1]),
-             value_to_string (&fs->id[1],
+             value_to_string (fs->id[1],
                              fctr->indep_var[1]));
       strcat (buf1, buf2);
     }
@@ -2221,11 +2247,11 @@
   char buf2[100];
 
   snprintf (buf, 100, "%s",
-          value_to_string (&fs->id[0], fctr->indep_var[0]));
+          value_to_string (fs->id[0], fctr->indep_var[0]));
                      
   if ( fctr->indep_var[1] ) 
     {
-      sprintf (buf2, ",%s)", value_to_string (&fs->id[1], fctr->indep_var[1]) 
);
+      sprintf (buf2, ",%s)", value_to_string (fs->id[1], fctr->indep_var[1]) );
       strcat (buf, buf2);
     }
 

Index: math/ChangeLog
===================================================================
RCS file: /sources/pspp/pspp/src/math/ChangeLog,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- math/ChangeLog      7 Dec 2006 05:16:33 -0000       1.11
+++ math/ChangeLog      7 Dec 2006 06:31:04 -0000       1.12
@@ -1,3 +1,8 @@
+Thu Dec  7 15:27:49 WST 2006 John Darrington <address@hidden>
+
+       * factor-stats.c factor-stats.h: Changed independent values to 
+       be pointers rather than copies.
+
 Wed Dec  6 21:14:59 2006  Ben Pfaff  <address@hidden>
 
        * coefficient.c: (pspp_coeff_get_value) Compare variable pointers

Index: math/factor-stats.c
===================================================================
RCS file: /sources/pspp/pspp/src/math/factor-stats.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- math/factor-stats.c 16 Apr 2006 01:05:15 -0000      1.3
+++ math/factor-stats.c 7 Dec 2006 06:31:04 -0000       1.4
@@ -60,7 +60,7 @@
    If val is null, then treat it as MISSING
 */
 void
-metrics_calc(struct metrics *fs, const union value *val, 
+metrics_calc (struct metrics *fs, const union value *val,
             double weight, int case_no)
 {
   struct weighted_value **wv;
@@ -252,16 +252,18 @@
 
 
 /* Create a factor statistics object with for N dependent vars
-   and ID as the value of the independent variable */
+   and ID0 and ID1 as the values of the independent variable */
 struct factor_statistics * 
-create_factor_statistics (int n, union value *id0, union value *id1)
+create_factor_statistics (int n,
+                         union value *id0,
+                         union value *id1)
 {
   struct factor_statistics *f;
 
   f = xmalloc (sizeof *f);
 
-  f->id[0] = *id0;
-  f->id[1] = *id1;
+  f->id[0] = id0;
+  f->id[1] = id1;
   f->m = xnmalloc (n, sizeof *f->m);
   memset (f->m, 0, sizeof(struct metrics) * n);
   f->n_var = n;
@@ -269,7 +271,6 @@
   return f;
 }
 
-
 void 
 metrics_destroy(struct metrics *m)
 {
@@ -284,6 +285,8 @@
 {
 
   int i; 
+  free (f->id[0]);
+  free (f->id[1]);
   for ( i = 0 ; i < f->n_var; ++i ) 
        metrics_destroy(&f->m[i]);
   free(f->m) ; 
@@ -291,8 +294,6 @@
 }
 
 
-
-
 int 
 factor_statistics_compare(const struct factor_statistics *f0,
                          const struct factor_statistics *f1, int width)
@@ -303,33 +304,30 @@
   assert(f0);
   assert(f1);
 
-  cmp0 = compare_values(&f0->id[0], &f1->id[0], width);
+  cmp0 = compare_values(f0->id[0], f1->id[0], width);
 
   if ( cmp0 != 0 ) 
     return cmp0;
 
 
-  if ( ( f0->id[1].f == SYSMIS )  && (f1->id[1].f != SYSMIS) ) 
+  if ( ( f0->id[1]->f == SYSMIS ) && (f1->id[1]->f != SYSMIS) )
     return 1;
 
-  if ( ( f0->id[1].f != SYSMIS )  && (f1->id[1].f == SYSMIS) ) 
+  if ( ( f0->id[1]->f != SYSMIS )  && (f1->id[1]->f == SYSMIS) )
     return -1;
 
-  return compare_values(&f0->id[1], &f1->id[1], width);
-  
+  return compare_values (f0->id[1], f1->id[1], width);
 }
 
 unsigned int 
-factor_statistics_hash(const struct factor_statistics *f, int width)
+factor_statistics_hash (const struct factor_statistics *f, int width)
 {
-  
   unsigned int h;
 
-  h = hash_value(&f->id[0], width);
+  h = hash_value (f->id[0], width);
   
-  if ( f->id[1].f != SYSMIS )
-    h += hash_value(&f->id[1], width);
+  if ( f->id[1]->f != SYSMIS )
+    h += hash_value(f->id[1], width);
 
   return h;
 }
-       

Index: math/factor-stats.h
===================================================================
RCS file: /sources/pspp/pspp/src/math/factor-stats.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- math/factor-stats.h 15 Mar 2006 03:29:11 -0000      1.2
+++ math/factor-stats.h 7 Dec 2006 06:31:04 -0000       1.3
@@ -1,7 +1,7 @@
 /* PSPP - A program for statistical analysis . -*-c-*-
 
 Copyright (C) 2004 Free Software Foundation, Inc.
-Author: John Darrington 2004
+Author: John Darrington 2004, 2006
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as
@@ -134,7 +134,7 @@
 struct factor_statistics {
 
   /* The values of the independent variables */
-  union value id[2];
+  union value *id[2];
 
   /* The an array stats for this factor, one for each dependent var */
   struct metrics *m;
@@ -146,8 +146,9 @@
 
 /* Create a factor statistics object with for N dependent vars
    and ID as the value of the independent variable */
-struct factor_statistics * 
-create_factor_statistics (int n, union value *id0, union value *id1);
+struct factor_statistics * create_factor_statistics (int n,
+                         union value *id0,
+                         union value *id1);
 
 
 void factor_statistics_free(struct factor_statistics *f);
@@ -159,8 +160,6 @@
 factor_statistics_compare(const struct factor_statistics *f0,
                          const struct factor_statistics *f1, int width);
 
-                             
-
 unsigned int 
 factor_statistics_hash(const struct factor_statistics *f, int width);
 

Index: math/sort.c
===================================================================
RCS file: /sources/pspp/pspp/src/math/sort.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- math/sort.c 25 Nov 2006 02:15:01 -0000      1.18
+++ math/sort.c 7 Dec 2006 06:31:04 -0000       1.19
@@ -35,7 +35,6 @@
 #include <data/settings.h>
 #include <data/variable.h>
 #include <data/storage-stream.h>
-#include <language/expressions/public.h>
 #include <libpspp/alloc.h>
 #include <libpspp/array.h>
 #include <libpspp/assertion.h>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]