mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Fixes from dawn
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4761 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
90f2d8ad55
commit
207ba80b4a
8 changed files with 357 additions and 90 deletions
|
@ -1,3 +1,7 @@
|
|||
Wed Aug 25 15:44:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
Fixes for memory leak in property-list parsing from dawn.
|
||||
|
||||
Wed Aug 25 11:37:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/Makefile.postamble: Added rules to build some files without
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSException_h_GNUSTEP_BASE_INCLUDE
|
||||
|
@ -65,6 +65,7 @@ extern NSString *NSInternalInconsistencyException;
|
|||
extern NSString *NSInvalidArgumentException;
|
||||
extern NSString *NSMallocException;
|
||||
extern NSString *NSRangeException;
|
||||
extern NSString *NSCharacterConversionException;
|
||||
|
||||
/* Exception handler definitions */
|
||||
typedef struct _NSHandler
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSString_h_GNUSTEP_BASE_INCLUDE
|
||||
|
@ -241,16 +241,16 @@ enum {
|
|||
+ (NSString*) stringWithString: (NSString*) aString;
|
||||
+ (NSString*) localizedStringWithFormat: (NSString*) format, ...;
|
||||
+ (NSString*) stringWithFormat: (NSString*)format
|
||||
arguments: (va_list)argList;
|
||||
arguments: (va_list)argList;
|
||||
- (id) initWithFormat: (NSString*)format
|
||||
locale: (NSDictionary*)dictionary;
|
||||
locale: (NSDictionary*)dictionary;
|
||||
- (id) initWithFormat: (NSString*)format
|
||||
locale: (NSDictionary*)dictionary
|
||||
arguments: (va_list)argList;
|
||||
locale: (NSDictionary*)dictionary
|
||||
arguments: (va_list)argList;
|
||||
- (NSString*) substringWithRange: (NSRange)aRange;
|
||||
- (NSComparisonResult) caseInsensitiveCompare: (NSString*)aString;
|
||||
- (BOOL) writeToFile: (NSString*)filename
|
||||
atomically: (BOOL)useAuxiliaryFile;
|
||||
atomically: (BOOL)useAuxiliaryFile;
|
||||
- (double) doubleValue;
|
||||
+ (NSStringEncoding*)availableStringEncodings;
|
||||
+ (NSString*)localizedNameOfStringEncoding:(NSStringEncoding)encoding;
|
||||
|
@ -259,7 +259,7 @@ enum {
|
|||
contentsEnd:(unsigned int *)contentsEndIndex
|
||||
forRange:(NSRange)aRange;
|
||||
- (NSRange)lineRangeForRange:(NSRange)aRange;
|
||||
|
||||
- (const char*) lossyCString;
|
||||
#endif
|
||||
|
||||
#ifndef NO_GNUSTEP
|
||||
|
@ -312,7 +312,14 @@ compiler warning.
|
|||
@interface NSMutableString : NSString <NSMutableString>
|
||||
@end
|
||||
|
||||
/* Because the compiler thinks that @".." strings are NXConstantString's. */
|
||||
/*
|
||||
* Because the compiler thinks that @".." strings are NXConstantString's.
|
||||
* NB. An NXConstantString has a length and a pointer to char as it's ivars
|
||||
* but an NSGCString also has a hash value - the code has to be careful not
|
||||
* to use the _hash ivar if the class is actually an NXConstantString.
|
||||
* If you modify and NSGCString method to use the _hash ivar, you must
|
||||
* override that method in NXConstantString, to avoid using the ivar.
|
||||
*/
|
||||
#include <Foundation/NSGString.h>
|
||||
#include <Foundation/NSGCString.h>
|
||||
@interface NXConstantString : NSGCString
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -338,6 +338,15 @@ static IMP msInitImp; /* designated initialiser for mutable */
|
|||
return (const char*)r;
|
||||
}
|
||||
|
||||
- (const char *) lossyCString
|
||||
{
|
||||
unsigned char *r = (unsigned char*)_fastMallocBuffer(_count+1);
|
||||
|
||||
memcpy(r, _contents_chars, _count);
|
||||
r[_count] = '\0';
|
||||
return (const char*)r;
|
||||
}
|
||||
|
||||
- (void) getCString: (char*)buffer
|
||||
{
|
||||
memcpy(buffer, _contents_chars, _count);
|
||||
|
@ -453,8 +462,7 @@ static IMP msInitImp; /* designated initialiser for mutable */
|
|||
return NO;
|
||||
c = fastClassOfInstance(anObject);
|
||||
|
||||
if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString
|
||||
|| c == _fastCls._NXConstantString)
|
||||
if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString)
|
||||
{
|
||||
NSGCString *other = (NSGCString*)anObject;
|
||||
|
||||
|
@ -470,6 +478,16 @@ static IMP msInitImp; /* designated initialiser for mutable */
|
|||
return NO;
|
||||
return YES;
|
||||
}
|
||||
else if (c == _fastCls._NXConstantString)
|
||||
{
|
||||
NSGCString *other = (NSGCString*)anObject;
|
||||
|
||||
if (_count != other->_count)
|
||||
return NO;
|
||||
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
else if (c == _fastCls._NSGString || c == _fastCls._NSGMutableString)
|
||||
{
|
||||
if (strCompCsUs(self, anObject, 0, (NSRange){0,_count}) == NSOrderedSame)
|
||||
|
@ -494,8 +512,7 @@ static IMP msInitImp; /* designated initialiser for mutable */
|
|||
if (aString == nil)
|
||||
return NO;
|
||||
c = fastClassOfInstance(aString);
|
||||
if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString
|
||||
|| c == _fastCls._NXConstantString)
|
||||
if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString)
|
||||
{
|
||||
NSGCString *other = (NSGCString*)aString;
|
||||
|
||||
|
@ -511,6 +528,16 @@ static IMP msInitImp; /* designated initialiser for mutable */
|
|||
return NO;
|
||||
return YES;
|
||||
}
|
||||
else if (c == _fastCls._NXConstantString)
|
||||
{
|
||||
NSGCString *other = (NSGCString*)aString;
|
||||
|
||||
if (_count != other->_count)
|
||||
return NO;
|
||||
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
else if (c == _fastCls._NSGString || c == _fastCls._NSGMutableString)
|
||||
{
|
||||
if (strCompCsUs(self, aString, 0, (NSRange){0,_count}) == NSOrderedSame)
|
||||
|
@ -700,7 +727,7 @@ static IMP msInitImp; /* designated initialiser for mutable */
|
|||
[NSException raise: NSGenericException
|
||||
format: @"%@ at line %u", data.err, data.lin];
|
||||
}
|
||||
return result;
|
||||
return AUTORELEASE(result);
|
||||
}
|
||||
|
||||
- (NSDictionary*) propertyListFromStringsFileFormat
|
||||
|
@ -723,7 +750,7 @@ static IMP msInitImp; /* designated initialiser for mutable */
|
|||
[NSException raise: NSGenericException
|
||||
format: @"%@ at line %u", data.err, data.lin];
|
||||
}
|
||||
return result;
|
||||
return AUTORELEASE(result);
|
||||
}
|
||||
|
||||
- (NSRange) rangeOfComposedCharacterSequenceAtIndex: (unsigned)anIndex
|
||||
|
@ -1137,6 +1164,22 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
|
|||
|
||||
@implementation NXConstantString
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
[NSException raise: NSGenericException
|
||||
format: @"Attempt to allocate an NXConstantString"];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id) initWithCStringNoCopy: (char*)byteString
|
||||
length: (unsigned int)length
|
||||
fromZone: (NSZone*)zone
|
||||
{
|
||||
[NSException raise: NSGenericException
|
||||
format: @"Attempt to init an NXConstantString"];
|
||||
return nil;
|
||||
}
|
||||
|
||||
/*
|
||||
* NXConstantString overrides [-dealloc] so that it is never deallocated.
|
||||
* If we pass an NXConstantString to another process or record it in an
|
||||
|
@ -1213,4 +1256,139 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
|
|||
return (unichar)_contents_chars[index];
|
||||
}
|
||||
|
||||
- (unsigned) hash
|
||||
{
|
||||
return _fastImp._NSString_hash(self, @selector(hash));
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id)anObject
|
||||
{
|
||||
Class c;
|
||||
if (anObject == self)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
if (anObject == nil)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
c = fastClassOfInstance(anObject);
|
||||
|
||||
if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString
|
||||
|| c == _fastCls._NXConstantString)
|
||||
{
|
||||
NXConstantString *other = (NXConstantString*)anObject;
|
||||
|
||||
if (_count != other->_count)
|
||||
return NO;
|
||||
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
else if (c == _fastCls._NSGString || c == _fastCls._NSGMutableString)
|
||||
{
|
||||
if (strCompCsUs(self, anObject, 0, (NSRange){0,_count}) == NSOrderedSame)
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
else if (c == nil)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else if (fastClassIsKindOfClass(c, _fastCls._NSString))
|
||||
{
|
||||
return _fastImp._NSString_isEqualToString_(self,
|
||||
@selector(isEqualToString:), anObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) isEqualToString: (NSString*)aString
|
||||
{
|
||||
Class c;
|
||||
|
||||
if (aString == self)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
if (aString == nil)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
c = fastClassOfInstance(aString);
|
||||
if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString
|
||||
|| c == _fastCls._NXConstantString)
|
||||
{
|
||||
NXConstantString *other = (NXConstantString*)aString;
|
||||
|
||||
if (_count != other->_count)
|
||||
return NO;
|
||||
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
else if (c == _fastCls._NSGString || c == _fastCls._NSGMutableString)
|
||||
{
|
||||
if (strCompCsUs(self, aString, 0, (NSRange){0,_count}) == NSOrderedSame)
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
else if (c == nil)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else if (fastClassIsKindOfClass(c, _fastCls._NSString))
|
||||
{
|
||||
return _fastImp._NSString_isEqualToString_(self,
|
||||
@selector(isEqualToString:), aString);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (id) mutableCopy
|
||||
{
|
||||
NSGMutableCString *obj;
|
||||
|
||||
obj = (NSGMutableCString*)NSAllocateObject(_fastCls._NSGMutableCString,
|
||||
0, NSDefaultMallocZone());
|
||||
if (obj)
|
||||
{
|
||||
obj = (*msInitImp)(obj, msInitSel, _count);
|
||||
if (obj)
|
||||
{
|
||||
NXConstantString *tmp = (NXConstantString*)obj;
|
||||
|
||||
memcpy(tmp->_contents_chars, _contents_chars, _count);
|
||||
tmp->_count = _count;
|
||||
tmp->_hash = 0;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
- (id) mutableCopyWithZone: (NSZone*)z
|
||||
{
|
||||
NSGMutableCString *obj;
|
||||
|
||||
obj = (NSGMutableCString*)NSAllocateObject(_fastCls._NSGMutableCString, 0, z);
|
||||
if (obj)
|
||||
{
|
||||
obj = (*msInitImp)(obj, msInitSel, _count);
|
||||
if (obj)
|
||||
{
|
||||
NXConstantString *tmp = (NXConstantString*)obj;
|
||||
|
||||
memcpy(tmp->_contents_chars, _contents_chars, _count);
|
||||
tmp->_count = _count;
|
||||
tmp->_hash = 0; // No hash available yet.
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -110,13 +110,16 @@
|
|||
{
|
||||
Class c;
|
||||
if (anObject == self)
|
||||
return YES;
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
if (anObject == nil)
|
||||
return NO;
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
c = fastClassOfInstance(anObject);
|
||||
if (c == _fastCls._NSGString || c == _fastCls._NSGMutableString
|
||||
|| c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString
|
||||
|| c == _fastCls._NXConstantString)
|
||||
|| c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString)
|
||||
{
|
||||
NSGString *other = (NSGString*)anObject;
|
||||
NSRange r = {0, _count};
|
||||
|
@ -146,13 +149,28 @@
|
|||
}
|
||||
return NO;
|
||||
}
|
||||
else if (c == _fastCls._NXConstantString)
|
||||
{
|
||||
NSGString *other = (NSGString*)anObject;
|
||||
NSRange r = {0, _count};
|
||||
|
||||
if (strCompUsCs(self, other, 0, r) == NSOrderedSame)
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
else if (c == nil)
|
||||
return NO;
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else if (fastClassIsKindOfClass(c, _fastCls._NSString))
|
||||
return _fastImp._NSString_isEqualToString_(self,
|
||||
@selector(isEqualToString:), anObject);
|
||||
{
|
||||
return _fastImp._NSString_isEqualToString_(self,
|
||||
@selector(isEqualToString:), anObject);
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
// Initializing Newly Allocated Strings
|
||||
|
@ -388,7 +406,7 @@
|
|||
[NSException raise: NSGenericException
|
||||
format: @"%@ at line %u", data.err, data.lin];
|
||||
}
|
||||
return result;
|
||||
return AUTORELEASE(result);
|
||||
}
|
||||
|
||||
- (NSDictionary*) propertyListFromStringsFileFormat
|
||||
|
@ -411,7 +429,7 @@
|
|||
[NSException raise: NSGenericException
|
||||
format: @"%@ at line %u", data.err, data.lin];
|
||||
}
|
||||
return result;
|
||||
return AUTORELEASE(result);
|
||||
}
|
||||
|
||||
|
||||
|
@ -506,18 +524,23 @@ static inline void
|
|||
stringIncrementCountAndMakeHoleAt(NSGMutableStringStruct *self,
|
||||
int index, int size)
|
||||
{
|
||||
#ifndef STABLE_MEMCPY
|
||||
{
|
||||
int i;
|
||||
for (i = self->_count; i >= index; i--)
|
||||
self->_contents_chars[i+size] = self->_contents_chars[i];
|
||||
}
|
||||
#else
|
||||
memcpy(self->_contents_chars + index,
|
||||
self->_contents_chars + index + size,
|
||||
2*(self->_count - index));
|
||||
#endif /* STABLE_MEMCPY */
|
||||
(self->_count) += size;
|
||||
if (self->_count || size)
|
||||
{
|
||||
NSCAssert(index+size<=self->_count,@"index+size>length");
|
||||
NSCAssert(self->_count+size<=self->_capacity,@"length+size>capacity");
|
||||
#ifndef STABLE_MEMCPY
|
||||
{
|
||||
int i;
|
||||
for (i = self->_count; i >= index; i--)
|
||||
self->_contents_chars[i+size] = self->_contents_chars[i];
|
||||
}
|
||||
#else
|
||||
memcpy(self->_contents_chars + index,
|
||||
self->_contents_chars + index + size,
|
||||
2*(self->_count - index));
|
||||
#endif /* STABLE_MEMCPY */
|
||||
(self->_count) += size;
|
||||
};
|
||||
(self->_hash) = 0;
|
||||
}
|
||||
|
||||
|
@ -525,18 +548,22 @@ static inline void
|
|||
stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
|
||||
int index, int size)
|
||||
{
|
||||
(self->_count) -= size;
|
||||
#ifndef STABLE_MEMCPY
|
||||
{
|
||||
int i;
|
||||
for (i = index; i <= self->_count; i++)
|
||||
self->_contents_chars[i] = self->_contents_chars[i+size];
|
||||
}
|
||||
#else
|
||||
memcpy(self->_contents_chars + index + size,
|
||||
self->_contents_chars + index,
|
||||
2*(self->_count - index));
|
||||
#endif // STABLE_MEMCPY
|
||||
if (self->_count || size)
|
||||
{
|
||||
NSCAssert(index+size<=self->_count,@"index+size>length");
|
||||
(self->_count) -= size;
|
||||
#ifndef STABLE_MEMCPY
|
||||
{
|
||||
int i;
|
||||
for (i = index; i <= self->_count; i++)
|
||||
self->_contents_chars[i] = self->_contents_chars[i+size];
|
||||
}
|
||||
#else
|
||||
memcpy(self->_contents_chars + index + size,
|
||||
self->_contents_chars + index,
|
||||
2*(self->_count - index));
|
||||
#endif // STABLE_MEMCPY
|
||||
};
|
||||
(self->_hash) = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
/* Caveats:
|
||||
|
@ -536,10 +536,13 @@ handle_printf_atsign (FILE *stream,
|
|||
format_to_go = formatter_pos+2;
|
||||
continue;
|
||||
}
|
||||
/* Specifiers from K&R C 2nd ed. */
|
||||
spec_pos = strpbrk(formatter_pos+1, "dioxXucsfeEgGpn\0");
|
||||
switch (*spec_pos)
|
||||
{
|
||||
#ifndef powerpc
|
||||
/* FIXME: vsprintf on powerpc apparently advances the arg list
|
||||
so this doesn't need to be done. Make a more general check
|
||||
for this */
|
||||
case 'd': case 'i': case 'o':
|
||||
case 'x': case 'X': case 'u': case 'c':
|
||||
va_arg(arg_list, int);
|
||||
|
@ -558,8 +561,8 @@ handle_printf_atsign (FILE *stream,
|
|||
case 'n':
|
||||
va_arg(arg_list, int*);
|
||||
break;
|
||||
#endif /* NOT powerpc */
|
||||
case '\0':
|
||||
/* Make sure loop exits on next iteration. */
|
||||
spec_pos--;
|
||||
break;
|
||||
}
|
||||
|
@ -1398,8 +1401,21 @@ handle_printf_atsign (FILE *stream,
|
|||
|
||||
- (const char*) cString
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return NULL;
|
||||
NSData *d = [self dataUsingEncoding: _DefaultStringEncoding
|
||||
allowLossyConversion: NO];
|
||||
if (d == nil)
|
||||
{
|
||||
[NSException raise: NSCharacterConversionException
|
||||
format: @"unable to convert to cString"];
|
||||
}
|
||||
return (const char*)[d bytes];
|
||||
}
|
||||
|
||||
- (const char*) lossyCString
|
||||
{
|
||||
NSData *d = [self dataUsingEncoding: _DefaultStringEncoding
|
||||
allowLossyConversion: YES];
|
||||
return (const char*)[d bytes];
|
||||
}
|
||||
|
||||
- (unsigned) cStringLength
|
||||
|
@ -1551,7 +1567,7 @@ handle_printf_atsign (FILE *stream,
|
|||
char t;
|
||||
unsigned char *buff;
|
||||
|
||||
buff = (unsigned char*)NSZoneMalloc(NSDefaultMallocZone(), len);
|
||||
buff = (unsigned char*)NSZoneMalloc(NSDefaultMallocZone(), len+1);
|
||||
if (!flag)
|
||||
{
|
||||
for (count = 0; count < len; count++)
|
||||
|
@ -1587,6 +1603,7 @@ handle_printf_atsign (FILE *stream,
|
|||
}
|
||||
}
|
||||
}
|
||||
buff[count] = '\0';
|
||||
return [NSData dataWithBytesNoCopy: buff length: count];
|
||||
}
|
||||
else if (encoding == NSUnicodeStringEncoding)
|
||||
|
@ -2438,7 +2455,7 @@ handle_printf_atsign (FILE *stream,
|
|||
[NSException raise: NSGenericException
|
||||
format: @"%@ at line %u", data.err, data.lin];
|
||||
}
|
||||
return result;
|
||||
return AUTORELEASE(result);
|
||||
}
|
||||
|
||||
- (NSDictionary*) propertyListFromStringsFileFormat
|
||||
|
@ -2464,7 +2481,7 @@ handle_printf_atsign (FILE *stream,
|
|||
[NSException raise: NSGenericException
|
||||
format: @"%@ at line %u", data.err, data.lin];
|
||||
}
|
||||
return result;
|
||||
return AUTORELEASE(result);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -72,6 +72,7 @@ NSString *NSInternalInconsistencyException =
|
|||
NSString *NSInvalidArgumentException = @"NSInvalidArgumentException";
|
||||
NSString *NSMallocException = @"NSMallocException";
|
||||
NSString *NSRangeException = @"NSRangeException";
|
||||
NSString *NSCharacterConversionException = @"NSCharacterConversionException";
|
||||
|
||||
/* Exception handler */
|
||||
NSUncaughtExceptionHandler *_NSUncaughtExceptionHandler;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -85,9 +85,6 @@ static Class plDictionary;
|
|||
static id (*plSet)(id, SEL, id, id);
|
||||
static id (*plInit)(id, SEL, void*, unsigned) = 0;
|
||||
static id (*plAlloc)(Class, SEL, NSZone*);
|
||||
#ifndef GS_WITH_GC
|
||||
static id (*plAutorelease)(id, SEL);
|
||||
#endif
|
||||
#if GSPLUNI
|
||||
static SEL plSel = @selector(initWithCharacters:length:);
|
||||
#else
|
||||
|
@ -103,10 +100,6 @@ static void setupPl(Class c)
|
|||
[c methodForSelector: @selector(allocWithZone:)];
|
||||
plInit = (id (*)(id, SEL, void*, unsigned))
|
||||
[c instanceMethodForSelector: plSel];
|
||||
#ifndef GS_WITH_GC
|
||||
plAutorelease = (id (*)(id, SEL))
|
||||
[c instanceMethodForSelector: @selector(autorelease)];
|
||||
#endif
|
||||
plArray = [NSGMutableArray class];
|
||||
plAdd = (id (*)(id, SEL, id))
|
||||
[plArray instanceMethodForSelector: @selector(addObject:)];
|
||||
|
@ -366,9 +359,6 @@ static inline id parseQuotedString(pldata* pld)
|
|||
}
|
||||
obj = (*plAlloc)(plCls, @selector(allocWithZone:), NSDefaultMallocZone());
|
||||
obj = (*plInit)(obj, plSel, (void*)chars, pld->pos - start - shrink);
|
||||
#ifndef GS_WITH_GC
|
||||
(*plAutorelease)(obj, @selector(autorelease));
|
||||
#endif
|
||||
}
|
||||
pld->pos++;
|
||||
return obj;
|
||||
|
@ -388,9 +378,6 @@ static inline id parseUnquotedString(pldata *pld)
|
|||
}
|
||||
obj = (*plAlloc)(plCls, @selector(allocWithZone:), NSDefaultMallocZone());
|
||||
obj = (*plInit)(obj, plSel, (void*)&pld->ptr[start], pld->pos-start);
|
||||
#ifndef GS_WITH_GC
|
||||
(*plAutorelease)(obj, @selector(autorelease));
|
||||
#endif
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -405,8 +392,8 @@ static id parsePlItem(pldata* pld)
|
|||
{
|
||||
NSMutableDictionary *dict;
|
||||
|
||||
dict = [[[plDictionary allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCapacity: 0] autorelease];
|
||||
dict = [[plDictionary allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCapacity: 0];
|
||||
pld->pos++;
|
||||
while (skipSpace(pld) == YES && pld->ptr[pld->pos] != '}')
|
||||
{
|
||||
|
@ -417,30 +404,48 @@ static id parsePlItem(pldata* pld)
|
|||
if (key == nil)
|
||||
return nil;
|
||||
if (skipSpace(pld) == NO)
|
||||
return nil;
|
||||
{
|
||||
RELEASE(key);
|
||||
return nil;
|
||||
}
|
||||
if (pld->ptr[pld->pos] != '=')
|
||||
{
|
||||
pld->err = @"unexpected character (wanted '=')";
|
||||
RELEASE(key);
|
||||
return nil;
|
||||
}
|
||||
pld->pos++;
|
||||
val = parsePlItem(pld);
|
||||
if (val == nil)
|
||||
return nil;
|
||||
{
|
||||
RELEASE(key);
|
||||
return nil;
|
||||
}
|
||||
if (skipSpace(pld) == NO)
|
||||
return nil;
|
||||
{
|
||||
RELEASE(key);
|
||||
RELEASE(val);
|
||||
return nil;
|
||||
}
|
||||
if (pld->ptr[pld->pos] == ';')
|
||||
pld->pos++;
|
||||
{
|
||||
pld->pos++;
|
||||
}
|
||||
else if (pld->ptr[pld->pos] != '}')
|
||||
{
|
||||
pld->err = @"unexpected character (wanted ';' or '}')";
|
||||
RELEASE(key);
|
||||
RELEASE(val);
|
||||
return nil;
|
||||
}
|
||||
(*plSet)(dict, @selector(setObject:forKey:), val, key);
|
||||
RELEASE(key);
|
||||
RELEASE(val);
|
||||
}
|
||||
if (pld->pos >= pld->end)
|
||||
{
|
||||
pld->err = @"unexpected end of string when parsing dictionary";
|
||||
RELEASE(dict);
|
||||
return nil;
|
||||
}
|
||||
pld->pos++;
|
||||
|
@ -451,8 +456,8 @@ static id parsePlItem(pldata* pld)
|
|||
{
|
||||
NSMutableArray *array;
|
||||
|
||||
array = [[[plArray allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCapacity: 0] autorelease];
|
||||
array = [[plArray allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCapacity: 0];
|
||||
pld->pos++;
|
||||
while (skipSpace(pld) == YES && pld->ptr[pld->pos] != ')')
|
||||
{
|
||||
|
@ -460,21 +465,31 @@ static id parsePlItem(pldata* pld)
|
|||
|
||||
val = parsePlItem(pld);
|
||||
if (val == nil)
|
||||
return nil;
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
if (skipSpace(pld) == NO)
|
||||
return nil;
|
||||
{
|
||||
RELEASE(val);
|
||||
return nil;
|
||||
}
|
||||
if (pld->ptr[pld->pos] == ',')
|
||||
pld->pos++;
|
||||
{
|
||||
pld->pos++;
|
||||
}
|
||||
else if (pld->ptr[pld->pos] != ')')
|
||||
{
|
||||
pld->err = @"unexpected character (wanted ',' or ')')";
|
||||
RELEASE(val);
|
||||
return nil;
|
||||
}
|
||||
(*plAdd)(array, @selector(addObject:), val);
|
||||
RELEASE(val);
|
||||
}
|
||||
if (pld->pos >= pld->end)
|
||||
{
|
||||
pld->err = @"unexpected end of string when parsing array";
|
||||
RELEASE(array);
|
||||
return nil;
|
||||
}
|
||||
pld->pos++;
|
||||
|
@ -488,7 +503,7 @@ static id parsePlItem(pldata* pld)
|
|||
unsigned char buf[BUFSIZ];
|
||||
unsigned len = 0;
|
||||
|
||||
data = [NSMutableData dataWithCapacity: 0];
|
||||
data = [[NSMutableData alloc] initWithCapacity: 0];
|
||||
pld->pos++;
|
||||
while (skipSpace(pld) == YES && pld->ptr[pld->pos] != '>')
|
||||
{
|
||||
|
@ -515,11 +530,13 @@ static id parsePlItem(pldata* pld)
|
|||
if (pld->pos >= pld->end)
|
||||
{
|
||||
pld->err = @"unexpected end of string when parsing data";
|
||||
RELEASE(data);
|
||||
return nil;
|
||||
}
|
||||
if (pld->ptr[pld->pos] != '>')
|
||||
{
|
||||
pld->err = @"unexpected character in string";
|
||||
RELEASE(data);
|
||||
return nil;
|
||||
}
|
||||
if (len > 0)
|
||||
|
@ -542,8 +559,8 @@ static id parseSfItem(pldata* pld)
|
|||
{
|
||||
NSMutableDictionary *dict;
|
||||
|
||||
dict = [[[plDictionary allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCapacity: 0] autorelease];
|
||||
dict = [[plDictionary allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCapacity: 0];
|
||||
while (skipSpace(pld) == YES)
|
||||
{
|
||||
id key;
|
||||
|
@ -558,40 +575,55 @@ static id parseSfItem(pldata* pld)
|
|||
if (skipSpace(pld) == NO)
|
||||
{
|
||||
pld->err = @"incomplete final entry (no semicolon?)";
|
||||
RELEASE(key);
|
||||
return nil;
|
||||
}
|
||||
if (pld->ptr[pld->pos] == ';')
|
||||
{
|
||||
pld->pos++;
|
||||
(*plSet)(dict, @selector(setObject:forKey:), @"", key);
|
||||
RELEASE(key);
|
||||
}
|
||||
else if (pld->ptr[pld->pos] == '=')
|
||||
{
|
||||
pld->pos++;
|
||||
if (skipSpace(pld) == NO)
|
||||
return nil;
|
||||
{
|
||||
RELEASE(key);
|
||||
return nil;
|
||||
}
|
||||
if (pld->ptr[pld->pos] == '"')
|
||||
val = parseQuotedString(pld);
|
||||
else
|
||||
val = parseUnquotedString(pld);
|
||||
if (val == nil)
|
||||
return nil;
|
||||
{
|
||||
RELEASE(key);
|
||||
return nil;
|
||||
}
|
||||
if (skipSpace(pld) == NO)
|
||||
{
|
||||
pld->err = @"missing final semicolon";
|
||||
RELEASE(key);
|
||||
RELEASE(val);
|
||||
return nil;
|
||||
}
|
||||
(*plSet)(dict, @selector(setObject:forKey:), val, key);
|
||||
RELEASE(key);
|
||||
RELEASE(val);
|
||||
if (pld->ptr[pld->pos] == ';')
|
||||
pld->pos++;
|
||||
else
|
||||
{
|
||||
pld->err = @"unexpected character (wanted ';')";
|
||||
RELEASE(dict);
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RELEASE(key);
|
||||
RELEASE(dict);
|
||||
pld->err = @"unexpected character (wanted '=' or ';')";
|
||||
return nil;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue