Patch #6262. New developers guide and resulting fixes and cleanups.
[pspp-builds.git] / src / language / stats / descriptives.c
index 3fd23c8f289217de552f7d6ffe543d838e71e205..72f7476ae4e89fbc42c6ebe340c134b9b0353b2d 100644 (file)
 #include <language/dictionary/split-file.h>
 #include <language/lexer/lexer.h>
 #include <language/lexer/variable-parser.h>
-#include <libpspp/alloc.h>
 #include <libpspp/array.h>
 #include <libpspp/compiler.h>
-#include <libpspp/magic.h>
 #include <libpspp/message.h>
 #include <libpspp/assertion.h>
 #include <math/moments.h>
 #include <output/manager.h>
 #include <output/table.h>
 
+#include "xalloc.h"
+
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 #define N_(msgid) msgid
@@ -123,7 +123,7 @@ static const struct dsc_statistic_info dsc_info[DSC_N_STATS] =
 struct dsc_var
   {
     const struct variable *v;         /* Variable to calculate on. */
-    char z_name[LONG_NAME_LEN + 1]; /* Name for z-score variable. */
+    char z_name[VAR_NAME_LEN + 1]; /* Name for z-score variable. */
     double valid, missing;     /* Valid, missing counts. */
     struct moments *moments;    /* Moments. */
     double min, max;            /* Maximum and mimimum values. */
@@ -495,7 +495,7 @@ static bool
 generate_z_varname (const struct dictionary *dict, struct dsc_proc *dsc, char *z_name,
                     const char *var_name, int *z_cnt)
 {
-  char name[LONG_NAME_LEN + 1];
+  char name[VAR_NAME_LEN + 1];
 
   /* Try a name based on the original variable name. */
   name[0] = 'Z';
@@ -699,16 +699,18 @@ calc_descriptives (struct dsc_proc *dsc, struct casereader *group,
   size_t i;
 
   if (!casereader_peek (group, 0, &c))
-    return;
+    {
+      casereader_destroy (group);
+      return;
+    }
   output_split_file_values (ds, &c);
   case_destroy (&c);
 
   group = casereader_create_filter_weight (group, dataset_dict (ds),
                                            NULL, NULL);
 
-  casereader_split (group, &pass1, &pass2);
-  if (dsc->max_moment <= MOMENT_MEAN)
-    casereader_destroy (pass2);
+  pass1 = group;
+  pass2 = dsc->max_moment <= MOMENT_MEAN ? NULL : casereader_clone (pass1);
 
   for (i = 0; i < dsc->var_cnt; i++)
     {
@@ -758,7 +760,10 @@ calc_descriptives (struct dsc_proc *dsc, struct casereader *group,
         }
     }
   if (!casereader_destroy (pass1))
-    return;
+    {
+      casereader_destroy (pass2);
+      return;
+    }
 
   /* Second pass for higher-order moments. */
   if (dsc->max_moment > MOMENT_MEAN)