Add check for word alignment

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6551 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 2000-05-03 03:14:14 +00:00
parent 7240b53230
commit 130e7c9aa3
7 changed files with 117 additions and 6 deletions

View file

@ -1,3 +1,13 @@
2000-05-02 Adam Fedor <fedor@gnu.org>
* configure.in: Add check for word alignment. Also don't define
HAVE_SYS_PROC_EXE on systems that need fake main.
* Headers/gnustep/base/config.h.in: Add define if word-align needed.
* Source/NSData.m:
([NSDataStatic -deserializeTypeTag:andCrossRef:atCursor:]): Use
memcpy if word alignment needed.
([NSMutableDataMalloc -serializeTypeTag:andCrossRef:]): Likewise.
2000-04-28 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSConnection.m: ([+defaultConnection]) create receive port.

View file

@ -24,6 +24,9 @@
#undef VSPRINTF_RETURNS_LENGTH
#undef VASPRINTF_RETURNS_LENGTH
/* Define if your system needs to have short/int word aligned */
#undef NEED_WORD_ALIGNMENT
/* Define if you have the register_printf_function function. */
#undef HAVE_REGISTER_PRINTF_FUNCTION

View file

@ -2073,6 +2073,11 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
format: @"Range: (%u, 1) Size: %d",
*cursor, length];
}
#ifdef NEED_WORD_ALIGNMENT
if ((*cursor % __alignof__(gsu16)) == 0)
memcpy(&x, (bytes + *cursor), 2);
else
#endif
x = *(gsu16*)(bytes + *cursor);
*cursor += 2;
*ref = (unsigned int)GSSwapBigI16ToHost(x);
@ -2088,6 +2093,11 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
format: @"Range: (%u, 1) Size: %d",
*cursor, length];
}
#ifdef NEED_WORD_ALIGNMENT
if ((*cursor % __alignof__(gsu32)) == 0)
memcpy(&x, (bytes + *cursor), 4);
else
#endif
x = *(gsu32*)(bytes + *cursor);
*cursor += 4;
*ref = (unsigned int)GSSwapBigI32ToHost(x);
@ -2976,6 +2986,14 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
[self _grow: length + 3];
}
*(gsu8*)(bytes + length++) = tag;
#ifdef NEED_WORD_ALIGNMENT
if ((length % __alignof__(gsu16)) == 0)
{
x = GSSwapHostI16ToBig(x);
memcpy((bytes + length), &x, 2);
}
else
#endif
*(gsu16*)(bytes + length) = GSSwapHostI16ToBig(x);
length += 2;
}
@ -2989,6 +3007,14 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
[self _grow: length + 5];
}
*(gsu8*)(bytes + length++) = tag;
#ifdef NEED_WORD_ALIGNMENT
if ((length % __alignof__(gsu32)) == 0)
{
x = GSSwapHostI32ToBig(x);
memcpy((bytes + length), &x, 4);
}
else
#endif
*(gsu32*)(bytes + length) = GSSwapHostI32ToBig(x);
length += 4;
}

View file

@ -9,6 +9,9 @@
#undef VSPRINTF_RETURNS_LENGTH
#undef VASPRINTF_RETURNS_LENGTH
/* Define if your system needs to have short/int word aligned */
#undef NEED_WORD_ALIGNMENT
/* The number of bytes in a int. */
#undef SIZEOF_INT

13
config/config.align.c Normal file
View file

@ -0,0 +1,13 @@
/* This program will most likely crash on systems that need shorts and ints
to be word aligned
*/
int main ()
{
char buf[12];
short sval = 4;
int ival = 3;
*(short *)(buf+1) = sval;
*(int *)(buf+1) = ival;
exit (0);
}

48
configure vendored
View file

@ -4166,20 +4166,52 @@ fi
# Linux (and others?) /proc contains a symlink to the executable
# file from which the process loaded its code. This can be used
# by NSBundle.m to locate the main bundle.
sys_proc_fs_exe=no;
if test $sys_proc_fs = yes; then
echo $ac_n "checking link to executable in /proc""... $ac_c" 1>&6
echo "configure:4172: checking link to executable in /proc" >&5
echo "configure:4173: checking link to executable in /proc" >&5
if test -L /proc/self/exe; then
cat >> confdefs.h <<\EOF
#define HAVE_PROC_FS_EXE_LINK 1
EOF
sys_proc_fs_exe=yes;
echo "$ac_t""yes" 1>&6
else
echo "$ac_t""no" 1>&6
fi
fi
#--------------------------------------------------------------------
# Check if short and int values need to be word aligned
#--------------------------------------------------------------------
echo $ac_n "checking short/int need to be word aligned""... $ac_c" 1>&6
echo "configure:4186: checking short/int need to be word aligned" >&5
if test "$cross_compiling" = yes; then
NEED_WORD_ALIGNMENT=1
else
cat > conftest.$ac_ext <<EOF
#line 4191 "configure"
#include "confdefs.h"
#include "$srcdir/config/config.align.c"
EOF
if { (eval echo configure:4195: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
NEED_WORD_ALIGNMENT=0
else
echo "configure: failed program was:" >&5
cat conftest.$ac_ext >&5
rm -fr conftest*
NEED_WORD_ALIGNMENT=1
fi
rm -fr conftest*
fi
cat >> confdefs.h <<EOF
#define NEED_WORD_ALIGNMENT $NEED_WORD_ALIGNMENT
EOF
if test $NEED_WORD_ALIGNMENT = 1; then
echo "$ac_t""yes" 1>&6
else
echo "$ac_t""no" 1>&6
fi
#--------------------------------------------------------------------
# Tools for making a DLL.
@ -4257,6 +4289,12 @@ else
else
GS_FAKE_MAIN=1
fi
if test $sys_proc_fs_exe = yes; then
cat >> confdefs.h <<\EOF
#define HAVE_PROC_FS_EXE_LINK 1
EOF
fi
fi

View file

@ -655,16 +655,31 @@ fi
# Linux (and others?) /proc contains a symlink to the executable
# file from which the process loaded its code. This can be used
# by NSBundle.m to locate the main bundle.
sys_proc_fs_exe=no;
if test $sys_proc_fs = yes; then
AC_MSG_CHECKING(link to executable in /proc)
if test -L /proc/self/exe; then
AC_DEFINE(HAVE_PROC_FS_EXE_LINK)
sys_proc_fs_exe=yes;
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
fi
#--------------------------------------------------------------------
# Check if short and int values need to be word aligned
#--------------------------------------------------------------------
AC_MSG_CHECKING(short/int needs to be word aligned)
AC_TRY_RUN([#include "$srcdir/config/config.align.c"],
NEED_WORD_ALIGNMENT=0,
NEED_WORD_ALIGNMENT=1,
NEED_WORD_ALIGNMENT=1)
AC_DEFINE_UNQUOTED(NEED_WORD_ALIGNMENT, $NEED_WORD_ALIGNMENT)
if test $NEED_WORD_ALIGNMENT = 1; then
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
#--------------------------------------------------------------------
# Tools for making a DLL.
@ -737,6 +752,9 @@ else
else
GS_FAKE_MAIN=1
fi
if test $sys_proc_fs_exe = yes; then
AC_DEFINE(HAVE_PROC_FS_EXE_LINK)
fi
fi
AC_SUBST(GS_FAKE_MAIN)