move compile-time assertions out of misc.c(#ifdef DEBUG) into Build.sh
This commit is contained in:
parent
73688b3b3c
commit
da83890648
54
Build.sh
54
Build.sh
@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.492 2011/12/02 22:55:45 tg Exp $'
|
||||
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.493 2011/12/03 00:01:26 tg Exp $'
|
||||
#-
|
||||
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
|
||||
# Thorsten Glaser <tg@mirbsd.org>
|
||||
@ -901,6 +901,7 @@ i=0
|
||||
if test $ct = gcc; then
|
||||
# The following tests run with -Werror (gcc only) if possible
|
||||
NOWARN=$DOWARN; phase=u
|
||||
ac_flags 0 wnooverflow -Wno-overflow
|
||||
ac_flags 1 fnostrictaliasing -fno-strict-aliasing
|
||||
ac_flags 1 fstackprotectorall -fstack-protector-all
|
||||
ac_flags 1 fwrapv -fwrapv
|
||||
@ -1173,7 +1174,7 @@ else
|
||||
#define EXTERN
|
||||
#define MKSH_INCLUDES_ONLY
|
||||
#include "sh.h"
|
||||
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.492 2011/12/02 22:55:45 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.493 2011/12/03 00:01:26 tg Exp $");
|
||||
int main(void) { printf("Hello, World!\n"); return (0); }
|
||||
EOF
|
||||
case $cm in
|
||||
@ -1488,6 +1489,55 @@ test 1 = $fv || check_categories="$check_categories no-histfile"
|
||||
ac_testdone
|
||||
ac_cppflags
|
||||
|
||||
save_CFLAGS=$CFLAGS
|
||||
test 1 = $HAVE_CAN_WNOOVERFLOW && CFLAGS="$CFLAGS -Wno-overflow"
|
||||
ac_testn compile_time_asserts_$$ '' 'whether compile-time assertions pass' <<-'EOF'
|
||||
#define MKSH_INCLUDES_ONLY
|
||||
#include "sh.h"
|
||||
struct ctasserts {
|
||||
#define cta(name, assertion) char name[(assertion) ? 1 : -1]
|
||||
/* this one should be defined by the standard */
|
||||
cta(char_is_1_char, (sizeof(char) == 1) && (sizeof(signed char) == 1) &&
|
||||
(sizeof(unsigned char) == 1));
|
||||
/* the next assertion is probably not really needed */
|
||||
cta(short_is_2_char, sizeof(short) == 2);
|
||||
cta(short_size_no_matter_of_signedness, sizeof(short) == sizeof(unsigned short));
|
||||
/* the next assertion is probably not really needed */
|
||||
cta(int_is_4_char, sizeof(int) == 4);
|
||||
cta(int_size_no_matter_of_signedness, sizeof(int) == sizeof(unsigned int));
|
||||
|
||||
cta(long_ge_int, sizeof(long) >= sizeof(int));
|
||||
|
||||
/* the next assertion is probably not really needed */
|
||||
cta(ari_is_4_char, sizeof(mksh_ari_t) == 4);
|
||||
/* but the next three are; we REQUIRE signed integer wraparound */
|
||||
cta(ari_is_signed, (mksh_ari_t)-1 < (mksh_ari_t)0);
|
||||
cta(ari_has_31_bit, 0 < (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 1));
|
||||
cta(ari_sign_32_bit_and_wrap,
|
||||
(mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 1) >
|
||||
(mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 2));
|
||||
/* the next assertion is probably not really needed */
|
||||
cta(uari_is_4_char, sizeof(mksh_uari_t) == 4);
|
||||
/* but the next four are; we REQUIRE unsigned integer wraparound */
|
||||
cta(uari_is_unsigned, (mksh_uari_t)-1 > (mksh_uari_t)0);
|
||||
cta(uari_has_31_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 2 + 1));
|
||||
cta(uari_has_32_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3));
|
||||
cta(uari_wrap_32_bit,
|
||||
(mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3) >
|
||||
(mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 4));
|
||||
|
||||
cta(sizet_size_no_matter_of_signedness, sizeof(ssize_t) == sizeof(size_t));
|
||||
cta(ptrdifft_sizet_same_size, sizeof(ptrdiff_t) == sizeof(size_t));
|
||||
cta(ptrdifft_voidptr_same_size, sizeof(ptrdiff_t) == sizeof(void *));
|
||||
cta(ptrdifft_funcptr_same_size, sizeof(ptrdiff_t) == sizeof(void (*)()));
|
||||
/* our formatting routines assume this */
|
||||
cta(ptr_fits_in_long, sizeof(ptrdiff_t) <= sizeof(long));
|
||||
};
|
||||
int main(void) { return (sizeof(struct ctasserts)); }
|
||||
EOF
|
||||
CFLAGS=$save_CFLAGS
|
||||
eval test 1 = \$HAVE_COMPILE_TIME_ASSERTS_$$ || exit 1
|
||||
|
||||
#
|
||||
# Compiler: Praeprocessor (only if needed)
|
||||
#
|
||||
|
15
misc.c
15
misc.c
@ -29,7 +29,7 @@
|
||||
#include <grp.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.177 2011/10/26 20:46:15 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.178 2011/12/03 00:01:27 tg Exp $");
|
||||
|
||||
/* type bits for unsigned char */
|
||||
unsigned char chtypes[UCHAR_MAX + 1];
|
||||
@ -1963,19 +1963,6 @@ chvt(const char *fn)
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
#define assert_eq(name, a, b) char name[a == b ? 1 : -1]
|
||||
#define assert_ge(name, a, b) char name[a >= b ? 1 : -1]
|
||||
assert_ge(intsize_is_okay, sizeof(int), 4);
|
||||
assert_eq(intsizes_are_okay, sizeof(int), sizeof(unsigned int));
|
||||
assert_ge(longsize_is_okay, sizeof(long), sizeof(int));
|
||||
assert_eq(arisize_is_okay, sizeof(mksh_ari_t), 4);
|
||||
assert_eq(uarisize_is_okay, sizeof(mksh_uari_t), 4);
|
||||
assert_eq(sizesizes_are_okay, sizeof(size_t), sizeof(ssize_t));
|
||||
assert_eq(ptrsizes_are_okay, sizeof(ptrdiff_t), sizeof(void *));
|
||||
assert_eq(ptrsize_is_sizet, sizeof(ptrdiff_t), sizeof(size_t));
|
||||
/* formatting routines assume this */
|
||||
assert_ge(ptr_fits_in_long, sizeof(long), sizeof(size_t));
|
||||
|
||||
char *
|
||||
strchr(char *p, int ch)
|
||||
{
|
||||
|
38
sh.h
38
sh.h
@ -151,10 +151,28 @@
|
||||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.507 2011/12/02 22:55:49 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.508 2011/12/03 00:01:28 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R40 2011/12/02"
|
||||
|
||||
/* arithmetics types */
|
||||
typedef int32_t mksh_ari_t;
|
||||
typedef uint32_t mksh_uari_t;
|
||||
|
||||
/* boolean type (no <stdbool.h> deliberately) */
|
||||
typedef unsigned char mksh_bool;
|
||||
#undef bool
|
||||
/* false MUST equal 0 */
|
||||
#undef false
|
||||
#undef true
|
||||
/* access macros for boolean type */
|
||||
#define bool mksh_bool
|
||||
/* values must have identity mapping between mksh_bool and short */
|
||||
#define false 0
|
||||
#define true 1
|
||||
/* make any-type into bool or short */
|
||||
#define tobool(cond) ((cond) ? true : false)
|
||||
|
||||
#ifndef MKSH_INCLUDES_ONLY
|
||||
|
||||
/* extra types */
|
||||
@ -344,24 +362,6 @@ extern int wcwidth(__WCHAR_TYPE__);
|
||||
#define BIT(i) (1 << (i))
|
||||
#define NELEM(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
||||
/* arithmetics types */
|
||||
typedef int32_t mksh_ari_t;
|
||||
typedef uint32_t mksh_uari_t;
|
||||
|
||||
/* boolean type (no <stdbool.h> deliberately) */
|
||||
typedef unsigned char mksh_bool;
|
||||
#undef bool
|
||||
/* false MUST equal 0 */
|
||||
#undef false
|
||||
#undef true
|
||||
/* access macros for boolean type */
|
||||
#define bool mksh_bool
|
||||
/* values must have identity mapping between mksh_bool and short */
|
||||
#define false 0
|
||||
#define true 1
|
||||
/* make any-type into bool or short */
|
||||
#define tobool(cond) ((cond) ? true : false)
|
||||
|
||||
/* these shall be smaller than 100 */
|
||||
#ifdef MKSH_CONSERVATIVE_FDS
|
||||
#define NUFILE 32 /* Number of user-accessible files */
|
||||
|
Loading…
x
Reference in New Issue
Block a user