From 2fbeae5c5702d984e62e771693b0237cf945f155 Mon Sep 17 00:00:00 2001
From: Martin Stjernholm <mast@lysator.liu.se>
Date: Sun, 1 Jul 2001 23:34:51 +0200
Subject: [PATCH] Avoid the missing initializer warnings if the compiler allows
 us to initialize unions.

Rev: src/acconfig.h:1.88
Rev: src/array.c:1.115
Rev: src/bignum.c:1.22
Rev: src/configure.in:1.530
Rev: src/encode.c:1.102
Rev: src/error.c:1.73
Rev: src/mapping.c:1.128
Rev: src/svalue.c:1.109
---
 src/acconfig.h   |  5 ++++-
 src/array.c      | 11 ++++++++++-
 src/bignum.c     |  7 ++++++-
 src/configure.in | 27 ++++++++++++++++++++++++++-
 src/encode.c     |  9 +++++++--
 src/error.c      |  9 +++++++--
 src/mapping.c    | 10 +++++-----
 src/svalue.c     |  9 +++++++--
 8 files changed, 72 insertions(+), 15 deletions(-)

diff --git a/src/acconfig.h b/src/acconfig.h
index e612fc9ae2..0940c2d7a9 100644
--- a/src/acconfig.h
+++ b/src/acconfig.h
@@ -1,5 +1,5 @@
 /*
- * $Id: acconfig.h,v 1.87 2001/06/12 18:50:27 grubba Exp $
+ * $Id: acconfig.h,v 1.88 2001/07/01 21:34:49 mast Exp $
  */
 #ifndef MACHINE_H
 #define MACHINE_H
@@ -422,6 +422,9 @@
 /* set this to the modifier type string to print FLOAT_TYPE, like "L" or "" */
 #undef PRINTPIKEFLOAT
 
+/* Define if the compiler understand union initializations. */
+#undef HAVE_UNION_INIT
+
 @BOTTOM@
 
 /* NT stuff */
diff --git a/src/array.c b/src/array.c
index c46a741aec..88825bc91d 100644
--- a/src/array.c
+++ b/src/array.c
@@ -23,7 +23,7 @@
 #include "stuff.h"
 #include "bignum.h"
 
-RCSID("$Id: array.c,v 1.114 2001/06/30 18:44:21 hubbe Exp $");
+RCSID("$Id: array.c,v 1.115 2001/07/01 21:34:50 mast Exp $");
 
 PMOD_EXPORT struct array empty_array=
 {
@@ -35,18 +35,27 @@ 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
 };
 PMOD_EXPORT struct array weak_empty_array=
 {
   PIKE_CONSTANT_MEMOBJ_INIT(1),
   &weak_shrink_empty_array, &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
 };
 PMOD_EXPORT struct array weak_shrink_empty_array=
 {
   PIKE_CONSTANT_MEMOBJ_INIT(1),
   &empty_array, &weak_empty_array, 0, 0, 0, ARRAY_WEAK_FLAG|ARRAY_WEAK_SHRINK,
   weak_shrink_empty_array.real_item,
+#ifdef HAVE_UNION_INIT
+  {{0, 0, {0}}}, /* Only to avoid warnings. */
+#endif
 };
 
 struct array *gc_internal_array = &empty_array;
diff --git a/src/bignum.c b/src/bignum.c
index d4edf5106c..19581433c0 100644
--- a/src/bignum.c
+++ b/src/bignum.c
@@ -8,7 +8,12 @@
 #include "svalue.h"
 #include "pike_error.h"
 
-struct svalue auto_bignum_program = { T_INT };
+struct svalue auto_bignum_program = {
+  T_INT, 0,
+#ifdef HAVE_UNION_INIT
+  {0}, /* Only to avoid warnings. */
+#endif
+};
 
 PMOD_EXPORT int gmp_library_loaded=0;
 int gmp_library_resolving=0;
diff --git a/src/configure.in b/src/configure.in
index 5ffd6f2314..7497e3478f 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -1,4 +1,4 @@
-AC_REVISION("$Id: configure.in,v 1.529 2001/06/29 23:26:48 hubbe Exp $")
+AC_REVISION("$Id: configure.in,v 1.530 2001/07/01 21:34:50 mast Exp $")
 AC_INIT(interpret.c)
 AC_CONFIG_HEADER(machine.h)
 
@@ -4964,6 +4964,31 @@ AC_DEFINE_UNQUOTED(PRINTPIKEFLOAT,"$pike_cv_printf_float_type")
 
 #######################################################################
 
+AC_MSG_CHECKING(if union initialization works)
+AC_CACHE_VAL(pike_cv_have_union_init, [
+  AC_TRY_COMPILE([], [
+    struct foo {int a; char *b;};
+    struct bar {int c[2];};
+    union anything
+    {
+      struct foo *foo;
+      struct bar *bar;
+    };
+    struct svalue
+    {
+      unsigned type;
+      unsigned subtype;
+      union anything u;
+    };
+    struct svalue my_svalue = {0, 0, {{17, "17"}}};
+  ], pike_cv_have_union_init=yes, pike_cv_have_union_init=no)])
+AC_MSG_RESULT($pike_cv_have_union_init)
+if test "$pike_cv_have_union_init" = yes; then
+  AC_DEFINE(HAVE_UNION_INIT)
+fi
+
+#######################################################################
+
 # Set info about shared libraries.
 AC_SUBST(SO)
 AC_SUBST(LDSHARED)
