Reapply some changes with modifications

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32074 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2011-02-11 14:07:49 +00:00
parent 336c7bf021
commit 51cf9b9cf9
4 changed files with 34 additions and 20 deletions

View file

@ -1,8 +1,14 @@
2011-02-11 Richard Frith-Macdonald <rfm@gnu.org>
Revert everything back to svn 32051 due to loads of commits of broken
code which have been occurring to fast for anyone to review, and either
don't compile or fail the testsuite.
* Source/NSPropertyList.m: Recommit with modification fixed and tested.
* Source/NSOperation.m: new tweak to avoid compiler warning.
* Source/GSPrivate.h: Recommit most recent version after testing.
2011-02-11 Richard Frith-Macdonald <rfm@gnu.org>
Revert everything back from boken code at 32071 to wrking code at 32051
due to loads of commits of code which have been occurring to fast for
anyone to review, and either don't compile or fail the testsuite.
Lets go through things checking that they at least compile with gcc
and pass the testsuite before we recommit them!

View file

@ -93,21 +93,41 @@ typedef struct objc_category* Category;
* arrays are allocated on the stack (for speed), but large arrays are
* allocated from the heap (to avoid stack overflow).
*/
#define GS_BEGINITEMBUF(P, S, T) { \
#if __GNUC__ > 3
__attribute__((unused)) static void GSFreeTempBuffer(void **b)
{
if (NULL != *b) free(*b);
}
# define GS_BEGINITEMBUF(P, S, T) { \
T _ibuf[GS_MAX_OBJECTS_FROM_STACK];\
T *P = _ibuf;\
__attribute__((cleanup(GSFreeTempBuffer))) void *_base = 0;\
if (S > GS_MAX_OBJECTS_FROM_STACK)\
{\
_base = malloc(S);\
P = _base;\
}
#else
# define GS_BEGINITEMBUF(P, S, T) { \
T _ibuf[(S) <= GS_MAX_OBJECTS_FROM_STACK ? (S) : 0]; \
T *_base = ((S) <= GS_MAX_OBJECTS_FROM_STACK) ? _ibuf \
: (T*)NSZoneMalloc(NSDefaultMallocZone(), (S) * sizeof(T)); \
T *(P) = _base;
#endif
/**
* Macro to manage memory for chunks of code that need to work with
* arrays of items. Use GS_BEGINITEMBUF() to start the block of code using
* the array and this macro to end it.
*/
#define GS_ENDITEMBUF() \
#if __GNUC__ > 3
# define GS_ENDITEMBUF() }
#else
# define GS_ENDITEMBUF() \
if (_base != _ibuf) \
NSZoneFree(NSDefaultMallocZone(), _base); \
}
#endif
/**
* Macro to manage memory for chunks of code that need to work with

View file

@ -570,8 +570,8 @@ static NSOperationQueue *mainQueue = nil;
if (total > 0)
{
BOOL invalidArg = NO;
GS_BEGINITEMBUF(buf, total, id)
NSUInteger toAdd = total;
GS_BEGINITEMBUF(buf, total, id)
[ops getObjects: buf];
for (index = 0; index < total; index++)

View file

@ -1464,22 +1464,13 @@ PString(NSString *obj, NSMutableData *output)
else if ([obj rangeOfCharacterFromSet: oldQuotables].length > 0
|| [obj characterAtIndex: 0] == '/')
{
unichar tmp[length <= 1024 ? length : 0];
unichar *ustring;
unichar *from;
unichar *end;
unsigned char *ptr;
int base = [output length];
int len = 0;
GS_BEGINITEMBUF(ustring, (length * sizeof(unichar)), unichar)
if (length <= 1024)
{
ustring = tmp;
}
else
{
ustring = NSAllocateCollectable(sizeof(unichar) * length, 0);
}
end = &ustring[length];
[obj getCharacters: ustring];
for (from = ustring; from < end; from++)
@ -1581,10 +1572,7 @@ PString(NSString *obj, NSMutableData *output)
}
*ptr++ = '"';
if (ustring != tmp)
{
NSZoneFree(NSDefaultMallocZone(), ustring);
}
GS_ENDITEMBUF();
}
else
{