summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrmanfredi <rmanfredi@2592e710-e01b-42a5-8df0-11608a6cc53d>2012-02-09 17:55:04 +0000
committerrmanfredi <rmanfredi@2592e710-e01b-42a5-8df0-11608a6cc53d>2012-02-09 17:55:04 +0000
commit079073d45867ae273825fe7b04659d8f00bfbd71 (patch)
treeca45c22d2fdebe87fe9db147252f62613eb33ca4
parent8233fb6494e96dff527497d4ae5eada2765be91b (diff)
Factorized definition of STATIC_ASSERT.
Converted integer and pointer size computations to allow cross-compiling. git-svn-id: svn://svn.code.sf.net/p/dist/code/trunk/dist@130 2592e710-e01b-42a5-8df0-11608a6cc53d
-rw-r--r--MANIFEST1
-rw-r--r--mcon/U/Assert.U17
-rw-r--r--mcon/U/alignbytes.U5
-rw-r--r--mcon/U/d_ipv6.U5
-rw-r--r--mcon/U/intsize.U119
-rw-r--r--mcon/U/ptrsize.U50
6 files changed, 86 insertions, 111 deletions
diff --git a/MANIFEST b/MANIFEST
index 54b558a..e0788cb 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -77,6 +77,7 @@ mcon/README Instructions on using metaconfig
mcon/U/ Holds Units for metaconfig
mcon/U/AAAAA.U Does magic before Head.U
mcon/U/Alpha_mieee.U Can -mieee be passed to cc?
+mcon/U/Assert.U Generates the "static_assert.h" file for tests
mcon/U/Begin.U "Beginning of configuration questions"
mcon/U/Checkcc.U A unit for checking the C compiler for sanity
mcon/U/Chk_MANI.U MANIFEST checks
diff --git a/mcon/U/Assert.U b/mcon/U/Assert.U
new file mode 100644
index 0000000..dfb33a1
--- /dev/null
+++ b/mcon/U/Assert.U
@@ -0,0 +1,17 @@
+?RCS:
+?RCS: Copyright (c) 2012 Raphael Manfredi
+?RCS:
+?RCS: You may redistribute only under the terms of the Artistic Licence,
+?RCS: as specified in the README file that comes with the distribution.
+?RCS: You may reuse parts of this distribution only within the terms of
+?RCS: that same Artistic Licence; a copy of which may be found at the root
+?RCS: of the source tree for dist 4.0.
+?RCS:
+?MAKE:Assert: cat
+?MAKE: -pick add $@ %<
+: static assertion checking include file
+$cat >static_assert.h <<'EOC'
+#define STATIC_ASSERT(expr) \
+ do { switch (0) { case ((expr) ? 1 : 0): case 0: break; } } while(0)
+EOC
+
diff --git a/mcon/U/alignbytes.U b/mcon/U/alignbytes.U
index f27fada..4a5764e 100644
--- a/mcon/U/alignbytes.U
+++ b/mcon/U/alignbytes.U
@@ -18,7 +18,7 @@
?RCS: Revision 3.0 1993/08/18 12:05:23 ram
?RCS: Baseline for dist 3.0 netwide release.
?RCS:
-?MAKE:alignbytes: Myread Trylink cat i_inttypes i_limits i_math
+?MAKE:alignbytes: Assert Myread Trylink cat i_inttypes i_limits i_math
?MAKE: -pick add $@ %<
?S:alignbytes:
?S: This variable holds the number of bytes required to align an
@@ -106,8 +106,7 @@ struct s {
union u b;
};
-#define STATIC_ASSERT(expr) \
- do { switch (0) { case ((expr) ? 1 : 0): case 0: break; } } while(0)
+#include "static_assert.h"
int
main(void)
diff --git a/mcon/U/d_ipv6.U b/mcon/U/d_ipv6.U
index 4d4b150..f2ed3f8 100644
--- a/mcon/U/d_ipv6.U
+++ b/mcon/U/d_ipv6.U
@@ -8,7 +8,7 @@
?RCS: that same Artistic Licence; a copy of which may be found at the root
?RCS: of the source tree for dist 4.0.
?RCS:
-?MAKE:d_ipv6: Trylink cat i_arpainet i_netdb i_syssock i_niin \
+?MAKE:d_ipv6: Assert Trylink cat i_arpainet i_netdb i_syssock i_niin \
i_winsock2 i_ws2tcpip
?MAKE: -pick add $@ %<
?S:d_ipv6:
@@ -52,8 +52,7 @@ case "$d_ipv6" in
#ifdef I_WS2TCPIP
#include "Ws2tcpip.h"
#endif
-#define STATIC_ASSERT(x) \
- do { switch (0) { case ((x) ? 1 : 0): case 0: break; } } while(0)
+#include "static_assert.h"
int main(void)
{
diff --git a/mcon/U/intsize.U b/mcon/U/intsize.U
index 38c5414..362ee4d 100644
--- a/mcon/U/intsize.U
+++ b/mcon/U/intsize.U
@@ -1,6 +1,6 @@
?RCS: $Id$
?RCS:
-?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
+?RCS: Copyright (c) 1991-1997, 2004-2006, 2012 Raphael Manfredi
?RCS:
?RCS: You may redistribute only under the terms of the Artistic Licence,
?RCS: as specified in the README file that comes with the distribution.
@@ -8,20 +8,7 @@
?RCS: that same Artistic Licence; a copy of which may be found at the root
?RCS: of the source tree for dist 4.0.
?RCS:
-?RCS: $Log: intsize.U,v $
-?RCS: Revision 3.0.1.2 1997/02/28 15:55:26 ram
-?RCS: patch61: avoid prompting the user if the test runs ok
-?RCS: patch61: moved code from longsize.U into there
-?RCS: patch61: new tests for shortsize as well
-?RCS:
-?RCS: Revision 3.0.1.1 1994/10/29 16:21:06 ram
-?RCS: patch36: added ?F: line for metalint file checking
-?RCS:
-?RCS: Revision 3.0 1993/08/18 12:08:52 ram
-?RCS: Baseline for dist 3.0 netwide release.
-?RCS:
-?MAKE:intsize longsize shortsize: \
- Myread cat rm +cc +optimize +ccflags +ldflags +libs
+?MAKE:intsize longsize shortsize: Assert Myread cat rm +cc +ccflags echo n c
?MAKE: -pick add $@ %<
?S:intsize:
?S: This variable contains the value of the INTSIZE symbol, which
@@ -47,78 +34,56 @@
?C: This symbol contains the value of sizeof(short) so that the C
?C: preprocessor can make decisions based on it.
?C:.
-?H:#define INTSIZE $intsize /**/
-?H:#define LONGSIZE $longsize /**/
-?H:#define SHORTSIZE $shortsize /**/
+?H:#define INTSIZE $intsize
+?H:#define LONGSIZE $longsize
+?H:#define SHORTSIZE $shortsize
?H:.
-?F:!intsize.out !intsize
+?T:types t size var
+?LINT: set intsize longsize shortsize
: check for lengths of integral types
echo " "
-case "$intsize" in
-'')
- echo "Checking to see how big your integers are..." >&4
- $cat >intsize.c <<'EOCP'
-#include <stdio.h>
-int main()
-{
+types=''
@if INTSIZE || intsize
- printf("intsize=%d;\n", sizeof(int));
+types="$types int"
@end
@if LONGSIZE || longsize
- printf("longsize=%d;\n", sizeof(long));
+types="$types long"
@end
@if SHORTSIZE || shortsize
- printf("shortsize=%d;\n", sizeof(short));
+types="$types short"
@end
- fflush(stdout);
- exit(0);
+for t in $types; do
+ $echo $n "Checking to see how big your ${t}s are...$c" >&4
+ for size in 2 4 8 16 error; do
+ $cat >try.c <<EOCP
+#include "static_assert.h"
+$t foo;
+int main()
+{
+ STATIC_ASSERT($size == sizeof(foo));
+ return 0;
}
EOCP
-# If $libs contains -lsfio, and sfio is mis-configured, then it
-# sometimes (apparently) runs and exits with a 0 status, but with no
-# output!. Thus we check with test -s whether we actually got any
-# output. I think it has to do with sfio's use of _exit vs. exit,
-# but I don't know for sure. --Andy Dougherty 1/27/97.
- if $cc $optimize $ccflags $ldflags -o intsize intsize.c $libs >/dev/null 2>&1 &&
- ./intsize > intsize.out 2>/dev/null && test -s intsize.out ; then
- eval `$cat intsize.out`
-@if INTSIZE || intsize
- echo "Your integers are $intsize bytes long."
-@end
-@if LONGSIZE || longsize
- echo "Your long integers are $longsize bytes long."
-@end
-@if SHORTSIZE || shortsize
- echo "Your short integers are $shortsize bytes long."
-@end
- else
- $cat >&4 <<EOM
-!
-Help! I can't compile and run the intsize test program: please enlighten me!
-(This is probably a misconfiguration in your system or libraries, and
-you really ought to fix it. Still, I'll try anyway.)
-!
-EOM
-@if INTSIZE || intsize
- dflt=4
- rp="What is the size of an integer (in bytes)?"
- . ./myread
- intsize="$ans"
-@end
-@if LONGSIZE || longsize
- dflt=$intsize
- rp="What is the size of a long integer (in bytes)?"
+ if $cc -c $ccflags try.c >/dev/null 2>&1; then break; fi
+ done
+ var=${t}size
+ case "$size" in
+ error)
+ echo " cannot compute it." >&4
+ case $t in
+ int) dflt=4;;
+ long) dflt=4;;
+ short) dflt=2;;
+ esac
+ rp="What is the size of the \"$t\" type (in bytes)?"
. ./myread
- longsize="$ans"
-@end
-@if SHORTSIZE || shortsize
- dflt=2
- rp="What is the size of a short integer (in bytes)?"
- . ./myread
- shortsize="$ans"
-@end
- fi
- ;;
-esac
-$rm -f intsize intsize.[co] intsize.out
+ eval $var="$ans"
+ ;;
+ *)
+ echo " $size bytes." >&4
+ eval $var=$size
+ ;;
+ esac
+done
+$rm -f try.*
diff --git a/mcon/U/ptrsize.U b/mcon/U/ptrsize.U
index 7a903aa..4e073d9 100644
--- a/mcon/U/ptrsize.U
+++ b/mcon/U/ptrsize.U
@@ -1,6 +1,6 @@
?RCS: $Id$
?RCS:
-?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
+?RCS: Copyright (c) 1991-1997, 2004-2006, 2012 Raphael Manfredi
?RCS:
?RCS: You may redistribute only under the terms of the Artistic Licence,
?RCS: as specified in the README file that comes with the distribution.
@@ -8,14 +8,7 @@
?RCS: that same Artistic Licence; a copy of which may be found at the root
?RCS: of the source tree for dist 4.0.
?RCS:
-?RCS: $Log: ptrsize.U,v $
-?RCS: Revision 3.0.1.1 1994/10/29 16:28:19 ram
-?RCS: patch36: added ?F: line for metalint file checking
-?RCS:
-?RCS: Revision 3.0 1993/08/18 12:09:37 ram
-?RCS: Baseline for dist 3.0 netwide release.
-?RCS:
-?MAKE:ptrsize: cat rm Myread +cc +ccflags
+?MAKE:ptrsize: Assert Myread cat rm +cc +ccflags echo n c
?MAKE: -pick add $@ %<
?S:ptrsize:
?S: This variable contains the value of the PTRSIZE symbol, which
@@ -25,34 +18,35 @@
?C: This symbol contains the size of a pointer, so that the C preprocessor
?C: can make decisions based on it.
?C:.
-?H:#define PTRSIZE $ptrsize /**/
+?H:#define PTRSIZE $ptrsize
?H:.
-?F:!try
+?T:size
: check for length of pointer
echo " "
-case "$ptrsize" in
-'')
- echo "Checking to see how big your pointers are..." >&4
- $cat >try.c <<'EOCP'
-#include <stdio.h>
+$echo $n "Checking to see how big your pointers are...$c" >&4
+for size in 2 4 8 16 error; do
+ $cat >try.c <<EOCP
+#include "static_assert.h"
+char *foo;
int main()
{
- printf("%d\n", sizeof(char *));
+ STATIC_ASSERT($size == sizeof(foo));
+ return 0;
}
EOCP
- if $cc $ccflags -o try try.c >/dev/null 2>&1 ; then
- dflt=`./try`
- else
- dflt='4'
- echo "(I can't seem to compile the test program. Guessing...)"
- fi
+ if $cc -c $ccflags try.c >/dev/null 2>&1; then break; fi
+done
+case "$size" in
+error)
+ echo " cannot compute it." >&4
+ rp="What is the size of a pointer type (in bytes)?"
+ . ./myread
+ ptrsize="$ans"
;;
*)
- dflt="$ptrsize"
+ echo " $size bytes." >&4
+ ptrsize=$size
;;
esac
-rp="What is the size of a pointer (in bytes)?"
-. ./myread
-ptrsize="$ans"
-$rm -f try.c try
+$rm -f try.*