diff --git a/src/encode.c b/src/encode.c
index a79b8c46f1..de194e5628 100644
--- a/src/encode.c
+++ b/src/encode.c
@@ -25,7 +25,7 @@
 #include "version.h"
 #include "bignum.h"
 
-RCSID("$Id: encode.c,v 1.101 2001/07/01 16:59:45 grubba Exp $");
+RCSID("$Id: encode.c,v 1.102 2001/07/01 21:34:50 mast Exp $");
 
 /* #define ENCODE_DEBUG */
 
@@ -525,7 +525,12 @@ static void encode_value2(struct svalue *val, struct encode_data *data)
 #endif
 
 {
-  static struct svalue dested = { T_INT, NUMBER_DESTRUCTED };
+  static struct svalue dested = {
+    T_INT, NUMBER_DESTRUCTED,
+#ifdef HAVE_UNION_INIT
+  {0}, /* Only to avoid warnings. */
+#endif
+  };
   INT32 i;
   struct svalue *tmp;
 
diff --git a/src/error.c b/src/error.c
index 039c9263fd..39ae2fe8b3 100644
--- a/src/error.c
+++ b/src/error.c
@@ -22,7 +22,7 @@
 #include "threads.h"
 #include "gc.h"
 
-RCSID("$Id: error.c,v 1.72 2001/06/18 15:44:40 grubba Exp $");
+RCSID("$Id: error.c,v 1.73 2001/07/01 21:34:50 mast Exp $");
 
 #undef ATTRIBUTE
 #define ATTRIBUTE(X)
@@ -132,7 +132,12 @@ PMOD_EXPORT void push_error(const char *description)
   f_aggregate(2);
 }
 
-PMOD_EXPORT struct svalue throw_value = { PIKE_T_INT };
+PMOD_EXPORT struct svalue throw_value = {
+  PIKE_T_INT, 0,
+#ifdef HAVE_UNION_INIT
+  {0}, /* Only to avoid warnings. */
+#endif
+};
 int throw_severity;
 static const char *in_error;
 
diff --git a/src/mapping.c b/src/mapping.c
index b6257ce53d..d8243ecc89 100644
--- a/src/mapping.c
+++ b/src/mapping.c
@@ -5,7 +5,7 @@
 \*/
 /**/
 #include "global.h"
-RCSID("$Id: mapping.c,v 1.127 2001/06/30 21:28:36 mast Exp $");
+RCSID("$Id: mapping.c,v 1.128 2001/07/01 21:34:51 mast Exp $");
 #include "main.h"
 #include "object.h"
 #include "mapping.h"
@@ -135,13 +135,13 @@ static void check_mapping_type_fields(struct mapping *m)
 #endif
 
 static struct mapping_data empty_data =
-  { PIKE_CONSTANT_MEMOBJ_INIT(1), 1, 0,0,0,0,0,0,0 };
+  { PIKE_CONSTANT_MEMOBJ_INIT(1), 1, 0,0,0,0,0,0, 0, 0,{0}};
 static struct mapping_data weak_ind_empty_data =
-  { PIKE_CONSTANT_MEMOBJ_INIT(1), 1, 0,0,0,0,0,0, MAPPING_WEAK_INDICES};
+  { PIKE_CONSTANT_MEMOBJ_INIT(1), 1, 0,0,0,0,0,0, MAPPING_WEAK_INDICES, 0,{0}};
 static struct mapping_data weak_val_empty_data =
-  { PIKE_CONSTANT_MEMOBJ_INIT(1), 1, 0,0,0,0,0,0, MAPPING_WEAK_VALUES};
+  { PIKE_CONSTANT_MEMOBJ_INIT(1), 1, 0,0,0,0,0,0, MAPPING_WEAK_VALUES, 0,{0}};
 static struct mapping_data weak_both_empty_data =
-  { PIKE_CONSTANT_MEMOBJ_INIT(1), 1, 0,0,0,0,0,0, MAPPING_WEAK };
+  { PIKE_CONSTANT_MEMOBJ_INIT(1), 1, 0,0,0,0,0,0, MAPPING_WEAK, 0,{0}};
 
 /* This function allocates the hash table and svalue space for a mapping
  * struct. The size is the max number of indices that can fit in the
diff --git a/src/svalue.c b/src/svalue.c
index bb76347e7f..c4be8fcc42 100644
--- a/src/svalue.c
+++ b/src/svalue.c
@@ -62,9 +62,14 @@ static int pike_isnan(double x)
 #endif /* HAVE__ISNAN */
 #endif /* HAVE_ISNAN */
 
-RCSID("$Id: svalue.c,v 1.108 2001/07/01 18:26:42 mast Exp $");
+RCSID("$Id: svalue.c,v 1.109 2001/07/01 21:34:51 mast Exp $");
 
-struct svalue dest_ob_zero = { T_INT, 0 };
+struct svalue dest_ob_zero = {
+  T_INT, 0,
+#ifdef HAVE_UNION_INIT
+  {0}, /* Only to avoid warnings. */
+#endif
+};
 
 /*
  * This routine frees a short svalue given a pointer to it and
-- 
GitLab