[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug37999 03/11] transformations: Relax the rules for transformation fin
From: |
Ben Pfaff |
Subject: |
[bug37999 03/11] transformations: Relax the rules for transformation finalizing. |
Date: |
Thu, 31 Jan 2013 22:03:25 -0800 |
The trns_chain data structure has a barely useful concept called
"finalization". In practice this is used to make sure that control
structures (e.g. DO IF) that are opened get closed (e.g. END IF). There
are currently some restrictions on finalizing: namely, transformations
can't be added after a chain is finalized. Since finalizers are barely
used, we can relax this restriction, which this commit does. This will be
used in an upcoming commit where the ability to add a transformation to a
finalized change becomes useful for a corner case.
---
src/data/transformations.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/data/transformations.c b/src/data/transformations.c
index 8321cf5..7f86728 100644
--- a/src/data/transformations.c
+++ b/src/data/transformations.c
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006, 2009, 2011 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2009, 2011, 2013 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
@@ -59,26 +59,25 @@ trns_chain_create (void)
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;
+ chain->finalized = true;
for (i = 0; i < chain->trns_cnt; i++)
{
struct transformation *trns = &chain->trns[i];
- if (trns->finalize != NULL)
- trns->finalize (trns->aux);
+ trns_finalize_func *finalize = trns->finalize;
+
+ trns->finalize = NULL;
+ if (finalize != NULL)
+ finalize (trns->aux);
}
- chain->finalized = true;
}
}
@@ -127,7 +126,7 @@ trns_chain_append (struct trns_chain *chain,
trns_finalize_func *finalize,
{
struct transformation *trns;
- assert (!chain->finalized);
+ chain->finalized = false;
if (chain->trns_cnt == chain->trns_cap)
chain->trns = x2nrealloc (chain->trns, &chain->trns_cap,
--
1.7.10.4
- [bug37999 00/11] Make RANK work with TEMPORARY., Ben Pfaff, 2013/02/01
- [bug37999 01/11] casegrouper: Add comments., Ben Pfaff, 2013/02/01
- [bug37999 04/11] RANK: Lowercase the name of "enum RANK_FUNC"., Ben Pfaff, 2013/02/01
- [bug37999 05/11] RANK: Remove write-only struct member 'ascending'., Ben Pfaff, 2013/02/01
- [bug37999 03/11] transformations: Relax the rules for transformation finalizing.,
Ben Pfaff <=
- [bug37999 06/11] RANK: Put #include directives into typical order., Ben Pfaff, 2013/02/01
- [bug37999 02/11] subcase: New function subcase_add_vars_always()., Ben Pfaff, 2013/02/01
- [bug37999 07/11] RANK: Simplify fraction_name() function., Ben Pfaff, 2013/02/01
- [bug37999 08/11] RANK: Simplify rank_sorted_file() with new function sum_weights()., Ben Pfaff, 2013/02/01
- [bug37999 09/11] RANK: Create all variables together, in order., Ben Pfaff, 2013/02/01
- [bug37999 11/11] RANK: Add support for temporary transformations., Ben Pfaff, 2013/02/01
- [bug37999 10/11] RANK: Adopt a new ranking implementation., Ben Pfaff, 2013/02/01