Solaris fixes for word alignment

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/freeze-1_0_0@9483 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 2001-03-23 18:48:55 +00:00
parent c947d43654
commit 099c2108ca
3 changed files with 28 additions and 0 deletions

View file

@ -210,6 +210,21 @@ serializeToInfo(id object, _NSSerializerInfo* info)
(*info->serImp)(info->data, serSel, slen);
dlen = (*info->lenImp)(info->data, lenSel);
(*info->setImp)(info->data, setSel, dlen + slen*sizeof(unichar));
#if NEED_WORD_ALIGNMENT
/*
* When packing data, an item may not be aligned on a
* word boundary, so we work with an aligned buffer
* and use memcmpy()
*/
if ((dlen % __alignof__(gsu32)) != 0)
{
unichar buffer[slen];
[object getCharacters: buffer];
memcpy((*info->datImp)(info->data, datSel) + dlen, buffer,
slen*sizeof(unichar));
}
else
#endif
[object getCharacters: (*info->datImp)(info->data, datSel) + dlen];
if (info->shouldUnique)
GSIMapAddPair(&info->map,

View file

@ -142,7 +142,13 @@ static inline int
decode (const void *ptr)
{
#if defined(WORDS_BIGENDIAN) && SIZEOF_INT == 4
#if NEED_WORD_ALIGNMENT
int value;
memcpy(&value, ptr, sizeof(int));
return value;
#else
return *(const int *) ptr;
#endif
#else /* defined(WORDS_BIGENDIAN) && SIZEOF_INT == 4 */
const unsigned char *p = ptr;
int result = *p & (1 << (CHAR_BIT - 1)) ? ~0 : 0;

View file

@ -9,6 +9,7 @@
#include <Foundation/NSException.h>
#include <Foundation/NSString.h>
#include <Foundation/NSThread.h>
#include <Foundation/NSAutoreleasePool.h>
#define N 10 /* Number of threads */
#define MAX_ITER 10000.0 /* Max number of iterations. */
@ -36,19 +37,23 @@ FILE *file;
- (void)runWith: (id)thing
{
int i, n;
CREATE_AUTORELEASE_POOL(pool);
NS_DURING
n = 1+(int)((MAX_ITER*rand())/(RAND_MAX+1.0));
fflush(stdout);
for (i = 0; i < n; i++)
{
fprintf(file, "%d ", i);
fflush(file);
}
fflush(stdout);
[NSException raise: @"Some exception" format: @"thread %d", ident];
NS_HANDLER
printf("%s: %s for thread %d\n", [[localException name] cString],
[[localException reason] cString], ident);
NS_ENDHANDLER
DESTROY(pool);
[NSThread exit];
}
@ -58,6 +63,7 @@ int main()
{
int i;
SingleThread *threads[N];
CREATE_AUTORELEASE_POOL(pool);
printf("We run %d threads.\n", N);
printf("Some of them might not raise exceptions,\n");
@ -81,5 +87,6 @@ int main()
printf("There's a runaway exception! Something is wrong!\n");
NS_ENDHANDLER
fclose(file);
DESTROY(pool);
return 0;
}