public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 4/4] Use conf.list to generate spec array
  2014-09-19 10:20 [PATCH 0/4] POSIX_* Wundef fixes Siddhesh Poyarekar
@ 2014-09-19 10:20 ` Siddhesh Poyarekar
  2014-10-01  9:17   ` [PATCH 4/4 v1.1] " Siddhesh Poyarekar
  2014-09-19 10:20 ` [PATCH 1/4] Remove Wundef warnings for specification macros Siddhesh Poyarekar
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Siddhesh Poyarekar @ 2014-09-19 10:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: roland

This patch adds support to generate the spec array in getconf from the
conf.list.  The generated code is mostly unchanged.  the only changes
are due to the change in layout of the spec and val arrays in the ELF.

The val array can also be auto-generated from conf.list once the
remaining macros are added to it.

	* posix/conf.list (SPEC:XBS5): Add sysconf prefix.
	* posix/confstr.c: Define NEED_SPEC_ARRAY to 0.
	* posix/posix-envs.def: Likewise.
	* sysdeps/posix/sysconf.c: Likewise.
	* posix/getconf.c: Define NEED_SPEC_ARRAY to 1.
	(specs): Remove array.
	* scripts/gen-conf.awk: Support generation of specs array.
---
 posix/conf.list         |  2 +-
 posix/confstr.c         |  4 +++-
 posix/getconf.c         | 20 +++-----------------
 posix/posix-envs.def    |  3 ++-
 scripts/gen-conf.awk    | 26 ++++++++++++++++++++++++++
 sysdeps/posix/sysconf.c |  1 +
 6 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/posix/conf.list b/posix/conf.list
index 07607b7..0a17666 100644
--- a/posix/conf.list
+++ b/posix/conf.list
@@ -104,7 +104,7 @@ SYSCONF:POSIX {
   RAW_SOCKETS
 }
 
-SPEC:XBS5 {
+SPEC:XBS5:_SC_XBS5 {
   ILP32_OFF32
   ILP32_OFFBIG
   LP64_OFF64
diff --git a/posix/confstr.c b/posix/confstr.c
index 1accfee..0400d7f 100644
--- a/posix/confstr.c
+++ b/posix/confstr.c
@@ -21,7 +21,9 @@
 #include <string.h>
 #include <confstr.h>
 #include "../version.h"
-#include "confdefs.h"
+
+#define NEED_SPEC_ARRAY 0
+#include <confdefs.h>
 
 /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes
    of BUF with the value corresponding to NAME and zero-terminate BUF.
diff --git a/posix/getconf.c b/posix/getconf.c
index 14d51d8..3c08688 100644
--- a/posix/getconf.c
+++ b/posix/getconf.c
@@ -26,6 +26,9 @@
 #include "../version.h"
 #define PACKAGE _libc_intl_domainname
 
+#define NEED_SPEC_ARRAY 1
+#include <confdefs.h>
+
 struct conf
   {
     const char *name;
@@ -387,23 +390,6 @@ static const struct conf vars[] =
   };
 
 
-static const struct { const char *name; int num; } specs[] =
-  {
-    { "XBS5_ILP32_OFF32", _SC_XBS5_ILP32_OFF32 },
-    { "XBS5_ILP32_OFFBIG", _SC_XBS5_ILP32_OFFBIG },
-    { "XBS5_LP64_OFF64", _SC_XBS5_LP64_OFF64 },
-    { "XBS5_LPBIG_OFFBIG", _SC_XBS5_LPBIG_OFFBIG },
-    { "POSIX_V6_ILP32_OFF32", _SC_V6_ILP32_OFF32 },
-    { "POSIX_V6_ILP32_OFFBIG", _SC_V6_ILP32_OFFBIG },
-    { "POSIX_V6_LP64_OFF64", _SC_V6_LP64_OFF64 },
-    { "POSIX_V6_LPBIG_OFFBIG", _SC_V6_LPBIG_OFFBIG },
-    { "POSIX_V7_ILP32_OFF32", _SC_V7_ILP32_OFF32 },
-    { "POSIX_V7_ILP32_OFFBIG", _SC_V7_ILP32_OFFBIG },
-    { "POSIX_V7_LP64_OFF64", _SC_V7_LP64_OFF64 },
-    { "POSIX_V7_LPBIG_OFFBIG", _SC_V7_LPBIG_OFFBIG },
-  };
-static const int nspecs = sizeof (specs) / sizeof (specs[0]);
-
 extern const char *__progname;
 
 
diff --git a/posix/posix-envs.def b/posix/posix-envs.def
index 9047d0c..0b33e02 100644
--- a/posix/posix-envs.def
+++ b/posix/posix-envs.def
@@ -42,7 +42,8 @@
    defined.  These are called with arguments V5, V6, V7 before and
    after the relevant groups of environments.  */
 
-#include "confdefs.h"
+#define NEED_SPEC_ARRAY 0
+#include <confdefs.h>
 
 START_ENV_GROUP (V7)
 
diff --git a/scripts/gen-conf.awk b/scripts/gen-conf.awk
index 45a4d44..1370646 100644
--- a/scripts/gen-conf.awk
+++ b/scripts/gen-conf.awk
@@ -17,12 +17,17 @@ $2 == "{" {
   split ($1, arr, ":")
   type = arr[1]
   prefix = arr[2]
+  if (arr[3] != "")
+    sc_prefix = arr[3]
+  else
+    sc_prefix = "_SC"
   next
 }
 
 $1 == "}" {
   prefix = ""
   type = ""
+  sc_prefix = ""
   next
 }
 
@@ -37,6 +42,7 @@ $1 == "}" {
   # CONFSTR: A configuration string
   # SYSCONF: A numeric value
   # SPEC: A specification
+  sc_prefixes[prefix][$1] = sc_prefix
   conf[prefix][$1] = type
 }
 
@@ -58,6 +64,26 @@ ENDFILE {
 	printf "# endif\n"
       }
       printf "#endif\n\n"
+
+      # Build a name -> sysconf number associative array to print a C array at
+      # the end.
+      if (conf[p][c] == "SPEC") {
+	name = sprintf ("%s_%s", p, c)
+	num = sprintf ("%s_%s", sc_prefixes[p][c], c)
+	spec[name] = num
+      }
     }
   }
+
+  # Print the specification array.  Define the macro NEED_SPEC_ARRAY before
+  # including confdefs.h to make it available in the compilation unit.
+  print "#if NEED_SPEC_ARRAY"
+  print "static const struct { const char *name; int num; } specs[] ="
+  print "  {"
+  for (s in spec) {
+    printf "    { \"%s\", %s },\n", s, spec[s]
+  }
+  print "  };"
+  print "static const int nspecs = sizeof (specs) / sizeof (specs[0]);"
+  print "#endif"
 }
diff --git a/sysdeps/posix/sysconf.c b/sysdeps/posix/sysconf.c
index c7b748b..bff59f4 100644
--- a/sysdeps/posix/sysconf.c
+++ b/sysdeps/posix/sysconf.c
@@ -31,6 +31,7 @@
 #include <sys/types.h>
 #include <regex.h>
 
+#define NEED_SPEC_ARRAY 0
 #include <confdefs.h>
 
 
-- 
1.9.3

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 0/4] POSIX_* Wundef fixes
@ 2014-09-19 10:20 Siddhesh Poyarekar
  2014-09-19 10:20 ` [PATCH 4/4] Use conf.list to generate spec array Siddhesh Poyarekar
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Siddhesh Poyarekar @ 2014-09-19 10:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: roland

This patch set fixes Wundef warnings for all POSIX_* macros and also
proposes a way to organize all of the sysconf variables so that
they're generated from one place (posix/conf.list) and are hence
typo-proof.  All patches have been verified on x86_64 to ensure that
they don't result in any significant changes in generated code.

[PATCH 1/4] Remove Wundef warnings for specification macros

- This is the initial patch that adds the conf.list file and macros
  and fixes one set of warnings.

[PATCH 2/4] Add _POSIX namespace SYSCONF macros to conf.list

- This is the second patch that adds the POSIX namespace sysconf
  macros to the list and fixes the remaining warnings.

[PATCH 3/4] Use PTHREAD_DESTRUCTOR_ITERATIONS

- This patch replaces the POSIX_THREAD_DESTRUCTOR_ITERATIONS with a
  view to unify getconf and sysconf usage.

[PATCH 4/4] Use conf.list to generate spec array

- This patch removes the hand-written specs variable and replaces it
  with an auto-generated array.  The vars array can be similarly
  replaced after adding all of its constituent variables to conf.list.
  I'll do that once these patches are in.

Siddhesh

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 1/4] Remove Wundef warnings for specification macros
  2014-09-19 10:20 [PATCH 0/4] POSIX_* Wundef fixes Siddhesh Poyarekar
  2014-09-19 10:20 ` [PATCH 4/4] Use conf.list to generate spec array Siddhesh Poyarekar
@ 2014-09-19 10:20 ` Siddhesh Poyarekar
  2014-09-23 12:57   ` Florian Weimer
  2014-09-19 10:20 ` [PATCH 3/4] Use PTHREAD_DESTRUCTOR_ITERATIONS Siddhesh Poyarekar
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Siddhesh Poyarekar @ 2014-09-19 10:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: roland

This patch adds a file conf.list that is used to generate macros to
determine if a macro is defined as set, unset or not defined.
gen-conf.awk processes this file and generates a header
(confdefs-defs.h) with these macros.  A new header confdefs.h includes
this generated header and defines accessor macros for the generated
macros.

Tested on x86_64.

	* posix/Makefile (before-compile): Add confdefs-defs.h.
	($(objpfx)confdefs-defs.h): New target.
	* posix/conf.list: New file.
	* posix/confdefs.h: New file.
	* posix/confstr.c: Include confdefs.h.
	(confstr): Use CONF_IS_* macros.
	* posix/posix-envs.def: Include confdefs.h.  Use CONF_IS_*
	macros.
	* scripts/gen-conf.awk: New file.
---
 posix/Makefile       |  7 +++++-
 posix/conf.list      | 23 +++++++++++++++++++
 posix/confdefs.h     | 15 +++++++++++++
 posix/confstr.c      | 28 ++++++++++++-----------
 posix/posix-envs.def | 50 +++++++++++++++++++++--------------------
 scripts/gen-conf.awk | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 148 insertions(+), 38 deletions(-)
 create mode 100644 posix/conf.list
 create mode 100644 posix/confdefs.h
 create mode 100644 scripts/gen-conf.awk

diff --git a/posix/Makefile b/posix/Makefile
index e6b69b4..abadc5a 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -99,7 +99,7 @@ others		:= getconf
 install-bin	:= getconf
 install-others-programs	:= $(inst_libexecdir)/getconf
 
-before-compile	+= testcases.h ptestcases.h
+before-compile	+= testcases.h ptestcases.h confdefs-defs.h
 
 # So they get cleaned up.
 generated += $(addprefix wordexp-test-result, 1 2 3 4 5 6 7 8 9 10) \
@@ -325,3 +325,8 @@ $(objpfx)getconf.speclist: getconf-speclist.c posix-envs.def
 # be built both makes it available for eyeball inspection and avoids the
 # surprise of things that look like compilation being done by 'make install'.
 others: $(objpfx)getconf.speclist
+
+$(objpfx)confdefs-defs.h: conf.list Makefile
+	$(make-target-directory)
+	$(AWK) -f $(..)scripts/gen-conf.awk $< > $@.tmp
+	mv -f $@.tmp $@
diff --git a/posix/conf.list b/posix/conf.list
new file mode 100644
index 0000000..d048568
--- /dev/null
+++ b/posix/conf.list
@@ -0,0 +1,23 @@
+# Configuration variables identified by getconf.  The heading of each section
+# is of the format TYPE:PREFIX:SC_PREFIX with the opening curly brace on the
+# same line.  TYPE can either be SYSCONF, PATHCONF, CONFSTR or SPEC.  In the
+# absence of SC_PREFIX, _SC is used as the SC_PREFIX.  Variable names are put
+# one on each line with a curly brace on its own line ending the section.
+
+SPEC:POSIX {
+  V6_ILP32_OFF32
+  V6_ILP32_OFFBIG
+  V6_LP64_OFF64
+  V6_LPBIG_OFFBIG
+  V7_ILP32_OFF32
+  V7_ILP32_OFFBIG
+  V7_LP64_OFF64
+  V7_LPBIG_OFFBIG
+}
+
+SPEC:XBS5 {
+  ILP32_OFF32
+  ILP32_OFFBIG
+  LP64_OFF64
+  LPBIG_OFFBIG
+}
diff --git a/posix/confdefs.h b/posix/confdefs.h
new file mode 100644
index 0000000..64f0e03
--- /dev/null
+++ b/posix/confdefs.h
@@ -0,0 +1,15 @@
+#ifndef __CONFDEFS_H__
+#define __CONFDEFS_H__
+
+#include <posix/confdefs-defs.h>
+
+#define CONF_DEF_UNDEFINED 1
+#define CONF_DEF_DEFINED_SET 2
+#define CONF_DEF_DEFINED_UNSET 3
+
+#define CONF_IS_DEFINED_SET(conf) (conf##_DEF == CONF_DEF_DEFINED_SET)
+#define CONF_IS_DEFINED_UNSET(conf) (conf##_DEF == CONF_DEF_DEFINED_UNSET)
+#define CONF_IS_UNDEFINED(conf) (conf##_DEF == CONF_DEF_UNDEFINED)
+#define CONF_IS_DEFINED(conf) (conf##_DEF != CONF_DEF_UNDEFINED)
+
+#endif
diff --git a/posix/confstr.c b/posix/confstr.c
index a2a1bf2..1accfee 100644
--- a/posix/confstr.c
+++ b/posix/confstr.c
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <confstr.h>
 #include "../version.h"
