void
caseproto_refresh_long_string_cache__ (const struct caseproto *proto_)
{
- struct caseproto *proto = (struct caseproto *) proto_;
+ struct caseproto *proto = CONST_CAST (struct caseproto *, proto_);
size_t n, i;
assert (proto->long_strings == NULL);
#include <stddef.h>
#include <stdlib.h>
#include <data/value.h>
+#include <libpspp/cast.h>
#include <libpspp/compiler.h>
/* Case prototype.
static inline struct caseproto *
caseproto_ref (const struct caseproto *proto_)
{
- struct caseproto *proto = (struct caseproto *) proto_;
+ struct caseproto *proto = CONST_CAST (struct caseproto *, proto_);
proto->ref_cnt++;
return proto;
}
struct casereader *
casereader_clone (const struct casereader *reader_)
{
- struct casereader *reader = (struct casereader *) reader_;
+ struct casereader *reader = CONST_CAST (struct casereader *, reader_);
struct casereader *clone;
if ( reader == NULL )
return NULL;
struct ccase *
casewindow_get_case (const struct casewindow *cw_, casenumber case_idx)
{
- struct casewindow *cw = (struct casewindow *) cw_;
+ struct casewindow *cw = CONST_CAST (struct casewindow *, cw_);
assert (case_idx >= 0 && case_idx < casewindow_get_case_cnt (cw));
if (casewindow_error (cw))
const struct caseproto *
datasheet_get_proto (const struct datasheet *ds_)
{
- struct datasheet *ds = (struct datasheet *) ds_;
+ struct datasheet *ds = CONST_CAST (struct datasheet *, ds_);
if (ds->proto == NULL)
{
size_t i;
{
size_t n_columns = datasheet_get_n_columns (ds);
struct ccase *c = case_create (datasheet_get_proto (ds));
- if (rw_case ((struct datasheet *) ds, OP_READ,
+ if (rw_case (CONST_CAST (struct datasheet *, ds), OP_READ,
row, 0, n_columns, case_data_all_rw (c)))
return c;
else
size_t column, union value *value)
{
assert (row >= 0);
- return rw_case ((struct datasheet *) ds, OP_READ, row, column, 1, value);
+ return rw_case (CONST_CAST (struct datasheet *, ds), OP_READ,
+ row, column, 1, value);
}
/* Stores VALUE into DS in the given ROW and COLUMN. VALUE must
const struct caseproto *
dict_get_proto (const struct dictionary *d_)
{
- struct dictionary *d = (struct dictionary *) d_;
+ struct dictionary *d = CONST_CAST (struct dictionary *, d_);
if (d->proto == NULL)
{
size_t i;
struct attrset *
dict_get_attributes (const struct dictionary *d)
{
- return (struct attrset *) &d->attributes;
+ return CONST_CAST (struct attrset *, &d->attributes);
}
/* Replaces D's attributes set by a copy of ATTRS. */
else
{
const struct taint *taint = casereader_get_taint (ds->source);
- taint_reset_successor_taint ((struct taint *) taint);
+ taint_reset_successor_taint (CONST_CAST (struct taint *, taint));
assert (!taint_has_tainted_successor (taint));
}
}
const struct caseproto *
subcase_get_proto (const struct subcase *sc_)
{
- struct subcase *sc = (struct subcase *) sc_;
+ struct subcase *sc = CONST_CAST (struct subcase *, sc_);
if (sc->proto == NULL)
{
#include <data/value.h>
#include <data/variable.h>
#include <libpspp/array.h>
+#include <libpspp/cast.h>
#include <libpspp/compiler.h>
#include <libpspp/hash-functions.h>
#include <libpspp/hmap.h>
val_labs_replace (struct val_labs *vls, const union value *value,
const char *label)
{
- struct val_lab *vl = (struct val_lab *) val_labs_lookup (vls, value);
+ struct val_lab *vl = CONST_CAST (struct val_lab *,
+ val_labs_lookup (vls, value));
if (vl != NULL)
{
atom_destroy (vl->label);
void
val_labs_remove (struct val_labs *vls, const struct val_lab *label_)
{
- struct val_lab *label = (struct val_lab *) label_;
+ struct val_lab *label = CONST_CAST (struct val_lab *, label_);
hmap_delete (&vls->labels, &label->node);
value_destroy (&label->value, vls->width);
atom_destroy (label->label);
var_attach_aux (const struct variable *v_,
void *aux, void (*aux_dtor) (struct variable *))
{
- struct variable *v = (struct variable *) v_ ; /* cast away const */
+ struct variable *v = CONST_CAST (struct variable *, v_);
assert (v->aux == NULL);
assert (aux != NULL);
v->aux = aux;
void
var_set_obs_vals (const struct variable *v_, struct cat_vals *cat_vals)
{
- struct variable *v = (struct variable *) v_ ; /* cast away const */
+ struct variable *v = CONST_CAST (struct variable *, v_ );
cat_stored_values_destroy (v->obs_vals);
v->obs_vals = cat_vals;
}
struct attrset *
var_get_attributes (const struct variable *v)
{
- return (struct attrset *) &v->attributes;
+ return CONST_CAST (struct attrset *, &v->attributes);
}
/* Replaces variable V's attributes set by a copy of ATTRS. */
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2009 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
{
struct array_var_set *avs = vs->aux;
- return (struct variable *) avs->var[idx];
+ return CONST_CAST (struct variable *, avs->var[idx]);
}
/* If VS contains a variable named NAME, sets *IDX to its index
static bool
count_trns_free (void *trns_)
{
- struct count_trns *trns = (struct count_trns *) trns_;
+ struct count_trns *trns = trns_;
pool_destroy (trns->pool);
return true;
}
/* PSPP - a program for statistical analysis.
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2009 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
#endif
#include <libpspp/abt.h>
+#include <libpspp/cast.h>
#include <stdbool.h>
p = p->down[dir];
dir = !after;
}
- ((struct abt_node *) p)->down[dir] = node;
- node->up = (struct abt_node *) p;
+ CONST_CAST (struct abt_node *, p)->down[dir] = node;
+ node->up = CONST_CAST (struct abt_node *, p);
abt_reaugmented (abt, node);
}
{
cmp = abt->compare (target, p, abt->aux);
if (cmp == 0)
- return (struct abt_node *) p;
+ return CONST_CAST (struct abt_node *, p);
}
return NULL;
p = p->down[1];
while (p->down[0] != NULL)
p = p->down[0];
- return (struct abt_node *) p;
+ return CONST_CAST (struct abt_node *, p);
}
}
p = p->down[0];
while (p->down[1] != NULL)
p = p->down[1];
- return (struct abt_node *) p;
+ return CONST_CAST (struct abt_node *, p);
}
}
/* PSPP - a program for statistical analysis.
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2009 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 <stdbool.h>
#include <stdint.h>
+#include <libpspp/cast.h>
+
static void rebalance_subtree (struct bt *, struct bt_node *, size_t);
static struct bt_node **down_link (struct bt *, struct bt_node *);
{
cmp = bt->compare (target, p, bt->aux);
if (cmp == 0)
- return (struct bt_node *) p;
+ return CONST_CAST (struct bt_node *, p);
}
return NULL;
break;
}
}
- return (struct bt_node *) q;
+ return CONST_CAST (struct bt_node *, q);
}
/* Searches BT for, and returns, the last node in in-order whose
break;
}
}
- return (struct bt_node *) q;
+ return CONST_CAST (struct bt_node *, q);
}
/* Returns the node in BT following P in in-order.
p = p->down[1];
while (p->down[0] != NULL)
p = p->down[0];
- return (struct bt_node *) p;
+ return CONST_CAST (struct bt_node *, p);
}
}
p = p->down[0];
while (p->down[1] != NULL)
p = p->down[1];
- return (struct bt_node *) p;
+ return CONST_CAST (struct bt_node *, p);
}
}
above, can easily be devised. */
#define CHECK_POINTER_COMPATIBILITY(A, B) ((void) sizeof ((A) == (B)))
+/* Equivalent to casting POINTER to TYPE, but also issues a
+ warning if the cast changes anything other than an outermost
+ "const" or "volatile" qualifier. */
+#define CONST_CAST(TYPE, POINTER) \
+ (CHECK_POINTER_HAS_TYPE (POINTER, TYPE), \
+ (TYPE) (POINTER))
+
/* Given POINTER, a pointer to the given MEMBER within structure
STRUCT, returns the address of the STRUCT. */
#define UP_CAST(POINTER, STRUCT, MEMBER) \
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2009 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
/* PSPP - a program for statistical analysis.
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2009 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
for (x = r0; x != r1; x = ll_next (x))
if (compare (x, target, aux) == 0)
break;
- return (struct ll *) x;
+ return CONST_CAST (struct ll *, x);
}
/* Returns the first node in R0...R1 for which PREDICATE returns
for (x = r0; x != r1; x = ll_next (x))
if (predicate (x, aux))
break;
- return (struct ll *) x;
+ return CONST_CAST (struct ll *, x);
}
/* Compares each pair of adjacent nodes in R0...R1
for (x = r0, y = ll_next (x); y != r1; x = y, y = ll_next (y))
if (compare (x, y, aux) == 0)
- return (struct ll *) x;
+ return CONST_CAST (struct ll *, x);
}
- return (struct ll *) r1;
+ return CONST_CAST (struct ll *, r1);
}
/* Returns the number of nodes in R0...R1.
if (compare (x, max, aux) > 0)
max = x;
}
- return (struct ll *) max;
+ return CONST_CAST (struct ll *, max);
}
/* Returns the least node in R0...R1 according to COMPARE given
if (compare (x, min, aux) < 0)
min = x;
}
- return (struct ll *) min;
+ return CONST_CAST (struct ll *, min);
}
/* Lexicographically compares A0...A1 to B0...B1.
while (r0 != r1 && compare (ll_prev (r0), r0, aux) <= 0);
}
- return (struct ll *) r0;
+ return CONST_CAST (struct ll *, r0);
}
/* Merges B0...B1 into A0...A1 according to COMPARE given
if (predicate (x, aux))
return NULL;
- return (struct ll *) partition;
+ return CONST_CAST (struct ll *, partition);
}
\f
#include <stddef.h>
#include <libpspp/cast.h>
+#include <libpspp/cast.h>
+
/* Embedded, circular doubly linked list.
Each list contains a single "null" element that separates the
static inline struct ll *
ll_null (const struct ll_list *list)
{
- return (struct ll *) &list->null;
+ return CONST_CAST (struct ll *, &list->null);
}
/* Returns the node following LL in its list,
/* PSPP - a program for statistical analysis.
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2009 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
for (x = r0; x != r1; x = llx_next (x))
if (compare (llx_data (x), target, aux) == 0)
break;
- return (struct llx *) x;
+ return CONST_CAST (struct llx *, x);
}
/* Returns the first node in R0...R1 for which PREDICATE returns
for (x = r0; x != r1; x = llx_next (x))
if (predicate (llx_data (x), aux))
break;
- return (struct llx *) x;
+ return CONST_CAST (struct llx *, x);
}
/* Compares each pair of adjacent nodes in R0...R1
for (x = r0, y = llx_next (x); y != r1; x = y, y = llx_next (y))
if (compare (llx_data (x), llx_data (y), aux) == 0)
- return (struct llx *) x;
+ return CONST_CAST (struct llx *, x);
}
- return (struct llx *) r1;
+ return CONST_CAST (struct llx *, r1);
}
/* Returns the number of nodes in R0...R1.
if (compare (llx_data (x), llx_data (max), aux) > 0)
max = x;
}
- return (struct llx *) max;
+ return CONST_CAST (struct llx *, max);
}
/* Returns the least node in R0...R1 according to COMPARE given
if (compare (llx_data (x), llx_data (min), aux) < 0)
min = x;
}
- return (struct llx *) min;
+ return CONST_CAST (struct llx *, min);
}
/* Lexicographically compares A0...A1 to B0...B1.
llx_data (r0), aux) <= 0);
}
- return (struct llx *) r0;
+ return CONST_CAST (struct llx *, r0);
}
/* Merges B0...B1 into A0...A1 according to COMPARE given
if (predicate (llx_data (x), aux))
return NULL;
- return (struct llx *) partition;
+ return CONST_CAST (struct llx *, partition);
}
\f
/* Allocates and returns a node using malloc. */
bool
range_set_contains (const struct range_set *rs_, unsigned long int position)
{
- struct range_set *rs = (struct range_set *) rs_;
+ struct range_set *rs = CONST_CAST (struct range_set *, rs_);
if (position < rs->cache_end && position >= rs->cache_start)
return rs->cache_value;
else
unsigned long int
range_set_scan (const struct range_set *rs_, unsigned long int start)
{
- struct range_set *rs = (struct range_set *) rs_;
+ struct range_set *rs = CONST_CAST (struct range_set *, rs_);
unsigned long int retval = ULONG_MAX;
struct bt_node *bt_node;
#include <stdbool.h>
#include <libpspp/bt.h>
+#include <libpspp/cast.h>
/* A set of ranges. */
struct range_set
range_set_next (const struct range_set *rs, const struct range_set_node *node)
{
return (node != NULL
- ? range_set_next__ (rs, (struct range_set_node *) node)
+ ? range_set_next__ (rs, CONST_CAST (struct range_set_node *, node))
: range_set_first__ (rs));
}
range_set_prev (const struct range_set *rs, const struct range_set_node *node)
{
return (node != NULL
- ? range_set_prev__ (rs, (struct range_set_node *) node)
+ ? range_set_prev__ (rs, CONST_CAST (struct range_set_node *, node))
: range_set_last__ (rs));
}
#include <string.h>
#include <libpspp/assertion.h>
+#include <libpspp/cast.h>
#include <libpspp/misc.h>
#include <libpspp/pool.h>
static struct leaf_node *
find_leaf_node (const struct sparse_array *spar_, unsigned long int key)
{
- struct sparse_array *spar = (struct sparse_array *) spar_;
+ struct sparse_array *spar = CONST_CAST (struct sparse_array *, spar_);
const union pointer *p;
int level;
scan_forward (const struct sparse_array *spar_, unsigned long int start,
unsigned long int *found)
{
- struct sparse_array *spar = (struct sparse_array *) spar_;
+ struct sparse_array *spar = CONST_CAST (struct sparse_array *, spar_);
/* Check the cache. */
if (start >> BITS_PER_LEVEL == spar->cache_ofs)
scan_reverse (const struct sparse_array *spar_, unsigned long int start,
unsigned long int *found)
{
- struct sparse_array *spar = (struct sparse_array *) spar_;
+ struct sparse_array *spar = CONST_CAST (struct sparse_array *, spar_);
/* Check the cache. */
if (start >> BITS_PER_LEVEL == spar->cache_ofs)
#include <stdint.h>
#include <stdlib.h>
+#include <libpspp/cast.h>
#include <libpspp/message.h>
#include <libpspp/pool.h>
char *
ds_cstr (const struct string *st_)
{
- struct string *st = (struct string *) st_;
+ struct string *st = CONST_CAST (struct string *, st_);
if (st->ss.string == NULL)
ds_extend (st, 1);
st->ss.string[st->ss.length] = '\0';
/* PSPP - a program for statistical analysis.
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2009 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 <libpspp/array.h>
#include <libpspp/assertion.h>
+#include <libpspp/cast.h>
#include "xalloc.h"
struct taint *
taint_clone (const struct taint *taint_)
{
- struct taint *taint = (struct taint *) taint_;
+ struct taint *taint = CONST_CAST (struct taint *, taint_);
assert (taint->ref_cnt > 0);
taint->ref_cnt++;
void
taint_propagate (const struct taint *from_, const struct taint *to_)
{
- struct taint *from = (struct taint *) from_;
- struct taint *to = (struct taint *) to_;
+ struct taint *from = CONST_CAST (struct taint *, from_);
+ struct taint *to = CONST_CAST (struct taint *, to_);
if (from != to)
{
void
taint_set_taint (const struct taint *taint_)
{
- struct taint *taint = (struct taint *) taint_;
+ struct taint *taint = CONST_CAST (struct taint *, taint_);
if (!taint->tainted)
recursively_set_taint (taint);
}
void
taint_reset_successor_taint (const struct taint *taint_)
{
- struct taint *taint = (struct taint *) taint_;
+ struct taint *taint = CONST_CAST (struct taint *, taint_);
if (taint->tainted_successor)
{
#include <stdlib.h>
#include <libpspp/assertion.h>
+#include <libpspp/cast.h>
#include "error.h"
#include "xalloc.h"
static bool
do_seek (const struct tmpfile *tf_, off_t offset)
{
- struct tmpfile *tf = (struct tmpfile *) tf_;
+ struct tmpfile *tf = CONST_CAST (struct tmpfile *, tf_);
if (!tmpfile_error (tf))
{
static bool
do_read (const struct tmpfile *tf_, void *buffer, size_t bytes)
{
- struct tmpfile *tf = (struct tmpfile *) tf_;
+ struct tmpfile *tf = CONST_CAST (struct tmpfile *, tf_);
assert (!tmpfile_error (tf));
if (bytes > 0 && fread (buffer, bytes, 1, tf->file) != 1)
/* PSPP - a program for statistical analysis.
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2009 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 <limits.h>
#include <libpspp/assertion.h>
+#include <libpspp/cast.h>
#include <libpspp/compiler.h>
static struct tower_node *abt_to_tower_node (const struct abt_node *);
unsigned long height,
unsigned long *node_start)
{
- struct tower *t = (struct tower *) t_;
+ struct tower *t = CONST_CAST (struct tower *, t_);
struct abt_node *p;
assert (height < tower_height (t));
struct tower_node *
tower_get (const struct tower *t_, unsigned long int index)
{
- struct tower *t = (struct tower *) t_;
+ struct tower *t = CONST_CAST (struct tower *, t_);
struct abt_node *p;
assert (index < tower_count (t));
double
percentile_calculate (const struct percentile *ptl, enum pc_alg alg)
{
- struct percentile *mutable = (struct percentile *) ptl;
+ struct percentile *mutable = CONST_CAST (struct percentile *, ptl);
const struct order_stats *os = &ptl->parent;
assert (os->cc == ptl->w);
struct chart *
chart_ref (const struct chart *chart_)
{
- struct chart *chart = (struct chart *) chart_;
+ struct chart *chart = CONST_CAST (struct chart *, chart_);
chart->ref_cnt++;
return chart;
}
caching. */
for (start = 0; start <= 32; start++)
{
- struct range_set *nonconst_rs = (struct range_set *) rs;
+ struct range_set *nonconst_rs = CONST_CAST (struct range_set *, rs);
nonconst_rs->cache_end = 0;
s1 = range_set_scan (rs, start);
s2 = next_1bit (pattern, start);