Skip to content

Commit

Permalink
Reapply some changes with modifications
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32074 72102866-910b-0410-8b05-ffd578937521
  • Loading branch information
rfm committed Feb 11, 2011
1 parent 336c7bf commit 51cf9b9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
12 changes: 9 additions & 3 deletions ChangeLog
@@ -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!

Expand Down
24 changes: 22 additions & 2 deletions Source/GSPrivate.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Source/NSOperation.m
Expand Up @@ -570,8 +570,8 @@ - (void) addOperations: (NSArray *)ops
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++)
Expand Down
16 changes: 2 additions & 14 deletions Source/NSPropertyList.m
Expand Up @@ -1464,22 +1464,13 @@ static inline void Append(void *bytes, unsigned length, NSMutableData *dst)
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++)
Expand Down Expand Up @@ -1581,10 +1572,7 @@ static inline void Append(void *bytes, unsigned length, NSMutableData *dst)
}
*ptr++ = '"';

if (ustring != tmp)
{
NSZoneFree(NSDefaultMallocZone(), ustring);
}
GS_ENDITEMBUF();
}
else
{
Expand Down

0 comments on commit 51cf9b9

Please sign in to comment.