+#include "confdefs.h"
 
 /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes
    of BUF with the value corresponding to NAME and zero-terminate BUF.
@@ -100,9 +101,9 @@ confstr (name, buf, len)
     case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
     case _CS_POSIX_V7_ILP32_OFF32_CFLAGS:
 #ifdef __ILP32_OFF32_CFLAGS
-# if _POSIX_V7_ILP32_OFF32 == -1
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFF32)
 #  error "__ILP32_OFF32_CFLAGS should not be defined"
-# elif !defined _POSIX_V7_ILP32_OFF32
+# elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFF32)
       if (__sysconf (_SC_V7_ILP32_OFF32) < 0)
 	break;
 # endif
@@ -115,9 +116,9 @@ confstr (name, buf, len)
     case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:
     case _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS:
 #ifdef __ILP32_OFFBIG_CFLAGS
-# if _POSIX_V7_ILP32_OFFBIG == -1
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFFBIG)
 #  error "__ILP32_OFFBIG_CFLAGS should not be defined"
-# elif !defined _POSIX_V7_ILP32_OFFBIG
+# elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFFBIG)
       if (__sysconf (_SC_V7_ILP32_OFFBIG) < 0)
 	break;
 # endif
@@ -130,9 +131,9 @@ confstr (name, buf, len)
     case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
     case _CS_POSIX_V7_LP64_OFF64_CFLAGS:
 #ifdef __LP64_OFF64_CFLAGS
-# if _POSIX_V7_LP64_OFF64 == -1
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_LP64_OFF64)
 #  error "__LP64_OFF64_CFLAGS should not be defined"
-# elif !defined _POSIX_V7_LP64_OFF64
+# elif CONF_IS_UNDEFINED (_POSIX_V7_LP64_OFF64)
       if (__sysconf (_SC_V7_LP64_OFF64) < 0)
 	break;
 # endif
@@ -145,9 +146,9 @@ confstr (name, buf, len)
     case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
     case _CS_POSIX_V7_ILP32_OFF32_LDFLAGS:
 #ifdef __ILP32_OFF32_LDFLAGS
-# if _POSIX_V7_ILP32_OFF32 == -1
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFF32 )
 #  error "__ILP32_OFF32_LDFLAGS should not be defined"
-# elif !defined _POSIX_V7_ILP32_OFF32
+# elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFF32)
       if (__sysconf (_SC_V7_ILP32_OFF32) < 0)
 	break;
 # endif
@@ -160,9 +161,9 @@ confstr (name, buf, len)
     case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:
     case _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS:
 #ifdef __ILP32_OFFBIG_LDFLAGS
-# if _POSIX_V7_ILP32_OFFBIG == -1
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFFBIG)
 #  error "__ILP32_OFFBIG_LDFLAGS should not be defined"
-# elif !defined _POSIX_V7_ILP32_OFFBIG
+# elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFFBIG)
       if (__sysconf (_SC_V7_ILP32_OFFBIG) < 0)
 	break;
 # endif
@@ -175,9 +176,9 @@ confstr (name, buf, len)
     case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
     case _CS_POSIX_V7_LP64_OFF64_LDFLAGS:
 #ifdef __LP64_OFF64_LDFLAGS
-# if _POSIX_V7_LP64_OFF64 == -1
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_LP64_OFF64)
 #  error "__LP64_OFF64_LDFLAGS should not be defined"
-# elif !defined _POSIX_V7_LP64_OFF64
+# elif CONF_IS_UNDEFINED (_POSIX_V7_LP64_OFF64)
       if (__sysconf (_SC_V7_LP64_OFF64) < 0)
 	break;
 # endif
@@ -188,7 +189,8 @@ confstr (name, buf, len)
 
     case _CS_LFS_CFLAGS:
     case _CS_LFS_LINTFLAGS:
-#if _POSIX_V6_ILP32_OFF32 == 1 && _POSIX_V6_ILP32_OFFBIG == 1
+#if (CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFF32) \
+     && CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFFBIG))
 # define __LFS_CFLAGS "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
       /* Signal that we want the new ABI.  */
       string = __LFS_CFLAGS;
diff --git a/posix/posix-envs.def b/posix/posix-envs.def
index 05043e9..9047d0c 100644
--- a/posix/posix-envs.def
+++ b/posix/posix-envs.def
@@ -42,35 +42,37 @@
    defined.  These are called with arguments V5, V6, V7 before and
    after the relevant groups of environments.  */
 
+#include "confdefs.h"
+
 START_ENV_GROUP (V7)
 
-#if _POSIX_V7_ILP32_OFF32 > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V7_ILP32_OFF32)
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
-#elif defined _POSIX_V7_ILP32_OFF32
+#elif CONF_IS_DEFINED (_POSIX_V7_ILP32_OFF32)
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
 #else
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
 #endif
 
-#if _POSIX_V7_ILP32_OFFBIG > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V7_ILP32_OFFBIG)
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
-#elif defined _POSIX_V7_ILP32_OFFBIG
+#elif CONF_IS_DEFINED (_POSIX_V7_ILP32_OFFBIG)
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
 #else
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
 #endif
 
-#if _POSIX_V7_LP64_OFF64 > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V7_LP64_OFF64)
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
-#elif defined _POSIX_V7_LP64_OFF64
+#elif CONF_IS_DEFINED (_POSIX_V7_LP64_OFF64)
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
 #else
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
 #endif
 
-#if _POSIX_V7_LPBIG_OFFBIG > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V7_LPBIG_OFFBIG)
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
-#elif defined _POSIX_V7_LPBIG_OFFBIG
+#elif CONF_IS_DEFINED (_POSIX_V7_LPBIG_OFFBIG)
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
 #else
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
@@ -80,33 +82,33 @@ END_ENV_GROUP (V7)
 
 START_ENV_GROUP (V6)
 
-#if _POSIX_V6_ILP32_OFF32 > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFF32)
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
-#elif defined _POSIX_V6_ILP32_OFF32
+#elif CONF_IS_DEFINED (_POSIX_V6_ILP32_OFF32)
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
 #else
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
 #endif
 
-#if _POSIX_V6_ILP32_OFFBIG > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFFBIG)
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
-#elif defined _POSIX_V6_ILP32_OFFBIG
+#elif CONF_IS_DEFINED (_POSIX_V6_ILP32_OFFBIG)
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
 #else
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
 #endif
 
-#if _POSIX_V6_LP64_OFF64 > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V6_LP64_OFF64)
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
-#elif defined _POSIX_V6_LP64_OFF64
+#elif CONF_IS_DEFINED (_POSIX_V6_LP64_OFF64)
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
 #else
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
 #endif
 
-#if _POSIX_V6_LPBIG_OFFBIG > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V6_LPBIG_OFFBIG)
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
-#elif defined _POSIX_V6_LPBIG_OFFBIG
+#elif CONF_IS_DEFINED (_POSIX_V6_LPBIG_OFFBIG)
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
 #else
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
@@ -116,33 +118,33 @@ END_ENV_GROUP (V6)
 
 START_ENV_GROUP (V5)
 
-#if _XBS5_ILP32_OFF32 > 0
+#if CONF_IS_DEFINED_SET (_XBS5_ILP32_OFF32)
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
-#elif defined _XBS5_ILP32_OFF32
+#elif CONF_IS_DEFINED (_XBS5_ILP32_OFF32)
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
 #else
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
 #endif
 
-#if _XBS5_ILP32_OFFBIG > 0
+#if CONF_IS_DEFINED_SET (_XBS5_ILP32_OFFBIG)
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
-#elif defined _XBS5_ILP32_OFFBIG
+#elif CONF_IS_DEFINED (_XBS5_ILP32_OFFBIG)
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
 #else
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
 #endif
 
-#if _XBS5_LP64_OFF64 > 0
+#if CONF_IS_DEFINED_SET (_XBS5_LP64_OFF64)
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
-#elif defined _XBS5_LP64_OFF64
+#elif CONF_IS_DEFINED (_XBS5_LP64_OFF64)
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
 #else
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
 #endif
 
-#if _XBS5_LPBIG_OFFBIG > 0
+#if CONF_IS_DEFINED_SET (_XBS5_LPBIG_OFFBIG)
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)
-#elif defined _XBS5_LPBIG_OFFBIG
+#elif CONF_IS_DEFINED (_XBS5_LPBIG_OFFBIG)
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)
 #else
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)
diff --git a/scripts/gen-conf.awk b/scripts/gen-conf.awk
new file mode 100644
index 0000000..45a4d44
--- /dev/null
+++ b/scripts/gen-conf.awk
@@ -0,0 +1,63 @@
+# Generate confdefs-defs.h with definitions for {CONF}_DEF for each
+# configuration variable that getconf or sysconf may use.  Currently it is
+# equipped only to generate such macros for specification macros and for
+# SYSCONF macros in the _POSIX namespace.
+
+BEGIN {
+  PROCINFO["sorted_in"] = "@val_type_asc"
+  prefix = ""
+}
+
+$1 ~ /^#/ || $0 ~ /^\s*$/ {
+  next
+}
+
+# Begin a new prefix.
+$2 == "{" {
+  split ($1, arr, ":")
+  type = arr[1]
+  prefix = arr[2]
+  next
+}
+
+$1 == "}" {
+  prefix = ""
+  type = ""
+  next
+}
+
+{
+  if (prefix == "" && type == "" && sc_prefix == "") {
+    print "Syntax error" > "/dev/stderr"
+    exit 1
+  }
+
+  # The prefix and variable names are indices and the value indicates what type
+  # of variable it is.  The possible options are:
+  # CONFSTR: A configuration string
+  # SYSCONF: A numeric value
+  # SPEC: A specification
+  conf[prefix][$1] = type
+}
+
+ENDFILE {
+  print "/* Autogenerated by gen-conf.awk.  */\n"
+
+  # Generate macros that specify if a sysconf macro is defined and/or set.
+  for (p in conf) {
+    for (c in conf[p]) {
+      printf "#ifndef _%s_%s\n", p, c
+      printf "# define _%s_%s_DEF CONF_DEF_UNDEFINED\n", p, c
+      # CONFSTR have string values and they are not set or unset.
+      if (conf[p][c] != "CONFSTR") {
+	printf "#else\n"
+	printf "# if _%s_%s > 0\n", p, c
+	printf "#  define _%s_%s_DEF CONF_DEF_DEFINED_SET\n", p, c
+	printf "# else\n"
+	printf "#  define _%s_%s_DEF CONF_DEF_DEFINED_UNSET\n", p, c
+	printf "# endif\n"
+      }
+      printf "#endif\n\n"
+    }
+  }
+}
-- 
1.9.3

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 3/4] Use PTHREAD_DESTRUCTOR_ITERATIONS
  2014-09-19 10:20 [PATCH 0/4] POSIX_* Wundef fixes Siddhesh Poyarekar
  2014-09-19 10:20 ` [PATCH 4/4] Use conf.list to generate spec array Siddhesh Poyarekar
  2014-09-19 10:20 ` [PATCH 1/4] Remove Wundef warnings for specification macros Siddhesh Poyarekar
@ 2014-09-19 10:20 ` Siddhesh Poyarekar
  2014-12-18  0:44   ` Roland McGrath
  2014-09-19 10:30 ` [PATCH 2/4] Add _POSIX namespace SYSCONF macros to conf.list Siddhesh Poyarekar
  2014-11-05 11:11 ` [PING] POSIX_* Wundef fixes Siddhesh Poyarekar
  4 siblings, 1 reply; 19+ messages in thread
From: Siddhesh Poyarekar @ 2014-09-19 10:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: roland

