From 03893561ee1207748ac52febca857af92d343725 Mon Sep 17 00:00:00 2001 From: fedor Date: Wed, 5 Jun 2002 03:51:12 +0000 Subject: [PATCH] Hack for bug in gcc 3.1 git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13774 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 11 +++++++++++ Documentation/coding-standards.texi | 16 ++++++++++++++-- Headers/gnustep/base/NSByteOrder.h | 19 ++++++++++++++++++- Source/GSFFIInvocation.m | 6 +++--- Source/externs.m | 2 ++ 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66711d856..03131fbdf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2002-06-04 Adam Fedor + + * Headers/gnustep/base/NSByteOrder.h: Hack for bug in gcc 3.1 + * Source/externs.m (_gcc3_1_hack): Idem. (modified patch from + benhur@inf.ufsm.br). + + * Source/GSFFIInvocation.m (gs_objc_msg_forward): Alloc closure + with fastMallocBuffer. + + * Documentation/coding-standards.texi: Update. + 2002-06-02 Richard Frith-Macdonald * Headers/Foundation/NSObject.h: Removed ([_dealloc]), diff --git a/Documentation/coding-standards.texi b/Documentation/coding-standards.texi index 64be88a97..e6a20dba2 100644 --- a/Documentation/coding-standards.texi +++ b/Documentation/coding-standards.texi @@ -71,6 +71,18 @@ This document explains the official coding standards which developers for GNUstep base should follow. Note that these standards are in addition to GNU coding standards, not a replacement of them. +To summarize, always add a ChangeLog message whenever your commit a +change. Make sure your patch, if possible, improves the operation of +the library, not just fixes things - i.e. there are many places where +things are just hacked together from long ago and really aren't +correct. It's better to rewrite the whole thing correctly, then just +make some temporary fix. + +Some particular pieces of code which may seem odd or wrong may in fact +be there for particular and obscure, but necessary reasons. If you +have questions, ask on @email{bug-gnustep@@gnu.org} or +@email{gnustep-dev@@gnu.org}. + @c ****************************************************************** @node ChangeLog Entries, Coding Style, Introduction, Top @section ChangeLog Entries @@ -134,7 +146,7 @@ x++, y++; Brackets should have space only before the leading bracket and after the trailing bracket (as in this example), though there are odd occasions -where those spcaes might be omitted ((eg. when brackets are doubled)). +where those spaces might be omitted ((eg. when brackets are doubled)). This applies to square brackets too. Where round brackets are used for type-casts or at the end of a statement, @@ -284,7 +296,7 @@ in use. @section Error Handling Initialization methods (e.g. -init) should, upon failure to -initialize the class, deallocate itself and return nil. This may mean +initialize the class, release itself and return nil. This may mean in certain cases, that it should catch exceptions, since the calling method will be expecting a nil object rather than an exception on failure. However, init methods should endeavor to provide some diff --git a/Headers/gnustep/base/NSByteOrder.h b/Headers/gnustep/base/NSByteOrder.h index fbf5d55f0..64516ded7 100644 --- a/Headers/gnustep/base/NSByteOrder.h +++ b/Headers/gnustep/base/NSByteOrder.h @@ -94,6 +94,12 @@ GSSwapHostI64ToLittle(gsu64 in) __attribute__((unused)); static inline gsu128 GSSwapHostI128ToLittle(gsu128 in) __attribute__((unused)); +#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1) +/* gcc 3.1 with option -O2 generates bad (i386?) code when compiling + the following inline functions inside a .m file. A call to a + dumb function seems to work. */ +extern void _gcc3_1_hack(void); +#endif static inline gsu16 GSSwapI16(gsu16 in) @@ -103,6 +109,9 @@ GSSwapI16(gsu16 in) gsu8 byt[2]; } dst; union swap *src = (union swap*)∈ +#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1) + _gcc3_1_hack(); +#endif dst.byt[0] = src->byt[1]; dst.byt[1] = src->byt[0]; return dst.num; @@ -116,6 +125,9 @@ GSSwapI32(gsu32 in) gsu8 byt[4]; } dst; union swap *src = (union swap*)∈ +#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1) + _gcc3_1_hack(); +#endif dst.byt[0] = src->byt[3]; dst.byt[1] = src->byt[2]; dst.byt[2] = src->byt[1]; @@ -131,6 +143,9 @@ GSSwapI64(gsu64 in) gsu8 byt[8]; } dst; union swap *src = (union swap*)∈ +#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1) + _gcc3_1_hack(); +#endif dst.byt[0] = src->byt[7]; dst.byt[1] = src->byt[6]; dst.byt[2] = src->byt[5]; @@ -150,6 +165,9 @@ GSSwapI128(gsu128 in) gsu8 byt[16]; } dst; union swap *src = (union swap*)∈ +#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1) + _gcc3_1_hack(); +#endif dst.byt[0] = src->byt[15]; dst.byt[1] = src->byt[14]; dst.byt[2] = src->byt[13]; @@ -293,7 +311,6 @@ NSSwapHostLongToLittle(unsigned long num) __attribute__((unused)); static inline unsigned short NSSwapHostShortToLittle(unsigned short num) __attribute__((unused)); - /* * Basic byte swapping routines and type conversions */ diff --git a/Source/GSFFIInvocation.m b/Source/GSFFIInvocation.m index a8e2ba5c8..7acbbaa54 100644 --- a/Source/GSFFIInvocation.m +++ b/Source/GSFFIInvocation.m @@ -167,12 +167,12 @@ static IMP gs_objc_msg_forward (SEL sel) NSCAssert1(sig, @"No signature for selector %@", NSStringFromSelector(sel)); /* Construct the frame and closure. */ - /* Note: We alloc cframe here, but it's passed to GSFFIInvocationCallback + /* Note: We malloc cframe here, but it's passed to GSFFIInvocationCallback where it becomes owned by the callback invocation, so we don't have to worry about freeing it */ cframe = cifframe_from_info([sig methodInfo], [sig numberOfArguments], NULL); - /* Free the closure through NSData */ - amemory = [NSMutableData dataWithLength: sizeof(ffi_closure)]; + /* Autorelease the closure through fastMallocBuffer */ + amemory = _fastMallocBuffer(sizeof(ffi_closure)); cclosure = [amemory mutableBytes]; if (cframe == NULL || cclosure == NULL) { diff --git a/Source/externs.m b/Source/externs.m index eff175d22..6a1c81661 100644 --- a/Source/externs.m +++ b/Source/externs.m @@ -688,3 +688,5 @@ const NSHashTableCallBacks NSPointerToStructHashCallBacks = (NSHT_describe_func_t) _NS_int_p_describe }; +/* For bug in gcc 3.1. See NSByteOrder.h */ +void _gcc3_1_hack(void){}