/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006, 2009 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2009, 2011, 2013, 2015 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/transformations.h>
+#include "data/transformations.h"
#include <assert.h>
#include <stdlib.h>
-#include <libpspp/str.h>
+#include "libpspp/str.h"
+#include "data/control-stack.h" /* XXX layering violation */
-#include "xalloc.h"
+#include "gl/xalloc.h"
/* A single transformation. */
struct transformation
transformation index. Normally 0 but set to the starting
index of a spliced chain after splicing. */
int idx_ofs;
- trns_finalize_func *finalize; /* Finalize proc. */
trns_proc_func *execute; /* Executes the transformation. */
trns_free_func *free; /* Garbage collector proc. */
void *aux; /* Auxiliary data. */
return chain;
}
-/* Finalizes all the transformations in CHAIN.
- A chain is only finalized once; afterward, calling this
- function is a no-op.
- Finalizers may add transformations to CHAIN, but after
- finalization the chain's contents are fixed, so that no more
- transformations may be added afterward. */
+/* Finalizes all the un-finalized transformations in CHAIN.
+ Any given transformation is only finalized once. */
void
trns_chain_finalize (struct trns_chain *chain)
{
- if (!chain->finalized)
+ while (!chain->finalized)
{
- size_t i;
-
- for (i = 0; i < chain->trns_cnt; i++)
- {
- struct transformation *trns = &chain->trns[i];
- if (trns->finalize != NULL)
- trns->finalize (trns->aux);
- }
+ ctl_stack_clear (); /* XXX layering violation */
chain->finalized = true;
}
}
return chain->trns_cnt == 0;
}
-/* Adds a transformation to CHAIN with finalize function
- FINALIZE, execute function EXECUTE, free function FREE, and
- auxiliary data AUX. */
+/* Adds a transformation to CHAIN with execute function EXECUTE, free function
+ FREE, and auxiliary data AUX. */
void
-trns_chain_append (struct trns_chain *chain, trns_finalize_func *finalize,
- trns_proc_func *execute, trns_free_func *free,
- void *aux)
+trns_chain_append (struct trns_chain *chain, trns_proc_func *execute,
+ trns_free_func *free, void *aux)
{
struct transformation *trns;
- assert (!chain->finalized);
+ chain->finalized = false;
if (chain->trns_cnt == chain->trns_cap)
chain->trns = x2nrealloc (chain->trns, &chain->trns_cap,
trns = &chain->trns[chain->trns_cnt++];
trns->idx_ofs = 0;
- trns->finalize = finalize;
trns->execute = execute;
trns->free = free;
trns->aux = aux;
}
dst->trns_cnt += src->trns_cnt;
+ src->trns_cnt = 0;
trns_chain_destroy (src);
}