The _POSIX_THREAD_DESTRUCTOR_ITERATIONS variable is not implemented by
getconf, so to get both getconf and sysconf on the same page, make the
latter use PTHREAD_DESTRUCTOR_ITERATIONS.

The generated code is unchanged on x86_64.

Siddhesh

	* posix/conf.list (SYSCONF:POSIX): Remove
	THREAD_DESTRUCTOR_ITERATIONS.
	* sysdeps/posix/sysconf.c (__sysconf): Use
	PTHREAD_DESTRUCTOR_ITERATIONS.
---
 posix/conf.list         | 1 -
 sysdeps/posix/sysconf.c | 4 ++--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/posix/conf.list b/posix/conf.list
index 6c870af..07607b7 100644
--- a/posix/conf.list
+++ b/posix/conf.list
@@ -100,7 +100,6 @@ SYSCONF:POSIX {
   USER_GROUPS_R
   VERSION
 # Additional variables not in getconf.
-  THREAD_DESTRUCTOR_ITERATIONS
   IPV6
   RAW_SOCKETS
 }
diff --git a/sysdeps/posix/sysconf.c b/sysdeps/posix/sysconf.c
index f5b65bf..c7b748b 100644
--- a/sysdeps/posix/sysconf.c
+++ b/sysdeps/posix/sysconf.c
@@ -555,8 +555,8 @@ __sysconf (name)
 #endif
 
     case _SC_THREAD_DESTRUCTOR_ITERATIONS:
-#if CONF_IS_DEFINED_SET (_POSIX_THREAD_DESTRUCTOR_ITERATIONS)
-      return _POSIX_THREAD_DESTRUCTOR_ITERATIONS;
+#if PTHREAD_DESTRUCTOR_ITERATIONS
+      return PTHREAD_DESTRUCTOR_ITERATIONS;
 #else
       return -1;
 #endif
-- 
1.9.3

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 2/4] Add _POSIX namespace SYSCONF macros to conf.list
  2014-09-19 10:20 [PATCH 0/4] POSIX_* Wundef fixes Siddhesh Poyarekar
                   ` (2 preceding siblings ...)
  2014-09-19 10:20 ` [PATCH 3/4] Use PTHREAD_DESTRUCTOR_ITERATIONS Siddhesh Poyarekar
