Respect the constness of caseproto.
[pspp-builds.git] / src / data / casereader-translator.c
index e3c764cdf241c049e13b636543866e3ce813188a..c193d404dcccdf08a1a73c96109ee00c44f9e0ef 100644 (file)
@@ -362,7 +362,7 @@ car_translate (struct ccase *input, void *car_)
 
 \f
 
-struct consolodator
+struct consolidator
 {
   const struct variable *key;
   const struct variable *weight;
@@ -378,7 +378,7 @@ struct consolodator
 static bool
 uniquify (const struct ccase *c, void *aux)
 {
-  struct consolodator *cdr = aux;
+  struct consolidator *cdr = aux;
   const union value *current_value = case_data (c, cdr->key);
   const int key_width = var_get_width (cdr->key);
   const double weight = cdr->weight ? case_data (c, cdr->weight)->f : 1.0;
@@ -414,15 +414,19 @@ uniquify (const struct ccase *c, void *aux)
 static struct ccase *
 consolodate_weight (struct ccase *input, void *aux)
 {
-  struct consolodator *cdr = aux;
+  struct consolidator *cdr = aux;
   struct ccase *c;
 
-  c = case_unshare_and_resize (input, cdr->proto);
-
   if (cdr->weight)
-    case_data_rw (c, cdr->weight)->f = cdr->prev_cc;
+    {
+      c = case_unshare (input);
+      case_data_rw (c, cdr->weight)->f = cdr->prev_cc;
+    }
   else
-    case_data_rw_idx (c, caseproto_get_n_widths (cdr->proto) - 1)->f = cdr->prev_cc;    
+    {
+      c = case_unshare_and_resize (input, cdr->proto);
+      case_data_rw_idx (c, caseproto_get_n_widths (cdr->proto) - 1)->f = cdr->prev_cc;    
+    }
 
   return c;
 }
@@ -431,7 +435,7 @@ consolodate_weight (struct ccase *input, void *aux)
 static bool
 uniquify_destroy (void *aux)
 {
-  struct consolodator *cdr = aux;
+  struct consolidator *cdr = aux;
 
   casereader_destroy (cdr->clone);
   free (cdr);
@@ -457,9 +461,9 @@ casereader_create_distinct (struct casereader *input,
 {
   struct casereader *u ;
   struct casereader *ud ;
-  const struct caseproto *output_proto = casereader_get_proto (input);
+  struct caseproto *output_proto = caseproto_clone (casereader_get_proto (input));
 
-  struct consolodator *cdr = xmalloc (sizeof (*cdr));
+  struct consolidator *cdr = xmalloc (sizeof (*cdr));
   cdr->n = 0;
   cdr->key = key;
   cdr->weight = weight;
@@ -480,5 +484,7 @@ casereader_create_distinct (struct casereader *input,
                                     consolodate_weight,
                                     uniquify_destroy,
                                     cdr);
+
+  return ud;
 }