From 8133371af7af551212ef1e0ae4c49cea35474c99 Mon Sep 17 00:00:00 2001 From: Martin Stjernholm <mast@lysator.liu.se> Date: Fri, 30 May 2008 17:19:03 +0200 Subject: [PATCH] Make use of the new svalue init macros and global constant svalues for 0 and 1. Rev: src/array.c:1.209 Rev: src/bignum.c:1.45 Rev: src/builtin_functions.c:1.669 Rev: src/code/ia32.c:1.48 Rev: src/encode.c:1.275 Rev: src/error.c:1.163 Rev: src/multiset.c:1.113 Rev: src/multiset.h:1.46 Rev: src/svalue.c:1.242 --- src/array.c | 10 +++------- src/bignum.c | 9 ++------- src/builtin_functions.c | 16 ++-------------- src/code/ia32.c | 8 ++------ src/encode.c | 16 +++------------- src/error.c | 9 ++------- src/multiset.c | 37 ++++++++----------------------------- src/multiset.h | 12 +++++++----- src/svalue.c | 10 +++++----- 9 files changed, 34 insertions(+), 93 deletions(-) diff --git a/src/array.c b/src/array.c index 6f27e36965..ececd275c8 100644 --- a/src/array.c +++ b/src/array.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: array.c,v 1.208 2008/05/12 13:24:44 grubba Exp $ +|| $Id: array.c,v 1.209 2008/05/30 15:19:02 mast Exp $ */ #include "global.h" @@ -38,9 +38,7 @@ PMOD_EXPORT struct array empty_array= 0, /* no types */ 0, /* no flags */ empty_array.real_item, /* Initialize the item pointer. */ -#ifdef HAVE_UNION_INIT - {{0, 0, {0}}}, /* Only to avoid warnings. */ -#endif + {SVALUE_INIT_FREE}, }; /** The empty weak array. */ @@ -49,9 +47,7 @@ PMOD_EXPORT struct array weak_empty_array= PIKE_CONSTANT_MEMOBJ_INIT(1), 0, &empty_array, 0, 0, 0, ARRAY_WEAK_FLAG, weak_empty_array.real_item, -#ifdef HAVE_UNION_INIT - {{0, 0, {0}}}, /* Only to avoid warnings. */ -#endif + {SVALUE_INIT_FREE}, }; struct array *first_array = &empty_array; diff --git a/src/bignum.c b/src/bignum.c index a807e5adab..957a256523 100644 --- a/src/bignum.c +++ b/src/bignum.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: bignum.c,v 1.44 2008/05/01 21:14:04 mast Exp $ +|| $Id: bignum.c,v 1.45 2008/05/30 15:19:02 mast Exp $ */ #include "global.h" @@ -17,12 +17,7 @@ #define sp Pike_sp -PMOD_EXPORT struct svalue auto_bignum_program = { - PIKE_T_FREE, 0, -#ifdef HAVE_UNION_INIT - {0}, /* Only to avoid warnings. */ -#endif -}; +PMOD_EXPORT struct svalue auto_bignum_program = SVALUE_INIT_FREE; PMOD_EXPORT struct program *get_auto_bignum_program(void) { diff --git a/src/builtin_functions.c b/src/builtin_functions.c index 8e8d0a1aad..d9a9b9f9d3 100644 --- a/src/builtin_functions.c +++ b/src/builtin_functions.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: builtin_functions.c,v 1.668 2008/05/29 20:08:14 nilsson Exp $ +|| $Id: builtin_functions.c,v 1.669 2008/05/30 15:19:02 mast Exp $ */ #include "global.h" @@ -7602,10 +7602,6 @@ PMOD_EXPORT void f_object_variablep(INT32 args) /*! @module Array */ -#ifdef HAVE_UNION_INIT -static const struct svalue one = {PIKE_T_INT, NUMBER_NUMBER, {1}}; -#endif - /*! @decl array uniq(array a) *! *! Remove elements that are duplicates. @@ -7625,23 +7621,15 @@ PMOD_EXPORT void f_uniq_array(INT32 args) { struct array *a, *b; struct mapping *m; -#ifndef HAVE_UNION_INIT - struct svalue one; -#endif int i, j=0,size=0; get_all_args("uniq", args, "%a", &a); push_mapping(m = allocate_mapping(a->size)); push_array(b = allocate_array(a->size)); -#ifndef HAVE_UNION_INIT - one.type = T_INT; - one.subtype = NUMBER_NUMBER; - one.u.integer = 1; -#endif for(i =0; i< a->size; i++) { - mapping_insert(m, ITEM(a)+i, &one); + mapping_insert(m, ITEM(a)+i, &svalue_int_one); if(m_sizeof(m) != size) { size=m_sizeof(m); diff --git a/src/code/ia32.c b/src/code/ia32.c index 18a29ebd2e..3390d8e1de 100644 --- a/src/code/ia32.c +++ b/src/code/ia32.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: ia32.c,v 1.47 2008/02/28 10:35:59 grubba Exp $ +|| $Id: ia32.c,v 1.48 2008/05/30 15:19:03 mast Exp $ */ /* @@ -570,11 +570,7 @@ static void ia32_push_int(INT32 x) static void ia32_push_string (INT32 x, int subtype) { size_t e; - struct svalue tmp = {PIKE_T_STRING, subtype, -#ifdef HAVE_UNION_INIT - {0} -#endif - }; + struct svalue tmp = SVALUE_INIT (PIKE_T_STRING, subtype, 0); enum ia32_reg tmp_reg = alloc_reg ((1 << fp_reg) | (1 << sp_reg)); load_fp_reg ((1 << tmp_reg) | (1 << sp_reg)); diff --git a/src/encode.c b/src/encode.c index 7f9fc2150b..7fe95315fb 100644 --- a/src/encode.c +++ b/src/encode.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: encode.c,v 1.274 2008/05/28 16:59:43 grubba Exp $ +|| $Id: encode.c,v 1.275 2008/05/30 15:19:02 mast Exp $ */ #include "global.h" @@ -498,12 +498,7 @@ static void encode_value2(struct svalue *val, struct encode_data *data, int forc #endif { - static struct svalue dested = { - T_INT, NUMBER_DESTRUCTED, -#ifdef HAVE_UNION_INIT - {0}, /* Only to avoid warnings. */ -#endif - }; + static struct svalue dested = SVALUE_INIT (T_INT, NUMBER_DESTRUCTED, 0); INT32 i; struct svalue *tmp; struct svalue entry_id; @@ -4900,12 +4895,7 @@ static INT32 my_decode(struct pike_string *tmp, #endif ) { struct svalue *res; - struct svalue val = { - T_INT, NUMBER_NUMBER, -#ifdef HAVE_UNION_INIT - {0}, /* Only to avoid warnings. */ -#endif /* HAVE_UNION_INIT */ - }; + struct svalue val = SVALUE_INIT_INT (0); val.u.integer = COUNTER_START; if ((res = low_mapping_lookup(data->decoded, &val))) { push_svalue(res); diff --git a/src/error.c b/src/error.c index 72c105dbaf..59ac6e9e61 100644 --- a/src/error.c +++ b/src/error.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: error.c,v 1.162 2008/05/27 19:36:00 grubba Exp $ +|| $Id: error.c,v 1.163 2008/05/30 15:19:03 mast Exp $ */ #define NO_PIKE_SHORTHAND @@ -235,12 +235,7 @@ PMOD_EXPORT void push_error(const char *description) f_aggregate(2); } -PMOD_EXPORT struct svalue throw_value = { - PIKE_T_INT, NUMBER_NUMBER, -#ifdef HAVE_UNION_INIT - {0}, /* Only to avoid warnings. */ -#endif -}; +PMOD_EXPORT struct svalue throw_value = SVALUE_INIT_FREE; int throw_severity; static const char *in_error; diff --git a/src/multiset.c b/src/multiset.c index f09002dfda..3908fc632a 100644 --- a/src/multiset.c +++ b/src/multiset.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: multiset.c,v 1.112 2008/05/11 21:30:59 mast Exp $ +|| $Id: multiset.c,v 1.113 2008/05/30 15:19:03 mast Exp $ */ #include "global.h" @@ -210,40 +210,26 @@ static struct multiset *gc_mark_multiset_pos = NULL; static struct multiset_data empty_ind_msd = { 1, 0, NULL, NULL, - {T_INT, 0, -#ifdef HAVE_UNION_INIT - {0} -#endif - }, + SVALUE_INIT_INT (0), 0, 0, 0, BIT_INT, 0, #ifdef HAVE_UNION_INIT - {{{0, 0, {0, 0, {0}}}}} + {{{NULL, NULL, SVALUE_INIT_INT (0)}}} #endif }; static struct multiset_data empty_indval_msd = { 1, 0, NULL, NULL, - {T_INT, 0, -#ifdef HAVE_UNION_INIT - {0} -#endif - }, + SVALUE_INIT_INT (0), 0, 0, 0, 0, MULTISET_INDVAL, #ifdef HAVE_UNION_INIT - {{{0, 0, {0, 0, {0}}}}} + {{{NULL, NULL, SVALUE_INIT_INT (0)}}} #endif }; -struct svalue svalue_int_one = {T_INT, NUMBER_NUMBER, -#ifdef HAVE_UNION_INIT - {1} -#endif - }; - void free_multiset_data (struct multiset_data *msd); #define INIT_MULTISET(L) do { \ @@ -2639,7 +2625,9 @@ PMOD_EXPORT struct svalue *multiset_lookup (struct multiset *l, check_svalue (key); if ((node = low_multiset_find_eq (l, key))) if (l->msd->flags & MULTISET_INDVAL) return &node->iv.val; - else return &svalue_int_one; + else + /* Caller better not try to change this. */ + return (struct svalue *) &svalue_int_one; else return NULL; } @@ -4351,9 +4339,6 @@ void init_multiset() RB_FLAG_MASK, MULTISET_FLAG_MARKER, test.i.ind.type); #undef msnode_check -#endif -#ifndef HAVE_UNION_INIT - svalue_int_one.u.integer = 1; #endif init_multiset_blocks(); } @@ -4361,12 +4346,6 @@ void init_multiset() /* Pike might exit without calling this. */ void exit_multiset() { -#ifdef PIKE_DEBUG - if (svalue_int_one.type != T_INT || - svalue_int_one.subtype != NUMBER_NUMBER || - svalue_int_one.u.integer != 1) - Pike_fatal ("svalue_int_one has been changed.\n"); -#endif free_all_multiset_blocks(); } diff --git a/src/multiset.h b/src/multiset.h index c00f3caafd..68eb6e3d1c 100644 --- a/src/multiset.h +++ b/src/multiset.h @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: multiset.h,v 1.45 2008/05/27 22:49:23 mast Exp $ +|| $Id: multiset.h,v 1.46 2008/05/30 15:19:03 mast Exp $ */ #ifndef MULTISET_H @@ -150,8 +150,6 @@ struct multiset extern struct multiset *first_multiset; extern struct multiset *gc_internal_multiset; -PMOD_EXPORT extern struct svalue svalue_int_one; - PMOD_EXPORT void multiset_clear_node_refs (struct multiset *l); #ifdef PIKE_DEBUG @@ -198,7 +196,9 @@ union msnode *low_multiset_find_eq (struct multiset *l, struct svalue *key); &(VAR)) #define low_get_multiset_value(MSD, NODE) \ - ((MSD)->flags & MULTISET_INDVAL ? &(NODE)->iv.val : &svalue_int_one) + ((MSD)->flags & MULTISET_INDVAL ? &(NODE)->iv.val : \ + /* Caller better not try to change this. */ \ + (struct svalue *) &svalue_int_one) #define low_set_multiset_value(MSD, NODE, VAL) do { \ if ((MSD)->flags & MULTISET_INDVAL) \ assign_svalue (&(NODE)->iv.val, VAL); \ @@ -354,7 +354,9 @@ PMOD_EXPORT int msnode_is_deleted (struct multiset *l, ptrdiff_t nodepos); #define get_multiset_value(L, NODEPOS) \ ((L)->msd->flags & MULTISET_INDVAL ? \ - &access_msnode ((L), (NODEPOS))->iv.val : &svalue_int_one) + &access_msnode ((L), (NODEPOS))->iv.val : \ + /* Caller better not try to change this. */ \ + (struct svalue *) &svalue_int_one) #define set_multiset_value(L, NODEPOS, VAL) do { \ if ((L)->msd->flags & MULTISET_INDVAL) \ assign_svalue (&access_msnode ((L), (NODEPOS))->iv.val, VAL); \ diff --git a/src/svalue.c b/src/svalue.c index 7a498087e9..49f7509a62 100644 --- a/src/svalue.c +++ b/src/svalue.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: svalue.c,v 1.241 2008/05/29 18:11:14 grubba Exp $ +|| $Id: svalue.c,v 1.242 2008/05/30 15:19:03 mast Exp $ */ #include "global.h" @@ -30,12 +30,12 @@ #define sp Pike_sp -const struct svalue dest_ob_zero = { - T_INT, 0, +PMOD_EXPORT const struct svalue svalue_int_zero = SVALUE_INIT_INT (0); #ifdef HAVE_UNION_INIT - {0}, /* Only to avoid warnings. */ +PMOD_EXPORT const struct svalue svalue_int_one = SVALUE_INIT_INT (1); +#else +PMOD_EXPORT struct svalue svalue_int_one = SVALUE_INIT_INT (1); #endif -}; #ifdef PIKE_DEBUG PMOD_EXPORT const char msg_type_error[] = -- GitLab