@ 2014-09-19 10:30 ` Siddhesh Poyarekar
  2014-12-18  0:41   ` Roland McGrath
  2014-11-05 11:11 ` [PING] POSIX_* Wundef fixes Siddhesh Poyarekar
  4 siblings, 1 reply; 19+ messages in thread
From: Siddhesh Poyarekar @ 2014-09-19 10:30 UTC (permalink / raw)
  To: libc-alpha; +Cc: roland

This fixes the remaining -Wundef warnings.  Tested on x86_64.

	* posix/conf.list: Add _POSIX sysconf namespace.
	* sysdeps/posix/sysconf.c: Include confdefs.h.
	(__sysconf): Use CONF_IS_* macros.
---
 posix/conf.list         |  90 +++++++++++++++++++++++++++
 sysdeps/posix/sysconf.c | 158 ++++++++++++++++++++++++------------------------
 2 files changed, 170 insertions(+), 78 deletions(-)

diff --git a/posix/conf.list b/posix/conf.list
index d048568..6c870af 100644
--- a/posix/conf.list
+++ b/posix/conf.list
@@ -15,6 +15,96 @@ SPEC:POSIX {
   V7_LPBIG_OFFBIG
 }
 
+SYSCONF:POSIX {
+  ADVISORY_INFO
+  ARG_MAX
+  ASYNCHRONOUS_IO
+  BARRIERS
+  BASE
+  CHILD_MAX
+  C_LANG_SUPPORT
+  C_LANG_SUPPORT_R
+  CLOCK_SELECTION
+  CPUTIME
+  DEVICE_IO
+  DEVICE_SPECIFIC
+  DEVICE_SPECIFIC_R
+  FD_MGMT
+  FIFO
+  FILE_ATTRIBUTES
+  FILE_LOCKING
+  FILE_SYSTEM
+  FSYNC
+  JOB_CONTROL
+  MAPPED_FILES
+  MEMLOCK
+  MEMLOCK_RANGE
+  MEMORY_PROTECTION
+  MESSAGE_PASSING
+  MONOTONIC_CLOCK
+  MULTI_PROCESS
+  NETWORKING
+  NGROUPS_MAX
+  OPEN_MAX
+  PII
+  PII_INTERNET
+  PII_INTERNET_DGRAM
+  PII_INTERNET_STREAM
+  PII_OSI
+  PII_OSI_CLTS
+  PII_OSI_COTS
+  PII_OSI_M
+  PII_SOCKET
+  PII_XTI
+  PIPE
+  POLL
+  PRIORITIZED_IO
+  PRIORITY_SCHEDULING
+  READER_WRITER_LOCKS
+  REALTIME_SIGNALS
+  REGEXP
+  SAVED_IDS
+  SELECT
+  SEMAPHORES
+  SHARED_MEMORY_OBJECTS
+  SHELL
+  SIGNALS
+  SINGLE_PROCESS
+  SPAWN
+  SPIN_LOCKS
+  SPORADIC_SERVER
+  SSIZE_MAX
+  STREAM_MAX
+  SYNCHRONIZED_IO
+  SYSTEM_DATABASE
+  SYSTEM_DATABASE_R
+  THREAD_ATTR_STACKADDR
+  THREAD_ATTR_STACKSIZE
+  THREAD_CPUTIME
+  THREAD_PRIO_INHERIT
+  THREAD_PRIO_PROTECT
+  THREAD_PRIORITY_SCHEDULING
+  THREAD_PROCESS_SHARED
+  THREADS
+  THREAD_SAFE_FUNCTIONS
+  THREAD_SPORADIC_SERVER
+  TIMEOUTS
+  TIMERS
+  TRACE
+  TRACE_EVENT_FILTER
+  TRACE_INHERIT
+  TRACE_LOG
+  TYPED_MEMORY_OBJECTS
+  TZNAME_MAX
+  USER_GROUPS
+  USER_GROUPS_R
+  VERSION
+# Additional variables not in getconf.
+  THREAD_DESTRUCTOR_ITERATIONS
+  IPV6
+  RAW_SOCKETS
+}
+
 SPEC:XBS5 {
   ILP32_OFF32
   ILP32_OFFBIG
diff --git a/sysdeps/posix/sysconf.c b/sysdeps/posix/sysconf.c
index e815cd5..f5b65bf 100644
--- a/sysdeps/posix/sysconf.c
+++ b/sysdeps/posix/sysconf.c
@@ -31,6 +31,8 @@
 #include <sys/types.h>
 #include <regex.h>
 
+#include <confdefs.h>
+
 
 #define NEED_CHECK_SPEC \
   (!defined _XBS5_ILP32_OFF32 || !defined _XBS5_ILP32_OFFBIG \
@@ -95,112 +97,112 @@ __sysconf (name)
       return MAX (__tzname_max (), _POSIX_TZNAME_MAX);
 
     case _SC_JOB_CONTROL:
-#if _POSIX_JOB_CONTROL > 0
+#if CONF_IS_DEFINED_SET (_POSIX_JOB_CONTROL)
       return _POSIX_JOB_CONTROL;
 #else
       return -1;
 #endif
 
     case _SC_SAVED_IDS:
-#if _POSIX_SAVED_IDS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_SAVED_IDS)
       return 1;
 #else
       return -1;
 #endif
 
     case _SC_REALTIME_SIGNALS:
-#if _POSIX_REALTIME_SIGNALS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_REALTIME_SIGNALS)
       return _POSIX_REALTIME_SIGNALS;
 #else
       return -1;
 #endif
 
     case _SC_PRIORITY_SCHEDULING:
-#if _POSIX_PRIORITY_SCHEDULING > 0
+#if CONF_IS_DEFINED_SET (_POSIX_PRIORITY_SCHEDULING)
       return _POSIX_PRIORITY_SCHEDULING;
 #else
       return -1;
 #endif
 
     case _SC_TIMERS:
-#if _POSIX_TIMERS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_TIMERS)
       return _POSIX_TIMERS;
 #else
       return -1;
 #endif
 
     case _SC_ASYNCHRONOUS_IO:
-#if _POSIX_ASYNCHRONOUS_IO > 0
+#if CONF_IS_DEFINED_SET (_POSIX_ASYNCHRONOUS_IO)
       return _POSIX_ASYNCHRONOUS_IO;
 #else
       return -1;
 #endif
 
     case _SC_PRIORITIZED_IO:
-#if _POSIX_PRIORITIZED_IO > 0
+#if CONF_IS_DEFINED_SET (_POSIX_PRIORITIZED_IO)
       return _POSIX_PRIORITIZED_IO;
 #else
       return -1;
 #endif
 
     case _SC_SYNCHRONIZED_IO:
-#if _POSIX_SYNCHRONIZED_IO > 0
+#if CONF_IS_DEFINED_SET (_POSIX_SYNCHRONIZED_IO)
       return _POSIX_SYNCHRONIZED_IO;
 #else
       return -1;
 #endif
 
     case _SC_FSYNC:
-#if _POSIX_FSYNC > 0
+#if CONF_IS_DEFINED_SET (_POSIX_FSYNC)
       return _POSIX_FSYNC;
 #else
       return -1;
 #endif
 
     case _SC_MAPPED_FILES:
-#if _POSIX_MAPPED_FILES > 0
+#if CONF_IS_DEFINED_SET (_POSIX_MAPPED_FILES)
       return _POSIX_MAPPED_FILES;
 #else
       return -1;
 #endif
 
     case _SC_MEMLOCK:
-#if _POSIX_MEMLOCK > 0
+#if CONF_IS_DEFINED_SET (_POSIX_MEMLOCK)
       return _POSIX_MEMLOCK;
 #else
       return -1;
 #endif
 
     case _SC_MEMLOCK_RANGE:
-#if _POSIX_MEMLOCK_RANGE > 0
+#if CONF_IS_DEFINED_SET (_POSIX_MEMLOCK_RANGE)
       return _POSIX_MEMLOCK_RANGE;
 #else
       return -1;
 #endif
 
     case _SC_MEMORY_PROTECTION:
-#if _POSIX_MEMORY_PROTECTION > 0
+#if CONF_IS_DEFINED_SET (_POSIX_MEMORY_PROTECTION)
       return _POSIX_MEMORY_PROTECTION;
 #else
       return -1;
 #endif
 
     case _SC_MESSAGE_PASSING:
-#if _POSIX_MESSAGE_PASSING > 0
+#if CONF_IS_DEFINED_SET (_POSIX_MESSAGE_PASSING)
       return _POSIX_MESSAGE_PASSING;
 #else
       return -1;
 #endif
 
     case _SC_SEMAPHORES:
-#if _POSIX_SEMAPHORES > 0
+#if CONF_IS_DEFINED_SET (_POSIX_SEMAPHORES)
       return _POSIX_SEMAPHORES;
 #else
       return -1;
 #endif
 
     case _SC_SHARED_MEMORY_OBJECTS:
-#if _POSIX_SHARED_MEMORY_OBJECTS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_SHARED_MEMORY_OBJECTS)
       return _POSIX_SHARED_MEMORY_OBJECTS;
 #else
       return -1;
@@ -353,49 +355,49 @@ __sysconf (name)
 #endif
 
     case _SC_PII:
-#if _POSIX_PII > 0
+#if CONF_IS_DEFINED_SET (_POSIX_PII)
       return 1;
 #else
       return -1;
 #endif
 
     case _SC_PII_XTI:
-#if _POSIX_PII_XTI > 0
+#if CONF_IS_DEFINED_SET (_POSIX_PII_XTI)
       return 1;
 #else
       return -1;
 #endif
 
     case _SC_PII_SOCKET:
-#if _POSIX_PII_SOCKET > 0
+#if CONF_IS_DEFINED_SET (_POSIX_PII_SOCKET)
       return 1;
 #else
       return -1;
 #endif
 
     case _SC_PII_INTERNET:
-#if _POSIX_PII_INTERNET > 0
+#if CONF_IS_DEFINED_SET (_POSIX_PII_INTERNET)
       return 1;
 #else
       return -1;
 #endif
 
     case _SC_PII_OSI:
-#if _POSIX_PII_OSI > 0
+#if CONF_IS_DEFINED_SET (_POSIX_PII_OSI)
       return 1;
 #else
       return -1;
 #endif
 
     case _SC_POLL:
-#if _POSIX_POLL > 0
+#if CONF_IS_DEFINED_SET (_POSIX_POLL)
       return 1;
 #else
       return -1;
 #endif
 
     case _SC_SELECT:
-#if _POSIX_SELECT > 0
+#if CONF_IS_DEFINED_SET (_POSIX_SELECT)
       return 1;
 #else
       return -1;
@@ -410,35 +412,35 @@ __sysconf (name)
 #endif
 
     case _SC_PII_INTERNET_STREAM:
-#if _POSIX_PII_INTERNET_STREAM > 0
+#if CONF_IS_DEFINED_SET (_POSIX_PII_INTERNET_STREAM)
       return 1;
 #else
       return -1;
 #endif
 
     case _SC_PII_INTERNET_DGRAM:
-#if _POSIX_PII_INTERNET_DGRAM > 0
+#if CONF_IS_DEFINED_SET (_POSIX_PII_INTERNET_DGRAM)
       return 1;
 #else
       return -1;
 #endif
 
     case _SC_PII_OSI_COTS:
-#if _POSIX_PII_OSI_COTS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_PII_OSI_COTS)
       return 1;
 #else
       return -1;
 #endif
 
     case _SC_PII_OSI_CLTS:
-#if _POSIX_PII_OSI_CLTS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_PII_OSI_CLTS)
       return 1;
 #else
       return -1;
 #endif
 
     case _SC_PII_OSI_M:
-#if _POSIX_PII_OSI_M > 0
+#if CONF_IS_DEFINED_SET (_POSIX_PII_OSI_M)
       return 1;
 #else
       return -1;
@@ -519,14 +521,14 @@ __sysconf (name)
 
       /* POSIX 1003.1c (POSIX Threads).  */
     case _SC_THREADS:
-#if _POSIX_THREADS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_THREADS)
       return _POSIX_THREADS;
 #else
       return -1;
 #endif
 
     case _SC_THREAD_SAFE_FUNCTIONS:
-#if _POSIX_THREAD_SAFE_FUNCTIONS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_THREAD_SAFE_FUNCTIONS)
       return _POSIX_THREAD_SAFE_FUNCTIONS;
 #else
       return -1;
@@ -553,7 +555,7 @@ __sysconf (name)
 #endif
 
     case _SC_THREAD_DESTRUCTOR_ITERATIONS:
-#if _POSIX_THREAD_DESTRUCTOR_ITERATIONS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_THREAD_DESTRUCTOR_ITERATIONS)
       return _POSIX_THREAD_DESTRUCTOR_ITERATIONS;
 #else
       return -1;
@@ -581,42 +583,42 @@ __sysconf (name)
 #endif
 
     case _SC_THREAD_ATTR_STACKADDR:
-#if _POSIX_THREAD_ATTR_STACKADDR > 0
+#if CONF_IS_DEFINED_SET (_POSIX_THREAD_ATTR_STACKADDR)
       return _POSIX_THREAD_ATTR_STACKADDR;
 #else
       return -1;
 #endif
 
     case _SC_THREAD_ATTR_STACKSIZE:
-#if _POSIX_THREAD_ATTR_STACKSIZE > 0
+#if CONF_IS_DEFINED_SET (_POSIX_THREAD_ATTR_STACKSIZE)
       return _POSIX_THREAD_ATTR_STACKSIZE;
 #else
       return -1;
 #endif
 
     case _SC_THREAD_PRIORITY_SCHEDULING:
-#if _POSIX_THREAD_PRIORITY_SCHEDULING > 0
+#if CONF_IS_DEFINED_SET (_POSIX_THREAD_PRIORITY_SCHEDULING)
       return _POSIX_THREAD_PRIORITY_SCHEDULING;
 #else
       return -1;
 #endif
 
     case _SC_THREAD_PRIO_INHERIT:
-#if _POSIX_THREAD_PRIO_INHERIT > 0
+#if CONF_IS_DEFINED_SET (_POSIX_THREAD_PRIO_INHERIT)
       return _POSIX_THREAD_PRIO_INHERIT;
 #else
       return -1;
 #endif
 
     case _SC_THREAD_PRIO_PROTECT:
-#if _POSIX_THREAD_PRIO_PROTECT > 0
+#if CONF_IS_DEFINED_SET (_POSIX_THREAD_PRIO_PROTECT)
       return _POSIX_THREAD_PRIO_PROTECT;
 #else
       return -1;
 #endif
 
     case _SC_THREAD_PROCESS_SHARED:
-#if _POSIX_THREAD_PROCESS_SHARED > 0
+#if CONF_IS_DEFINED_SET (_POSIX_THREAD_PROCESS_SHARED)
       return _POSIX_THREAD_PROCESS_SHARED;
 #else
       return -1;
@@ -833,152 +835,152 @@ __sysconf (name)
 #endif
 
     case _SC_ADVISORY_INFO:
-#if _POSIX_ADVISORY_INFO > 0
+#if CONF_IS_DEFINED_SET (_POSIX_ADVISORY_INFO)
       return _POSIX_ADVISORY_INFO;
 #else
       return -1;
 #endif
 
     case _SC_BARRIERS:
-#if _POSIX_BARRIERS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_BARRIERS)
       return _POSIX_BARRIERS;
 #else
       return -1;
 #endif
 
     case _SC_BASE:
-#if _POSIX_BASE > 0
+#if CONF_IS_DEFINED_SET (_POSIX_BASE)
       return _POSIX_BASE;
 #else
       return -1;
 #endif
     case _SC_C_LANG_SUPPORT:
-#if _POSIX_C_LANG_SUPPORT > 0
+#if CONF_IS_DEFINED_SET (_POSIX_C_LANG_SUPPORT)
       return _POSIX_C_LANG_SUPPORT;
 #else
       return -1;
 #endif
     case _SC_C_LANG_SUPPORT_R:
-#if _POSIX_C_LANG_SUPPORT_R > 0
+#if CONF_IS_DEFINED_SET (_POSIX_C_LANG_SUPPORT_R)
       return _POSIX_C_LANG_SUPPORT_R;
 #else
       return -1;
 #endif
 
     case _SC_CLOCK_SELECTION:
-#if _POSIX_CLOCK_SELECTION > 0
+#if CONF_IS_DEFINED_SET (_POSIX_CLOCK_SELECTION)
       return _POSIX_CLOCK_SELECTION;
 #else
       return -1;
 #endif
 
     case _SC_CPUTIME:
-#if _POSIX_CPUTIME > 0
+#if CONF_IS_DEFINED_SET (_POSIX_CPUTIME)
       return _POSIX_CPUTIME;
 #else
       return -1;
 #endif
 
     case _SC_DEVICE_IO:
-#if _POSIX_DEVICE_IO > 0
+#if CONF_IS_DEFINED_SET (_POSIX_DEVICE_IO)
       return _POSIX_DEVICE_IO;
 #else
       return -1;
 #endif
     case _SC_DEVICE_SPECIFIC:
-#if _POSIX_DEVICE_SPECIFIC > 0
+#if CONF_IS_DEFINED_SET (_POSIX_DEVICE_SPECIFIC)
       return _POSIX_DEVICE_SPECIFIC;
 #else
       return -1;
 #endif
     case _SC_DEVICE_SPECIFIC_R:
-#if _POSIX_DEVICE_SPECIFIC_R > 0
+#if CONF_IS_DEFINED_SET (_POSIX_DEVICE_SPECIFIC_R)
       return _POSIX_DEVICE_SPECIFIC_R;
 #else
       return -1;
 #endif
 
     case _SC_FD_MGMT:
-#if _POSIX_FD_MGMT > 0
+#if CONF_IS_DEFINED_SET (_POSIX_FD_MGMT)
       return _POSIX_FD_MGMT;
 #else
       return -1;
 #endif
 
     case _SC_FIFO:
-#if _POSIX_FIFO > 0
+#if CONF_IS_DEFINED_SET (_POSIX_FIFO)
       return _POSIX_FIFO;
 #else
       return -1;
 #endif
     case _SC_PIPE:
-#if _POSIX_PIPE > 0
+#if CONF_IS_DEFINED_SET (_POSIX_PIPE)
       return _POSIX_PIPE;
 #else
       return -1;
 #endif
 
     case _SC_FILE_ATTRIBUTES:
-#if _POSIX_FILE_ATTRIBUTES > 0
+#if CONF_IS_DEFINED_SET (_POSIX_FILE_ATTRIBUTES)
       return _POSIX_FILE_ATTRIBUTES;
 #else
       return -1;
 #endif
     case _SC_FILE_LOCKING:
-#if _POSIX_FILE_LOCKING > 0
+#if CONF_IS_DEFINED_SET (_POSIX_FILE_LOCKING)
       return _POSIX_FILE_LOCKING;
 #else
       return -1;
 #endif
     case _SC_FILE_SYSTEM:
-#if _POSIX_FILE_SYSTEM > 0
+#if CONF_IS_DEFINED_SET (_POSIX_FILE_SYSTEM)
       return _POSIX_FILE_SYSTEM;
 #else
       return -1;
 #endif
 
     case _SC_MONOTONIC_CLOCK:
-#if _POSIX_MONOTONIC_CLOCK
+#if CONF_IS_DEFINED_SET (_POSIX_MONOTONIC_CLOCK)
       return _POSIX_MONOTONIC_CLOCK;
 #else
       return -1;
 #endif
 
     case _SC_MULTI_PROCESS:
-#if _POSIX_MULTI_PROCESS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_MULTI_PROCESS)
       return _POSIX_MULTI_PROCESS;
 #else
       return -1;
 #endif
     case _SC_SINGLE_PROCESS:
-#if _POSIX_SINGLE_PROCESS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_SINGLE_PROCESS)
       return _POSIX_SINGLE_PROCESS;
 #else
       return -1;
 #endif
 
     case _SC_NETWORKING:
-#if _POSIX_NETWORKING > 0
+#if CONF_IS_DEFINED_SET (_POSIX_NETWORKING)
       return _POSIX_NETWORKING;
 #else
       return -1;
 #endif
 
     case _SC_READER_WRITER_LOCKS:
-#if _POSIX_READER_WRITER_LOCKS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_READER_WRITER_LOCKS)
       return _POSIX_READER_WRITER_LOCKS;
 #else
       return -1;
 #endif
     case _SC_SPIN_LOCKS:
-#if _POSIX_SPIN_LOCKS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_SPIN_LOCKS)
       return _POSIX_SPIN_LOCKS;
 #else
       return -1;
 #endif
 
     case _SC_REGEXP:
-#if _POSIX_REGEXP > 0
+#if CONF_IS_DEFINED_SET (_POSIX_REGEXP)
       return _POSIX_REGEXP;
 #else
       return -1;
@@ -989,81 +991,81 @@ __sysconf (name)
       return -1;
 
     case _SC_SHELL:
-#if _POSIX_SHELL > 0
+#if CONF_IS_DEFINED_SET (_POSIX_SHELL)
       return _POSIX_SHELL;
 #else
       return -1;
 #endif
 
     case _SC_SIGNALS:
-#ifdef _POSIX_SIGNALS
+#if CONF_IS_DEFINED (_POSIX_SIGNALS)
       return _POSIX_SIGNALS;
 #else
       return -1;
 #endif
 
     case _SC_SPAWN:
-#if _POSIX_SPAWN > 0
+#if CONF_IS_DEFINED_SET (_POSIX_SPAWN)
       return _POSIX_SPAWN;
 #else
       return -1;
 #endif
 
     case _SC_SPORADIC_SERVER:
-#if _POSIX_SPORADIC_SERVER > 0
+#if CONF_IS_DEFINED_SET (_POSIX_SPORADIC_SERVER)
       return _POSIX_SPORADIC_SERVER;
 #else
       return -1;
 #endif
     case _SC_THREAD_SPORADIC_SERVER:
-#if _POSIX_THREAD_SPORADIC_SERVER > 0
+#if CONF_IS_DEFINED_SET (_POSIX_THREAD_SPORADIC_SERVER)
       return _POSIX_THREAD_SPORADIC_SERVER;
 #else
       return -1;
 #endif
 
     case _SC_SYSTEM_DATABASE:
-#if _POSIX_SYSTEM_DATABASE > 0
+#if CONF_IS_DEFINED_SET (_POSIX_SYSTEM_DATABASE)
       return _POSIX_SYSTEM_DATABASE;
 #else
       return -1;
 #endif
     case _SC_SYSTEM_DATABASE_R:
-#if _POSIX_SYSTEM_DATABASE_R > 0
+#if CONF_IS_DEFINED_SET (_POSIX_SYSTEM_DATABASE_R)
       return _POSIX_SYSTEM_DATABASE_R;
 #else
       return -1;
 #endif
 
     case _SC_THREAD_CPUTIME:
-#if _POSIX_THREAD_CPUTIME > 0
+#if CONF_IS_DEFINED_SET (_POSIX_THREAD_CPUTIME)
       return _POSIX_THREAD_CPUTIME;
 #else
       return -1;
 #endif
 
     case _SC_TIMEOUTS:
-#if _POSIX_TIMEOUTS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_TIMEOUTS)
       return _POSIX_TIMEOUTS;
 #else
       return -1;
 #endif
 
     case _SC_TYPED_MEMORY_OBJECTS:
-#if _POSIX_TYPED_MEMORY_OBJECTS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_TYPED_MEMORY_OBJECTS)
       return _POSIX_TYPED_MEMORY_OBJECTS;
 #else
       return -1;
 #endif
 
     case _SC_USER_GROUPS:
-#if _POSIX_USER_GROUPS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_USER_GROUPS)
       return _POSIX_USER_GROUPS;
 #else
       return -1;
 #endif
     case _SC_USER_GROUPS_R:
-#if _POSIX_USER_GROUPS_R > 0
+#if CONF_IS_DEFINED_SET (_POSIX_USER_GROUPS_R)
       return _POSIX_USER_GROUPS_R;
 #else
       return -1;
@@ -1128,25 +1130,25 @@ __sysconf (name)
 #endif
 
     case _SC_TRACE:
-#if _POSIX_TRACE > 0
+#if CONF_IS_DEFINED_SET (_POSIX_TRACE)
       return _POSIX_TRACE;
 #else
       return -1;
 #endif
     case _SC_TRACE_EVENT_FILTER:
-#if _POSIX_TRACE_EVENT_FILTER > 0
+#if CONF_IS_DEFINED_SET (_POSIX_TRACE_EVENT_FILTER)
       return _POSIX_TRACE_EVENT_FILTER;
 #else
       return -1;
 #endif
     case _SC_TRACE_INHERIT:
-#if _POSIX_TRACE_INHERIT > 0
+#if CONF_IS_DEFINED_SET (_POSIX_TRACE_INHERIT)
       return _POSIX_TRACE_INHERIT;
 #else
       return -1;
 #endif
     case _SC_TRACE_LOG:
-#if _POSIX_TRACE_LOG > 0
+#if CONF_IS_DEFINED_SET (_POSIX_TRACE_LOG)
       return _POSIX_TRACE_LOG;
 #else
       return -1;
@@ -1183,14 +1185,14 @@ __sysconf (name)
       return 0;
 
     case _SC_IPV6:
-#if _POSIX_IPV6 > 0
+#if CONF_IS_DEFINED_SET (_POSIX_IPV6)
       return _POSIX_IPV6;
 #else
       return -1;
 #endif
 
     case _SC_RAW_SOCKETS:
-#if _POSIX_RAW_SOCKETS > 0
+#if CONF_IS_DEFINED_SET (_POSIX_RAW_SOCKETS)
       return _POSIX_RAW_SOCKETS;
 #else
       return -1;
-- 
1.9.3

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/4] Remove Wundef warnings for specification macros
  2014-09-19 10:20 ` [PATCH 1/4] Remove Wundef warnings for specification macros Siddhesh Poyarekar
