This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Configure gets d_u32align wrong
[metaconfig.git] / U / perl / d_u32align.U
CommitLineData
d85168a5
JH
1?RCS: $Id$
2?RCS:
3?RCS: Copyright (c) 2001, Jarkko Hietaniemi
4?RCS:
5?RCS: You may redistribute only under the terms of the Artistic Licence,
6?RCS: as specified in the README file that comes with the distribution.
7?RCS: You may reuse parts of this distribution only within the terms of
8?RCS: that same Artistic Licence; a copy of which may be found at the root
9?RCS: of the source tree for dist 3.0.
10?RCS:
3b148aa9 11?MAKE:d_u32align: Compile cat rm Oldconfig run i_stdlib \
9589ed74 12 byteorder u32type Myread Setvar u8type signal_t
d85168a5
JH
13?MAKE: -pick add $@ %<
14?S:d_u32align:
15?S: This variable tells whether you must access character data
16?S: through U32-aligned pointers.
17?S:.
18?C:U32_ALIGNMENT_REQUIRED:
19?C: This symbol, if defined, indicates that you must access
20?C: character data through U32-aligned pointers.
21?C:.
98813c8a
JH
22?H:?%<:#ifndef U32_ALIGNMENT_REQUIRED
23?H:?%<:#$d_u32align U32_ALIGNMENT_REQUIRED /**/
24?H:?%<:#endif
d85168a5 25?H:.
d85168a5
JH
26$cat <<EOM
27
28Checking to see whether you can access character data unalignedly...
29EOM
a0d5d9d4
JH
30case "$d_u32align" in
31'') $cat >try.c <<EOCP
d85168a5 32#include <stdio.h>
3b148aa9
JH
33#$i_stdlib I_STDLIB
34#ifdef I_STDLIB
35#include <stdlib.h>
36#endif
d85168a5 37#define U32 $u32type
99457da0
JH
38#define BYTEORDER 0x$byteorder
39#define U8 $u8type
9589ed74
JH
40#include <signal.h>
41#ifdef SIGBUS
42$signal_t bletch(s) int s; { exit(4); }
43#endif
d85168a5
JH
44int main() {
45#if BYTEORDER == 0x1234 || BYTEORDER == 0x4321
6a2a4e4f 46 U8 buf[8];
d85168a5
JH
47 U32 *up;
48 int i;
49
50 if (sizeof(U32) != 4) {
51 printf("sizeof(U32) is not 4, but %d\n", sizeof(U32));
52 exit(1);
53 }
54
55 fflush(stdout);
56
9589ed74
JH
57#ifdef SIGBUS
58 signal(SIGBUS, bletch);
59#endif
60
6a2a4e4f
JH
61 buf[0] = 0;
62 buf[1] = 0;
63 buf[2] = 0;
64 buf[3] = 1;
750213d3 65 buf[4] = 0;
6a2a4e4f
JH
66 buf[5] = 0;
67 buf[6] = 0;
750213d3 68 buf[7] = 1;
6a2a4e4f 69
d85168a5
JH
70 for (i = 0; i < 4; i++) {
71 up = (U32*)(buf + i);
72 if (! ((*up == 1 << (8*i)) || /* big-endian */
73 (*up == 1 << (8*(3-i))) /* little-endian */
74 )
75 )
76 {
77 printf("read failed (%x)\n", *up);
78 exit(2);
79 }
80 }
81
82 /* write test */
83 for (i = 0; i < 4; i++) {
84 up = (U32*)(buf + i);
85 *up = 0xBeef;
86 if (*up != 0xBeef) {
87 printf("write failed (%x)\n", *up);
88 exit(3);
89 }
90 }
91
92 exit(0);
93#else
94 printf("1\n");
95 exit(1);
96#endif
97 return 0;
98}
99EOCP
100set try
101if eval $compile_ok; then
99457da0 102 echo "(Testing for character data alignment may crash the test. That's okay.)" >&4
0f00356b 103 $run ./try 2>&1 >/dev/null
d85168a5
JH
104 case "$?" in
105 0) cat >&4 <<EOM
106You can access character data pretty unalignedly.
107EOM
108 d_u32align="$undef"
109 ;;
110 *) cat >&4 <<EOM
111It seems that you must access character data in an aligned manner.
112EOM
113 d_u32align="$define"
114 ;;
115 esac
d85168a5
JH
116else
117 rp='Can you access character data at unaligned addresses?'
118 dflt='n'
119 . ./myread
120 case "$ans" in
121 [yY]*) d_u32align="$undef" ;;
122 *) d_u32align="$define" ;;
123 esac
124fi
6a9b907f 125$rm -f core core.try.* try.core
a0d5d9d4
JH
126;;
127esac
d85168a5 128