subcase: Rename subcase_destroy() to subcase_uninit().
[pspp] / src / data / case-matcher.c
index a1251cb74cbfd816c7dab2ed54129659a0215e0b..e1ad48fde0853c7f1a477b8532ca4987fe7acbfc 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009, 2011 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
 
 #include <config.h>
 
-#include <data/case-matcher.h>
+#include "data/case-matcher.h"
 
 #include <stdlib.h>
 
-#include <data/case.h>
-#include <data/subcase.h>
-#include <data/value.h>
-#include <libpspp/assertion.h>
+#include "data/case.h"
+#include "data/subcase.h"
+#include "data/value.h"
+#include "libpspp/assertion.h"
 
-#include "xalloc.h"
+#include "gl/xalloc.h"
 
 struct case_matcher_input
   {
@@ -68,8 +68,11 @@ case_matcher_add_input (struct case_matcher *cm, const struct subcase *by,
   struct case_matcher_input *input;
 
   if (cm->n_inputs == 0)
-    cm->by_values = xmalloc (subcase_get_n_values (by)
-                             * sizeof *cm->by_values);
+    {
+      cm->by_values = xmalloc (sizeof *cm->by_values
+                               * subcase_get_n_fields (by));
+      caseproto_init_values (subcase_get_proto (by), cm->by_values);
+    }
   else
     assert (subcase_conformable (by, &cm->inputs[0].by_vars));
 
@@ -90,10 +93,16 @@ case_matcher_destroy (struct case_matcher *cm)
     {
       size_t i;
 
+      if (cm->by_values != NULL)
+        {
+          caseproto_destroy_values (subcase_get_proto (&cm->inputs[0].by_vars),
+                                    cm->by_values);
+          free (cm->by_values);
+        }
       for (i = 0; i < cm->n_inputs; i++)
         {
           struct case_matcher_input *input = &cm->inputs[i];
-          subcase_destroy (&input->by_vars);
+          subcase_uninit (&input->by_vars);
         }
       free (cm->inputs);
       free (cm);