@ 2014-09-23 12:57   ` Florian Weimer
  2014-09-23 14:46     ` Siddhesh Poyarekar
  0 siblings, 1 reply; 19+ messages in thread
From: Florian Weimer @ 2014-09-23 12:57 UTC (permalink / raw)
  To: Siddhesh Poyarekar, libc-alpha; +Cc: roland

On 09/19/2014 12:20 PM, Siddhesh Poyarekar wrote:
> +$(objpfx)confdefs-defs.h: conf.list Makefile
> +	$(make-target-directory)
> +	$(AWK) -f $(..)scripts/gen-conf.awk $< > $@.tmp
> +	mv -f $@.tmp $@

Missing dependency on $(..)scripts/gen-conf.awk, I think.

> diff --git a/posix/conf.list b/posix/conf.list
> new file mode 100644
> index 0000000..d048568
> --- /dev/null
> +++ b/posix/conf.list
> @@ -0,0 +1,23 @@
> +# Configuration variables identified by getconf.  The heading of each section
> +# is of the format TYPE:PREFIX:SC_PREFIX with the opening curly brace on the
> +# same line.  TYPE can either be SYSCONF, PATHCONF, CONFSTR or SPEC.  In the
> +# absence of SC_PREFIX, _SC is used as the SC_PREFIX.  Variable names are put
> +# one on each line with a curly brace on its own line ending the section.

“SPEC:POSIX” does not match the “TYPE:PREFIX:SC_PREFIX” pattern. 
Looking at the awk script, “:SC_PREFIX” appears superfluous.

    #ifdef __ILP32_OFF32_CFLAGS
    # if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFF32)
    #  error "__ILP32_OFF32_CFLAGS should not be defined"

I wonder what the purpose of these #errors are.  Is this intended to 
help with porting?

-- 
Florian Weimer / Red Hat Product Security

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/4] Remove Wundef warnings for specification macros
  2014-09-23 12:57   ` Florian Weimer
@ 2014-09-23 14:46     ` Siddhesh Poyarekar
  2014-10-01  9:15       ` [PATCH 1/4 v1.1] " Siddhesh Poyarekar
  0 siblings, 1 reply; 19+ messages in thread
From: Siddhesh Poyarekar @ 2014-09-23 14:46 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha, roland

[-- Attachment #1: Type: text/plain, Size: 1516 bytes --]

On Tue, Sep 23, 2014 at 02:57:18PM +0200, Florian Weimer wrote:
> On 09/19/2014 12:20 PM, Siddhesh Poyarekar wrote:
> >+$(objpfx)confdefs-defs.h: conf.list Makefile
> >+	$(make-target-directory)
> >+	$(AWK) -f $(..)scripts/gen-conf.awk $< > $@.tmp
> >+	mv -f $@.tmp $@
> 
> Missing dependency on $(..)scripts/gen-conf.awk, I think.

Right, thanks.

> 
> >diff --git a/posix/conf.list b/posix/conf.list
> >new file mode 100644
> >index 0000000..d048568
> >--- /dev/null
> >+++ b/posix/conf.list
> >@@ -0,0 +1,23 @@
> >+# Configuration variables identified by getconf.  The heading of each section
> >+# is of the format TYPE:PREFIX:SC_PREFIX with the opening curly brace on the
> >+# same line.  TYPE can either be SYSCONF, PATHCONF, CONFSTR or SPEC.  In the
> >+# absence of SC_PREFIX, _SC is used as the SC_PREFIX.  Variable names are put
> >+# one on each line with a curly brace on its own line ending the section.
> 
> “SPEC:POSIX” does not match the “TYPE:PREFIX:SC_PREFIX” pattern. Looking at
> the awk script, “:SC_PREFIX” appears superfluous.

Ugh, I wrote that description after Patch 4/4, which is why it shows
the final version of what the script does.  I'll fix it up.

> 
>    #ifdef __ILP32_OFF32_CFLAGS
>    # if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFF32)
>    #  error "__ILP32_OFF32_CFLAGS should not be defined"
> 
> I wonder what the purpose of these #errors are.  Is this intended to help
> with porting?

That was my impression.

Siddhesh

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 1/4 v1.1] Remove Wundef warnings for specification macros
  2014-09-23 14:46     ` Siddhesh Poyarekar
@ 2014-10-01  9:15       ` Siddhesh Poyarekar
  2014-12-18  0:41         ` Roland McGrath
  0 siblings, 1 reply; 19+ messages in thread
From: Siddhesh Poyarekar @ 2014-10-01  9:15 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha, roland

[-- Attachment #1: Type: text/plain, Size: 13368 bytes --]

Hi,

Here's an updated version of this patch based on Florian's feedback.
Tested on x86_64.

Siddhesh

commit 01f70b23d014d27898be8fa3d7a216c671007365
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date:   Wed Oct 1 14:34:08 2014 +0530

    Remove Wundef warnings for specification macros
    
    This patch adds a file conf.list that is used to generate macros to
    determine if a macro is defined as set, unset or not defined.
    gen-conf.awk processes this file and generates a header
    (confdefs-defs.h) with these macros.  A new header confdefs.h includes
    this generated header and defines accessor macros for the generated
    macros.
    
    Tested on x86_64.
    
    	* posix/Makefile (before-compile): Add confdefs-defs.h.
    	($(objpfx)confdefs-defs.h): New target.
    	* posix/conf.list: New file.
    	* posix/confdefs.h: New file.
    	* posix/confstr.c: Include confdefs.h.
    	(confstr): Use CONF_IS_* macros.
    	* posix/posix-envs.def: Include confdefs.h.  Use CONF_IS_*
    	macros.
    	* scripts/gen-conf.awk: New file.

diff --git a/posix/Makefile b/posix/Makefile
index e6b69b4..bdf6e73 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -99,7 +99,7 @@ others		:= getconf
 install-bin	:= getconf
 install-others-programs	:= $(inst_libexecdir)/getconf
 
-before-compile	+= testcases.h ptestcases.h
+before-compile	+= testcases.h ptestcases.h confdefs-defs.h
 
 # So they get cleaned up.
 generated += $(addprefix wordexp-test-result, 1 2 3 4 5 6 7 8 9 10) \
@@ -325,3 +325,8 @@ $(objpfx)getconf.speclist: getconf-speclist.c posix-envs.def
 # be built both makes it available for eyeball inspection and avoids the
 # surprise of things that look like compilation being done by 'make install'.
 others: $(objpfx)getconf.speclist
+
+$(objpfx)confdefs-defs.h: conf.list Makefile $(..)scripts/gen-conf.awk
+	$(make-target-directory)
+	$(AWK) -f $(..)scripts/gen-conf.awk $< > $@.tmp
+	mv -f $@.tmp $@
diff --git a/posix/conf.list b/posix/conf.list
new file mode 100644
index 0000000..3470895
--- /dev/null
+++ b/posix/conf.list
@@ -0,0 +1,22 @@
+# Configuration variables identified by getconf.  The heading of each section
+# is of the format TYPE:PREFIX with the opening curly brace on the same line.
+# TYPE can either be SYSCONF, PATHCONF, CONFSTR or SPEC.  Variable names are
+# put one on each line with a curly brace on its own line ending the section.
+
+SPEC:POSIX {
+  V6_ILP32_OFF32
+  V6_ILP32_OFFBIG
+  V6_LP64_OFF64
+  V6_LPBIG_OFFBIG
+  V7_ILP32_OFF32
+  V7_ILP32_OFFBIG
+  V7_LP64_OFF64
+  V7_LPBIG_OFFBIG
+}
+
+SPEC:XBS5 {
+  ILP32_OFF32
+  ILP32_OFFBIG
+  LP64_OFF64
+  LPBIG_OFFBIG
+}
diff --git a/posix/confdefs.h b/posix/confdefs.h
new file mode 100644
index 0000000..64f0e03
--- /dev/null
+++ b/posix/confdefs.h
@@ -0,0 +1,15 @@
+#ifndef __CONFDEFS_H__
+#define __CONFDEFS_H__
+
+#include <posix/confdefs-defs.h>
+
+#define CONF_DEF_UNDEFINED 1
+#define CONF_DEF_DEFINED_SET 2
+#define CONF_DEF_DEFINED_UNSET 3
+
+#define CONF_IS_DEFINED_SET(conf) (conf##_DEF == CONF_DEF_DEFINED_SET)
+#define CONF_IS_DEFINED_UNSET(conf) (conf##_DEF == CONF_DEF_DEFINED_UNSET)
+#define CONF_IS_UNDEFINED(conf) (conf##_DEF == CONF_DEF_UNDEFINED)
+#define CONF_IS_DEFINED(conf) (conf##_DEF != CONF_DEF_UNDEFINED)
+
+#endif
diff --git a/posix/confstr.c b/posix/confstr.c
index a2a1bf2..1accfee 100644
--- a/posix/confstr.c
+++ b/posix/confstr.c
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <confstr.h>
 #include "../version.h"
+#include "confdefs.h"
 
 /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes
    of BUF with the value corresponding to NAME and zero-terminate BUF.
@@ -100,9 +101,9 @@ confstr (name, buf, len)
     case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
     case _CS_POSIX_V7_ILP32_OFF32_CFLAGS:
 #ifdef __ILP32_OFF32_CFLAGS
-# if _POSIX_V7_ILP32_OFF32 == -1
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFF32)
 #  error "__ILP32_OFF32_CFLAGS should not be defined"
-# elif !defined _POSIX_V7_ILP32_OFF32
+# elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFF32)
       if (__sysconf (_SC_V7_ILP32_OFF32) < 0)
 	break;
 # endif
@@ -115,9 +116,9 @@ confstr (name, buf, len)
     case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:
     case _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS:
 #ifdef __ILP32_OFFBIG_CFLAGS
-# if _POSIX_V7_ILP32_OFFBIG == -1
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFFBIG)
 #  error "__ILP32_OFFBIG_CFLAGS should not be defined"
-# elif !defined _POSIX_V7_ILP32_OFFBIG
+# elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFFBIG)
       if (__sysconf (_SC_V7_ILP32_OFFBIG) < 0)
 	break;
 # endif
@@ -130,9 +131,9 @@ confstr (name, buf, len)
     case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
     case _CS_POSIX_V7_LP64_OFF64_CFLAGS:
 #ifdef __LP64_OFF64_CFLAGS
-# if _POSIX_V7_LP64_OFF64 == -1
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_LP64_OFF64)
 #  error "__LP64_OFF64_CFLAGS should not be defined"
-# elif !defined _POSIX_V7_LP64_OFF64
+# elif CONF_IS_UNDEFINED (_POSIX_V7_LP64_OFF64)
       if (__sysconf (_SC_V7_LP64_OFF64) < 0)
 	break;
 # endif
@@ -145,9 +146,9 @@ confstr (name, buf, len)
     case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
     case _CS_POSIX_V7_ILP32_OFF32_LDFLAGS:
 #ifdef __ILP32_OFF32_LDFLAGS
-# if _POSIX_V7_ILP32_OFF32 == -1
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFF32 )
 #  error "__ILP32_OFF32_LDFLAGS should not be defined"
-# elif !defined _POSIX_V7_ILP32_OFF32
+# elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFF32)
       if (__sysconf (_SC_V7_ILP32_OFF32) < 0)
 	break;
 # endif
@@ -160,9 +161,9 @@ confstr (name, buf, len)
     case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:
     case _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS:
 #ifdef __ILP32_OFFBIG_LDFLAGS
-# if _POSIX_V7_ILP32_OFFBIG == -1
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_ILP32_OFFBIG)
 #  error "__ILP32_OFFBIG_LDFLAGS should not be defined"
-# elif !defined _POSIX_V7_ILP32_OFFBIG
+# elif CONF_IS_UNDEFINED (_POSIX_V7_ILP32_OFFBIG)
       if (__sysconf (_SC_V7_ILP32_OFFBIG) < 0)
 	break;
 # endif
@@ -175,9 +176,9 @@ confstr (name, buf, len)
     case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
     case _CS_POSIX_V7_LP64_OFF64_LDFLAGS:
 #ifdef __LP64_OFF64_LDFLAGS
-# if _POSIX_V7_LP64_OFF64 == -1
+# if CONF_IS_DEFINED_UNSET (_POSIX_V7_LP64_OFF64)
 #  error "__LP64_OFF64_LDFLAGS should not be defined"
-# elif !defined _POSIX_V7_LP64_OFF64
+# elif CONF_IS_UNDEFINED (_POSIX_V7_LP64_OFF64)
       if (__sysconf (_SC_V7_LP64_OFF64) < 0)
 	break;
 # endif
@@ -188,7 +189,8 @@ confstr (name, buf, len)
 
     case _CS_LFS_CFLAGS:
     case _CS_LFS_LINTFLAGS:
-#if _POSIX_V6_ILP32_OFF32 == 1 && _POSIX_V6_ILP32_OFFBIG == 1
+#if (CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFF32) \
+     && CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFFBIG))
 # define __LFS_CFLAGS "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
       /* Signal that we want the new ABI.  */
       string = __LFS_CFLAGS;
diff --git a/posix/posix-envs.def b/posix/posix-envs.def
index 05043e9..9047d0c 100644
--- a/posix/posix-envs.def
+++ b/posix/posix-envs.def
@@ -42,35 +42,37 @@
    defined.  These are called with arguments V5, V6, V7 before and
    after the relevant groups of environments.  */
 
+#include "confdefs.h"
+
 START_ENV_GROUP (V7)
 
-#if _POSIX_V7_ILP32_OFF32 > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V7_ILP32_OFF32)
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
-#elif defined _POSIX_V7_ILP32_OFF32
+#elif CONF_IS_DEFINED (_POSIX_V7_ILP32_OFF32)
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
 #else
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
 #endif
 
-#if _POSIX_V7_ILP32_OFFBIG > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V7_ILP32_OFFBIG)
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
-#elif defined _POSIX_V7_ILP32_OFFBIG
+#elif CONF_IS_DEFINED (_POSIX_V7_ILP32_OFFBIG)
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
 #else
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
 #endif
 
-#if _POSIX_V7_LP64_OFF64 > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V7_LP64_OFF64)
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
-#elif defined _POSIX_V7_LP64_OFF64
+#elif CONF_IS_DEFINED (_POSIX_V7_LP64_OFF64)
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
 #else
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
 #endif
 
-#if _POSIX_V7_LPBIG_OFFBIG > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V7_LPBIG_OFFBIG)
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
-#elif defined _POSIX_V7_LPBIG_OFFBIG
+#elif CONF_IS_DEFINED (_POSIX_V7_LPBIG_OFFBIG)
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
 #else
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
@@ -80,33 +82,33 @@ END_ENV_GROUP (V7)
 
 START_ENV_GROUP (V6)
 
-#if _POSIX_V6_ILP32_OFF32 > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFF32)
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
-#elif defined _POSIX_V6_ILP32_OFF32
+#elif CONF_IS_DEFINED (_POSIX_V6_ILP32_OFF32)
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
 #else
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
 #endif
 
-#if _POSIX_V6_ILP32_OFFBIG > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V6_ILP32_OFFBIG)
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
-#elif defined _POSIX_V6_ILP32_OFFBIG
+#elif CONF_IS_DEFINED (_POSIX_V6_ILP32_OFFBIG)
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
 #else
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
 #endif
 
-#if _POSIX_V6_LP64_OFF64 > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V6_LP64_OFF64)
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
-#elif defined _POSIX_V6_LP64_OFF64
+#elif CONF_IS_DEFINED (_POSIX_V6_LP64_OFF64)
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
 #else
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
 #endif
 
-#if _POSIX_V6_LPBIG_OFFBIG > 0
+#if CONF_IS_DEFINED_SET (_POSIX_V6_LPBIG_OFFBIG)
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
-#elif defined _POSIX_V6_LPBIG_OFFBIG
+#elif CONF_IS_DEFINED (_POSIX_V6_LPBIG_OFFBIG)
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
 #else
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
@@ -116,33 +118,33 @@ END_ENV_GROUP (V6)
 
 START_ENV_GROUP (V5)
 
-#if _XBS5_ILP32_OFF32 > 0
+#if CONF_IS_DEFINED_SET (_XBS5_ILP32_OFF32)
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
-#elif defined _XBS5_ILP32_OFF32
+#elif CONF_IS_DEFINED (_XBS5_ILP32_OFF32)
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
 #else
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
 #endif
 
-#if _XBS5_ILP32_OFFBIG > 0
+#if CONF_IS_DEFINED_SET (_XBS5_ILP32_OFFBIG)
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
-#elif defined _XBS5_ILP32_OFFBIG
+#elif CONF_IS_DEFINED (_XBS5_ILP32_OFFBIG)
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
 #else
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
 #endif
 
-#if _XBS5_LP64_OFF64 > 0
+#if CONF_IS_DEFINED_SET (_XBS5_LP64_OFF64)
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
-#elif defined _XBS5_LP64_OFF64
+#elif CONF_IS_DEFINED (_XBS5_LP64_OFF64)
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
 #else
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
 #endif
 
-#if _XBS5_LPBIG_OFFBIG > 0
+#if CONF_IS_DEFINED_SET (_XBS5_LPBIG_OFFBIG)
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)
-#elif defined _XBS5_LPBIG_OFFBIG
+#elif CONF_IS_DEFINED (_XBS5_LPBIG_OFFBIG)
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)
 #else
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)
diff --git a/scripts/gen-conf.awk b/scripts/gen-conf.awk
new file mode 100644
index 0000000..45a4d44
--- /dev/null
+++ b/scripts/gen-conf.awk
@@ -0,0 +1,63 @@
+# Generate confdefs-defs.h with definitions for {CONF}_DEF for each
+# configuration variable that getconf or sysconf may use.  Currently it is
+# equipped only to generate such macros for specification macros and for
+# SYSCONF macros in the _POSIX namespace.
+
+BEGIN {
+  PROCINFO["sorted_in"] = "@val_type_asc"
+  prefix = ""
+}
+
+$1 ~ /^#/ || $0 ~ /^\s*$/ {
+  next
+}
+
+# Begin a new prefix.
+$2 == "{" {
+  split ($1, arr, ":")
+  type = arr[1]
+  prefix = arr[2]
+  next
+}
+
+$1 == "}" {
+  prefix = ""
+  type = ""
+  next
+}
+
+{
+  if (prefix == "" && type == "" && sc_prefix == "") {
+    print "Syntax error" > "/dev/stderr"
+    exit 1
+  }
+
+  # The prefix and variable names are indices and the value indicates what type
+  # of variable it is.  The possible options are:
+  # CONFSTR: A configuration string
+  # SYSCONF: A numeric value
+  # SPEC: A specification
+  conf[prefix][$1] = type
+}
+
+ENDFILE {
+  print "/* Autogenerated by gen-conf.awk.  */\n"
+
+  # Generate macros that specify if a sysconf macro is defined and/or set.
+  for (p in conf) {
+    for (c in conf[p]) {
+      printf "#ifndef _%s_%s\n", p, c
+      printf "# define _%s_%s_DEF CONF_DEF_UNDEFINED\n", p, c
+      # CONFSTR have string values and they are not set or unset.
+      if (conf[p][c] != "CONFSTR") {
+	printf "#else\n"
+	printf "# if _%s_%s > 0\n", p, c
+	printf "#  define _%s_%s_DEF CONF_DEF_DEFINED_SET\n", p, c
+	printf "# else\n"
+	printf "#  define _%s_%s_DEF CONF_DEF_DEFINED_UNSET\n", p, c
+	printf "# endif\n"
+      }
+      printf "#endif\n\n"
+    }
+  }
+}

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 4/4 v1.1] Use conf.list to generate spec array
  2014-09-19 10:20 ` [PATCH 4/4] Use conf.list to generate spec array Siddhesh Poyarekar
@ 2014-10-01  9:17   ` Siddhesh Poyarekar
  2014-12-18  0:48     ` Roland McGrath
  0 siblings, 1 reply; 19+ messages in thread
From: Siddhesh Poyarekar @ 2014-10-01  9:17 UTC (permalink / raw)
  To: libc-alpha; +Cc: roland

[-- Attachment #1: Type: text/plain, Size: 5716 bytes --]

This patch also had to be updated due to 1/4 to update the comment in
conf.list.  Tested on x86_64.

Siddhesh

commit 218aad6c5df66ad432b9083db7e3f0cb4da686d6
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date:   Wed Oct 1 14:36:03 2014 +0530

    Use conf.list to generate spec array
    
    This patch adds support to generate the spec array in getconf from the
    conf.list.  The generated code is mostly unchanged.  the only changes
    are due to the change in layout of the spec and val arrays in the ELF.
    
    The val array can also be auto-generated from conf.list once the
    remaining macros are added to it.
    
    	* posix/conf.list (SPEC:XBS5): Add sysconf prefix.
    	* posix/confstr.c: Define NEED_SPEC_ARRAY to 0.
    	* posix/posix-envs.def: Likewise.
    	* sysdeps/posix/sysconf.c: Likewise.
    	* posix/getconf.c: Define NEED_SPEC_ARRAY to 1.
    	(specs): Remove array.
    	* scripts/gen-conf.awk: Support generation of specs array.

diff --git a/posix/conf.list b/posix/conf.list
index 000b908..0a17666 100644
--- a/posix/conf.list
+++ b/posix/conf.list
@@ -1,7 +1,8 @@
 # Configuration variables identified by getconf.  The heading of each section
-# is of the format TYPE:PREFIX with the opening curly brace on the same line.
-# TYPE can either be SYSCONF, PATHCONF, CONFSTR or SPEC.  Variable names are
-# put one on each line with a curly brace on its own line ending the section.
+# is of the format TYPE:PREFIX:SC_PREFIX with the opening curly brace on the
+# same line.  TYPE can either be SYSCONF, PATHCONF, CONFSTR or SPEC.  In the
+# absence of SC_PREFIX, _SC is used as the SC_PREFIX.  Variable names are put
+# one on each line with a curly brace on its own line ending the section.
 
 SPEC:POSIX {
   V6_ILP32_OFF32
@@ -103,7 +104,7 @@ SYSCONF:POSIX {
   RAW_SOCKETS
 }
 
-SPEC:XBS5 {
+SPEC:XBS5:_SC_XBS5 {
   ILP32_OFF32
   ILP32_OFFBIG
   LP64_OFF64
diff --git a/posix/confstr.c b/posix/confstr.c
index 1accfee..0400d7f 100644
--- a/posix/confstr.c
+++ b/posix/confstr.c
@@ -21,7 +21,9 @@
 #include <string.h>
 #include <confstr.h>
 #include "../version.h"
-#include "confdefs.h"
+
+#define NEED_SPEC_ARRAY 0
+#include <confdefs.h>
 
 /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes
    of BUF with the value corresponding to NAME and zero-terminate BUF.
diff --git a/posix/getconf.c b/posix/getconf.c
index 14d51d8..3c08688 100644
--- a/posix/getconf.c
+++ b/posix/getconf.c
@@ -26,6 +26,9 @@
 #include "../version.h"
 #define PACKAGE _libc_intl_domainname
 
+#define NEED_SPEC_ARRAY 1
+#include <confdefs.h>
+
 struct conf
   {
     const char *name;
@@ -387,23 +390,6 @@ static const struct conf vars[] =
   };
 
 
-static const struct { const char *name; int num; } specs[] =
-  {
-    { "XBS5_ILP32_OFF32", _SC_XBS5_ILP32_OFF32 },
-    { "XBS5_ILP32_OFFBIG", _SC_XBS5_ILP32_OFFBIG },
-    { "XBS5_LP64_OFF64", _SC_XBS5_LP64_OFF64 },
-    { "XBS5_LPBIG_OFFBIG", _SC_XBS5_LPBIG_OFFBIG },
-    { "POSIX_V6_ILP32_OFF32", _SC_V6_ILP32_OFF32 },
-    { "POSIX_V6_ILP32_OFFBIG", _SC_V6_ILP32_OFFBIG },
-    { "POSIX_V6_LP64_OFF64", _SC_V6_LP64_OFF64 },
-    { "POSIX_V6_LPBIG_OFFBIG", _SC_V6_LPBIG_OFFBIG },
-    { "POSIX_V7_ILP32_OFF32", _SC_V7_ILP32_OFF32 },
-    { "POSIX_V7_ILP32_OFFBIG", _SC_V7_ILP32_OFFBIG },
-    { "POSIX_V7_LP64_OFF64", _SC_V7_LP64_OFF64 },
-    { "POSIX_V7_LPBIG_OFFBIG", _SC_V7_LPBIG_OFFBIG },
-  };
-static const int nspecs = sizeof (specs) / sizeof (specs[0]);
-
 extern const char *__progname;
 
 
diff --git a/posix/posix-envs.def b/posix/posix-envs.def
index 9047d0c..0b33e02 100644
--- a/posix/posix-envs.def
+++ b/posix/posix-envs.def
@@ -42,7 +42,8 @@
    defined.  These are called with arguments V5, V6, V7 before and
    after the relevant groups of environments.  */
 
-#include "confdefs.h"
+#define NEED_SPEC_ARRAY 0
+#include <confdefs.h>
 
 START_ENV_GROUP (V7)
 
diff --git a/scripts/gen-conf.awk b/scripts/gen-conf.awk
index 45a4d44..1370646 100644
--- a/scripts/gen-conf.awk
+++ b/scripts/gen-conf.awk
@@ -17,12 +17,17 @@ $2 == "{" {
   split ($1, arr, ":")
   type = arr[1]
   prefix = arr[2]
+  if (arr[3] != "")
+    sc_prefix = arr[3]
+  else
+    sc_prefix = "_SC"
   next
 }
 
 $1 == "}" {
   prefix = ""
   type = ""
+  sc_prefix = ""
   next
 }
 
@@ -37,6 +42,7 @@ $1 == "}" {
   # CONFSTR: A configuration string
   # SYSCONF: A numeric value
   # SPEC: A specification
+  sc_prefixes[prefix][$1] = sc_prefix
   conf[prefix][$1] = type
 }
 
@@ -58,6 +64,26 @@ ENDFILE {
 	printf "# endif\n"
       }
       printf "#endif\n\n"
+
+      # Build a name -> sysconf number associative array to print a C array at
+      # the end.
+      if (conf[p][c] == "SPEC") {
+	name = sprintf ("%s_%s", p, c)
+	num = sprintf ("%s_%s", sc_prefixes[p][c], c)
+	spec[name] = num
+      }
     }
   }
+
+  # Print the specification array.  Define the macro NEED_SPEC_ARRAY before
+  # including confdefs.h to make it available in the compilation unit.
+  print "#if NEED_SPEC_ARRAY"
+  print "static const struct { const char *name; int num; } specs[] ="
+  print "  {"
+  for (s in spec) {
+    printf "    { \"%s\", %s },\n", s, spec[s]
+  }
+  print "  };"
+  print "static const int nspecs = sizeof (specs) / sizeof (specs[0]);"
+  print "#endif"
 }
diff --git a/sysdeps/posix/sysconf.c b/sysdeps/posix/sysconf.c
index c7b748b..bff59f4 100644
--- a/sysdeps/posix/sysconf.c
+++ b/sysdeps/posix/sysconf.c
@@ -31,6 +31,7 @@
 #include <sys/types.h>
 #include <regex.h>
 
+#define NEED_SPEC_ARRAY 0
 #include <confdefs.h>
 
 

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PING] POSIX_* Wundef fixes
  2014-09-19 10:20 [PATCH 0/4] POSIX_* Wundef fixes Siddhesh Poyarekar
                   ` (3 preceding siblings ...)
  2014-09-19 10:30 ` [PATCH 2/4] Add _POSIX namespace SYSCONF macros to conf.list Siddhesh Poyarekar
@ 2014-11-05 11:11 ` Siddhesh Poyarekar
  2014-11-06  3:00   ` Roland McGrath
  2014-12-10  8:14   ` [PING2] " Siddhesh Poyarekar
  4 siblings, 2 replies; 19+ messages in thread
From: Siddhesh Poyarekar @ 2014-11-05 11:11 UTC (permalink / raw)
  To: libc-alpha; +Cc: roland

[-- Attachment #1: Type: text/plain, Size: 1740 bytes --]

This patch series is pending review:

- Remove Wundef warnings for specification macros
    http://patchwork.sourceware.org/patch/3045/

- Add _POSIX namespace SYSCONF macros to conf.list
    http://patchwork.sourceware.org/patch/2922/

- Use PTHREAD_DESTRUCTOR_ITERATIONS
    http://patchwork.sourceware.org/patch/2919/

- Use conf.list to generate spec array
    http://patchwork.sourceware.org/patch/3046/

Siddhesh

On Fri, Sep 19, 2014 at 03:50:03PM +0530, Siddhesh Poyarekar wrote:
> This patch set fixes Wundef warnings for all POSIX_* macros and also
> proposes a way to organize all of the sysconf variables so that
> they're generated from one place (posix/conf.list) and are hence
> typo-proof.  All patches have been verified on x86_64 to ensure that
> they don't result in any significant changes in generated code.
> 
> [PATCH 1/4] Remove Wundef warnings for specification macros
> 
> - This is the initial patch that adds the conf.list file and macros
>   and fixes one set of warnings.
> 
> [PATCH 2/4] Add _POSIX namespace SYSCONF macros to conf.list
> 
> - This is the second patch that adds the POSIX namespace sysconf
>   macros to the list and fixes the remaining warnings.
> 
> [PATCH 3/4] Use PTHREAD_DESTRUCTOR_ITERATIONS
> 
> - This patch replaces the POSIX_THREAD_DESTRUCTOR_ITERATIONS with a
>   view to unify getconf and sysconf usage.
> 
> [PATCH 4/4] Use conf.list to generate spec array
> 
> - This patch removes the hand-written specs variable and replaces it
>   with an auto-generated array.  The vars array can be similarly
>   replaced after adding all of its constituent variables to conf.list.
>   I'll do that once these patches are in.
> 
> Siddhesh
> 

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PING] POSIX_* Wundef fixes
  2014-11-05 11:11 ` [PING] POSIX_* Wundef fixes Siddhesh Poyarekar
@ 2014-11-06  3:00   ` Roland McGrath
  2014-12-10  8:14   ` [PING2] " Siddhesh Poyarekar
  1 sibling, 0 replies; 19+ messages in thread
From: Roland McGrath @ 2014-11-06  3:00 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: libc-alpha

Sorry it's been so long.  I hope to get to this this week.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PING2] POSIX_* Wundef fixes
  2014-11-05 11:11 ` [PING] POSIX_* Wundef fixes Siddhesh Poyarekar
  2014-11-06  3:00   ` Roland McGrath
@ 2014-12-10  8:14   ` Siddhesh Poyarekar
  1 sibling, 0 replies; 19+ messages in thread
From: Siddhesh Poyarekar @ 2014-12-10  8:14 UTC (permalink / raw)
  To: libc-alpha; +Cc: roland

[-- Attachment #1: Type: text/plain, Size: 577 bytes --]

Ping.  Patches are unchanged after a rebase.

Siddhesh

On Wed, Nov 05, 2014 at 04:40:58PM +0530, Siddhesh Poyarekar wrote:
> This patch series is pending review:
> 
> - Remove Wundef warnings for specification macros
>     http://patchwork.sourceware.org/patch/3045/
> 
> - Add _POSIX namespace SYSCONF macros to conf.list
>     http://patchwork.sourceware.org/patch/2922/
> 
> - Use PTHREAD_DESTRUCTOR_ITERATIONS
>     http://patchwork.sourceware.org/patch/2919/
> 
> - Use conf.list to generate spec array
>     http://patchwork.sourceware.org/patch/3046/

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/4 v1.1] Remove Wundef warnings for specification macros
  2014-10-01  9:15       ` [PATCH 1/4 v1.1] " Siddhesh Poyarekar
@ 2014-12-18  0:41         ` Roland McGrath
  0 siblings, 0 replies; 19+ messages in thread
From: Roland McGrath @ 2014-12-18  0:41 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: Florian Weimer, libc-alpha

"confdefs-defs" just seems like an inane name.  Please find something better.

I think "posix-conf-vars.list" would be a better name than "conf.list",
which sounds too generic.

> +$(objpfx)confdefs-defs.h: conf.list Makefile $(..)scripts/gen-conf.awk
> +	$(make-target-directory)
> +	$(AWK) -f $(..)scripts/gen-conf.awk $< > $@.tmp
> +	mv -f $@.tmp $@

The usual way we do this is:

$(objpfx)confdefs-defs.h: $(..)scripts/gen-conf.awk conf.list Makefile 
[...]
	$(AWK) -f $(filter-out Makefile, $^) > $@.tmp

> --- /dev/null
> +++ b/posix/confdefs.h
> @@ -0,0 +1,15 @@
> +#ifndef __CONFDEFS_H__
> +#define __CONFDEFS_H__

Missing comment and copyright header.  Guard macro is just _FOO_H, no
extra leading underscore and no trailing underscores.

> +#include <posix/confdefs-defs.h>

Where does posix/confdefs-defs.h come from??  Is that just hitting because
of -I$(common-objdir) and the generated code happens to be in the posix/
build subdirectory?

If you're including the generated file, just <confdefs-defs.h> is the right
syntax.  If it needs to be used by code compiled outside the posix/
subdirectory (which I don't think it should), then put the generated file
in $(common-objdir) directly.

As well as a new name for both this file and the generated file, this file
needs substantial commentary explaining the rationale and how to use the
macros.

> +#define CONF_DEF_UNDEFINED 1
> +#define CONF_DEF_DEFINED_SET 2
> +#define CONF_DEF_DEFINED_UNSET 3
> +
> +#define CONF_IS_DEFINED_SET(conf) (conf##_DEF == CONF_DEF_DEFINED_SET)
> +#define CONF_IS_DEFINED_UNSET(conf) (conf##_DEF == CONF_DEF_DEFINED_UNSET)
> +#define CONF_IS_UNDEFINED(conf) (conf##_DEF == CONF_DEF_UNDEFINED)
> +#define CONF_IS_DEFINED(conf) (conf##_DEF != CONF_DEF_UNDEFINED)

Style is to use tabs between the lhs and rhs to line up all the rhs.

Incidentally, it seems more proper to me to use a prefix for the
constructed magic macro names, rather than a suffix.  
i.e. CONF_DEF_##conf or the like.

> --- a/posix/confstr.c
> +++ b/posix/confstr.c
> @@ -21,6 +21,7 @@
>  #include <string.h>
>  #include <confstr.h>
>  #include "../version.h"
> +#include "confdefs.h"

Use <> syntax for generated files (or sysdeps files, or almost any case in
libc).

> --- /dev/null
> +++ b/scripts/gen-conf.awk

Let's give it a less generic-sounding name.  Maybe "posix-conf-vars"?

> +  PROCINFO["sorted_in"] = "@val_type_asc"

I couldn't even find what this means in the Gawk manual.  It's probably
better to avoid such obscure features if it's not prohibitive.  At the very
least, you need a clear comment about what this magic does.

> +# Begin a new prefix.
> +$2 == "{" {
> +  split ($1, arr, ":")
> +  type = arr[1]
> +  prefix = arr[2]
> +  next
> +}

Why not just make the syntax use separate words rather than splitting on a
colon?  If some are optional, match with $NF == "{".

> +{
> +  if (prefix == "" && type == "" && sc_prefix == "") {
> +    print "Syntax error" > "/dev/stderr"
> +    exit 1
> +  }

You can use FILENAME and FNR to produce C-x `-compatible error messages.

> +ENDFILE {

Just use END.

> +  print "/* Autogenerated by gen-conf.awk.  */\n"

Include "DO NOT EDIT!".

This is OK with those cleanups.


Thanks,
Roland

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/4] Add _POSIX namespace SYSCONF macros to conf.list
  2014-09-19 10:30 ` [PATCH 2/4] Add _POSIX namespace SYSCONF macros to conf.list Siddhesh Poyarekar
@ 2014-12-18  0:41   ` Roland McGrath
  0 siblings, 0 replies; 19+ messages in thread
From: Roland McGrath @ 2014-12-18  0:41 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: libc-alpha

OK modulo file renamings for 1/4.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/4] Use PTHREAD_DESTRUCTOR_ITERATIONS
  2014-09-19 10:20 ` [PATCH 3/4] Use PTHREAD_DESTRUCTOR_ITERATIONS Siddhesh Poyarekar
@ 2014-12-18  0:44   ` Roland McGrath
  2014-12-30  3:17     ` Siddhesh Poyarekar
  0 siblings, 1 reply; 19+ messages in thread
From: Roland McGrath @ 2014-12-18  0:44 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: libc-alpha

Is there any reason not to just add the _POSIX_* name to getconf?

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/4 v1.1] Use conf.list to generate spec array
  2014-10-01  9:17   ` [PATCH 4/4 v1.1] " Siddhesh Poyarekar
@ 2014-12-18  0:48     ` Roland McGrath
  2014-12-30  3:18       ` Siddhesh Poyarekar
  0 siblings, 1 reply; 19+ messages in thread
From: Roland McGrath @ 2014-12-18  0:48 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: libc-alpha

> +SPEC:XBS5:_SC_XBS5 {

As I mentioned in 1/4, just use whitespace as separator.
It simplifies the awk code.

> +  print "static const int nspecs = sizeof (specs) / sizeof (specs[0]);"

I know you are just reproducing what the current source has.
But this should be size_t and the loop referring to it changed too.

Otherwise OK.

Thanks,
Roland

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/4] Use PTHREAD_DESTRUCTOR_ITERATIONS
  2014-12-18  0:44   ` Roland McGrath
@ 2014-12-30  3:17     ` Siddhesh Poyarekar
  0 siblings, 0 replies; 19+ messages in thread
From: Siddhesh Poyarekar @ 2014-12-30  3:17 UTC (permalink / raw)
  To: Roland McGrath; +Cc: libc-alpha

[-- Attachment #1: Type: text/plain, Size: 309 bytes --]

On Wed, Dec 17, 2014 at 04:44:15PM -0800, Roland McGrath wrote:
> Is there any reason not to just add the _POSIX_* name to getconf?

There isn't.  I've dropped this patch.  When I move the variable list
from getconf.c to posix-conf-vars.list, the _POSIX_* name will
automatically get added.

Siddhesh

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/4 v1.1] Use conf.list to generate spec array
  2014-12-18  0:48     ` Roland McGrath
@ 2014-12-30  3:18       ` Siddhesh Poyarekar
  0 siblings, 0 replies; 19+ messages in thread
From: Siddhesh Poyarekar @ 2014-12-30  3:18 UTC (permalink / raw)
  To: Roland McGrath; +Cc: libc-alpha

[-- Attachment #1: Type: text/plain, Size: 242 bytes --]

On Wed, Dec 17, 2014 at 04:48:31PM -0800, Roland McGrath wrote:
> I know you are just reproducing what the current source has.
> But this should be size_t and the loop referring to it changed too.

I pushed it as a separate change.

Siddhesh

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 4/4] Use conf.list to generate spec array
  2014-09-19  8:33 [PATCH 2/4] Add _POSIX namespace SYSCONF macros to conf.list Siddhesh Poyarekar
@ 2014-09-19  8:33 ` Siddhesh Poyarekar
  0 siblings, 0 replies; 19+ messages in thread
From: Siddhesh Poyarekar @ 2014-09-19  8:33 UTC (permalink / raw)
  To: libc-alpha; +Cc: roland

---
 posix/conf.list         |  2 +-
 posix/confstr.c         |  4 +++-
 posix/getconf.c         | 20 +++-----------------
 posix/posix-envs.def    |  3 ++-
 scripts/gen-conf.awk    | 26 ++++++++++++++++++++++++++
 sysdeps/posix/sysconf.c |  1 +
 6 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/posix/conf.list b/posix/conf.list
index 07607b7..0a17666 100644
--- a/posix/conf.list
+++ b/posix/conf.list
@@ -104,7 +104,7 @@ SYSCONF:POSIX {
   RAW_SOCKETS
 }
 
-SPEC:XBS5 {
+SPEC:XBS5:_SC_XBS5 {
   ILP32_OFF32
   ILP32_OFFBIG
   LP64_OFF64
diff --git a/posix/confstr.c b/posix/confstr.c
index 1accfee..0400d7f 100644
--- a/posix/confstr.c
+++ b/posix/confstr.c
@@ -21,7 +21,9 @@
 #include <string.h>
 #include <confstr.h>
 #include "../version.h"
-#include "confdefs.h"
+
+#define NEED_SPEC_ARRAY 0
+#include <confdefs.h>
 
 /* If BUF is not NULL and LEN > 0, fill in at most LEN - 1 bytes
    of BUF with the value corresponding to NAME and zero-terminate BUF.
diff --git a/posix/getconf.c b/posix/getconf.c
index 14d51d8..3c08688 100644
--- a/posix/getconf.c
+++ b/posix/getconf.c
@@ -26,6 +26,9 @@
 #include "../version.h"
 #define PACKAGE _libc_intl_domainname
 
+#define NEED_SPEC_ARRAY 1
+#include <confdefs.h>
+
 struct conf
   {
     const char *name;
@@ -387,23 +390,6 @@ static const struct conf vars[] =
   };
 
 
-static const struct { const char *name; int num; } specs[] =
-  {
-    { "XBS5_ILP32_OFF32", _SC_XBS5_ILP32_OFF32 },
-    { "XBS5_ILP32_OFFBIG", _SC_XBS5_ILP32_OFFBIG },
-    { "XBS5_LP64_OFF64", _SC_XBS5_LP64_OFF64 },
-    { "XBS5_LPBIG_OFFBIG", _SC_XBS5_LPBIG_OFFBIG },
-    { "POSIX_V6_ILP32_OFF32", _SC_V6_ILP32_OFF32 },
-    { "POSIX_V6_ILP32_OFFBIG", _SC_V6_ILP32_OFFBIG },
-    { "POSIX_V6_LP64_OFF64", _SC_V6_LP64_OFF64 },
-    { "POSIX_V6_LPBIG_OFFBIG", _SC_V6_LPBIG_OFFBIG },
-    { "POSIX_V7_ILP32_OFF32", _SC_V7_ILP32_OFF32 },
-    { "POSIX_V7_ILP32_OFFBIG", _SC_V7_ILP32_OFFBIG },
-    { "POSIX_V7_LP64_OFF64", _SC_V7_LP64_OFF64 },
-    { "POSIX_V7_LPBIG_OFFBIG", _SC_V7_LPBIG_OFFBIG },
-  };
-static const int nspecs = sizeof (specs) / sizeof (specs[0]);
-
 extern const char *__progname;
 
 
diff --git a/posix/posix-envs.def b/posix/posix-envs.def
index 9047d0c..0b33e02 100644
--- a/posix/posix-envs.def
+++ b/posix/posix-envs.def
@@ -42,7 +42,8 @@
    defined.  These are called with arguments V5, V6, V7 before and
    after the relevant groups of environments.  */
 
-#include "confdefs.h"
+#define NEED_SPEC_ARRAY 0
+#include <confdefs.h>
 
 START_ENV_GROUP (V7)
 
diff --git a/scripts/gen-conf.awk b/scripts/gen-conf.awk
index 45a4d44..1370646 100644
--- a/scripts/gen-conf.awk
+++ b/scripts/gen-conf.awk
@@ -17,12 +17,17 @@ $2 == "{" {
   split ($1, arr, ":")
   type = arr[1]
   prefix = arr[2]
+  if (arr[3] != "")
+    sc_prefix = arr[3]
+  else
+    sc_prefix = "_SC"
   next
 }
 
 $1 == "}" {
   prefix = ""
   type = ""
+  sc_prefix = ""
   next
 }
 
@@ -37,6 +42,7 @@ $1 == "}" {
   # CONFSTR: A configuration string
   # SYSCONF: A numeric value
   # SPEC: A specification
+  sc_prefixes[prefix][$1] = sc_prefix
   conf[prefix][$1] = type
 }
 
@@ -58,6 +64,26 @@ ENDFILE {
 	printf "# endif\n"
       }
       printf "#endif\n\n"
+
+      # Build a name -> sysconf number associative array to print a C array at
+      # the end.
+      if (conf[p][c] == "SPEC") {
+	name = sprintf ("%s_%s", p, c)
+	num = sprintf ("%s_%s", sc_prefixes[p][c], c)
+	spec[name] = num
+      }
     }
   }
+
+  # Print the specification array.  Define the macro NEED_SPEC_ARRAY before
+  # including confdefs.h to make it available in the compilation unit.
+  print "#if NEED_SPEC_ARRAY"
+  print "static const struct { const char *name; int num; } specs[] ="
+  print "  {"
+  for (s in spec) {
+    printf "    { \"%s\", %s },\n", s, spec[s]
+  }
+  print "  };"
+  print "static const int nspecs = sizeof (specs) / sizeof (specs[0]);"
+  print "#endif"
 }
diff --git a/sysdeps/posix/sysconf.c b/sysdeps/posix/sysconf.c
index c7b748b..bff59f4 100644
--- a/sysdeps/posix/sysconf.c
+++ b/sysdeps/posix/sysconf.c
@@ -31,6 +31,7 @@
 #include <sys/types.h>
 #include <regex.h>
 
+#define NEED_SPEC_ARRAY 0
 #include <confdefs.h>
 
 
-- 
1.9.3

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2014-12-30  3:17 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-19 10:20 [PATCH 0/4] POSIX_* Wundef fixes Siddhesh Poyarekar
2014-09-19 10:20 ` [PATCH 4/4] Use conf.list to generate spec array Siddhesh Poyarekar
2014-10-01  9:17   ` [PATCH 4/4 v1.1] " Siddhesh Poyarekar
2014-12-18  0:48     ` Roland McGrath
2014-12-30  3:18       ` Siddhesh Poyarekar
2014-09-19 10:20 ` [PATCH 1/4] Remove Wundef warnings for specification macros Siddhesh Poyarekar
2014-09-23 12:57   ` Florian Weimer
2014-09-23 14:46     ` Siddhesh Poyarekar
2014-10-01  9:15       ` [PATCH 1/4 v1.1] " Siddhesh Poyarekar
2014-12-18  0:41         ` Roland McGrath
2014-09-19 10:20 ` [PATCH 3/4] Use PTHREAD_DESTRUCTOR_ITERATIONS Siddhesh Poyarekar
2014-12-18  0:44   ` Roland McGrath
2014-12-30  3:17     ` Siddhesh Poyarekar
2014-09-19 10:30 ` [PATCH 2/4] Add _POSIX namespace SYSCONF macros to conf.list Siddhesh Poyarekar
2014-12-18  0:41   ` Roland McGrath
2014-11-05 11:11 ` [PING] POSIX_* Wundef fixes Siddhesh Poyarekar
2014-11-06  3:00   ` Roland McGrath
2014-12-10  8:14   ` [PING2] " Siddhesh Poyarekar
  -- strict thread matches above, loose matches on Subject: below --
2014-09-19  8:33 [PATCH 2/4] Add _POSIX namespace SYSCONF macros to conf.list Siddhesh Poyarekar
2014-09-19  8:33 ` [PATCH 4/4] Use conf.list to generate spec array Siddhesh Poyarekar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).