Thread: [Substrate-commits] SF.net SVN: substrate: [265] trunk
Brought to you by:
landonf
|
From: <la...@us...> - 2006-08-30 18:51:29
|
Revision: 265
http://svn.sourceforge.net/substrate/?rev=265&view=rev
Author: landonf
Date: 2006-08-30 11:51:24 -0700 (Wed, 30 Aug 2006)
Log Message:
-----------
r5677@zadder: landonf | 2006-08-30 11:49:09 -0700
Clean up some compile warnings
Modified Paths:
--------------
trunk/Tests/NSUnicodeString.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5677
Modified: trunk/Tests/NSUnicodeString.m
===================================================================
--- trunk/Tests/NSUnicodeString.m 2006-08-30 07:57:46 UTC (rev 264)
+++ trunk/Tests/NSUnicodeString.m 2006-08-30 18:51:24 UTC (rev 265)
@@ -31,6 +31,8 @@
#include <Foundation/NSString.h>
#include <Foundation/NSAutoreleasePool.h>
+#include <string.h>
+
/*
* Test data for all supported encodings
*/
@@ -186,15 +188,15 @@
START_TEST (test_initWithBytesNoCopyLengthEncodingFreeWhenDone) {
NSString *string;
- const void *bytes;
+ void *bytes;
/* No free, UTF-16-BE */
- string = [[NSString alloc] initWithBytesNoCopy: NSUnicodeStringEncoding_data length: sizeof(NSUnicodeStringEncoding_data) encoding: NSUnicodeStringEncoding freeWhenDone: NO];
+ string = [[NSString alloc] initWithBytesNoCopy: (void *) NSUnicodeStringEncoding_data length: sizeof(NSUnicodeStringEncoding_data) encoding: NSUnicodeStringEncoding freeWhenDone: NO];
fail_if(string == nil, "-[NSString initWithBytesNoCopy: length: encoding: freeWhenDone: NO] returned nil with a UTF-16-BE encoded string.");
[string release];
/* No free, UTF-16-LE */
- string = [[NSString alloc] initWithBytesNoCopy: NSUnicodeStringEncodingLE_data length: sizeof(NSUnicodeStringEncodingLE_data) encoding: NSUnicodeStringEncoding freeWhenDone: NO];
+ string = [[NSString alloc] initWithBytesNoCopy: (void *) NSUnicodeStringEncodingLE_data length: sizeof(NSUnicodeStringEncodingLE_data) encoding: NSUnicodeStringEncoding freeWhenDone: NO];
fail_if(string == nil, "-[NSString initWithBytesNoCopy: length: encoding: freeWhenDone: NO] returned nil with a UTF-16-LE encoded string.");
[string release];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-08-30 21:43:39
|
Revision: 266
http://svn.sourceforge.net/substrate/?rev=266&view=rev
Author: landonf
Date: 2006-08-30 14:43:26 -0700 (Wed, 30 Aug 2006)
Log Message:
-----------
r5679@zadder: landonf | 2006-08-30 14:37:37 -0700
Consolidate into two designated initializers, and implement a number of C string initialization methods.
Modified Paths:
--------------
trunk/Foundation/NSSimpleCString.m
trunk/Foundation/NSString.h
trunk/Foundation/NSString.m
trunk/Foundation/NSUnicodeString.m
trunk/Tests/Foundation.c
trunk/Tests/NSString.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5677
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5679
Modified: trunk/Foundation/NSSimpleCString.m
===================================================================
--- trunk/Foundation/NSSimpleCString.m 2006-08-30 18:51:24 UTC (rev 265)
+++ trunk/Foundation/NSSimpleCString.m 2006-08-30 21:43:26 UTC (rev 266)
@@ -54,10 +54,22 @@
*/
@implementation NSSimpleCString
-- initWithCString:(const char *) byteString {
- _numBytes = strlen(byteString);
- _bytes = (char *)malloc(_numBytes+1);
- bcopy(byteString, _bytes, _numBytes+1);
+- initWithBytes:(const void *)bytes length:(unsigned int)length encoding:(NSStringEncoding)encoding {
+ self = [super init];
+ if (!self)
+ return nil;
+
+ /* We only speak one encoding. */
+ if (encoding != NSASCIIStringEncoding) {
+ [self release];
+ [NSException raise: NSInvalidArgumentException format: @"Unknown NSStringEncoding"];
+ return nil;
+ }
+
+ _bytes = NSZoneMalloc(NULL, length);
+ _numBytes = length;
+ memcpy(_bytes, bytes, _numBytes);
+
return self;
}
@@ -71,6 +83,7 @@
}
- (unichar) characterAtIndex:(unsigned int) index {
+ /* ASCII can be directly mapped to UTF-16 */
return (unichar) _bytes[index];
}
@@ -79,6 +92,7 @@
}
- (unsigned int) cStringLength {
+ /* 1 byte per character */
return _numBytes;
}
Modified: trunk/Foundation/NSString.h
===================================================================
--- trunk/Foundation/NSString.h 2006-08-30 18:51:24 UTC (rev 265)
+++ trunk/Foundation/NSString.h 2006-08-30 21:43:26 UTC (rev 266)
@@ -117,14 +117,24 @@
- (const char *) cString;
/* Initialization */
++ string;
+- initWithCString:(const char *)cStr encoding:(NSStringEncoding)encoding;
- (id) initWithBytes:(const void *)bytes length:(unsigned int)len encoding:(NSStringEncoding)encoding;
- (id) initWithBytesNoCopy:(void *)bytes length:(unsigned int)len encoding:(NSStringEncoding)encoding freeWhenDone:(BOOL) shouldFree;
+/* Encoding */
++ (NSStringEncoding) defaultCStringEncoding;
+
+/* Deprecated */
++ stringWithCString:(const char *)cStr;
+- initWithCString:(const char *)cStr;
+- initWithCString:(const char *)cStr length:(unsigned int)length;
+
@end
/*
* The following must be here to support compiler instantiation
- * of constant strings. Do not ever use the directly.
+ * of constant strings. Do not ever use them directly.
*/
extern struct objc_class _NSConstantStringClassReference;
Modified: trunk/Foundation/NSString.m
===================================================================
--- trunk/Foundation/NSString.m 2006-08-30 18:51:24 UTC (rev 265)
+++ trunk/Foundation/NSString.m 2006-08-30 21:43:26 UTC (rev 266)
@@ -80,6 +80,57 @@
@implementation NSString
/*!
+ * @name Encodings
+ * @{
+ */
+
+/*!
+ * Returns the default encoding used by C string handling methods.
+ * This value can not be changed programatically, and callers
+ * should avoid using implicit encoding.
+ */
++ (NSStringEncoding) defaultCStringEncoding {
+ /* Everything is a UTF-8 string. I swear. */
+ return NSUTF8StringEncoding;
+}
+
+/*! @} */
+
+
+/*!
+ * @name Allocation and Initialization
+ * @{
+ */
+
+/*!
+ * Allocate and initialize an NSString instance with the supplied C string.
+ * @param cStr NULL-terminted C string.
+ * @return Allocated and initialized NSString instance.
+ */
++ stringWithCString:(const char *)cStr {
+ return [[[self alloc] initWithCString:cStr] autorelease];
+}
+
+/*!
+ * Allocate and initialize an empty NSString instance.
+ * @return New empty NSString instance.
+ */
++ string {
+ [self release];
+ return [[[NSUnicodeString alloc] init] autorelease];
+}
+
+/*!
+ * Initialize the receiver with the supplied C string, encoded according to encoding.
+ * @param cStr NULL-terminated C string.
+ * @param encoding Character encoding for the C string.
+ * @return Newly initialized NSString instance.
+ */
+- initWithCString:(const char *)cStr encoding:(NSStringEncoding)encoding {
+ return [self initWithBytes: cStr length: strlen(cStr) encoding: encoding];
+}
+
+/*!
* Initializes the receiver with bytes, of length, of the specified encoding.
* @param bytes String data, not null-terminated.
* @param length Length of data.
@@ -87,7 +138,7 @@
* @return Newly initialized string.
*/
- (id) initWithBytes:(const void *)bytes length:(unsigned int)length encoding:(NSStringEncoding)encoding {
- self = [self init];
+ self = [super init];
if (!self)
return nil;
@@ -100,7 +151,10 @@
/* Otherwise, instantiate a concrete string */
[self release];
- self = [[NSUnicodeString alloc] initWithBytes: bytes length: length encoding: encoding];
+ if (encoding == NSASCIIStringEncoding)
+ self = [[NSSimpleCString alloc] initWithBytes: bytes length: length encoding: encoding];
+ else
+ self = [[NSUnicodeString alloc] initWithBytes: bytes length: length encoding: encoding];
return self;
}
@@ -119,7 +173,7 @@
* @return Newly initialized string.
*/
- (id) initWithBytesNoCopy:(void *)bytes length:(unsigned int)length encoding:(NSStringEncoding)encoding freeWhenDone:(BOOL)freeWhenDone {
- self = [self init];
+ self = [super init];
if (!self)
return nil;
@@ -136,11 +190,17 @@
return self;
}
+
/*!
+ * @}
+ * Allocation and Initialization.
+ */
+
+/*!
* Returns length.
*/
- (unsigned int) length {
- [NSException raise: NSGenericException format: @"-[NSString length] is abstract"];
+ [self _subclassResponsibility: _cmd];
/* Unreachable */
return 0;
}
@@ -151,7 +211,7 @@
* past the end of the receiver.
*/
- (unichar) characterAtIndex:(unsigned int) index {
- [NSException raise: NSGenericException format: @"-[NSString characterAtIndex:] is abstract"];
+ [self _subclassResponsibility: _cmd];
/* Unreachable */
return 0;
}
@@ -164,22 +224,6 @@
}
/*!
- * Returns representation of the receiver as a C string
- * in the default C encoding. This method has been deprecated in
- * favor of UTF8String.
- *
- * If the string can not be converted with the default encoding,
- * an NSCharacterConversionException will be raised.
- *
- * The string returned by this method will be freed when the
- * receiver is deallocated.
- */
-- (char *) cString {
- /* TODO Unimplemented */
- return nil;
-}
-
-/*!
* Fills buffer with the characters contained within aRange
* of the string. An NSRangeException is raised if aRange
* is not fully contained within the receiver.
@@ -198,23 +242,55 @@
}
}
+/*!
+ * Returns representation of the receiver as a C string
+ * in the default C encoding. This method has been deprecated in
+ * favor of UTF8String.
+ *
+ * If the string can not be converted with the default encoding,
+ * an NSCharacterConversionException will be raised.
+ *
+ * The string returned by this method will be freed when the
+ * receiver is deallocated.
+ * @todo Unimplemented.
+ */
+- (char *) cString {
+ /* TODO Unimplemented */
+ return nil;
+}
+
- (NSString *) description {
return self;
}
-@end
+/*!
+ * @name Deprecated
+ * @{
+ */
-@implementation NSString(NSStringCreation)
-
-+ stringWithCString:(const char *)cStr {
- return [[[self alloc] initWithCString:cStr] autorelease];
+/*!
+ * Initialize the receiver with the supplied C string, using the default string encoding.
+ * @deprecated Caller's should make use of initWithCString:encoding: instead.
+ * @param cStr NULL-terminted C string.
+ * @return Allocated and initialized NSString instance.
+ */
+- initWithCString:(const char *)cStr {
+ return [self initWithCString: cStr encoding: [NSString defaultCStringEncoding]];
}
-- initWithCString:(const char *)cStr {
- [self release];
- return [[NSSimpleCString alloc] initWithCString:cStr];
+/*!
+ * Initialize the receiver with the supplied C string, of length, using the default string encoding.
+ * @deprecated Caller's should make use of initWithCString:encoding: or initWithBytes:length:encoding: instead.
+ * @param cStr C string, using the default system encoding.
+ * @param length Number of characters in string.
+ * @return Newly initialized NSString instance.
+ */
+- initWithCString:(const char *)cStr length:(unsigned int)length {
+ return [self initWithBytes: cStr length: length encoding: [NSString defaultCStringEncoding]];
}
+/*! @} */
+
@end
/*! @} */
Modified: trunk/Foundation/NSUnicodeString.m
===================================================================
--- trunk/Foundation/NSUnicodeString.m 2006-08-30 18:51:24 UTC (rev 265)
+++ trunk/Foundation/NSUnicodeString.m 2006-08-30 21:43:26 UTC (rev 266)
@@ -84,6 +84,12 @@
[super dealloc];
}
+/*!
+ * @name Initialization
+ * @internal
+ * @{
+ */
+
/*! Initialize the string.
* @todo Need better heuristics for determining destination buffer length, and
* for deciding when we should call realloc.
@@ -329,6 +335,20 @@
return self;
}
+/*! @} */
+
+/*!
+ * @name Accessing Data
+ * @internal
+ * @{
+ */
+
+- (unsigned int) length {
+ return _length;
+}
+
+/*! @} */
+
@end
/*! @} */
Modified: trunk/Tests/Foundation.c
===================================================================
--- trunk/Tests/Foundation.c 2006-08-30 18:51:24 UTC (rev 265)
+++ trunk/Tests/Foundation.c 2006-08-30 21:43:26 UTC (rev 266)
@@ -43,6 +43,8 @@
/* Standard Foundation Suites */
Suite *s = NSZone_suite();
SRunner *sr = srunner_create(s);
+ srunner_add_suite(sr, NSString_suite());
+ srunner_add_suite(sr, NSUnicodeString_suite());
srunner_add_suite(sr, NSAutoreleasePool_suite());
srunner_add_suite(sr, NSData_suite());
srunner_add_suite(sr, NSMutableData_suite());
@@ -54,8 +56,6 @@
srunner_add_suite(sr, NSRange_suite());
srunner_add_suite(sr, NSGeometry_suite());
srunner_add_suite(sr, NSByteOrder_suite());
- srunner_add_suite(sr, NSString_suite());
- srunner_add_suite(sr, NSUnicodeString_suite());
if (argc == 2)
srunner_set_xml(sr, argv[1]);
Modified: trunk/Tests/NSString.m
===================================================================
--- trunk/Tests/NSString.m 2006-08-30 18:51:24 UTC (rev 265)
+++ trunk/Tests/NSString.m 2006-08-30 21:43:26 UTC (rev 266)
@@ -90,6 +90,32 @@
}
END_TEST
+/* Encodings */
+
+START_TEST (test_cls_defaultCStringEncoding) {
+ /* We can't test for much here. Let's just call the method */
+ fail_unless([NSString defaultCStringEncoding]);
+}
+END_TEST
+
+
+/* Initialization */
+
+START_TEST (test_cls_string) {
+ NSString *empty;
+
+ empty = [NSString string];
+ fail_unless([empty length] == 0, "+[NSString string] returned a string with a non-zero length");
+}
+END_TEST
+
+START_TEST (test_cls_stringWithCString) {
+ NSString *string;
+ string = [NSString stringWithCString: TEST_STRING];
+ fail_unless([string length] == sizeof(TEST_STRING) - 1, "+[NSString stringWithCString] returned a string with incorrect length (Expected %d, got %d)", sizeof(TEST_STRING) - 1, [string length]);
+}
+END_TEST
+
START_TEST (test_initWithBytes) {
NSString *string;
@@ -98,6 +124,14 @@
}
END_TEST
+START_TEST (test_initWithCStringEncoding) {
+ NSString *string;
+
+ string = [[NSString alloc] initWithCString: TEST_STRING encoding: NSUTF8StringEncoding];
+ fail_if(string == nil, "-[NSString initWithCString: encoding:] returned nil");
+}
+END_TEST
+
START_TEST (test_initWithBytesNoCopyLengthEncodingFreeWhenDone) {
NSString *string;
char testData[] = "Hello, Universe!";
@@ -131,9 +165,17 @@
suite_add_tcase(s, tc_subclass);
tcase_add_test(tc_subclass, test_subclass_initWithBytes);
+ TCase *tc_encoding = tcase_create("Encodings");
+ tcase_add_checked_fixture(tc_encoding, setUp, tearDown);
+ suite_add_tcase(s, tc_encoding);
+ tcase_add_test(tc_subclass, test_cls_defaultCStringEncoding);
+
TCase *tc_init = tcase_create("Initialization");
tcase_add_checked_fixture(tc_init, setUp, tearDown);
suite_add_tcase(s, tc_init);
+ tcase_add_test(tc_init, test_cls_string);
+ tcase_add_test(tc_init, test_cls_stringWithCString);
+ tcase_add_test(tc_init, test_initWithCStringEncoding);
tcase_add_test(tc_init, test_initWithBytes);
tcase_add_test(tc_init, test_initWithBytesNoCopyLengthEncodingFreeWhenDone);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-08-30 23:20:32
|
Revision: 267
http://svn.sourceforge.net/substrate/?rev=267&view=rev
Author: landonf
Date: 2006-08-30 16:20:17 -0700 (Wed, 30 Aug 2006)
Log Message:
-----------
r5681@zadder: landonf | 2006-08-30 15:35:05 -0700
Fixes for designated initializers, minor test reorganization
r5682@zadder: landonf | 2006-08-30 16:19:30 -0700
Fix a small bug in NSObject's methodForSelector
Modified Paths:
--------------
trunk/Foundation/NSObject.m
trunk/Foundation/NSUnicodeString.m
trunk/Tests/NSObject.m
trunk/Tests/NSString.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5679
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5682
Modified: trunk/Foundation/NSObject.m
===================================================================
--- trunk/Foundation/NSObject.m 2006-08-30 21:43:26 UTC (rev 266)
+++ trunk/Foundation/NSObject.m 2006-08-30 23:20:17 UTC (rev 267)
@@ -423,7 +423,7 @@
if (aSelector == NULL)
[NSException raise: NSInvalidArgumentException format: @"null selector"];
- method = LFObjectGetInstanceMethod(LFObjectGetClass(self), aSelector);
+ method = LFObjectGetInstanceMethod(self, aSelector);
return LFMethodGetIMP(method);
}
Modified: trunk/Foundation/NSUnicodeString.m
===================================================================
--- trunk/Foundation/NSUnicodeString.m 2006-08-30 21:43:26 UTC (rev 266)
+++ trunk/Foundation/NSUnicodeString.m 2006-08-30 23:20:17 UTC (rev 267)
@@ -99,7 +99,8 @@
UErrorCode err = U_ZERO_ERROR;
size_t allocSize;
- if(![self init])
+ self = [super init];
+ if (!self)
return nil;
/* Acquire a converter, and make an educated guess as to the correct allocation */
@@ -267,9 +268,6 @@
* Unless the string is encoded as UTF-16 in the host's native byte order, it will be copied.
*/
- (id) initWithBytesNoCopy:(void *)bytes length:(unsigned int)length encoding:(NSStringEncoding)encoding freeWhenDone:(BOOL)freeWhenDone {
- if (![self init])
- return self;
-
/* If we're supplied a UTF-16 string, we might just be able to use it ... */
if (encoding == NSUnicodeStringEncoding && length) {
BOOL isNativeBOM;
@@ -302,6 +300,11 @@
/* UTF-16 in native byte order */
if (isNativeBOM) {
+ /* We're the designated initializer! */
+ self = [super init];
+ if (!self)
+ return nil;
+
if (stripBOM) {
/* Strip off the BOM and make sure we free() the
* original pointer */
Modified: trunk/Tests/NSObject.m
===================================================================
--- trunk/Tests/NSObject.m 2006-08-30 21:43:26 UTC (rev 266)
+++ trunk/Tests/NSObject.m 2006-08-30 23:20:17 UTC (rev 267)
@@ -348,6 +348,19 @@
}
END_TEST
+START_TEST (test_NSObject_methodForSelector) {
+ Test *tst = [Test new];
+
+ fail_if([tst methodForSelector:@selector(init)] == nil, "-[Test respondsToSelector:] returned nil for an inherited instance method (-[NSObject init].");
+ fail_if([tst methodForSelector:@selector(testInstanceMethod)] == nil, "-[Test respondsToSelector:] returned nil for a valid instance method (testInstanceMethod).");
+ fail_unless([tst methodForSelector:@selector(nonsense)] == nil, "-[Test respondsToSelector:] returned nil for a non-existent instance method ('nonsense').");
+
+ [tst release];
+}
+END_TEST
+
+
+
START_TEST (test_NSObject_conformsToProtocol) {
NSObject *obj = [NSObject new];
Test *tst = [Test new];
@@ -403,6 +416,7 @@
tcase_add_test(tc_introspection, test_NSObject_isMemberOfClass);
tcase_add_test(tc_introspection, test_NSObject_instancesRespondToSelector);
tcase_add_test(tc_introspection, test_NSObject_respondsToSelector);
+ tcase_add_test(tc_introspection, test_NSObject_methodForSelector);
tcase_add_test(tc_introspection, test_NSObject_conformsToProtocol);
return (s);
Modified: trunk/Tests/NSString.m
===================================================================
--- trunk/Tests/NSString.m 2006-08-30 21:43:26 UTC (rev 266)
+++ trunk/Tests/NSString.m 2006-08-30 23:20:17 UTC (rev 267)
@@ -45,6 +45,18 @@
@implementation NSStringBrokenSubclass
@end
+@interface NSDumbString : NSString
+@end
+@implementation NSDumbString
+- (unichar) characterAtIndex:(unsigned int) index {
+ return (unichar) TEST_STRING[index];
+}
+
+- (unsigned int) length {
+ return sizeof(TEST_STRING) - 1;
+}
+@end
+
static NSAutoreleasePool *releasePool;
static void setUp(void) {
@@ -160,15 +172,10 @@
suite_add_tcase(s, tc_constant);
tcase_add_test(tc_constant, test_NSConstantString);
- TCase *tc_subclass = tcase_create("Subclassing");
- tcase_add_checked_fixture(tc_subclass, setUp, tearDown);
- suite_add_tcase(s, tc_subclass);
- tcase_add_test(tc_subclass, test_subclass_initWithBytes);
-
TCase *tc_encoding = tcase_create("Encodings");
tcase_add_checked_fixture(tc_encoding, setUp, tearDown);
suite_add_tcase(s, tc_encoding);
- tcase_add_test(tc_subclass, test_cls_defaultCStringEncoding);
+ tcase_add_test(tc_encoding, test_cls_defaultCStringEncoding);
TCase *tc_init = tcase_create("Initialization");
tcase_add_checked_fixture(tc_init, setUp, tearDown);
@@ -179,5 +186,10 @@
tcase_add_test(tc_init, test_initWithBytes);
tcase_add_test(tc_init, test_initWithBytesNoCopyLengthEncodingFreeWhenDone);
+ TCase *tc_subclass = tcase_create("Subclassing");
+ tcase_add_checked_fixture(tc_subclass, setUp, tearDown);
+ suite_add_tcase(s, tc_subclass);
+ tcase_add_test(tc_subclass, test_subclass_initWithBytes);
+
return (s);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-08-31 00:02:40
|
Revision: 268
http://svn.sourceforge.net/substrate/?rev=268&view=rev
Author: landonf
Date: 2006-08-30 17:02:26 -0700 (Wed, 30 Aug 2006)
Log Message:
-----------
Implement support for NSString's dataUsingEncoding:(NSStringEncoding)encoding allowLossyConversion:(BOOL)lossy, and modify the NSUnicodeString tests to use it.
allowLossyConversion: NO is still unimplemented.
Modified Paths:
--------------
trunk/Foundation/NSString.h
trunk/Foundation/NSString.m
trunk/Foundation/NSUnicodeString.m
trunk/Tests/NSString.m
trunk/Tests/NSUnicodeString.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5682
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5684
Modified: trunk/Foundation/NSString.h
===================================================================
--- trunk/Foundation/NSString.h 2006-08-30 23:20:17 UTC (rev 267)
+++ trunk/Foundation/NSString.h 2006-08-31 00:02:26 UTC (rev 268)
@@ -39,6 +39,8 @@
#include <Foundation/NSObject.h>
#include <Foundation/NSRange.h>
+@class NSData;
+
/*!
* @ingroup NSString
* @{
@@ -117,13 +119,15 @@
- (const char *) cString;
/* Initialization */
-+ string;
-- initWithCString:(const char *)cStr encoding:(NSStringEncoding)encoding;
++ (id) string;
++ (id) stringWithCString:(const char *)cStr encoding:(NSStringEncoding)encoding;
+- (id) initWithCString:(const char *)cStr encoding:(NSStringEncoding)encoding;
- (id) initWithBytes:(const void *)bytes length:(unsigned int)len encoding:(NSStringEncoding)encoding;
- (id) initWithBytesNoCopy:(void *)bytes length:(unsigned int)len encoding:(NSStringEncoding)encoding freeWhenDone:(BOOL) shouldFree;
/* Encoding */
+ (NSStringEncoding) defaultCStringEncoding;
+- (NSData *) dataUsingEncoding:(NSStringEncoding)encoding allowLossyConversion:(BOOL)lossy;
/* Deprecated */
+ stringWithCString:(const char *)cStr;
Modified: trunk/Foundation/NSString.m
===================================================================
--- trunk/Foundation/NSString.m 2006-08-30 23:20:17 UTC (rev 267)
+++ trunk/Foundation/NSString.m 2006-08-31 00:02:26 UTC (rev 268)
@@ -94,6 +94,38 @@
return NSUTF8StringEncoding;
}
+/*!
+ * Convert the receiving string to the specified encoding, returning
+ * the result as an instance of NSData.
+ * If allowLossyConversion is NO, and the encoding conversion can not be done
+ * without data loss, nil will be returned.
+ * @param encoding Encoding to convert receiver to.
+ * @param lossy If YES, permits lossy conversion.
+ * @return NSData object containing the converted string data, or nil on failure.
+ */
+- (NSData *) dataUsingEncoding:(NSStringEncoding)encoding allowLossyConversion:(BOOL)lossy {
+ /*
+ * Ineffecient superclass implementation.
+ * We acquire a copy our UTF-16 byte array, instantiate a zero-copy
+ * NSUnicodeString instance, and ask it to convert the array for us.
+ */
+ NSUnicodeString *ucnv;
+ unsigned int length;
+ unichar *buffer;
+ NSData *result;
+
+ length = [self length];
+ buffer = NSZoneMalloc(NULL, length * sizeof(unichar));
+ [self getCharacters: buffer];
+ /* Length required here is byte length, not character length. Ugh */
+ ucnv = [[NSUnicodeString alloc] initWithBytesNoCopy: buffer length: length * sizeof(unichar) encoding: NSUnicodeStringEncoding freeWhenDone: YES];
+
+ result = [ucnv dataUsingEncoding: encoding allowLossyConversion: lossy];
+ [ucnv release];
+
+ return result;
+}
+
/*! @} */
@@ -103,19 +135,20 @@
*/
/*!
- * Allocate and initialize an NSString instance with the supplied C string.
+ * Allocate and initialize an NSString instance with the supplied C string, of the specified encoding.
* @param cStr NULL-terminted C string.
+ * @param encoding Character encoding for the C String
* @return Allocated and initialized NSString instance.
*/
-+ stringWithCString:(const char *)cStr {
- return [[[self alloc] initWithCString:cStr] autorelease];
++ (id) stringWithCString:(const char *)cStr encoding:(NSStringEncoding)encoding {
+ return [[[self alloc] initWithCString: cStr encoding: encoding] autorelease];
}
/*!
* Allocate and initialize an empty NSString instance.
* @return New empty NSString instance.
*/
-+ string {
++ (id) string {
[self release];
return [[[NSUnicodeString alloc] init] autorelease];
}
@@ -269,7 +302,18 @@
*/
/*!
- * Initialize the receiver with the supplied C string, using the default string encoding.
+ * Allocate and initialize an NSString instance with the supplied C string, using the default C string encoding.
+ * @deprecated Use stringWithCString:encoding: instead.
+ * @param cStr NULL-terminted C string.
+ * @return Allocated and initialized NSString instance.
+ */
++ stringWithCString:(const char *)cStr {
+ return [self stringWithCString: cStr encoding: [self defaultCStringEncoding]];
+}
+
+
+/*!
+ * Initialize the receiver with the supplied C string, using the default C string encoding.
* @deprecated Caller's should make use of initWithCString:encoding: instead.
* @param cStr NULL-terminted C string.
* @return Allocated and initialized NSString instance.
Modified: trunk/Foundation/NSUnicodeString.m
===================================================================
--- trunk/Foundation/NSUnicodeString.m 2006-08-30 23:20:17 UTC (rev 267)
+++ trunk/Foundation/NSUnicodeString.m 2006-08-31 00:02:26 UTC (rev 268)
@@ -34,6 +34,7 @@
#endif
#include <Foundation/NSUnicodeString.h>
+#include <Foundation/NSData.h>
#include <Foundation/NSException.h>
@@ -250,6 +251,7 @@
continue;
} else {
[NSException raise: NSInternalInconsistencyException format: @"Failure in IBM ICU's ucnv_toUChars()"];
+ NSZoneFree(NULL, _string);
ucnv_close(conv);
[self release];
return nil;
@@ -352,6 +354,168 @@
/*! @} */
+/*!
+ * @name Encoding
+ * @{
+ */
+
+/*! Convert to the specified encoding.
+ * @todo Need better heuristics for determining destination buffer length, and
+ * for deciding when we should call realloc.
+ */
+- (NSData *) dataUsingEncoding:(NSStringEncoding)encoding allowLossyConversion:(BOOL)lossy {
+ UConverter *conv;
+ UErrorCode err = U_ZERO_ERROR;
+ void *bytes;
+ size_t allocSize;
+
+ /* Acquire a converter, and make an educated guess as to the correct allocation */
+ switch (encoding) {
+ /* 7-bit ASCII encoding, using 8-bit characters. */
+ case NSASCIIStringEncoding:
+ conv = ucnv_open("US-ASCII", &err);
+ allocSize = _length;
+ break;
+
+ /* 8-bit EUC encoding for Japanese. */
+ case NSJapaneseEUCStringEncoding:
+ conv = ucnv_open("EUC-JP", &err);
+ allocSize = _length;
+ break;
+
+ /* 8-bit Unicode encoding (UTF-8). */
+ case NSUTF8StringEncoding:
+ conv = ucnv_open("UTF-8", &err);
+ allocSize = _length;
+ break;
+
+ /* 8-bit ISO Latin 1 Encoding. */
+ case NSISOLatin1StringEncoding:
+ conv = ucnv_open("latin1", &err);
+ allocSize = _length;
+ break;
+
+ /* 7-bit non-lossy Unicode encoding (UTF-7). */
+ case NSNonLossyASCIIStringEncoding:
+ conv = ucnv_open("UTF-7", &err);
+ allocSize = _length;
+ break;
+
+ /* 8-bit Japanese Shift_JIS Encoding. */
+ case NSShiftJISStringEncoding:
+ conv = ucnv_open("Shift_JIS", &err);
+ allocSize = _length;
+ break;
+
+ /* 8-bit ISO Latin 2 Encoding. */
+ case NSISOLatin2StringEncoding:
+ conv = ucnv_open("latin2", &err);
+ allocSize = _length;
+ break;
+
+ case NSProprietaryStringEncoding: /* Fall through to UTF-16 */
+ /* Canonical encoding for NSString objects (UTF-16). */
+ case NSUnicodeStringEncoding:
+ /* UTF-16-LE is the canonical byte ordering for UTF-16 strings in
+ * both Substrate and Apple's Foundation */
+ conv = ucnv_open("UTF-16-LE", &err);
+ allocSize = _length;
+ break;
+
+ /* Microsoft Windows codepage 1251 for Cryillic characters. */
+ case NSWindowsCP1251StringEncoding:
+ conv = ucnv_open("windows-1251", &err);
+ allocSize = _length;
+ break;
+
+ /* Microsoft Windows codepage 1252 (WinLatin1). */
+ case NSWindowsCP1252StringEncoding:
+ conv = ucnv_open("windows-1252", &err);
+ allocSize = _length;
+ break;
+
+ /* Microsoft Windows codepage 1253, for Greek characters. */
+ case NSWindowsCP1253StringEncoding:
+ conv = ucnv_open("windows-1253", &err);
+ allocSize = _length;
+ break;
+
+ /* Microsoft Windows codepage 1254, for Turkish characters. */
+ case NSWindowsCP1254StringEncoding:
+ conv = ucnv_open("windows-1254", &err);
+ allocSize = _length;
+ break;
+
+ /* Microsoft Windows codepage 1250 (WinLatin2). */
+ case NSWindowsCP1250StringEncoding:
+ conv = ucnv_open("windows-1250", &err);
+ allocSize = _length;
+ break;
+
+ /* ISO 2022 Japanese for e-mail. */
+ case NSISO2022JPStringEncoding:
+ conv = ucnv_open("ISO-2022-JP", &err);
+ allocSize = _length;
+ break;
+
+ /* Legacy Mac Roman Encoding. */
+ case NSMacOSRomanStringEncoding:
+ conv = ucnv_open("macintosh", &err);
+ allocSize = _length;
+ break;
+
+ /* Unhandled encodings */
+ case NSNEXTSTEPStringEncoding:
+ case NSSymbolStringEncoding:
+ default:
+ [NSException raise: NSInvalidArgumentException format: @"Unknown NSStringEncoding"];
+ return nil;
+ }
+
+ /* Did ucnv_open() fail? */
+ if (U_FAILURE(err)) {
+ [NSException raise: NSInternalInconsistencyException format: @"Failure in IBM ICU's ucnv_open()"];
+ [self release];
+ return nil;
+ }
+
+ /* Do the conversion */
+ bytes = NSZoneMalloc(NULL, allocSize);
+ while (1) {
+ size_t newAllocSize;
+
+ err = U_ZERO_ERROR;
+ newAllocSize = ucnv_fromUChars(conv, bytes, allocSize, _string, _length, &err);
+
+ if (U_SUCCESS(err)) {
+ /* Don't bother calling realloc for very small differences */
+ if (newAllocSize != allocSize && newAllocSize - allocSize >= 5)
+ bytes = NSZoneRealloc(NULL, bytes, newAllocSize);
+ allocSize = newAllocSize;
+ break;
+ }
+
+ if (err == U_BUFFER_OVERFLOW_ERROR) {
+ allocSize = newAllocSize;
+ bytes = NSZoneRealloc(NULL, bytes, allocSize);
+ continue;
+ } else {
+ [NSException raise: NSInternalInconsistencyException format: @"Failure in IBM ICU's ucnv_toUChars()"];
+ NSZoneFree(NULL, bytes);
+ ucnv_close(conv);
+ [self release];
+ return nil;
+ }
+ }
+
+ /* Success. Let's shove it into an NSData instance */
+ return [NSData dataWithBytesNoCopy: bytes length: allocSize freeWhenDone: YES];
+}
+
+
+
+/*! @} */
+
@end
/*! @} */
Modified: trunk/Tests/NSString.m
===================================================================
--- trunk/Tests/NSString.m 2006-08-30 23:20:17 UTC (rev 267)
+++ trunk/Tests/NSString.m 2006-08-31 00:02:26 UTC (rev 268)
@@ -34,6 +34,7 @@
#endif
#include <Foundation/NSString.h>
+#include <Foundation/NSData.h>
#include <Foundation/NSException.h>
#include <Foundation/NSAutoreleasePool.h>
#include "LFObjCRuntime.h"
@@ -48,6 +49,11 @@
@interface NSDumbString : NSString
@end
@implementation NSDumbString
+
+- (id) initWithBytes:(const void *)bytes length:(unsigned int) length encoding:(NSStringEncoding)encoding {
+ return self;
+}
+
- (unichar) characterAtIndex:(unsigned int) index {
return (unichar) TEST_STRING[index];
}
@@ -110,6 +116,14 @@
}
END_TEST
+START_TEST (test_dataUsingEncodingAllowLossyConversion) {
+ NSString *string = [NSDumbString stringWithCString: TEST_STRING encoding: NSASCIIStringEncoding];
+ NSData *data = [string dataUsingEncoding: NSASCIIStringEncoding allowLossyConversion: NO];
+ fail_if(data == nil, "-[NSData dataUsingEncoding: NSASCIIStringEncoding allowLossyConversion: NO] returned nil.");
+ fail_unless([data length] == sizeof(TEST_STRING) - 1, "-[NSData length] returned unexpected byte length (Expected %d, got %d)", sizeof(TEST_STRING), [data length]);
+ fail_unless(strncmp([data bytes], TEST_STRING, sizeof(TEST_STRING - 1)) == 0, "-[NSData dataUsingEncoding: NSASCIIStringEncoding allowLossyConversion: NO] returned unexpected data.");
+}
+END_TEST
/* Initialization */
@@ -176,6 +190,7 @@
tcase_add_checked_fixture(tc_encoding, setUp, tearDown);
suite_add_tcase(s, tc_encoding);
tcase_add_test(tc_encoding, test_cls_defaultCStringEncoding);
+ tcase_add_test(tc_encoding, test_dataUsingEncodingAllowLossyConversion);
TCase *tc_init = tcase_create("Initialization");
tcase_add_checked_fixture(tc_init, setUp, tearDown);
Modified: trunk/Tests/NSUnicodeString.m
===================================================================
--- trunk/Tests/NSUnicodeString.m 2006-08-30 23:20:17 UTC (rev 267)
+++ trunk/Tests/NSUnicodeString.m 2006-08-31 00:02:26 UTC (rev 268)
@@ -28,6 +28,7 @@
#include <config.h>
#endif
+#include <Foundation/NSData.h>
#include <Foundation/NSString.h>
#include <Foundation/NSAutoreleasePool.h>
@@ -88,20 +89,22 @@
0xb9, 0x74, 0x69, 0x6e, 0x79
};
+/* English UTF-16-LE "Hello, Universe", assembled by byte
+ * UTF-16-LE is the canonical UTF-16 string encoding for both Substrate
+ * and Apple's foundation. */
+static const unsigned char NSUnicodeStringEncoding_data[] = {
+ 0xff, 0xfe, 0x48, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x6f, 0x00,
+ 0x2c, 0x00, 0x20, 0x00, 0x55, 0x00, 0x6e, 0x00, 0x69, 0x00, 0x76, 0x00,
+ 0x65, 0x00, 0x72, 0x00, 0x73, 0x00, 0x65, 0x00, 0x0, 0x0
+};
+
/* English UTF-16-BE "Hello, Universe", assembled by byte */
-static const unsigned char NSUnicodeStringEncoding_data[] = {
+static const unsigned char NSUnicodeStringEncodingBE_data[] = {
0xfe, 0xff, 0x00, 0x48, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x6f,
0x00, 0x2c, 0x00, 0x20, 0x00, 0x55, 0x00, 0x6e, 0x00, 0x69, 0x00, 0x76,
0x00, 0x65, 0x00, 0x72, 0x00, 0x73, 0x00, 0x65, 0x0, 0x0
};
-/* English UTF-16-LE "Hello, Universe", assembled by byte */
-static const unsigned char NSUnicodeStringEncodingLE_data[] = {
- 0xff, 0xfe, 0x48, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x6f, 0x00,
- 0x2c, 0x00, 0x20, 0x00, 0x55, 0x00, 0x6e, 0x00, 0x69, 0x00, 0x76, 0x00,
- 0x65, 0x00, 0x72, 0x00, 0x73, 0x00, 0x65, 0x00, 0x0, 0x0
-};
-
/* Russian */
static const unsigned char NSWindowsCP1251StringEncoding_data[] = {
0xc0, 0xe2, 0xf2, 0xee, 0xec, 0xe0, 0xf2, 0xe8, 0xe7, 0xe0, 0xf6,
@@ -163,8 +166,12 @@
START_TEST(test_ ## stringEncoding) { \
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \
NSString *string; \
+ NSData *data; \
string = [[NSString alloc] initWithBytes: stringEncoding ## _data length: sizeof(stringEncoding ## _data) encoding: stringEncoding]; \
fail_if(string == nil, "-[NSString initWithBytes: length: encoding:] return nil for NSStringEncoding %d.", stringEncoding); \
+ data = [string dataUsingEncoding: stringEncoding allowLossyConversion: NO]; \
+ fail_if(data == nil, "-[NSString dataUsingEncoding: allowLossyConversion:] return nil for NSStringEncoding %d.", stringEncoding); \
+ fail_unless(memcmp([data bytes], stringEncoding ## _data, sizeof(stringEncoding ## _data)) == 0, "-[NSString dataUsingEncoding: allowLossyConversion:] return data that does not match the original for NSStringEncoding %d.", stringEncoding); \
[pool release]; \
[string release]; \
} \
@@ -191,26 +198,26 @@
void *bytes;
/* No free, UTF-16-BE */
- string = [[NSString alloc] initWithBytesNoCopy: (void *) NSUnicodeStringEncoding_data length: sizeof(NSUnicodeStringEncoding_data) encoding: NSUnicodeStringEncoding freeWhenDone: NO];
+ string = [[NSString alloc] initWithBytesNoCopy: (void *) NSUnicodeStringEncodingBE_data length: sizeof(NSUnicodeStringEncodingBE_data) encoding: NSUnicodeStringEncoding freeWhenDone: NO];
fail_if(string == nil, "-[NSString initWithBytesNoCopy: length: encoding: freeWhenDone: NO] returned nil with a UTF-16-BE encoded string.");
[string release];
/* No free, UTF-16-LE */
- string = [[NSString alloc] initWithBytesNoCopy: (void *) NSUnicodeStringEncodingLE_data length: sizeof(NSUnicodeStringEncodingLE_data) encoding: NSUnicodeStringEncoding freeWhenDone: NO];
+ string = [[NSString alloc] initWithBytesNoCopy: (void *) NSUnicodeStringEncoding_data length: sizeof(NSUnicodeStringEncoding_data) encoding: NSUnicodeStringEncoding freeWhenDone: NO];
fail_if(string == nil, "-[NSString initWithBytesNoCopy: length: encoding: freeWhenDone: NO] returned nil with a UTF-16-LE encoded string.");
[string release];
/* Free, UTF-16-BE */
- bytes = malloc(sizeof(NSUnicodeStringEncoding_data));
- memcpy(bytes, NSUnicodeStringEncoding_data, sizeof(NSUnicodeStringEncoding_data));
- string = [[NSString alloc] initWithBytesNoCopy: bytes length: sizeof(NSUnicodeStringEncoding_data) encoding: NSUnicodeStringEncoding freeWhenDone: YES];
+ bytes = malloc(sizeof(NSUnicodeStringEncodingBE_data));
+ memcpy(bytes, NSUnicodeStringEncodingBE_data, sizeof(NSUnicodeStringEncodingBE_data));
+ string = [[NSString alloc] initWithBytesNoCopy: bytes length: sizeof(NSUnicodeStringEncodingBE_data) encoding: NSUnicodeStringEncoding freeWhenDone: YES];
fail_if(string == nil, "-[NSString initWithBytesNoCopy: length: encoding: freeWhenDone: YES] returned nil with a UTF-16-BE encoded string.");
[string release];
/* Free, UTF-16-LE */
- bytes = malloc(sizeof(NSUnicodeStringEncodingLE_data));
- memcpy(bytes, NSUnicodeStringEncodingLE_data, sizeof(NSUnicodeStringEncodingLE_data));
- string = [[NSString alloc] initWithBytesNoCopy: bytes length: sizeof(NSUnicodeStringEncodingLE_data) encoding: NSUnicodeStringEncoding freeWhenDone: YES];
+ bytes = malloc(sizeof(NSUnicodeStringEncoding_data));
+ memcpy(bytes, NSUnicodeStringEncoding_data, sizeof(NSUnicodeStringEncoding_data));
+ string = [[NSString alloc] initWithBytesNoCopy: bytes length: sizeof(NSUnicodeStringEncoding_data) encoding: NSUnicodeStringEncoding freeWhenDone: YES];
fail_if(string == nil, "-[NSString initWithBytesNoCopy: length: encoding: freeWhenDone: YES] returned nil with a UTF-16-LE encoded string.");
[string release];
}
@@ -238,9 +245,5 @@
tcase_add_test(tc_init, test_NSMacOSRomanStringEncoding);
tcase_add_test(tc_init, test_initWithBytesNoCopyLengthEncodingFreeWhenDone);
-#ifdef TODO_NSData
-#error Add a test on the conversion result using dataUsingEncoding:allowLossyConversion: once NSData has been implemented!
-#endif
-
return (s);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-08-31 02:09:20
|
Revision: 269
http://svn.sourceforge.net/substrate/?rev=269&view=rev
Author: landonf
Date: 2006-08-30 19:09:09 -0700 (Wed, 30 Aug 2006)
Log Message:
-----------
Add support for lossy and non-lossy conversions
Modified Paths:
--------------
trunk/Foundation/NSUnicodeString.h
trunk/Foundation/NSUnicodeString.m
trunk/Tests/NSUnicodeString.m
Modified: trunk/Foundation/NSUnicodeString.h
===================================================================
--- trunk/Foundation/NSUnicodeString.h 2006-08-31 00:02:26 UTC (rev 268)
+++ trunk/Foundation/NSUnicodeString.h 2006-08-31 02:09:09 UTC (rev 269)
@@ -33,8 +33,10 @@
*/
#include <Foundation/NSString.h>
+
+#include <unicode/ucnv.h>
+#include <unicode/ucnv_err.h>
#include <unicode/ustring.h>
-#include <unicode/ucnv.h>
/*!
* @ingroup NSUnicodeString
Modified: trunk/Foundation/NSUnicodeString.m
===================================================================
--- trunk/Foundation/NSUnicodeString.m 2006-08-31 00:02:26 UTC (rev 268)
+++ trunk/Foundation/NSUnicodeString.m 2006-08-31 02:09:09 UTC (rev 269)
@@ -228,6 +228,17 @@
return nil;
}
+ /* Skip bad code points. This *seems* to be what Apple does,
+ * but I could be wrong */
+ ucnv_setFromUCallBack(conv, UCNV_FROM_U_CALLBACK_SKIP, NULL, NULL, NULL, &err);
+
+ /* Did ucnv_setFromUCallback() fail? */
+ if (U_FAILURE(err)) {
+ [NSException raise: NSInternalInconsistencyException format: @"Failure in IBM ICU's ucnv_setFromUCallback()"];
+ ucnv_close(conv);
+ return nil;
+ }
+
/* Do the conversion */
_string = NSZoneMalloc(NULL, allocSize);
while (1) {
@@ -250,7 +261,7 @@
_string = NSZoneRealloc(NULL, _string, allocSize);
continue;
} else {
- [NSException raise: NSInternalInconsistencyException format: @"Failure in IBM ICU's ucnv_toUChars()"];
+ [NSException raise: NSCharacterConversionException format: @"Failure in IBM ICU's ucnv_toUChars()"];
NSZoneFree(NULL, _string);
ucnv_close(conv);
[self release];
@@ -475,10 +486,22 @@
/* Did ucnv_open() fail? */
if (U_FAILURE(err)) {
[NSException raise: NSInternalInconsistencyException format: @"Failure in IBM ICU's ucnv_open()"];
- [self release];
return nil;
}
+ /* Set up lossy character handling */
+ if (lossy)
+ ucnv_setFromUCallBack(conv, UCNV_FROM_U_CALLBACK_SKIP, NULL, NULL, NULL, &err);
+ else
+ ucnv_setFromUCallBack(conv, UCNV_FROM_U_CALLBACK_STOP, NULL, NULL, NULL, &err);
+
+ /* Did ucnv_setFromUCallback() fail? */
+ if (U_FAILURE(err)) {
+ [NSException raise: NSInternalInconsistencyException format: @"Failure in IBM ICU's ucnv_setFromUCallback()"];
+ ucnv_close(conv);
+ return nil;
+ }
+
/* Do the conversion */
bytes = NSZoneMalloc(NULL, allocSize);
while (1) {
@@ -499,11 +522,16 @@
allocSize = newAllocSize;
bytes = NSZoneRealloc(NULL, bytes, allocSize);
continue;
+ } else if (err == U_ILLEGAL_CHAR_FOUND) {
+ /* Invalid character sequence found for the given
+ * destination encoding scheme */
+ NSZoneFree(NULL, bytes);
+ ucnv_close(conv);
+ return nil;
} else {
[NSException raise: NSInternalInconsistencyException format: @"Failure in IBM ICU's ucnv_toUChars()"];
NSZoneFree(NULL, bytes);
ucnv_close(conv);
- [self release];
return nil;
}
}
@@ -511,8 +539,6 @@
/* Success. Let's shove it into an NSData instance */
return [NSData dataWithBytesNoCopy: bytes length: allocSize freeWhenDone: YES];
}
-
-
/*! @} */
Modified: trunk/Tests/NSUnicodeString.m
===================================================================
--- trunk/Tests/NSUnicodeString.m 2006-08-31 00:02:26 UTC (rev 268)
+++ trunk/Tests/NSUnicodeString.m 2006-08-31 02:09:09 UTC (rev 269)
@@ -33,8 +33,21 @@
#include <Foundation/NSAutoreleasePool.h>
#include <string.h>
+#include <stdlib.h>
/*
+ * Test setup/teardown
+ */
+static NSAutoreleasePool *releasePool;
+static void setUp(void) {
+ releasePool = [[NSAutoreleasePool alloc] init];
+}
+
+static void tearDown(void) {
+ [releasePool release];
+}
+
+/*
* Test data for all supported encodings
*/
@@ -164,7 +177,6 @@
#define ENCODING_INIT_TEST(stringEncoding) \
START_TEST(test_ ## stringEncoding) { \
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \
NSString *string; \
NSData *data; \
string = [[NSString alloc] initWithBytes: stringEncoding ## _data length: sizeof(stringEncoding ## _data) encoding: stringEncoding]; \
@@ -172,7 +184,6 @@
data = [string dataUsingEncoding: stringEncoding allowLossyConversion: NO]; \
fail_if(data == nil, "-[NSString dataUsingEncoding: allowLossyConversion:] return nil for NSStringEncoding %d.", stringEncoding); \
fail_unless(memcmp([data bytes], stringEncoding ## _data, sizeof(stringEncoding ## _data)) == 0, "-[NSString dataUsingEncoding: allowLossyConversion:] return data that does not match the original for NSStringEncoding %d.", stringEncoding); \
- [pool release]; \
[string release]; \
} \
END_TEST
@@ -223,10 +234,26 @@
}
END_TEST
+START_TEST (test_dataUsingEncodingStringEncodingAllowLossyConversion) {
+ NSString *string;
+ NSData *data;
+
+ /* Try lossy and non-lossy conversion from EUC to ASCII */
+ string = [[NSString alloc] initWithBytes: NSJapaneseEUCStringEncoding_data length: sizeof(NSJapaneseEUCStringEncoding_data) encoding: NSJapaneseEUCStringEncoding];
+ data = [string dataUsingEncoding: NSASCIIStringEncoding allowLossyConversion: YES];
+ fail_if(data == nil, "-[NSString dataUsingEncoding: NSASCIIStringEncoding allowLossyConversion: YES] returned nil.");
+
+
+ data = [string dataUsingEncoding: NSASCIIStringEncoding allowLossyConversion: NO];
+ fail_unless(data == nil, "-[NSString dataUsingEncoding: NSASCIIStringEncoding allowLossyConversion: NO] did not return nil with lossy data.");
+}
+END_TEST
+
Suite *NSUnicodeString_suite(void) {
Suite *s = suite_create("NSUnicodeString");
TCase *tc_init = tcase_create("Initialization");
+ tcase_add_checked_fixture(tc_init, setUp, tearDown);
suite_add_tcase(s, tc_init);
tcase_add_test(tc_init, test_NSASCIIStringEncoding);
tcase_add_test(tc_init, test_NSJapaneseEUCStringEncoding);
@@ -245,5 +272,10 @@
tcase_add_test(tc_init, test_NSMacOSRomanStringEncoding);
tcase_add_test(tc_init, test_initWithBytesNoCopyLengthEncodingFreeWhenDone);
+ TCase *tc_conv = tcase_create("Conversion");
+ tcase_add_checked_fixture(tc_conv, setUp, tearDown);
+ suite_add_tcase(s, tc_conv);
+ tcase_add_test(tc_conv, test_dataUsingEncodingStringEncodingAllowLossyConversion);
+
return (s);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-08-31 22:35:59
|
Revision: 283
http://svn.sourceforge.net/substrate/?rev=283&view=rev
Author: landonf
Date: 2006-08-31 15:35:54 -0700 (Thu, 31 Aug 2006)
Log Message:
-----------
r5716@zadder: landonf | 2006-08-31 15:35:22 -0700
Unbreak objc exception autoconf macros
Modified Paths:
--------------
trunk/aclocal.m4
trunk/configure.ac
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5713
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
Modified: trunk/aclocal.m4
===================================================================
--- trunk/aclocal.m4 2006-08-31 22:26:28 UTC (rev 282)
+++ trunk/aclocal.m4 2006-08-31 22:35:54 UTC (rev 283)
@@ -313,7 +313,8 @@
# Results:
# Result is cached.
# Substitutes OBJC_EXCEPTIONS_DEFINE and OBJC_EXCEPTIONS_CFLAGS
-# If enabled, OBJC_EXCEPTIONS is defined to 1.
+# If enabled, OBJC_EXCEPTIONS is defined to 1, and OBJC_EXCEPTIONS
+# variable is set to "yes"
#------------------------------------------------------------------------
AC_DEFUN([OD_OBJC_EXCEPTIONS],[
AC_REQUIRE([AC_PROG_OBJC])
@@ -345,11 +346,13 @@
# If we can enable exceptions, do we want to?
if test x"$ac_cv_objc_exceptions" = "xyes" && test x"$ac_cv_objc_fobjc_exceptions" = "xyes"; then
+ OBJC_EXCEPTIONS="yes"
OBJC_EXCEPTIONS_CFLAGS="-fobjc-exceptions"
- OBJC_EXCEPTIONS_DEFINE="#define OBJC_EXCEPTIONS 1"
+ OBJC_EXCEPTIONS_DEFINE="\\#define OBJC_EXCEPTIONS 1"
else
+ OBJC_EXCEPTIONS="no"
OBJC_EXCEPTIONS_CFLAGS=""
- OBJC_EXCEPTIONS_DEFINE=""
+ OBJC_EXCEPTIONS_DEFINE="/* \\#undef OBJC_EXCEPTIONS */"
fi
AC_SUBST([OBJC_EXCEPTIONS_CFLAGS])
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2006-08-31 22:26:28 UTC (rev 282)
+++ trunk/configure.ac 2006-08-31 22:35:54 UTC (rev 283)
@@ -59,7 +59,7 @@
OD_OBJC_EXCEPTIONS
# Check whether -fno-constant-cfstrings is supported
OD_OBJC_NOCFCONSTANTSTRING
-if test x"$OBJC_EXCEPTIONS_DEFINE" != "x"; then
+if test x"$OBJC_EXCEPTIONS" = "xyes"; then
AC_MSG_NOTICE([Objective-C exception handling: @try @catch @throw])
else
AC_MSG_NOTICE([Exception handling: NS_DURING NS_HANDLER])
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-08-31 22:26:27
|
Revision: 281
http://svn.sourceforge.net/substrate/?rev=281&view=rev
Author: landonf
Date: 2006-08-31 15:26:13 -0700 (Thu, 31 Aug 2006)
Log Message:
-----------
r5712@zadder: landonf | 2006-08-31 14:44:59 -0700
Checkpoint commit of old-style exception stack handling
Modified Paths:
--------------
trunk/Foundation/LFObjCRuntime.h.in
trunk/Foundation/Makefile.in
trunk/Foundation/NSConcreteData.m
trunk/Foundation/NSException.h
trunk/Foundation/NSException.m
Added Paths:
-----------
trunk/Foundation/LFObjCExceptionStack.m
trunk/Foundation/LFObjCGNUException.m
Removed Paths:
-------------
trunk/Foundation/LFObjCAppleRuntime.m
trunk/Foundation/LFObjCGNURuntime.m
trunk/Foundation/NSClassicException.h
trunk/Foundation/NSFuncallException.h
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5684
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5712
Deleted: trunk/Foundation/LFObjCAppleRuntime.m
===================================================================
--- trunk/Foundation/LFObjCAppleRuntime.m 2006-08-31 07:30:41 UTC (rev 280)
+++ trunk/Foundation/LFObjCAppleRuntime.m 2006-08-31 22:26:13 UTC (rev 281)
@@ -1,288 +0,0 @@
-/*
- * LFObjCAppleRuntime.m vi:ts=4:sw=4:expandtab:
- * Apple Objective-C Runtime Abstraction and Support Code
- *
- * Copyright (C) 2005 - 2006 Landon Fuller <la...@op...>
- * All rights reserved.
- *
- * Author: Landon Fuller <la...@op...>
- *
- * This file is part of libFoundation.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation.
- *
- * We disclaim all warranties with regard to this software, including all
- * implied warranties of merchantability and fitness, in no event shall
- * we be liable for any special, indirect or consequential damages or any
- * damages whatsoever resulting from loss of use, data or profits, whether in
- * an action of contract, negligence or other tortious action, arising out of
- * or in connection with the use or performance of this software.
- */
-
-/*!
- * @file
- * @internal
- * @brief LFObjCRuntime
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef APPLE_RUNTIME
-
-/******************************************************************************
- * Supporting exceptions on Apple's runtime requires maintaining a per-thread
- * stack of exception handlers. Handlers are pushed and popped off the stack
- * at the beginning and end of every try/catch block, via a runtime function
- * call. When an exception occurs, our LFObjC_ExceptionThrow() function is
- * called, and we need to longjmp to the current exception handler at the top
- * of the per-thread handler stack.
- *****************************************************************************/
-
-#include <Foundation/NSZone.h>
-#include <Foundation/NSException.h>
-#include <Foundation/LFObjCRuntime.h>
-#include <Foundation/spin.h>
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <setjmp.h>
-
-/* Number of exception handlers to store in each bucket.
- * Selected arbitrarily. */
-#define EHS_BUCKET_SIZE 16
-
-/* Forward declarations */
-static void LFObjC_ExceptionThrow (id);
-static void LFObjC_ExceptionTryEnter (void *);
-static void LFObjC_ExceptionTryExit (void *);
-static id LFObjC_ExceptionExtract (void *);
-static int LFObjC_ExceptionMatch (Class, id);
-static void free_exception_handler_stack_tls (void *);
-
-/* The compiler will pass this structure to LFObjC_ExceptionThrow() */
-typedef struct LFObjCLocalExceptionData {
- jmp_buf buf;
- id *pointers[4];
-} LFObjCLocalExceptionData;
-
-/* Per-thread stack of exception handler buckets, each bucket
- * holds EHS_BUCKET_SIZE handlers */
-typedef struct LFExceptionHandlerBucket {
- int count;
- LFObjCLocalExceptionData *excData[EHS_BUCKET_SIZE];
- struct LFExceptionHandlerBucket *next;
-} LFExceptionHandlerBucket;
-
-/* We modify the pointer in this structure so that we don't
- * have to call pthread_setspecific() repeatedly */
-typedef struct LFExceptionHandler_TLS {
- LFExceptionHandlerBucket *bucket;
-} LFExceptionHandler_TLS;
-
-/* Per-thread EH stack key */
-static pthread_key_t LFExceptionHandlerStack_key;
-
-/*!
- * Exception handling functions for the Apple Objective-C runtime.
- * @internal
- */
-objc_exception_functions_t objc_exc_funcs = {
- 0,
- LFObjC_ExceptionThrow,
- LFObjC_ExceptionTryEnter,
- LFObjC_ExceptionTryExit,
- LFObjC_ExceptionExtract,
- LFObjC_ExceptionMatch
-};
-
-
-/* Uncaught exception handler */
-static LFUncaughtExceptionHandler *ueh_handler;
-static slock_t ueh_lock;
-
-/*!
- * Set Objective-C Uncaught Exception Handler.
- * @internal
- */
-LF_PRIVATE void LFObjCSetUncaughtExceptionHandler (LFUncaughtExceptionHandler *handler) {
- SpinLockAcquire(&ueh_lock);
- ueh_handler = handler;
- SpinLockRelease(&ueh_lock);
-}
-
-/*!
- * Get Objective-C Uncaught Exception Handler.
- * @internal
- */
-LF_PRIVATE LFUncaughtExceptionHandler *LFObjCGetUncaughtExceptionHandler (void) {
- LFUncaughtExceptionHandler *handler;
- SpinLockAcquire(&ueh_lock);
- handler = ueh_handler;
- SpinLockRelease(&ueh_lock);
-
- return handler;
-}
-
-/*!
- * Initialize the Objective-C Exception Handler.
- * @internal
- */
-LF_PRIVATE void LFObjCInitExceptionHandler (LFUncaughtExceptionHandler *handler) {
- /* Initialize the lock */
- SpinLockInit(&ueh_lock);
- ueh_handler = handler;
-
- /* Initialize our pthread key */
- pthread_key_create(&LFExceptionHandlerStack_key, free_exception_handler_stack_tls);
-
- /* Set up exception handling functions */
- objc_exception_set_functions((objc_exception_functions_t *) &objc_exc_funcs);
-}
-
-/*!
- * Throw an exception.
- * @internal
- */
-static void LFObjC_ExceptionThrow (id exception) {
- LFExceptionHandler_TLS *ehsTLS;
- LFObjCLocalExceptionData *lfexcData;
- LFExceptionHandlerBucket *bucket;
-
- /* Grab the stack */
- ehsTLS = (LFExceptionHandler_TLS *) pthread_getspecific(LFExceptionHandlerStack_key);
-
- /* If the stack is NULL or the bucket is empty, someone forgot to catch
- * the exception. Call the uncaught exception handler and fire SIGTRAP */
- if (!ehsTLS || !ehsTLS->bucket || ehsTLS->bucket->count == 0) {
- LFUncaughtExceptionHandler *handler;
-
- /* Acquire a lock and get the current ueh_handler */
- SpinLockAcquire(&ueh_lock);
- handler = ueh_handler;
- SpinLockRelease(&ueh_lock);
-
- /* Call and then fire SIGTRAP */
- handler(exception);
- kill(getpid(), SIGTRAP);
- }
-
- /* Pop our exception data */
- bucket = ehsTLS->bucket;
- assert(bucket);
- lfexcData = bucket->excData[bucket->count - 1];
- assert(lfexcData);
- bucket->count--;
-
- /* Store the exception in the first pointer */
- lfexcData->pointers[0] = (void *) exception;
-
- /* On my mark. */
- _longjmp(lfexcData->buf, 1);
-}
-
-/*!
- * Enter a @try/@catch block.
- * @internal
- */
-static void LFObjC_ExceptionTryEnter (void *excData) {
- LFExceptionHandler_TLS *ehsTLS;
- LFExceptionHandlerBucket *new, *bucket;
-
- /* Grab the stack */
- ehsTLS = (LFExceptionHandler_TLS *) pthread_getspecific(LFExceptionHandlerStack_key);
-
- /* Allocate and initialize the stack TLS holder if needed */
- if (!ehsTLS) {
- ehsTLS = NSZoneMalloc(NULL, sizeof(LFExceptionHandler_TLS));
- ehsTLS->bucket = NULL;
- pthread_setspecific(LFExceptionHandlerStack_key, ehsTLS);
- }
-
- /* Allocate and initialize a bucket if needed */
- if (!ehsTLS->bucket || ehsTLS->bucket->count == EHS_BUCKET_SIZE) {
- new = NSZoneMalloc(NULL, sizeof(LFExceptionHandlerBucket));
-
- /* Will either get set to NULL or the next bucket */
- new->next = ehsTLS->bucket;
- new->count = 0;
-
- ehsTLS->bucket = new;
- }
-
- /* Add our data to the bucket */
- bucket = ehsTLS->bucket;
- bucket->excData[bucket->count] = excData;
- bucket->count++;
-
- return;
-}
-
-/*!
- * Exit a @try/@catch block.
- * @internal
- */
-static void LFObjC_ExceptionTryExit (void *excData) {
- LFExceptionHandler_TLS *ehsTLS;
- LFExceptionHandlerBucket *bucket;
-
- /* Grab the stack */
- ehsTLS = (LFExceptionHandler_TLS *) pthread_getspecific(LFExceptionHandlerStack_key);
- assert(ehsTLS);
-
- /* Decrease the bucket count (ie, pop the excData) */
- bucket = ehsTLS->bucket;
- assert(bucket->excData[bucket->count - 1] == excData);
- bucket->count--;
-
- /* If the bucket is empty, and this isn't the last bucket available,
- * free the current bucket. */
- if (bucket->count == 0 && bucket->next != NULL) {
- ehsTLS->bucket = bucket->next;
- NSZoneFree(NULL, bucket);
- }
-
- return;
-}
-
-/*!
- * Extract the Objective-C object from the local exception data.
- * @internal
- */
-static id LFObjC_ExceptionExtract (void *excData) {
- LFObjCLocalExceptionData *lfexcData = (LFObjCLocalExceptionData *) excData;
- /* We stored the exception in the first pointer */
- return (id) lfexcData->pointers[0];
-}
-
-/*!
- * Match a given exception against the supplied class.
- * @internal
- */
-static int LFObjC_ExceptionMatch (Class excClass, id exception) {
- return [exception isKindOfClass: excClass];
-}
-
-/*!
- * Deallocate the exception stack TLS.
- * @internal
- */
-static void free_exception_handler_stack_tls (void *keyData) {
- LFExceptionHandler_TLS *ehsTLS = (LFExceptionHandler_TLS *) keyData;
-
- /* There will only ever be one bucket left behind by LFObjC_ExceptionTryExit() */
- if (ehsTLS->bucket)
- NSZoneFree(NULL, ehsTLS->bucket);
-
- NSZoneFree(NULL, ehsTLS);
-}
-
-#endif /* APPLE_RUNTIME */
Added: trunk/Foundation/LFObjCExceptionStack.m
===================================================================
--- trunk/Foundation/LFObjCExceptionStack.m (rev 0)
+++ trunk/Foundation/LFObjCExceptionStack.m 2006-08-31 22:26:13 UTC (rev 281)
@@ -0,0 +1,310 @@
+/*
+ * LFObjCExceptionStack.m vi:ts=4:sw=4:expandtab:
+ *
+ * Generic Exception Stack Implementation.
+ * Compatible with both new-style language exceptions as implemented by
+ * the Apple runtime, and old-style NS_DURING exceptions in both runtimes.
+ *
+ * Copyright (C) 2005 - 2006 Landon Fuller <la...@op...>
+ * All rights reserved.
+ *
+ * Author: Landon Fuller <la...@op...>
+ *
+ * This file is part of libFoundation.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ *
+ * We disclaim all warranties with regard to this software, including all
+ * implied warranties of merchantability and fitness, in no event shall
+ * we be liable for any special, indirect or consequential damages or any
+ * damages whatsoever resulting from loss of use, data or profits, whether in
+ * an action of contract, negligence or other tortious action, arising out of
+ * or in connection with the use or performance of this software.
+ */
+
+/*!
+ * @file
+ * @internal
+ * @brief LFObjCRuntime
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if defined(APPLE_RUNTIME) || (defined(GNU_RUNTIME) && !defined(OBJC_EXCEPTIONS))
+
+/******************************************************************************
+ * This code implementions binary-compatible exception handling for both
+ * new and old-style exceptions in the Apple Objective-C runtime.
+ *
+ * It also implements non-binary compatible exception handling support for
+ * old-style exceptions in GNU's Objective-C runtime.
+ *
+ * We maintain a per-thread stack of exception handlers. Handlers are pushed
+ * and popped off the stack at the beginning and end of every try/catch block,
+ * via a runtime function call. When an exception occurs, our
+ * LFObjC_ExceptionThrow() function is called, and we need to longjmp to the
+ * current exception handler at the top of the per-thread handler stack.
+ *
+ * The push/pop runtime function calls are handled automatically by the
+ * new-style exception support in Apple's runtime. With old-style exceptions,
+ * we manually implement the equivalent using preprocessor macros.
+ *****************************************************************************/
+
+#include <Foundation/NSZone.h>
+#include <Foundation/NSException.h>
+#include <Foundation/LFObjCRuntime.h>
+#include <Foundation/spin.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <setjmp.h>
+
+/* Number of exception handlers to store in each bucket.
+ * Selected arbitrarily. */
+#define EHS_BUCKET_SIZE 16
+
+/* Forward declarations */
+static void LFObjC_ExceptionThrow (id);
+static void LFObjC_ExceptionTryEnter (void *);
+static void LFObjC_ExceptionTryExit (void *);
+static id LFObjC_ExceptionExtract (void *);
+static int LFObjC_ExceptionMatch (Class, id);
+static void free_exception_handler_stack_tls (void *);
+
+/* Per-thread stack of exception handler buckets, each bucket
+ * holds EHS_BUCKET_SIZE handlers */
+typedef struct LFExceptionHandlerBucket {
+ int count;
+ LFObjCLocalExceptionData *excData[EHS_BUCKET_SIZE];
+ struct LFExceptionHandlerBucket *next;
+} LFExceptionHandlerBucket;
+
+/* We modify the pointer in this structure so that we don't
+ * have to call pthread_setspecific() repeatedly */
+typedef struct LFExceptionHandler_TLS {
+ LFExceptionHandlerBucket *bucket;
+} LFExceptionHandler_TLS;
+
+/* Per-thread EH stack key */
+static pthread_key_t LFExceptionHandlerStack_key;
+
+/* Uncaught exception handler */
+static LFUncaughtExceptionHandler *ueh_handler;
+static slock_t ueh_lock;
+
+/* Expose our exception stack functions */
+#if defined APPLE_RUNTIME
+/*!
+ * Exception handling functions for the Apple Objective-C runtime.
+ * @internal
+ */
+objc_exception_functions_t objc_exc_funcs = {
+ 0,
+ LFObjC_ExceptionThrow,
+ LFObjC_ExceptionTryEnter,
+ LFObjC_ExceptionTryExit,
+ LFObjC_ExceptionExtract,
+ LFObjC_ExceptionMatch
+};
+#endif /* APPLE_RUNTIME */
+
+void _NSAddHandler (LFObjCLocalExceptionData *excData) {
+ LFObjC_ExceptionTryEnter(excData);
+}
+
+void _NSRemoveHandler (LFObjCLocalExceptionData *excData) {
+ LFObjC_ExceptionTryExit(excData);
+}
+
+NSException *_NSExceptionFromHandler (LFObjCLocalExceptionData *excData) {
+ return LFObjC_ExceptionExtract(excData);
+}
+
+/*!
+ * Set Objective-C Uncaught Exception Handler.
+ * @internal
+ */
+LF_PRIVATE void LFObjCSetUncaughtExceptionHandler (LFUncaughtExceptionHandler *handler) {
+ SpinLockAcquire(&ueh_lock);
+ ueh_handler = handler;
+ SpinLockRelease(&ueh_lock);
+}
+
+/*!
+ * Get Objective-C Uncaught Exception Handler.
+ * @internal
+ */
+LF_PRIVATE LFUncaughtExceptionHandler *LFObjCGetUncaughtExceptionHandler (void) {
+ LFUncaughtExceptionHandler *handler;
+ SpinLockAcquire(&ueh_lock);
+ handler = ueh_handler;
+ SpinLockRelease(&ueh_lock);
+
+ return handler;
+}
+
+/*!
+ * Initialize the Objective-C Exception Handler.
+ * @internal
+ */
+LF_PRIVATE void LFObjCInitExceptionHandler (LFUncaughtExceptionHandler *handler) {
+ /* Initialize the lock */
+ SpinLockInit(&ueh_lock);
+ ueh_handler = handler;
+
+ /* Initialize our pthread key */
+ pthread_key_create(&LFExceptionHandlerStack_key, free_exception_handler_stack_tls);
+
+#if defined(APPLE_RUNTIME) && defined(OBJC_EXCEPTIONS)
+ /* Set up exception handling functions for the Apple runtime */
+ objc_exception_set_functions((objc_exception_functions_t *) &objc_exc_funcs);
+#endif
+}
+
+/*!
+ * Throw an exception.
+ * @internal
+ */
+LF_PRIVATE void LFObjC_ExceptionThrow (id exception) {
+ LFExceptionHandler_TLS *ehsTLS;
+ LFObjCLocalExceptionData *lfexcData;
+ LFExceptionHandlerBucket *bucket;
+
+ /* Grab the stack */
+ ehsTLS = (LFExceptionHandler_TLS *) pthread_getspecific(LFExceptionHandlerStack_key);
+
+ /* If the stack is NULL or the bucket is empty, someone forgot to catch
+ * the exception. Call the uncaught exception handler and fire SIGTRAP */
+ if (!ehsTLS || !ehsTLS->bucket || ehsTLS->bucket->count == 0) {
+ LFUncaughtExceptionHandler *handler;
+
+ /* Acquire a lock and get the current ueh_handler */
+ SpinLockAcquire(&ueh_lock);
+ handler = ueh_handler;
+ SpinLockRelease(&ueh_lock);
+
+ /* Call and then fire SIGTRAP */
+ handler(exception);
+ kill(getpid(), SIGTRAP);
+ }
+
+ /* Pop our exception data */
+ bucket = ehsTLS->bucket;
+ assert(bucket);
+ lfexcData = bucket->excData[bucket->count - 1];
+ assert(lfexcData);
+ bucket->count--;
+
+ /* Store the exception in the first pointer */
+ lfexcData->pointers[0] = (void *) exception;
+
+ /* On my mark. */
+ _longjmp(lfexcData->buf, 1);
+}
+
+/*!
+ * Enter a @try/@catch block.
+ * @internal
+ */
+static void LFObjC_ExceptionTryEnter (void *excData) {
+ LFExceptionHandler_TLS *ehsTLS;
+ LFExceptionHandlerBucket *new, *bucket;
+
+ /* Grab the stack */
+ ehsTLS = (LFExceptionHandler_TLS *) pthread_getspecific(LFExceptionHandlerStack_key);
+
+ /* Allocate and initialize the stack TLS holder if needed */
+ if (!ehsTLS) {
+ ehsTLS = NSZoneMalloc(NULL, sizeof(LFExceptionHandler_TLS));
+ ehsTLS->bucket = NULL;
+ pthread_setspecific(LFExceptionHandlerStack_key, ehsTLS);
+ }
+
+ /* Allocate and initialize a bucket if needed */
+ if (!ehsTLS->bucket || ehsTLS->bucket->count == EHS_BUCKET_SIZE) {
+ new = NSZoneMalloc(NULL, sizeof(LFExceptionHandlerBucket));
+
+ /* Will either get set to NULL or the next bucket */
+ new->next = ehsTLS->bucket;
+ new->count = 0;
+
+ ehsTLS->bucket = new;
+ }
+
+ /* Add our data to the bucket */
+ bucket = ehsTLS->bucket;
+ bucket->excData[bucket->count] = excData;
+ bucket->count++;
+
+ return;
+}
+
+/*!
+ * Exit a @try/@catch block.
+ * @internal
+ */
+static void LFObjC_ExceptionTryExit (void *excData) {
+ LFExceptionHandler_TLS *ehsTLS;
+ LFExceptionHandlerBucket *bucket;
+
+ /* Grab the stack */
+ ehsTLS = (LFExceptionHandler_TLS *) pthread_getspecific(LFExceptionHandlerStack_key);
+ assert(ehsTLS);
+
+ /* Decrease the bucket count (ie, pop the excData) */
+ bucket = ehsTLS->bucket;
+ assert(bucket->excData[bucket->count - 1] == excData);
+ bucket->count--;
+
+ /* If the bucket is empty, and this isn't the last bucket available,
+ * free the current bucket. */
+ if (bucket->count == 0 && bucket->next != NULL) {
+ ehsTLS->bucket = bucket->next;
+ NSZoneFree(NULL, bucket);
+ }
+
+ return;
+}
+
+/*!
+ * Extract the Objective-C object from the local exception data.
+ * @internal
+ */
+static id LFObjC_ExceptionExtract (void *excData) {
+ LFObjCLocalExceptionData *lfexcData = (LFObjCLocalExceptionData *) excData;
+ /* We stored the exception in the first pointer */
+ return (id) lfexcData->pointers[0];
+}
+
+/*!
+ * Match a given exception against the supplied class.
+ * @internal
+ */
+static int LFObjC_ExceptionMatch (Class excClass, id exception) {
+ return [exception isKindOfClass: excClass];
+}
+
+/*!
+ * Deallocate the exception stack TLS.
+ * @internal
+ */
+static void free_exception_handler_stack_tls (void *keyData) {
+ LFExceptionHandler_TLS *ehsTLS = (LFExceptionHandler_TLS *) keyData;
+
+ /* There will only ever be one bucket left behind by LFObjC_ExceptionTryExit() */
+ if (ehsTLS->bucket)
+ NSZoneFree(NULL, ehsTLS->bucket);
+
+ NSZoneFree(NULL, ehsTLS);
+}
+
+#endif /* APPLE_RUNTIME || (GNU_RUNTIME && !OBJC_EXCEPTIONS) */
Property changes on: trunk/Foundation/LFObjCExceptionStack.m
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/Foundation/LFObjCGNUException.m
===================================================================
--- trunk/Foundation/LFObjCGNUException.m (rev 0)
+++ trunk/Foundation/LFObjCGNUException.m 2006-08-31 22:26:13 UTC (rev 281)
@@ -0,0 +1,160 @@
+/*
+ * LFObjCGNUException.m vi:ts=4:sw=4:expandtab:
+ * New-style language exception handling for the GNU Objective-C runtime.
+ *
+ * Copyright (C) 2005 - 2006 Landon Fuller <la...@op...>
+ * All rights reserved.
+ *
+ * Author: Landon Fuller <la...@op...>
+ *
+ * This file is part of libFoundation.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ *
+ * We disclaim all warranties with regard to this software, including all
+ * implied warranties of merchantability and fitness, in no event shall
+ * we be liable for any special, indirect or consequential damages or any
+ * damages whatsoever resulting from loss of use, data or profits, whether in
+ * an action of contract, negligence or other tortious action, arising out of
+ * or in connection with the use or performance of this software.
+ */
+
+/*!
+ * @file
+ * @internal
+ * @brief LFObjCRuntime
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if defined(GNU_RUNTIME) && defined(LF_OBJC_LANGUAGE_EXCEPTIONS)
+
+/* This is unfortunately required to use RTLD_NEXT on Linux systems */
+#define _GNU_SOURCE
+
+#include <Foundation/NSZone.h>
+#include <Foundation/NSException.h>
+#include <Foundation/LFObjCRuntime.h>
+#include <Foundation/spin.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <signal.h>
+
+# include <dlfcn.h>
+/* GCC's exception handling and stack unwinding routines */
+# include <unwind.h>
+
+/* Uncaught exception handler */
+static LFUncaughtExceptionHandler *ueh_handler;
+static slock_t ueh_lock;
+
+/*! libgcc's _Unwind_RaiseException()
+ * @internal */
+static _Unwind_Reason_Code (*_real_Unwind_RaiseException)(struct _Unwind_Exception *e);
+
+/*!
+ * Set Objective-C Uncaught Exception Handler.
+ * @internal
+ */
+LF_PRIVATE void LFObjCSetUncaughtExceptionHandler (LFUncaughtExceptionHandler *handler) {
+ SpinLockAcquire(&ueh_lock);
+ ueh_handler = handler;
+ SpinLockRelease(&ueh_lock);
+}
+
+/*!
+ * Get Objective-C Uncaught Exception Handler.
+ * @internal
+ */
+LF_PRIVATE LFUncaughtExceptionHandler *LFObjCGetUncaughtExceptionHandler (void) {
+ LFUncaughtExceptionHandler *handler;
+ SpinLockAcquire(&ueh_lock);
+ handler = ueh_handler;
+ SpinLockRelease(&ueh_lock);
+
+ return handler;
+}
+
+/*!
+ * Initialize the Objective-C Exception Handler.
+ * @internal
+ */
+LF_PRIVATE void LFObjCInitExceptionHandler (LFUncaughtExceptionHandler *handler) {
+ /* Initialize the lock */
+ SpinLockInit(&ueh_lock);
+ ueh_handler = handler;
+
+#ifdef RTLD_NEXT
+ /* Locate the _Unwind_RaiseException symbol */
+ _real_Unwind_RaiseException = dlsym(RTLD_NEXT, "_Unwind_RaiseException");
+#endif /* RTLD_NEXT */
+
+}
+
+/*!
+ * Throw an exception.
+ * @internal
+ */
+LF_PRIVATE void LFObjC_ExceptionThrow (id exception) {
+ @throw exception;
+}
+
+/******************************************************************************
+ * XXX: Temporary Hack.
+ *
+ * When using the GNU Objective-C runtime, support for a default
+ * Objective-C exception handler is implemented by overriding gcc's
+ * _Unwind_RaiseException, calling the true _Unwind_RaiseException,
+ * and checking for _URC_END_OF_STACK, which signals that no exception
+ * handler was found.
+ *
+ * This is wrong, wrong, wrong, (really wrong!), but there is currently
+ * no other way to implement this functionality.
+ *
+ * See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27466 for my libobjc
+ * enhancement request.
+ ******************************************************************************/
+
+/*! Our _Unwind_RaiseException()
+ * @internal */
+_Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *uwe) {
+ _Unwind_Reason_Code err;
+
+ err = _real_Unwind_RaiseException(uwe);
+ if (err == _URC_END_OF_STACK) {
+ LFUncaughtExceptionHandler *handler;
+
+ /* Acquire a lock and get the current ueh_handler */
+ SpinLockAcquire(&ueh_lock);
+ handler = ueh_handler;
+ SpinLockRelease(&ueh_lock);
+
+ /* If a handler is available, call it.
+ * We manually re-raise the _Unwind_Exception so that we can get
+ * access to the thrown Objective-C object without digging
+ * into the private libobjc structures */
+ @try {
+ _real_Unwind_RaiseException(uwe);
+ }
+ @catch (id exc) {
+ ueh_handler(exc);
+ }
+ }
+
+ /* Fire SIGTRAP */
+ kill(getpid(), SIGTRAP);
+
+ /* We're going to return objc_exception_throw(), where abort() will be
+ * called immediately. Unless someone caught SIGTRAP, this should
+ * be unreachable */
+ return err;
+}
+
+#endif /* GNU_RUNTIME && LF_OBJC_LANGUAGE_EXCEPTIONS */
Property changes on: trunk/Foundation/LFObjCGNUException.m
___________________________________________________________________
Name: svn:eol-style
+ native
Deleted: trunk/Foundation/LFObjCGNURuntime.m
===================================================================
--- trunk/Foundation/LFObjCGNURuntime.m 2006-08-31 07:30:41 UTC (rev 280)
+++ trunk/Foundation/LFObjCGNURuntime.m 2006-08-31 22:26:13 UTC (rev 281)
@@ -1,152 +0,0 @@
-/*
- * LFObjCGNURuntime.m vi:ts=4:sw=4:expandtab:
- * GNU Objective-C Runtime Abstraction and Support Code
- *
- * Copyright (C) 2005 - 2006 Landon Fuller <la...@op...>
- * All rights reserved.
- *
- * Author: Landon Fuller <la...@op...>
- *
- * This file is part of libFoundation.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation.
- *
- * We disclaim all warranties with regard to this software, including all
- * implied warranties of merchantability and fitness, in no event shall
- * we be liable for any special, indirect or consequential damages or any
- * damages whatsoever resulting from loss of use, data or profits, whether in
- * an action of contract, negligence or other tortious action, arising out of
- * or in connection with the use or performance of this software.
- */
-
-/*!
- * @file
- * @internal
- * @brief LFObjCRuntime
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef GNU_RUNTIME
-
-/* This is unfortunately required to use RTLD_NEXT on Linux systems */
-#define _GNU_SOURCE
-
-#include <Foundation/NSZone.h>
-#include <Foundation/NSException.h>
-#include <Foundation/LFObjCRuntime.h>
-#include <Foundation/spin.h>
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <signal.h>
-
-# include <dlfcn.h>
-/* GCC's exception handling and stack unwinding routines */
-# include <unwind.h>
-
-/* Uncaught exception handler */
-static LFUncaughtExceptionHandler *ueh_handler;
-static slock_t ueh_lock;
-
-/*! libgcc's _Unwind_RaiseException()
- * @internal */
-static _Unwind_Reason_Code (*_real_Unwind_RaiseException)(struct _Unwind_Exception *e);
-
-/*!
- * Set Objective-C Uncaught Exception Handler.
- * @internal
- */
-LF_PRIVATE void LFObjCSetUncaughtExceptionHandler (LFUncaughtExceptionHandler *handler) {
- SpinLockAcquire(&ueh_lock);
- ueh_handler = handler;
- SpinLockRelease(&ueh_lock);
-}
-
-/*!
- * Get Objective-C Uncaught Exception Handler.
- * @internal
- */
-LF_PRIVATE LFUncaughtExceptionHandler *LFObjCGetUncaughtExceptionHandler (void) {
- LFUncaughtExceptionHandler *handler;
- SpinLockAcquire(&ueh_lock);
- handler = ueh_handler;
- SpinLockRelease(&ueh_lock);
-
- return handler;
-}
-
-/*!
- * Initialize the Objective-C Exception Handler.
- * @internal
- */
-LF_PRIVATE void LFObjCInitExceptionHandler (LFUncaughtExceptionHandler *handler) {
- /* Initialize the lock */
- SpinLockInit(&ueh_lock);
- ueh_handler = handler;
-
-#ifdef RTLD_NEXT
- /* Locate the _Unwind_RaiseException symbol */
- _real_Unwind_RaiseException = dlsym(RTLD_NEXT, "_Unwind_RaiseException");
-#endif /* RTLD_NEXT */
-
-}
-
-/******************************************************************************
- * XXX: Temporary Hack.
- *
- * When using the GNU Objective-C runtime, support for a default
- * Objective-C exception handler is implemented by overriding gcc's
- * _Unwind_RaiseException, calling the true _Unwind_RaiseException,
- * and checking for _URC_END_OF_STACK, which signals that no exception
- * handler was found.
- *
- * This is wrong, wrong, wrong, (really wrong!), but there is currently
- * no other way to implement this functionality.
- *
- * See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27466 for my libobjc
- * enhancement request.
- ******************************************************************************/
-
-/*! Our _Unwind_RaiseException()
- * @internal */
-_Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *uwe) {
- _Unwind_Reason_Code err;
-
- err = _real_Unwind_RaiseException(uwe);
- if (err == _URC_END_OF_STACK) {
- LFUncaughtExceptionHandler *handler;
-
- /* Acquire a lock and get the current ueh_handler */
- SpinLock...
[truncated message content] |
|
From: <la...@us...> - 2006-08-31 22:26:40
|
Revision: 282
http://svn.sourceforge.net/substrate/?rev=282&view=rev
Author: landonf
Date: 2006-08-31 15:26:28 -0700 (Thu, 31 Aug 2006)
Log Message:
-----------
r5713@zadder: landonf | 2006-08-31 15:25:21 -0700
Clean up LF_PRIVATE usage (should be used for implementation, not header declaration)
Finish work on exception stack handling for gcc <4.0
Modified Paths:
--------------
trunk/Foundation/LFHash.h
trunk/Foundation/LFObjCRuntime.h.in
trunk/Foundation/Makefile.in
trunk/Foundation/NSConcreteData.m
trunk/Foundation/NSException.h
trunk/Foundation/NSException.m
trunk/Foundation/port.h
trunk/Mk/autoconf.mk.in
trunk/aclocal.m4
trunk/configure.ac
Added Paths:
-----------
trunk/Foundation/LFGNUException.m
trunk/Foundation/LFStackException.m
Removed Paths:
-------------
trunk/Foundation/LFObjCExceptionStack.m
trunk/Foundation/LFObjCGNUException.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5712
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5713
Added: trunk/Foundation/LFGNUException.m
===================================================================
--- trunk/Foundation/LFGNUException.m (rev 0)
+++ trunk/Foundation/LFGNUException.m 2006-08-31 22:26:28 UTC (rev 282)
@@ -0,0 +1,153 @@
+/*
+ * LFGNUException.m vi:ts=4:sw=4:expandtab:
+ * New-style language exception handling for the GNU Objective-C runtime.
+ *
+ * Copyright (C) 2005 - 2006 Landon Fuller <la...@op...>
+ * All rights reserved.
+ *
+ * Author: Landon Fuller <la...@op...>
+ *
+ * This file is part of libFoundation.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ *
+ * We disclaim all warranties with regard to this software, including all
+ * implied warranties of merchantability and fitness, in no event shall
+ * we be liable for any special, indirect or consequential damages or any
+ * damages whatsoever resulting from loss of use, data or profits, whether in
+ * an action of contract, negligence or other tortious action, arising out of
+ * or in connection with the use or performance of this software.
+ */
+
+/*!
+ * @file
+ * @internal
+ * @brief Support functions for new-style objective-C exception handling in
+ * the GNU runtime.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if defined(GNU_RUNTIME) && defined(OBJC_EXCEPTIONS)
+
+/* This is unfortunately required to use RTLD_NEXT on Linux systems */
+#define _GNU_SOURCE
+
+#include <Foundation/NSZone.h>
+#include <Foundation/NSException.h>
+#include <Foundation/LFRuntime.h>
+#include <Foundation/spin.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <signal.h>
+
+# include <dlfcn.h>
+/* GCC's exception handling and stack unwinding routines */
+# include <unwind.h>
+
+/* Uncaught exception handler */
+static LFUncaughtExceptionHandler *ueh_handler;
+static slock_t ueh_lock;
+
+/*! libgcc's _Unwind_RaiseException()
+ * @internal */
+static _Unwind_Reason_Code (*_real_Unwind_RaiseException)(struct _Unwind_Exception *e);
+
+/*!
+ * Set Objective-C Uncaught Exception Handler.
+ * @internal
+ */
+LF_PRIVATE void LFSetUncaughtExceptionHandler (LFUncaughtExceptionHandler *handler) {
+ SpinLockAcquire(&ueh_lock);
+ ueh_handler = handler;
+ SpinLockRelease(&ueh_lock);
+}
+
+/*!
+ * Get Objective-C Uncaught Exception Handler.
+ * @internal
+ */
+LF_PRIVATE LFUncaughtExceptionHandler *LFGetUncaughtExceptionHandler (void) {
+ LFUncaughtExceptionHandler *handler;
+ SpinLockAcquire(&ueh_lock);
+ handler = ueh_handler;
+ SpinLockRelease(&ueh_lock);
+
+ return handler;
+}
+
+/*!
+ * Initialize the Objective-C Exception Handler.
+ * @internal
+ */
+LF_PRIVATE void LFInitExceptionHandler (LFUncaughtExceptionHandler *handler) {
+ /* Initialize the lock */
+ SpinLockInit(&ueh_lock);
+ ueh_handler = handler;
+
+#ifdef RTLD_NEXT
+ /* Locate the _Unwind_RaiseException symbol */
+ _real_Unwind_RaiseException = dlsym(RTLD_NEXT, "_Unwind_RaiseException");
+#endif /* RTLD_NEXT */
+
+}
+
+/******************************************************************************
+ * XXX: Temporary Hack.
+ *
+ * When using the GNU Objective-C runtime, support for a default
+ * Objective-C exception handler is implemented by overriding gcc's
+ * _Unwind_RaiseException, calling the true _Unwind_RaiseException,
+ * and checking for _URC_END_OF_STACK, which signals that no exception
+ * handler was found.
+ *
+ * This is wrong, wrong, wrong, (really wrong!), but there is currently
+ * no other way to implement this functionality.
+ *
+ * See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27466 for my libobjc
+ * enhancement request.
+ ******************************************************************************/
+
+/*! Our _Unwind_RaiseException()
+ * @internal */
+_Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *uwe) {
+ _Unwind_Reason_Code err;
+
+ err = _real_Unwind_RaiseException(uwe);
+ if (err == _URC_END_OF_STACK) {
+ LFUncaughtExceptionHandler *handler;
+
+ /* Acquire a lock and get the current ueh_handler */
+ SpinLockAcquire(&ueh_lock);
+ handler = ueh_handler;
+ SpinLockRelease(&ueh_lock);
+
+ /* If a handler is available, call it.
+ * We manually re-raise the _Unwind_Exception so that we can get
+ * access to the thrown Objective-C object without digging
+ * into the private libobjc structures */
+ @try {
+ _real_Unwind_RaiseException(uwe);
+ }
+ @catch (id exc) {
+ ueh_handler(exc);
+ }
+ }
+
+ /* Fire SIGTRAP */
+ kill(getpid(), SIGTRAP);
+
+ /* We're going to return objc_exception_throw(), where abort() will be
+ * called immediately. Unless someone caught SIGTRAP, this should
+ * be unreachable */
+ return err;
+}
+
+#endif /* GNU_RUNTIME && OBJC_EXCEPTIONS */
Property changes on: trunk/Foundation/LFGNUException.m
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/Foundation/LFHash.h
===================================================================
--- trunk/Foundation/LFHash.h 2006-08-31 22:26:13 UTC (rev 281)
+++ trunk/Foundation/LFHash.h 2006-08-31 22:26:28 UTC (rev 282)
@@ -35,7 +35,7 @@
-------------------------------------------------------------------------------
*/
-LF_PRIVATE uint32_t LFHashWord(const uint32_t *k, size_t length, uint32_t initval);
-LF_PRIVATE uint32_t LFHashLittle(const void *key, size_t length, uint32_t initval);
-LF_PRIVATE void LFHashLittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb);
-LF_PRIVATE uint32_t LFHashBig(const void *key, size_t length, uint32_t initval);
+uint32_t LFHashWord(const uint32_t *k, size_t length, uint32_t initval);
+uint32_t LFHashLittle(const void *key, size_t length, uint32_t initval);
+void LFHashLittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb);
+uint32_t LFHashBig(const void *key, size_t length, uint32_t initval);
Deleted: trunk/Foundation/LFObjCExceptionStack.m
===================================================================
--- trunk/Foundation/LFObjCExceptionStack.m 2006-08-31 22:26:13 UTC (rev 281)
+++ trunk/Foundation/LFObjCExceptionStack.m 2006-08-31 22:26:28 UTC (rev 282)
@@ -1,310 +0,0 @@
-/*
- * LFObjCExceptionStack.m vi:ts=4:sw=4:expandtab:
- *
- * Generic Exception Stack Implementation.
- * Compatible with both new-style language exceptions as implemented by
- * the Apple runtime, and old-style NS_DURING exceptions in both runtimes.
- *
- * Copyright (C) 2005 - 2006 Landon Fuller <la...@op...>
- * All rights reserved.
- *
- * Author: Landon Fuller <la...@op...>
- *
- * This file is part of libFoundation.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation.
- *
- * We disclaim all warranties with regard to this software, including all
- * implied warranties of merchantability and fitness, in no event shall
- * we be liable for any special, indirect or consequential damages or any
- * damages whatsoever resulting from loss of use, data or profits, whether in
- * an action of contract, negligence or other tortious action, arising out of
- * or in connection with the use or performance of this software.
- */
-
-/*!
- * @file
- * @internal
- * @brief LFObjCRuntime
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#if defined(APPLE_RUNTIME) || (defined(GNU_RUNTIME) && !defined(OBJC_EXCEPTIONS))
-
-/******************************************************************************
- * This code implementions binary-compatible exception handling for both
- * new and old-style exceptions in the Apple Objective-C runtime.
- *
- * It also implements non-binary compatible exception handling support for
- * old-style exceptions in GNU's Objective-C runtime.
- *
- * We maintain a per-thread stack of exception handlers. Handlers are pushed
- * and popped off the stack at the beginning and end of every try/catch block,
- * via a runtime function call. When an exception occurs, our
- * LFObjC_ExceptionThrow() function is called, and we need to longjmp to the
- * current exception handler at the top of the per-thread handler stack.
- *
- * The push/pop runtime function calls are handled automatically by the
- * new-style exception support in Apple's runtime. With old-style exceptions,
- * we manually implement the equivalent using preprocessor macros.
- *****************************************************************************/
-
-#include <Foundation/NSZone.h>
-#include <Foundation/NSException.h>
-#include <Foundation/LFObjCRuntime.h>
-#include <Foundation/spin.h>
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <setjmp.h>
-
-/* Number of exception handlers to store in each bucket.
- * Selected arbitrarily. */
-#define EHS_BUCKET_SIZE 16
-
-/* Forward declarations */
-static void LFObjC_ExceptionThrow (id);
-static void LFObjC_ExceptionTryEnter (void *);
-static void LFObjC_ExceptionTryExit (void *);
-static id LFObjC_ExceptionExtract (void *);
-static int LFObjC_ExceptionMatch (Class, id);
-static void free_exception_handler_stack_tls (void *);
-
-/* Per-thread stack of exception handler buckets, each bucket
- * holds EHS_BUCKET_SIZE handlers */
-typedef struct LFExceptionHandlerBucket {
- int count;
- LFObjCLocalExceptionData *excData[EHS_BUCKET_SIZE];
- struct LFExceptionHandlerBucket *next;
-} LFExceptionHandlerBucket;
-
-/* We modify the pointer in this structure so that we don't
- * have to call pthread_setspecific() repeatedly */
-typedef struct LFExceptionHandler_TLS {
- LFExceptionHandlerBucket *bucket;
-} LFExceptionHandler_TLS;
-
-/* Per-thread EH stack key */
-static pthread_key_t LFExceptionHandlerStack_key;
-
-/* Uncaught exception handler */
-static LFUncaughtExceptionHandler *ueh_handler;
-static slock_t ueh_lock;
-
-/* Expose our exception stack functions */
-#if defined APPLE_RUNTIME
-/*!
- * Exception handling functions for the Apple Objective-C runtime.
- * @internal
- */
-objc_exception_functions_t objc_exc_funcs = {
- 0,
- LFObjC_ExceptionThrow,
- LFObjC_ExceptionTryEnter,
- LFObjC_ExceptionTryExit,
- LFObjC_ExceptionExtract,
- LFObjC_ExceptionMatch
-};
-#endif /* APPLE_RUNTIME */
-
-void _NSAddHandler (LFObjCLocalExceptionData *excData) {
- LFObjC_ExceptionTryEnter(excData);
-}
-
-void _NSRemoveHandler (LFObjCLocalExceptionData *excData) {
- LFObjC_ExceptionTryExit(excData);
-}
-
-NSException *_NSExceptionFromHandler (LFObjCLocalExceptionData *excData) {
- return LFObjC_ExceptionExtract(excData);
-}
-
-/*!
- * Set Objective-C Uncaught Exception Handler.
- * @internal
- */
-LF_PRIVATE void LFObjCSetUncaughtExceptionHandler (LFUncaughtExceptionHandler *handler) {
- SpinLockAcquire(&ueh_lock);
- ueh_handler = handler;
- SpinLockRelease(&ueh_lock);
-}
-
-/*!
- * Get Objective-C Uncaught Exception Handler.
- * @internal
- */
-LF_PRIVATE LFUncaughtExceptionHandler *LFObjCGetUncaughtExceptionHandler (void) {
- LFUncaughtExceptionHandler *handler;
- SpinLockAcquire(&ueh_lock);
- handler = ueh_handler;
- SpinLockRelease(&ueh_lock);
-
- return handler;
-}
-
-/*!
- * Initialize the Objective-C Exception Handler.
- * @internal
- */
-LF_PRIVATE void LFObjCInitExceptionHandler (LFUncaughtExceptionHandler *handler) {
- /* Initialize the lock */
- SpinLockInit(&ueh_lock);
- ueh_handler = handler;
-
- /* Initialize our pthread key */
- pthread_key_create(&LFExceptionHandlerStack_key, free_exception_handler_stack_tls);
-
-#if defined(APPLE_RUNTIME) && defined(OBJC_EXCEPTIONS)
- /* Set up exception handling functions for the Apple runtime */
- objc_exception_set_functions((objc_exception_functions_t *) &objc_exc_funcs);
-#endif
-}
-
-/*!
- * Throw an exception.
- * @internal
- */
-LF_PRIVATE void LFObjC_ExceptionThrow (id exception) {
- LFExceptionHandler_TLS *ehsTLS;
- LFObjCLocalExceptionData *lfexcData;
- LFExceptionHandlerBucket *bucket;
-
- /* Grab the stack */
- ehsTLS = (LFExceptionHandler_TLS *) pthread_getspecific(LFExceptionHandlerStack_key);
-
- /* If the stack is NULL or the bucket is empty, someone forgot to catch
- * the exception. Call the uncaught exception handler and fire SIGTRAP */
- if (!ehsTLS || !ehsTLS->bucket || ehsTLS->bucket->count == 0) {
- LFUncaughtExceptionHandler *handler;
-
- /* Acquire a lock and get the current ueh_handler */
- SpinLockAcquire(&ueh_lock);
- handler = ueh_handler;
- SpinLockRelease(&ueh_lock);
-
- /* Call and then fire SIGTRAP */
- handler(exception);
- kill(getpid(), SIGTRAP);
- }
-
- /* Pop our exception data */
- bucket = ehsTLS->bucket;
- assert(bucket);
- lfexcData = bucket->excData[bucket->count - 1];
- assert(lfexcData);
- bucket->count--;
-
- /* Store the exception in the first pointer */
- lfexcData->pointers[0] = (void *) exception;
-
- /* On my mark. */
- _longjmp(lfexcData->buf, 1);
-}
-
-/*!
- * Enter a @try/@catch block.
- * @internal
- */
-static void LFObjC_ExceptionTryEnter (void *excData) {
- LFExceptionHandler_TLS *ehsTLS;
- LFExceptionHandlerBucket *new, *bucket;
-
- /* Grab the stack */
- ehsTLS = (LFExceptionHandler_TLS *) pthread_getspecific(LFExceptionHandlerStack_key);
-
- /* Allocate and initialize the stack TLS holder if needed */
- if (!ehsTLS) {
- ehsTLS = NSZoneMalloc(NULL, sizeof(LFExceptionHandler_TLS));
- ehsTLS->bucket = NULL;
- pthread_setspecific(LFExceptionHandlerStack_key, ehsTLS);
- }
-
- /* Allocate and initialize a bucket if needed */
- if (!ehsTLS->bucket || ehsTLS->bucket->count == EHS_BUCKET_SIZE) {
- new = NSZoneMalloc(NULL, sizeof(LFExceptionHandlerBucket));
-
- /* Will either get set to NULL or the next bucket */
- new->next = ehsTLS->bucket;
- new->count = 0;
-
- ehsTLS->bucket = new;
- }
-
- /* Add our data to the bucket */
- bucket = ehsTLS->bucket;
- bucket->excData[bucket->count] = excData;
- bucket->count++;
-
- return;
-}
-
-/*!
- * Exit a @try/@catch block.
- * @internal
- */
-static void LFObjC_ExceptionTryExit (void *excData) {
- LFExceptionHandler_TLS *ehsTLS;
- LFExceptionHandlerBucket *bucket;
-
- /* Grab the stack */
- ehsTLS = (LFExceptionHandler_TLS *) pthread_getspecific(LFExceptionHandlerStack_key);
- assert(ehsTLS);
-
- /* Decrease the bucket count (ie, pop the excData) */
- bucket = ehsTLS->bucket;
- assert(bucket->excData[bucket->count - 1] == excData);
- bucket->count--;
-
- /* If the bucket is empty, and this isn't the last bucket available,
- * free the current bucket. */
- if (bucket->count == 0 && bucket->next != NULL) {
- ehsTLS->bucket = bucket->next;
- NSZoneFree(NULL, bucket);
- }
-
- return;
-}
-
-/*!
- * Extract the Objective-C object from the local exception data.
- * @internal
- */
-static id LFObjC_ExceptionExtract (void *excData) {
- LFObjCLocalExceptionData *lfexcData = (LFObjCLocalExceptionData *) excData;
- /* We stored the exception in the first pointer */
- return (id) lfexcData->pointers[0];
-}
-
-/*!
- * Match a given exception against the supplied class.
- * @internal
- */
-static int LFObjC_ExceptionMatch (Class excClass, id exception) {
- return [exception isKindOfClass: excClass];
-}
-
-/*!
- * Deallocate the exception stack TLS.
- * @internal
- */
-static void free_exception_handler_stack_tls (void *keyData) {
- LFExceptionHandler_TLS *ehsTLS = (LFExceptionHandler_TLS *) keyData;
-
- /* There will only ever be one bucket left behind by LFObjC_ExceptionTryExit() */
- if (ehsTLS->bucket)
- NSZoneFree(NULL, ehsTLS->bucket);
-
- NSZoneFree(NULL, ehsTLS);
-}
-
-#endif /* APPLE_RUNTIME || (GNU_RUNTIME && !OBJC_EXCEPTIONS) */
Deleted: trunk/Foundation/LFObjCGNUException.m
===================================================================
--- trunk/Foundation/LFObjCGNUException.m 2006-08-31 22:26:13 UTC (rev 281)
+++ trunk/Foundation/LFObjCGNUException.m 2006-08-31 22:26:28 UTC (rev 282)
@@ -1,160 +0,0 @@
-/*
- * LFObjCGNUException.m vi:ts=4:sw=4:expandtab:
- * New-style language exception handling for the GNU Objective-C runtime.
- *
- * Copyright (C) 2005 - 2006 Landon Fuller <la...@op...>
- * All rights reserved.
- *
- * Author: Landon Fuller <la...@op...>
- *
- * This file is part of libFoundation.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation.
- *
- * We disclaim all warranties with regard to this software, including all
- * implied warranties of merchantability and fitness, in no event shall
- * we be liable for any special, indirect or consequential damages or any
- * damages whatsoever resulting from loss of use, data or profits, whether in
- * an action of contract, negligence or other tortious action, arising out of
- * or in connection with the use or performance of this software.
- */
-
-/*!
- * @file
- * @internal
- * @brief LFObjCRuntime
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#if defined(GNU_RUNTIME) && defined(LF_OBJC_LANGUAGE_EXCEPTIONS)
-
-/* This is unfortunately required to use RTLD_NEXT on Linux systems */
-#define _GNU_SOURCE
-
-#include <Foundation/NSZone.h>
-#include <Foundation/NSException.h>
-#include <Foundation/LFObjCRuntime.h>
-#include <Foundation/spin.h>
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <signal.h>
-
-# include <dlfcn.h>
-/* GCC's exception handling and stack unwinding routines */
-# include <unwind.h>
-
-/* Uncaught exception handler */
-static LFUncaughtExceptionHandler *ueh_handler;
-static slock_t ueh_lock;
-
-/*! libgcc's _Unwind_RaiseException()
- * @internal */
-static _Unwind_Reason_Code (*_real_Unwind_RaiseException)(struct _Unwind_Exception *e);
-
-/*!
- * Set Objective-C Uncaught Exception Handler.
- * @internal
- */
-LF_PRIVATE void LFObjCSetUncaughtExceptionHandler (LFUncaughtExceptionHandler *handler) {
- SpinLockAcquire(&ueh_lock);
- ueh_handler = handler;
- SpinLockRelease(&ueh_lock);
-}
-
-/*!
- * Get Objective-C Uncaught Exception Handler.
- * @internal
- */
-LF_PRIVATE LFUncaughtExceptionHandler *LFObjCGetUncaughtExceptionHandler (void) {
- LFUncaughtExceptionHandler *handler;
- SpinLockAcquire(&ueh_lock);
- handler = ueh_handler;
- SpinLockRelease(&ueh_lock);
-
- return handler;
-}
-
-/*!
- * Initialize the Objective-C Exception Handler.
- * @internal
- */
-LF_PRIVATE void LFObjCInitExceptionHandler (LFUncaughtExceptionHandler *handler) {
- /* Initialize the lock */
- SpinLockInit(&ueh_lock);
- ueh_handler = handler;
-
-#ifdef RTLD_NEXT
- /* Locate the _Unwind_RaiseException symbol */
- _real_Unwind_RaiseException = dlsym(RTLD_NEXT, "_Unwind_RaiseException");
-#endif /* RTLD_NEXT */
-
-}
-
-/*!
- * Throw an exception.
- * @internal
- */
-LF_PRIVATE void LFObjC_ExceptionThrow (id exception) {
- @throw exception;
-}
-
-/******************************************************************************
- * XXX: Temporary Hack.
- *
- * When using the GNU Objective-C runtime, support for a default
- * Objective-C exception handler is implemented by overriding gcc's
- * _Unwind_RaiseException, calling the true _Unwind_RaiseException,
- * and checking for _URC_END_OF_STACK, which signals that no exception
- * handler was found.
- *
- * This is wrong, wrong, wrong, (really wrong!), but there is currently
- * no other way to implement this functionality.
- *
- * See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27466 for my libobjc
- * enhancement request.
- ******************************************************************************/
-
-/*! Our _Unwind_RaiseException()
- * @internal */
-_Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *uwe) {
- _Unwind_Reason_Code err;
-
- err = _real_Unwind_RaiseException(uwe);
- if (err == _URC_END_OF_STACK) {
- LFUncaughtExceptionHandler *handler;
-
- /* Acquire a lock and get the current ueh_handler */
- SpinLockAcquire(&ueh_lock);
- handler = ueh_handler;
- SpinLockRelease(&ueh_lock);
-
- /* If a handler is available, call it.
- * We manually re-raise the _Unwind_Exception so that we can get
- * access to the thrown Objective-C object without digging
- * into the private libobjc structures */
- @try {
- _real_Unwind_RaiseException(uwe);
- }
- @catch (id exc) {
- ueh_handler(exc);
- }
- }
-
- /* Fire SIGTRAP */
- kill(getpid(), SIGTRAP);
-
- /* We're going to return objc_exception_throw(), where abort() will be
- * called immediately. Unless someone caught SIGTRAP, this should
- * be unreachable */
- return err;
-}
-
-#endif /* GNU_RUNTIME && LF_OBJC_LANGUAGE_EXCEPTIONS */
Modified: trunk/Foundation/LFObjCRuntime.h.in
===================================================================
--- trunk/Foundation/LFObjCRuntime.h.in 2006-08-31 22:26:13 UTC (rev 281)
+++ trunk/Foundation/LFObjCRuntime.h.in 2006-08-31 22:26:28 UTC (rev 282)
@@ -89,6 +89,10 @@
#ifdef LF_SPI
+/*
+ * Runtime-specific Exception Handling
+ */
+
/*!
* Uncaught exception handler function type.
* Mirrors NSUncaughtExceptionHandler.
@@ -114,12 +118,6 @@
*/
LF_PRIVATE LFUncaughtExceptionHandler *LFObjCGetUncaughtExceptionHandler (void);
-/*!
- * Throw an exception.
- * @internal
- */
-LF_PRIVATE void LFObjC_ExceptionThrow (id exception);
-
#endif /* LF_SPI */
#if defined(GNU_RUNTIME)
Added: trunk/Foundation/LFStackException.m
===================================================================
--- trunk/Foundation/LFStackException.m (rev 0)
+++ trunk/Foundation/LFStackException.m 2006-08-31 22:26:28 UTC (rev 282)
@@ -0,0 +1,314 @@
+/*
+ * LFObjCExceptionStack.m vi:ts=4:sw=4:expandtab:
+ *
+ * Generic Exception Stack Implementation.
+ * Compatible with both new-style language exceptions as implemented by
+ * the Apple runtime, and old-style NS_DURING exceptions in both runtimes.
+ *
+ * Copyright (C) 2005 - 2006 Landon Fuller <la...@op...>
+ * All rights reserved.
+ *
+ * Author: Landon Fuller <la...@op...>
+ *
+ * This file is part of libFoundation.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ *
+ * We disclaim all warranties with regard to this software, including all
+ * implied warranties of merchantability and fitness, in no event shall
+ * we be liable for any special, indirect or consequential damages or any
+ * damages whatsoever resulting from loss of use, data or profits, whether in
+ * an action of contract, negligence or other tortious action, arising out of
+ * or in connection with the use or performance of this software.
+ */
+
+/*!
+ * @file
+ * @internal
+ * @brief LFObjCRuntime
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if defined(APPLE_RUNTIME) || (defined(GNU_RUNTIME) && !defined(OBJC_EXCEPTIONS))
+
+/******************************************************************************
+ * This code implementions binary-compatible exception handling for both
+ * new and old-style exceptions in the Apple Objective-C runtime.
+ *
+ * It also implements non-binary compatible exception handling support for
+ * old-style exceptions in GNU's Objective-C runtime.
+ *
+ * We maintain a per-thread stack of exception handlers. Handlers are pushed
+ * and popped off the stack at the beginning and end of every try/catch block,
+ * via a runtime function call. When an exception occurs, our
+ * LFObjC_ExceptionThrow() function is called, and we need to longjmp to the
+ * current exception handler at the top of the per-thread handler stack.
+ *
+ * The push/pop runtime function calls are handled automatically by the
+ * new-style exception support in Apple's runtime. With old-style exceptions,
+ * we manually implement the equivalent using preprocessor macros.
+ *****************************************************************************/
+
+#include <Foundation/NSZone.h>
+#include <Foundation/NSException.h>
+#include <Foundation/LFObjCRuntime.h>
+#include <Foundation/spin.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <setjmp.h>
+
+/* Number of exception handlers to store in each bucket.
+ * Selected arbitrarily. */
+#define EHS_BUCKET_SIZE 16
+
+/* Forward declarations */
+static void LFObjC_ExceptionThrow (id);
+static void LFObjC_ExceptionTryEnter (void *);
+static void LFObjC_ExceptionTryExit (void *);
+static id LFObjC_ExceptionExtract (void *);
+static int LFObjC_ExceptionMatch (Class, id);
+static void free_exception_handler_stack_tls (void *);
+
+/* Per-thread stack of exception handler buckets, each bucket
+ * holds EHS_BUCKET_SIZE handlers */
+typedef struct LFExceptionHandlerBucket {
+ int count;
+ LFObjCLocalExceptionData *excData[EHS_BUCKET_SIZE];
+ struct LFExceptionHandlerBucket *next;
+} LFExceptionHandlerBucket;
+
+/* We modify the pointer in this structure so that we don't
+ * have to call pthread_setspecific() repeatedly */
+typedef struct LFExceptionHandler_TLS {
+ LFExceptionHandlerBucket *bucket;
+} LFExceptionHandler_TLS;
+
+/* Per-thread EH stack key */
+static pthread_key_t LFExceptionHandlerStack_key;
+
+/* Uncaught exception handler */
+static LFUncaughtExceptionHandler *ueh_handler;
+static slock_t ueh_lock;
+
+/* Expose our exception stack functions */
+#if defined APPLE_RUNTIME
+/*!
+ * Exception handling functions for the Apple Objective-C runtime.
+ * @internal
+ */
+objc_exception_functions_t objc_exc_funcs = {
+ 0,
+ LFObjC_ExceptionThrow,
+ LFObjC_ExceptionTryEnter,
+ LFObjC_ExceptionTryExit,
+ LFObjC_ExceptionExtract,
+ LFObjC_ExceptionMatch
+};
+#endif /* APPLE_RUNTIME */
+
+void _NSAddHandler (LFObjCLocalExceptionData *excData) {
+ LFObjC_ExceptionTryEnter(excData);
+}
+
+void _NSRemoveHandler (LFObjCLocalExceptionData *excData) {
+ LFObjC_ExceptionTryExit(excData);
+}
+
+NSException *_NSExceptionObjectFromHandler (LFObjCLocalExceptionData *excData) {
+ return LFObjC_ExceptionExtract(excData);
+}
+
+LF_PRIVATE void _NSExceptionThrow (id e) {
+ LFObjC_ExceptionThrow(e);
+}
+
+/*!
+ * Set Objective-C Uncaught Exception Handler.
+ * @internal
+ */
+LF_PRIVATE void LFObjCSetUncaughtExceptionHandler (LFUncaughtExceptionHandler *handler) {
+ SpinLockAcquire(&ueh_lock);
+ ueh_handler = handler;
+ SpinLockRelease(&ueh_lock);
+}
+
+/*!
+ * Get Objective-C Uncaught Exception Handler.
+ * @internal
+ */
+LF_PRIVATE LFUncaughtExceptionHandler *LFObjCGetUncaughtExceptionHandler (void) {
+ LFUncaughtExceptionHandler *handler;
+ SpinLockAcquire(&ueh_lock);
+ handler = ueh_handler;
+ SpinLockRelease(&ueh_lock);
+
+ return handler;
+}
+
+/*!
+ * Initialize the Objective-C Exception Handler.
+ * @internal
+ */
+LF_PRIVATE void LFObjCInitExceptionHandler (LFUncaughtExceptionHandler *handler) {
+ /* Initialize the lock */
+ SpinLockInit(&ueh_lock);
+ ueh_handler = handler;
+
+ /* Initialize our pthread key */
+ pthread_key_create(&LFExceptionHandlerStack_key, free_exception_handler_stack_tls);
+
+#if defined(APPLE_RUNTIME) && defined(OBJC_EXCEPTIONS)
+ /* Set up exception handling functions for the Apple runtime */
+ objc_exception_set_functions((objc_exception_functions_t *) &objc_exc_funcs);
+#endif
+}
+
+/*!
+ * Throw an exception.
+ * @internal
+ */
+LF_PRIVATE void LFObjC_ExceptionThrow (id exception) {
+ LFExceptionHandler_TLS *ehsTLS;
+ LFObjCLocalExceptionData *lfexcData;
+ LFExceptionHandlerBucket *bucket;
+
+ /* Grab the stack */
+ ehsTLS = (LFExceptionHandler_TLS *) pthread_getspecific(LFExceptionHandlerStack_key);
+
+ /* If the stack is NULL or the bucket is empty, someone forgot to catch
+ * the exception. Call the uncaught ex...
[truncated message content] |
|
From: <la...@us...> - 2006-09-01 03:54:00
|
Revision: 290
http://svn.sourceforge.net/substrate/?rev=290&view=rev
Author: landonf
Date: 2006-08-31 20:53:57 -0700 (Thu, 31 Aug 2006)
Log Message:
-----------
Fix type punned alias breakage through the judicious use of unions.
This should fix the unit test failures on linux-amd64
Modified Paths:
--------------
trunk/Foundation/NSByteOrder.m
trunk/Tests/NSByteOrder.m
Modified: trunk/Foundation/NSByteOrder.m
===================================================================
--- trunk/Foundation/NSByteOrder.m 2006-09-01 02:44:30 UTC (rev 289)
+++ trunk/Foundation/NSByteOrder.m 2006-09-01 03:53:57 UTC (rev 290)
@@ -24,6 +24,27 @@
#include <Foundation/NSByteOrder.h>
+/*
+ * According to ISO C99, 6.5:
+ * An object shall have its stored value accessed only by an lvalue expression
+ * that has one of the following types:
+ * ...
+ * - an aggregate or union type that includes on of the aforementioned
+ * types among its members (including, recursively, a member of a
+ * subagregate or contained union)
+ * ...
+ * So, that's exactly what we do:
+ */
+union fcast {
+ float number;
+ NSSwappedFloat swapped;
+};
+
+union dcast {
+ double number;
+ NSSwappedDouble swapped;
+};
+
LF_DECLARE unsigned int
NSHostByteOrder()
{
@@ -185,29 +206,25 @@
LF_DECLARE NSSwappedFloat
NSConvertHostFloatToSwapped(float x)
{
- NSSwappedFloat f;
- f.v = *((unsigned long *)&x);
- return f;
+ return ((union fcast *)&x)->swapped;
}
LF_DECLARE float
NSConvertSwappedFloatToHost(NSSwappedFloat x)
{
- return *((float *)&x.v);
+ return ((union fcast *)&x.v)->number;
}
LF_DECLARE NSSwappedDouble
NSConvertHostDoubleToSwapped(double x)
{
- NSSwappedDouble d;
- d.v = *((unsigned long long *)&x);
- return d;
+ return ((union dcast *)&x)->swapped;
}
LF_DECLARE double
NSConvertSwappedDoubleToHost(NSSwappedDouble x)
{
- return *((double *)&x.v);
+ return ((union dcast *)&x.v)->number;
}
LF_DECLARE NSSwappedFloat
Modified: trunk/Tests/NSByteOrder.m
===================================================================
--- trunk/Tests/NSByteOrder.m 2006-09-01 02:44:30 UTC (rev 289)
+++ trunk/Tests/NSByteOrder.m 2006-09-01 03:53:57 UTC (rev 290)
@@ -250,7 +250,7 @@
START_TEST (test_NSConvertHostFloatToSwapped) {
float x = 21345.0;
NSSwappedFloat f = NSConvertHostFloatToSwapped(x);
- fail_unless(memcmp(&x, &f, 4) == 0, "NSConvertHostFloatToSwapped() returned differing memory.\n");
+ fail_unless(memcmp(&x, &f, sizeof(x)) == 0, "NSConvertHostFloatToSwapped() returned incorrect value (Expected: %f, got: %f)\n", x, NSConvertSwappedFloatToHost(f));
}
END_TEST
@@ -259,14 +259,14 @@
float x;
f.v = 0x1234ABCD;
x = NSConvertSwappedFloatToHost(f);
- fail_unless(memcmp(&x, &f, 4) == 0, "NSConvertSwappedFloatToHost() returned differing memory.\n");
+ fail_unless(memcmp(&x, &f, sizeof(x)) == 0, "NSConvertSwappedFloatToHost() returned incorrect value. (Expected: %f, got: %f)", x, NSConvertSwappedFloatToHost(f));
}
END_TEST
START_TEST (test_NSConvertHostDoubleToSwapped) {
double x = 21345.0;
NSSwappedDouble d = NSConvertHostDoubleToSwapped(x);
- fail_unless(memcmp(&x, &d, 8) == 0, "NSConvertHostDoubleToSwapped() returned differing memory.\n");
+ fail_unless(memcmp(&x, &d, sizeof(x)) == 0, "NSConvertHostDoubleToSwapped() returned incorrect value. (Expected: %f, got: %f)", x, NSConvertSwappedDoubleToHost(d));
}
END_TEST
@@ -275,7 +275,7 @@
double x;
d.v = 0x1234ABCDABCD1234ULL;
x = NSConvertSwappedDoubleToHost(d);
- fail_unless(memcmp(&x, &d, 8) == 0, "NSConvertSwappedDoubleToHost() returned differing memory.\n");
+ fail_unless(memcmp(&x, &d, sizeof(x)) == 0, "NSConvertSwappedDoubleToHost() returned incorrect value (Expected: %f, got %f)", NSConvertSwappedDoubleToHost(d), x);
}
END_TEST
@@ -307,7 +307,7 @@
#else
NSSwappedDouble expected = NSSwapDouble(d);
#endif
- fail_unless(memcmp(&expected, &x, 8) == 0, "NSSwapBigDoubleToHost() returned incorrect data.\n");
+ fail_unless(memcmp(&expected, &x, sizeof(x)) == 0, "NSSwapBigDoubleToHost() returned incorrect value (Expected: %f, got: %f)", NSConvertSwappedDoubleToHost(expected), x);
}
END_TEST
@@ -321,7 +321,7 @@
#else
NSSwappedFloat expected = NSSwapFloat(f);
#endif
- fail_unless(memcmp(&expected, &x, 4) == 0, "NSSwapBigDoubleToHost() returned incorrect data.\n");
+ fail_unless(memcmp(&expected, &x, sizeof(x)) == 0, "NSSwapBigFloatToHost() returned incorrect value (Expected: %f, got: %f)", NSConvertSwappedFloatToHost(expected), x);
}
END_TEST
@@ -334,7 +334,7 @@
#else
NSSwappedDouble expected = NSSwapDouble(x_);
#endif
- fail_if(d.v != expected.v, "NSSwapHostDoubleToBig() returned incorrect data.\n");
+ fail_unless(NSConvertSwappedDoubleToHost(d) == NSConvertSwappedDoubleToHost(expected), "NSSwapHostDoubleToBig() returned incorrect value (Expected: %f, got: %f)", NSConvertSwappedDoubleToHost(expected), NSConvertSwappedDoubleToHost(d));
}
END_TEST
@@ -347,7 +347,7 @@
#else
NSSwappedFloat expected = NSSwapFloat(x_);
#endif
- fail_if(f.v != expected.v, "NSSwapHostDoubleToBig() returned incorrect data.\n");
+ fail_unless(NSConvertSwappedFloatToHost(f) == NSConvertSwappedFloatToHost(expected), "NSSwapHostFloatToBig() returned incorrect value (Expected: %f, got: %f)", NSConvertSwappedFloatToHost(expected), NSConvertSwappedFloatToHost(f));
}
END_TEST
@@ -361,7 +361,7 @@
#else
NSSwappedDouble expected = d;
#endif
- fail_unless(memcmp(&expected, &x, 8) == 0, "NSSwapLittleDoubleToHost() returned incorrect data.\n");
+ fail_unless(memcmp(&expected, &x, sizeof(x)) == 0, "NSSwapLittleDoubleToHost() returned incorrect value (Expected: %f, got: %f)", NSConvertSwappedDoubleToHost(expected), x);
}
END_TEST
@@ -375,7 +375,7 @@
#else
NSSwappedFloat expected = f;
#endif
- fail_unless(memcmp(&expected, &x, 4) == 0, "NSSwapLittleDoubleToHost() returned incorrect data.\n");
+ fail_unless(memcmp(&expected, &x, sizeof(x)) == 0, "NSSwapLittleFloatToHost() returned incorrect value (Expected: %f, got: %f)", NSConvertSwappedFloatToHost(expected), x);
}
END_TEST
@@ -388,7 +388,7 @@
#else
NSSwappedDouble expected = x_;
#endif
- fail_if(d.v != expected.v, "NSSwapHostDoubleToLittle() returned incorrect data.\n");
+ fail_unless(NSConvertSwappedDoubleToHost(d) == NSConvertSwappedDoubleToHost(expected), "NSSwapHostDoubleToLittle() returned incorrect value (Expected: %f, got: %f)", NSConvertSwappedDoubleToHost(expected), NSConvertSwappedDoubleToHost(d));
}
END_TEST
@@ -401,7 +401,7 @@
#else
NSSwappedFloat expected = x_;
#endif
- fail_if(f.v != expected.v, "NSSwapHostDoubleToLittle() returned incorrect data.\n");
+ fail_unless(NSConvertSwappedFloatToHost(f) == NSConvertSwappedFloatToHost(expected), "NSSwapHostFloatToLittle() returned incorrect value (Expected: %f, got: %f)", NSConvertSwappedFloatToHost(expected), NSConvertSwappedFloatToHost(f));
}
END_TEST
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-01 05:10:00
|
Revision: 291
http://svn.sourceforge.net/substrate/?rev=291&view=rev
Author: landonf
Date: 2006-08-31 22:09:57 -0700 (Thu, 31 Aug 2006)
Log Message:
-----------
Avoid stomping on CFLAGS/LDFLAGS
Modified Paths:
--------------
trunk/Mk/autoconf.mk.in
trunk/platform.m4
Modified: trunk/Mk/autoconf.mk.in
===================================================================
--- trunk/Mk/autoconf.mk.in 2006-09-01 03:53:57 UTC (rev 290)
+++ trunk/Mk/autoconf.mk.in 2006-09-01 05:09:57 UTC (rev 291)
@@ -49,7 +49,7 @@
LIB_FILE = @LIB_FILE@
LDFLAGS_DEBUG = @LDFLAGS_DEBUG@
LDFLAGS_OPTIMIZE = @LDFLAGS_OPTIMIZE@
-LDFLAGS = @LDFLAGS_DEFAULT@
+LDFLAGS = @LDFLAGS_DEFAULT@ @LDFLAGS@
RANLIB = @RANLIB@
LF_STDINT_INC = @LF_STDINT_INC@
Modified: trunk/platform.m4
===================================================================
--- trunk/platform.m4 2006-09-01 03:53:57 UTC (rev 290)
+++ trunk/platform.m4 2006-09-01 05:09:57 UTC (rev 291)
@@ -447,7 +447,7 @@
SHLIB_LD_LIBS='${LIBS}'
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
LD_LIBRARY_PATH_VAR="LIBPATH"
@@ -458,7 +458,7 @@
else
do64bit_ok=yes
EXTRA_CFLAGS="-q64"
- LDFLAGS="-q64"
+ PLATFORM_LDFLAGS="-q64"
RANLIB="${RANLIB} -X64"
AR="${AR} -X64"
SHLIB_LD_FLAGS="-b64"
@@ -486,7 +486,7 @@
SHLIB_CFLAGS=""
SHLIB_LD_LIBS='${LIBS}'
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
LD_LIBRARY_PATH_VAR="LIBPATH"
LIB_NEEDS_EXP_FILE=1
LIB_EXPORT_FILE_SUFFIX='${LIB_VERSION}${DBGX}.exp'
@@ -504,7 +504,7 @@
else
do64bit_ok=yes
EXTRA_CFLAGS="-q64"
- LDFLAGS="-q64"
+ PLATFORM_LDFLAGS="-q64"
RANLIB="${RANLIB} -X64"
AR="${AR} -X64"
SHLIB_LD_FLAGS="-b64"
@@ -535,21 +535,21 @@
SHLIB_LD="shlicc -r"
SHLIB_LD_LIBS='${LIBS}'
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
;;
bsdi4.*)
SHLIB_CFLAGS="-export-dynamic -fPIC"
SHLIB_LD="cc -shared"
SHLIB_LD_LIBS='${LIBS}'
SHLIB_SUFFIX=".so"
- LDFLAGS="-export-dynamic"
+ PLATFORM_LDFLAGS="-export-dynamic"
;;
dgux*)
SHLIB_CFLAGS="-K PIC"
SHLIB_LD="cc -G"
SHLIB_LD_LIBS=""
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
;;
hpux11.*)
# Use updated header definitions where possible
@@ -563,7 +563,7 @@
SHLIB_CFLAGS="+z"
SHLIB_LD="ld -b"
SHLIB_LD_LIBS='${LIBS}'
- LDFLAGS="-Wl,-E"
+ PLATFORM_LDFLAGS="-Wl,-E"
LD_LIBRARY_PATH_VAR="SHLIB_PATH"
fi
if test "$GCC" = "yes" ; then
@@ -593,10 +593,10 @@
do64bit_ok=yes
if test "`uname -m`" = "ia64" ; then
EXTRA_CFLAGS="+DD64"
- LDFLAGS="+DD64 $LDFLAGS"
+ PLATFORM_LDFLAGS="+DD64 $LDFLAGS"
else
EXTRA_CFLAGS="+DA2.0W"
- LDFLAGS="+DA2.0W $LDFLAGS"
+ PLATFORM_LDFLAGS="+DA2.0W $LDFLAGS"
fi
fi
fi
@@ -609,7 +609,7 @@
SHLIB_CFLAGS="+z"
SHLIB_LD="ld -b"
SHLIB_LD_LIBS=""
- LDFLAGS="-Wl,-E"
+ PLATFORM_LDFLAGS="-Wl,-E"
LD_LIBRARY_PATH_VAR="SHLIB_PATH"
fi
;;
@@ -618,7 +618,7 @@
SHLIB_SUFFIX=".a"
SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r -G 0"
SHLIB_LD_LIBS='${LIBS}'
- LDFLAGS="-Wl,-D,08000000"
+ PLATFORM_LDFLAGS="-Wl,-D,08000000"
SHARED_LIB_SUFFIX='${LIB_VERSION}${DBGX}.a'
;;
irix5.*)
@@ -627,7 +627,7 @@
SHLIB_LD_LIBS='${LIBS}'
SHLIB_SUFFIX=".so"
EXTRA_CFLAGS=""
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
;;
irix6.*)
SHLIB_CFLAGS=""
@@ -636,7 +636,7 @@
SHLIB_SUFFIX=".so"
if test "$GCC" = "yes" ; then
EXTRA_CFLAGS="-mabi=n32"
- LDFLAGS="-mabi=n32"
+ PLATFORM_LDFLAGS="-mabi=n32"
else
case $target_os in
irix6.3)
@@ -647,7 +647,7 @@
EXTRA_CFLAGS="-n32"
;;
esac
- LDFLAGS="-n32"
+ PLATFORM_LDFLAGS="-n32"
fi
;;
irix646.*)
@@ -656,7 +656,7 @@
SHLIB_LD="ld -n32 -shared -rdata_shared"
SHLIB_LD_LIBS='${LIBS}'
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
# Check to enable 64-bit flags for compiler/linker
@@ -667,7 +667,7 @@
do64bit_ok=yes
SHLIB_LD="ld -64 -shared -rdata_shared"
EXTRA_CFLAGS="-64"
- LDFLAGS="-64"
+ PLATFORM_LDFLAGS="-64"
fi
fi
;;
@@ -677,7 +677,7 @@
SHLIB_SUFFIX=".so"
SHLIB_LD="${CC} -shared"
- LDFLAGS="-rdynamic"
+ PLATFORM_LDFLAGS="-rdynamic"
case $target_cpu in
alpha*)
EXTRA_CFLAGS="-mieee"
@@ -690,7 +690,7 @@
SHLIB_SUFFIX=".so"
SHLIB_LD="${CC} -shared"
- LDFLAGS="-rdynamic"
+ PLATFORM_LDFLAGS="-rdynamic"
case $target_cpu in
alpha*)
EXTRA_CFLAGS="-mieee"
@@ -719,7 +719,7 @@
SHLIB_LD="cc -G"
SHLIB_LD_LIBS=""
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
;;
MP-RAS-*)
# config.guess doesn't support these systems
@@ -727,16 +727,16 @@
SHLIB_LD="cc -G"
SHLIB_LD_LIBS=""
SHLIB_SUFFIX=".so"
- LDFLAGS="-Wl,-Bexport"
+ PLATFORM_LDFLAGS="-Wl,-Bexport"
;;
netbsd*|freebsd[[1-2]].*|openbsd*)
# Not available on all versions: check for include file.
# NetBSD/SPARC needs -fPIC, -fpic will not do.
SHLIB_CFLAGS="-fPIC"
SHLIB_LD="${CC} -shared"
- LDFLAGS="-rdynamic"
+ PLATFORM_LDFLAGS="-rdynamic"
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
AC_MSG_CHECKING(for ELF)
AC_EGREP_CPP(yes, [
#ifdef __ELF__
@@ -759,12 +759,12 @@
SHLIB_LD="${CC} -shared"
SHLIB_LD_LIBS='${LIBS}'
SHLIB_SUFFIX=".so"
- LDFLAGS="-export-dynamic"
+ PLATFORM_LDFLAGS="-export-dynamic"
if test "${TCL_THREADS}" = "1" ; then
# The -pthread needs to go in the CFLAGS, not LIBS
LIBS=`echo $LIBS | sed s/-pthread//`
EXTRA_CFLAGS="-pthread"
- LDFLAGS="$LDFLAGS -pthread"
+ PLATFORM_LDFLAGS="$LDFLAGS -pthread"
fi
case $target_os in
freebsd3.*)
@@ -790,7 +790,7 @@
SHLIB_LD="cc -nostdlib -r"
SHLIB_LD_LIBS=""
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
;;
openedition*)
# IBM OS/390
@@ -804,7 +804,7 @@
SHLIB_LD='ld -R -export $@:'
SHLIB_LD_LIBS=""
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
;;
osf1*1.*)
# OSF/1 1.3 from OSF using ELF, and derivatives, including AD2
@@ -816,7 +816,7 @@
fi
SHLIB_LD_LIBS=""
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
;;
osf1V*)
# Digital OSF/1
@@ -828,7 +828,7 @@
fi
SHLIB_LD_LIBS=""
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
if test "$GCC" = "yes" ; then
EXTRA_CFLAGS="-mieee"
else
@@ -843,7 +843,7 @@
LIBS="$LIBS -lpthread -lmach -lexc"
else
EXTRA_CFLAGS="${EXTRA_CFLAGS} -pthread"
- LDFLAGS="-pthread"
+ PLATFORM_LDFLAGS="-pthread"
fi
fi
@@ -855,22 +855,22 @@
SHLIB_LD="ld -Bshareable -x"
SHLIB_LD_LIBS=""
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
;;
riscos*)
SHLIB_CFLAGS="-G 0"
SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r -G 0"
SHLIB_LD_LIBS='${LIBS}'
SHLIB_SUFFIX=".a"
- LDFLAGS="-Wl,-D,08000000"
+ PLATFORM_LDFLAGS="-Wl,-D,08000000"
;;
SCO_SV*)
if test "$GCC" = "yes" ; then
SHLIB_CFLAGS="-fPIC -melf"
- LDFLAGS="-melf -Wl,-Bexport"
+ PLATFORM_LDFLAGS="-melf -Wl,-Bexport"
else
SHLIB_CFLAGS="-Kpic -belf"
- LDFLAGS="-belf -Wl,-Bexport"
+ PLATFORM_LDFLAGS="-belf -Wl,-Bexport"
fi
SHLIB_LD="ld -G"
SHLIB_LD_LIBS=""
@@ -881,14 +881,14 @@
SHLIB_LD="cc -G"
SHLIB_LD_LIBS=""
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
;;
sunos4*)
SHLIB_CFLAGS="-PIC"
SHLIB_LD="ld"
SHLIB_LD_LIBS=""
SHLIB_SUFFIX=".so"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
# SunOS can't handle version numbers with dots in them in library
# specs, like -ltcl7.5, so use -ltcl75 instead. Also, it
@@ -908,7 +908,7 @@
AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, [], [Define to use posix thread semantics on Sun OS 5])
SHLIB_CFLAGS="-KPIC"
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
# Check to enable 64-bit flags for compiler/linker
if test "$do64bit" = "yes" ; then
@@ -920,10 +920,10 @@
do64bit_ok=yes
if test "$do64bitVIS" = "yes" ; then
EXTRA_CFLAGS="-xarch=v9a"
- LDFLAGS="-xarch=v9a"
+ PLATFORM_LDFLAGS="-xarch=v9a"
else
EXTRA_CFLAGS="-xarch=v9"
- LDFLAGS="-xarch=v9"
+ PLATFORM_LDFLAGS="-xarch=v9"
fi
fi
else
@@ -947,7 +947,7 @@
SHLIB_SUFFIX=".a"
SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r -G 0"
SHLIB_LD_LIBS='${LIBS}'
- LDFLAGS="-Wl,-D,08000000"
+ PLATFORM_LDFLAGS="-Wl,-D,08000000"
if test "$GCC" != "yes" ; then
EXTRA_CFLAGS="-DHAVE_TZSET -std1"
fi
@@ -961,14 +961,14 @@
# that don't grok the -Bexport option. Test that it does.
hold_ldflags=$LDFLAGS
AC_MSG_CHECKING(for ld accepts -Bexport flag)
- LDFLAGS="${LDFLAGS} -Wl,-Bexport"
+ PLATFORM_LDFLAGS="${LDFLAGS} -Wl,-Bexport"
AC_TRY_LINK(, [int i;], found=yes, found=no)
- LDFLAGS=$hold_ldflags
+ PLATFORM_LDFLAGS=$hold_ldflags
AC_MSG_RESULT($found)
if test $found = yes; then
- LDFLAGS="-Wl,-Bexport"
+ PLATFORM_LDFLAGS="-Wl,-Bexport"
else
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
fi
;;
esac
@@ -983,7 +983,7 @@
SHLIB_CFLAGS=""
SHLIB_LD=""
SHLIB_SUFFIX=""
- LDFLAGS=""
+ PLATFORM_LDFLAGS=""
fi
# If we're running gcc, then change the C flags for compiling shared
@@ -1074,6 +1074,8 @@
fi
+ LDFLAGS="$LDFLAGS $PLATFORM_LDFLAGS"
+
AC_SUBST(CFLAGS)
AC_SUBST(CFLAGS_DEBUG)
AC_SUBST(CFLAGS_OPTIMIZE)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-01 19:05:43
|
Revision: 292
http://svn.sourceforge.net/substrate/?rev=292&view=rev
Author: landonf
Date: 2006-09-01 12:05:27 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
Implement cString accessor
Modified Paths:
--------------
trunk/Foundation/NSString.m
trunk/Tests/NSString.m
Modified: trunk/Foundation/NSString.m
===================================================================
--- trunk/Foundation/NSString.m 2006-09-01 05:09:57 UTC (rev 291)
+++ trunk/Foundation/NSString.m 2006-09-01 19:05:27 UTC (rev 292)
@@ -34,6 +34,7 @@
#include <Foundation/NSString.h>
#include <Foundation/NSUnicodeString.h>
+#include <Foundation/NSData.h>
#include <Foundation/NSException.h>
#include <Foundation/NSObjCRuntime.h>
#include <Foundation/NSObjectPrivate.h>
@@ -94,6 +95,7 @@
return NSUTF8StringEncoding;
}
+
/*!
* Convert the receiving string to the specified encoding, returning
* the result as an instance of NSData.
@@ -277,19 +279,33 @@
/*!
* Returns representation of the receiver as a C string
- * in the default C encoding. This method has been deprecated in
- * favor of UTF8String.
+ * in the default C encoding.
+ * @deprecated This method has been deprecated in favor of
+ * UTF8String.
*
* If the string can not be converted with the default encoding,
* an NSCharacterConversionException will be raised.
*
- * The string returned by this method will be freed when the
- * receiver is deallocated.
- * @todo Unimplemented.
+ * The string returned by this method is added to the autorelease
+ * pool.
*/
- (const char *) cString {
- /* TODO Unimplemented */
- return NULL;
+ NSData *data;
+ NSMutableData *mutable;
+
+ /* A rather ineffecient implementation */
+ data = [self dataUsingEncoding: [NSString defaultCStringEncoding] allowLossyConversion: NO];
+ if (!data)
+ [NSException raise: NSCharacterConversionException format:
+ @"Unable to convert string to the default C string encoding."];
+
+ mutable = [data mutableCopy];
+ /* Append a NULL terminator */
+ [mutable appendBytes: "" length: sizeof("")];
+
+ /* Return a to-be-autoreleased C string*/
+ [mutable autorelease];
+ return [mutable bytes];
}
- (NSString *) description {
Modified: trunk/Tests/NSString.m
===================================================================
--- trunk/Tests/NSString.m 2006-09-01 05:09:57 UTC (rev 291)
+++ trunk/Tests/NSString.m 2006-09-01 19:05:27 UTC (rev 292)
@@ -51,6 +51,7 @@
@implementation NSDumbString
- (id) initWithBytes:(const void *)bytes length:(unsigned int) length encoding:(NSStringEncoding)encoding {
+ self = [super init];
return self;
}
@@ -177,7 +178,20 @@
}
END_TEST
+START_TEST (test_cString) {
+ NSString *string;
+ const char *cStr;
+ string = [[NSDumbString alloc] init];
+ fail_if(string == nil);
+
+ cStr = [string cString];
+ fail_if(cStr == NULL, "-[NSString cString] returned nil.");
+
+ fail_unless(strcmp(cStr, TEST_STRING) == 0, "-[NSString cString] returned unexpected string (Expected: %s, got: %s).", TEST_STRING, cStr);
+}
+END_TEST
+
Suite *NSString_suite(void) {
Suite *s = suite_create("NSString");
@@ -191,6 +205,7 @@
suite_add_tcase(s, tc_encoding);
tcase_add_test(tc_encoding, test_cls_defaultCStringEncoding);
tcase_add_test(tc_encoding, test_dataUsingEncodingAllowLossyConversion);
+ tcase_add_test(tc_encoding, test_cString);
TCase *tc_init = tcase_create("Initialization");
tcase_add_checked_fixture(tc_init, setUp, tearDown);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-02 00:10:29
|
Revision: 293
http://svn.sourceforge.net/substrate/?rev=293&view=rev
Author: landonf
Date: 2006-09-01 17:10:20 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
r301@bluefish: landonf | 2006-09-01 14:49:26 -0700
We needs WORDS_BIGENDIAN defined, or we get the byte order wrong on big-endian platforms. Pull it in from config.h
Modified Paths:
--------------
trunk/Foundation/NSByteOrder.m
trunk/Tests/NSByteOrder.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:301
Modified: trunk/Foundation/NSByteOrder.m
===================================================================
--- trunk/Foundation/NSByteOrder.m 2006-09-01 19:05:27 UTC (rev 292)
+++ trunk/Foundation/NSByteOrder.m 2006-09-02 00:10:20 UTC (rev 293)
@@ -22,6 +22,10 @@
* or in connection with the use or performance of this software.
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <Foundation/NSByteOrder.h>
/*
Modified: trunk/Tests/NSByteOrder.m
===================================================================
--- trunk/Tests/NSByteOrder.m 2006-09-01 19:05:27 UTC (rev 292)
+++ trunk/Tests/NSByteOrder.m 2006-09-02 00:10:20 UTC (rev 293)
@@ -22,6 +22,9 @@
* or in connection with the use or performance of this software.
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <check.h>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-02 00:10:39
|
Revision: 294
http://svn.sourceforge.net/substrate/?rev=294&view=rev
Author: landonf
Date: 2006-09-01 17:10:31 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
r302@bluefish: landonf | 2006-09-01 14:51:02 -0700
Implement cStringUsingEncoding:(NSStringEncoding)encoding, and use it for cString and UTF8String
Modified Paths:
--------------
trunk/Foundation/NSSimpleCString.m
trunk/Foundation/NSString.h
trunk/Foundation/NSString.m
trunk/Tests/Foundation.c
trunk/Tests/Foundation.h
trunk/Tests/Makefile.in
trunk/Tests/NSException.m
trunk/Tests/NSString.m
trunk/Tests/NSZone.m
Added Paths:
-----------
trunk/Tests/NSSimpleString.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:301
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:302
Modified: trunk/Foundation/NSSimpleCString.m
===================================================================
--- trunk/Foundation/NSSimpleCString.m 2006-09-02 00:10:20 UTC (rev 293)
+++ trunk/Foundation/NSSimpleCString.m 2006-09-02 00:10:31 UTC (rev 294)
@@ -31,6 +31,7 @@
#include <Foundation/NSException.h>
#include <Foundation/NSString.h>
+#include <Foundation/NSData.h>
#include <string.h>
/*!
@@ -87,8 +88,18 @@
return (unichar) _bytes[index];
}
-- (const char *) cString {
- return _bytes;
+- (const char *) cStringUsingEncoding:(NSStringEncoding)encoding {
+ /* We can handle UTF-8 and ASCII with no conversion overhead. */
+ if (encoding == NSUTF8StringEncoding || encoding == NSASCIIStringEncoding) {
+ /* Get an autoreleased byte array */
+ NSMutableData *data = [NSMutableData dataWithBytes: _bytes length: _numBytes];
+
+ /* Append a NULL terminator */
+ [data appendBytes: "" length: sizeof("")];
+ return [data bytes];
+ } else {
+ return [super cStringUsingEncoding:encoding];
+ }
}
- (unsigned int) cStringLength {
Modified: trunk/Foundation/NSString.h
===================================================================
--- trunk/Foundation/NSString.h 2006-09-02 00:10:20 UTC (rev 293)
+++ trunk/Foundation/NSString.h 2006-09-02 00:10:31 UTC (rev 294)
@@ -116,7 +116,6 @@
- (void) getCharacters:(unichar *)buffer;
- (void) getCharacters:(unichar *)buffer range:(NSRange)aRange;
-- (const char *) cString;
/* Initialization */
+ (id) string;
@@ -128,11 +127,14 @@
/* Encoding */
+ (NSStringEncoding) defaultCStringEncoding;
- (NSData *) dataUsingEncoding:(NSStringEncoding)encoding allowLossyConversion:(BOOL)lossy;
+- (const char *) cStringUsingEncoding:(NSStringEncoding)encoding;
+- (const char *) UTF8String;
/* Deprecated */
+ stringWithCString:(const char *)cStr;
- initWithCString:(const char *)cStr;
- initWithCString:(const char *)cStr length:(unsigned int)length;
+- (const char *) cString;
@end
Modified: trunk/Foundation/NSString.m
===================================================================
--- trunk/Foundation/NSString.m 2006-09-02 00:10:20 UTC (rev 293)
+++ trunk/Foundation/NSString.m 2006-09-02 00:10:31 UTC (rev 294)
@@ -278,23 +278,22 @@
}
/*!
- * Returns representation of the receiver as a C string
- * in the default C encoding.
- * @deprecated This method has been deprecated in favor of
- * UTF8String.
+ * Returns representation of the receiver as a NULL-terminated C string,
+ * using the supplied encoding.
*
* If the string can not be converted with the default encoding,
* an NSCharacterConversionException will be raised.
*
- * The string returned by this method is added to the autorelease
- * pool.
+ * The string returned by this method is owned by the receiver and
+ * will be autoreleased -- you must copy the result if you wish to
+ * retain it ouside of the current autorelease context.
*/
-- (const char *) cString {
+- (const char *) cStringUsingEncoding:(NSStringEncoding)encoding {
NSData *data;
NSMutableData *mutable;
/* A rather ineffecient implementation */
- data = [self dataUsingEncoding: [NSString defaultCStringEncoding] allowLossyConversion: NO];
+ data = [self dataUsingEncoding: encoding allowLossyConversion: NO];
if (!data)
[NSException raise: NSCharacterConversionException format:
@"Unable to convert string to the default C string encoding."];
@@ -303,11 +302,40 @@
/* Append a NULL terminator */
[mutable appendBytes: "" length: sizeof("")];
- /* Return a to-be-autoreleased C string*/
+ /* Return a to-be-autoreleased C string */
[mutable autorelease];
return [mutable bytes];
}
+/*!
+ * Returns representation of the receiver as a UTF-8 encoding C string.
+ *
+ * The string returned by this method is owned by the receiver and
+ * will be autoreleased -- you must copy the result if you wish to
+ * retain it ouside of the current autorelease context.
+ */
+- (const char *) UTF8String {
+ return [self cStringUsingEncoding: NSUTF8StringEncoding];
+}
+
+
+/*!
+ * Returns representation of the receiver as a C string
+ * in the default C encoding.
+ * @deprecated This method has been deprecated in favor of
+ * UTF8String.
+ *
+ * If the string can not be converted with the default encoding,
+ * an NSCharacterConversionException will be raised.
+ *
+ * The string returned by this method is owned by the receiver and
+ * will be autoreleased -- you must copy the result if you wish to
+ * retain it ouside of the current autorelease context.
+ */
+- (const char *) cString {
+ return [self cStringUsingEncoding: [NSString defaultCStringEncoding]];
+}
+
- (NSString *) description {
return self;
}
Modified: trunk/Tests/Foundation.c
===================================================================
--- trunk/Tests/Foundation.c 2006-09-02 00:10:20 UTC (rev 293)
+++ trunk/Tests/Foundation.c 2006-09-02 00:10:31 UTC (rev 294)
@@ -44,6 +44,7 @@
Suite *s = NSZone_suite();
SRunner *sr = srunner_create(s);
srunner_add_suite(sr, NSString_suite());
+ srunner_add_suite(sr, NSSimpleString_suite());
srunner_add_suite(sr, NSUnicodeString_suite());
srunner_add_suite(sr, NSAutoreleasePool_suite());
srunner_add_suite(sr, NSData_suite());
Modified: trunk/Tests/Foundation.h
===================================================================
--- trunk/Tests/Foundation.h 2006-09-02 00:10:20 UTC (rev 293)
+++ trunk/Tests/Foundation.h 2006-09-02 00:10:31 UTC (rev 294)
@@ -33,6 +33,7 @@
Suite *NSObject_suite(void);
Suite *NSProcessInfo_suite(void);
Suite *NSString_suite(void);
+Suite *NSSimpleString_suite(void);
Suite *NSUnicodeString_suite(void);
Suite *NSRange_suite(void);
Suite *NSGeometry_suite(void);
Modified: trunk/Tests/Makefile.in
===================================================================
--- trunk/Tests/Makefile.in 2006-09-02 00:10:20 UTC (rev 293)
+++ trunk/Tests/Makefile.in 2006-09-02 00:10:31 UTC (rev 294)
@@ -14,8 +14,9 @@
FOUNDATION_OBJS= Foundation.o NSAutoreleasePool.o NSException.o NSZone.o \
NSObjectAllocation.o NSObject.o NSProcessInfo.o \
- NSString.o NSUnicodeString.o NSRange.o NSGeometry.o \
- NSData.o NSMutableData.o NSConcreteData.o NSByteOrder.o
+ NSString.o NSSimpleString.o NSUnicodeString.o NSRange.o \
+ NSGeometry.o NSData.o NSMutableData.o NSConcreteData.o \
+ NSByteOrder.o
SPINLOCK_OBJS= s_lock.o
all: Foundation Spinlocks
Modified: trunk/Tests/NSException.m
===================================================================
--- trunk/Tests/NSException.m 2006-09-02 00:10:20 UTC (rev 293)
+++ trunk/Tests/NSException.m 2006-09-02 00:10:31 UTC (rev 294)
@@ -33,6 +33,17 @@
/* For strcmp */
#include <string.h>
+static NSAutoreleasePool *releasePool;
+
+static void setUp (void) {
+ releasePool = [[NSAutoreleasePool alloc] init];
+}
+
+static void tearDown (void) {
+ [releasePool release];
+}
+
+
START_TEST (test_initWithName) {
NSException *e;
#ifdef TODO_NSDictionary
@@ -45,19 +56,14 @@
e = [[NSException alloc] initWithName: @"Test" reason: @"Failure" userInfo: userInfo];
fail_if(e == nil, "-[[NSException alloc] initWithName: reason: userInfo:] returned nil");
-#ifndef TODO_NSString
name = [e name];
- fail_unless(strcmp([name cString], "Test") == 0, "-[NSException name] returned invalid name. (Expected %s, got %s)", "Test", [name cString]);
-#else
-# error Implement once NSString is functional
-#endif
+ fail_unless(strcmp([name UTF8String], "Test") == 0, "-[NSException name] returned invalid name. (Expected %s, got %s)", "Test", [name UTF8String]);
[e release];
}
END_TEST
START_TEST (test_exceptionWithName) {
- NSAutoreleasePool *pool;
NSException *e;
#ifdef TODO_NSDictionary
NSDictionary *userInfo;
@@ -65,22 +71,14 @@
NSDictionary *userInfo = NULL;
#endif
- pool = [[NSAutoreleasePool alloc] init];
-
e = [NSException exceptionWithName: @"Test" reason: @"Failure" userInfo: userInfo];
fail_if(e == nil, "+[NSException exceptionWithName: reason: userInfo:] returned nil");
-
- [pool release];
}
END_TEST
START_TEST (test_raiseformat) {
- NSAutoreleasePool *pool;
BOOL wasRaised = NO;
- pool = [[NSAutoreleasePool alloc] init];
-
-
NS_DURING
[NSException raise: NSGenericException format: @"Fred %@", NSOldStyleException];
NS_HANDLER
@@ -88,8 +86,6 @@
NS_ENDHANDLER
fail_unless(wasRaised, "+[NSException raise: format:] did not throw an exception.");
-
- [pool release];
}
END_TEST
@@ -113,23 +109,14 @@
}
START_TEST (test_raiseformatarguments) {
- NSAutoreleasePool *pool;
-
- pool = [[NSAutoreleasePool alloc] init];
-
fail_unless(call_raiseFormatArguments(@"Fred %@", @"Jones"), "+[NSException raise: format: arguments:] did not throw an exception.");
-
- [pool release];
}
END_TEST
START_TEST (test_raise) {
- NSAutoreleasePool *pool;
NSException *e;
BOOL wasRaised = NO;
- pool = [[NSAutoreleasePool alloc] init];
-
e = [NSException exceptionWithName: @"Test" reason: @"Failure" userInfo: nil];
fail_if(e == nil, "+[NSException exceptionWithName: reason: userInfo:] returned nil");
@@ -141,13 +128,10 @@
NS_ENDHANDLER
fail_unless(wasRaised, "-[NSException raise] did not throw an exception.");
-
- [pool release];
}
END_TEST
START_TEST (test_copy) {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSException *e = [NSException exceptionWithName: @"Test" reason: @"Failure" userInfo: nil];
NSException *copy = [e copy];
Class class = LFGetClass("NSException");
@@ -156,7 +140,6 @@
fail_unless([copy class] == class, "-[NSException copy] did not return an object of class NSException.");
[copy release];
- [pool release];
}
END_TEST
@@ -170,7 +153,6 @@
START_TEST (test_NSSetUncaughtExceptionHandler) {
NSUncaughtExceptionHandler *handler;
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
/* Set the handler */
NSSetUncaughtExceptionHandler(ueh_handler);
@@ -181,30 +163,19 @@
/* Now let's trigger its use */
[NSException raise: @"TestException" format: @"TestException"];
-
- /* This is never reached if the above was successful */
- [pool release];
}
END_TEST
START_TEST (test_default_NSUncaughtExceptionHandler) {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
/* Trigger the default handler */
[NSException raise: @"TestException" format: @"TestException"];
-
- /* This is never reached if the above was successful */
- [pool release];
}
END_TEST
START_TEST (test_LFObjCExceptionHandling) {
- NSAutoreleasePool *pool;
NSException *e;
- pool = [[NSAutoreleasePool alloc] init];
-
e = [NSException exceptionWithName: @"Test" reason: @"Failure" userInfo: nil];
fail_if(e == nil, "+[NSException exceptionWithName: reason: userInfo:] returned nil");
@@ -214,19 +185,13 @@
NS_HANDLER
fail_unless(localException == e, "Exception support code did not throw correct exception. (Expected %p, got %p)", e, localException);
NS_ENDHANDLER
-
- [pool release];
-
}
END_TEST
START_TEST (test_NSExceptionLegacyExceptions) {
- NSAutoreleasePool *pool;
NSException *e;
BOOL wasRaised = NO;
- pool = [[NSAutoreleasePool alloc] init];
-
e = [NSException exceptionWithName: @"Test" reason: @"Failure" userInfo: nil];
fail_if(e == nil, "+[NSException exceptionWithName: reason: userInfo:] returned nil");
@@ -239,9 +204,6 @@
NS_ENDHANDLER
fail_unless(wasRaised, "-[NSException raise] did not throw an exception.");
-
- [pool release];
-
}
END_TEST
@@ -277,6 +239,7 @@
Suite *s = suite_create("NSException");
TCase *tc = tcase_create("Default");
+ tcase_add_checked_fixture(tc, setUp, tearDown);
suite_add_tcase(s, tc);
tcase_add_test(tc, test_exceptionWithName);
tcase_add_test(tc, test_initWithName);
@@ -286,6 +249,7 @@
tcase_add_test(tc, test_copy);
TCase *tc_exceptions = tcase_create("Standard Runtime Exception Handling");
+ tcase_add_checked_fixture(tc_exceptions, setUp, tearDown);
suite_add_tcase(s, tc_exceptions);
tcase_add_test(tc_exceptions, test_LFObjCExceptionHandling);
tcase_add_test(tc_exceptions, test_NSExceptionLegacyExceptions);
@@ -293,6 +257,7 @@
tcase_add_test(tc_exceptions, test_NS_VALUERETURN);
TCase *tc_uncaught = tcase_create("Uncaught Exception Handling");
+ tcase_add_checked_fixture(tc_uncaught, setUp, tearDown);
suite_add_tcase(s, tc_uncaught);
tcase_add_test_raise_signal(tc_uncaught, test_NSSetUncaughtExceptionHandler, SIGILL);
tcase_add_test_raise_signal(tc_uncaught, test_default_NSUncaughtExceptionHandler, SIGTRAP);
Added: trunk/Tests/NSSimpleString.m
===================================================================
--- trunk/Tests/NSSimpleString.m (rev 0)
+++ trunk/Tests/NSSimpleString.m 2006-09-02 00:10:31 UTC (rev 294)
@@ -0,0 +1,115 @@
+/*
+ * NSSimpleString.m
+ * Foundation Unit Tests
+ *
+ * Copyright (C) 2005 - 2006 Landon Fuller <la...@op...>
+ * All rights reserved.
+ *
+ * This file is part of libFoundation.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ *
+ * We disclaim all warranties with regard to this software, including all
+ * implied warranties of merchantability and fitness, in no event shall
+ * we be liable for any special, indirect or consequential damages or any
+ * damages whatsoever resulting from loss of use, data or profits, whether in
+ * an action of contract, negligence or other tortious action, arising out of
+ * or in connection with the use or performance of this software.
+ */
+
+#include <check.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+#include <Foundation/NSString.h>
+#include <Foundation/NSData.h>
+#include <Foundation/NSException.h>
+#include <Foundation/NSAutoreleasePool.h>
+#include "LFObjCRuntime.h"
+
+/*
+ * Tests that are specific to the NSSimpleString concrete implementation.
+ *
+ * These tests make some assumptions about NSString instantiation, and thus may
+ * not directly apply to other Foundation implementations -- but they certainly
+ * shouldn't fail.
+ */
+
+const char TEST_STRING[] = "Hello, World.";
+
+static NSAutoreleasePool *releasePool;
+
+static void setUp(void) {
+ releasePool = [[NSAutoreleasePool alloc] init];
+}
+
+static void tearDown(void) {
+ [releasePool release];
+}
+
+/* Encoding */
+START_TEST (test_cStringUsingEncoding) {
+ NSString *string;
+ const char *cStr;
+
+ string = [[NSString alloc] initWithCString: TEST_STRING];
+ fail_if(string == nil);
+
+ cStr = [string cStringUsingEncoding: NSASCIIStringEncoding];
+ fail_if(cStr == NULL, "-[NSString cStringUsingEncoding:] returned nil.");
+ fail_unless(strcmp(cStr, TEST_STRING) == 0, "-[NSString cString] returned unexpected string (Expected: %s, got: %s).", TEST_STRING, cStr);
+}
+END_TEST
+
+START_TEST (test_UTF8String) {
+ NSString *string;
+ const char *cStr;
+
+ string = [[NSString alloc] initWithCString: TEST_STRING];
+ fail_if(string == nil);
+
+ cStr = [string UTF8String];
+ fail_if(cStr == NULL, "-[NSString UTF8String] returned nil.");
+
+ fail_unless(strcmp(cStr, TEST_STRING) == 0, "-[NSString UTF8String] returned unexpected string (Expected: %s, got: %s).", TEST_STRING, cStr);
+}
+END_TEST
+
+START_TEST (test_cString) {
+ NSString *string;
+ const char *cStr;
+
+ string = [[NSString alloc] initWithCString: TEST_STRING];
+ fail_if(string == nil);
+
+ cStr = [string cString];
+ fail_if(cStr == NULL, "-[NSString cString] returned nil.");
+
+ fail_unless(strcmp(cStr, TEST_STRING) == 0, "-[NSString cString] returned unexpected string (Expected: %s, got: %s).", TEST_STRING, cStr);
+}
+END_TEST
+
+Suite *NSSimpleString_suite(void) {
+ Suite *s = suite_create("NSSimpleString");
+
+ TCase *tc_encoding = tcase_create("Encodings");
+ tcase_add_checked_fixture(tc_encoding, setUp, tearDown);
+ suite_add_tcase(s, tc_encoding);
+ tcase_add_test(tc_encoding, test_cStringUsingEncoding);
+ tcase_add_test(tc_encoding, test_UTF8String);
+ tcase_add_test(tc_encoding, test_cString);
+
+ return (s);
+}
Modified: trunk/Tests/NSString.m
===================================================================
--- trunk/Tests/NSString.m 2006-09-02 00:10:20 UTC (rev 293)
+++ trunk/Tests/NSString.m 2006-09-02 00:10:31 UTC (rev 294)
@@ -178,6 +178,33 @@
}
END_TEST
+START_TEST (test_cStringUsingEncoding) {
+ NSString *string;
+ const char *cStr;
+
+ string = [[NSDumbString alloc] init];
+ fail_if(string == nil);
+
+ cStr = [string cStringUsingEncoding: NSASCIIStringEncoding];
+ fail_if(cStr == NULL, "-[NSString cStringUsingEncoding:] returned nil.");
+ fail_unless(strcmp(cStr, TEST_STRING) == 0, "-[NSString cString] returned unexpected string (Expected: %s, got: %s).", TEST_STRING, cStr);
+}
+END_TEST
+
+START_TEST (test_UTF8String) {
+ NSString *string;
+ const char *cStr;
+
+ string = [[NSDumbString alloc] init];
+ fail_if(string == nil);
+
+ cStr = [string UTF8String];
+ fail_if(cStr == NULL, "-[NSString UTF8String] returned nil.");
+
+ fail_unless(strcmp(cStr, TEST_STRING) == 0, "-[NSString UTF8String] returned unexpected string (Expected: %s, got: %s).", TEST_STRING, cStr);
+}
+END_TEST
+
START_TEST (test_cString) {
NSString *string;
const char *cStr;
@@ -205,6 +232,8 @@
suite_add_tcase(s, tc_encoding);
tcase_add_test(tc_encoding, test_cls_defaultCStringEncoding);
tcase_add_test(tc_encoding, test_dataUsingEncodingAllowLossyConversion);
+ tcase_add_test(tc_encoding, test_cStringUsingEncoding);
+ tcase_add_test(tc_encoding, test_UTF8String);
tcase_add_test(tc_encoding, test_cString);
TCase *tc_init = tcase_create("Initialization");
Modified: trunk/Tests/NSZone.m
===================================================================
--- trunk/Tests/NSZone.m 2006-09-02 00:10:20 UTC (rev 293)
+++ trunk/Tests/NSZone.m 2006-09-02 00:10:31 UTC (rev 294)
@@ -180,7 +180,7 @@
NSZone *zone = NSCreateZone(10, 10, YES);
NSSetZoneName(zone, @"Monkey");
name = NSZoneName(zone);
- fail_unless(strcmp("Monkey", [name cString]) == 0, "NSSetZoneName failed, NZZoneName returned incorrect name (expected: Monkey, got: %s)", [name cString]);
+ fail_unless(strcmp("Monkey", [name UTF8String]) == 0, "NSSetZoneName failed, NZZoneName returned incorrect name (expected: Monkey, got: %s)", [name UTF8String]);
}
END_TEST
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-02 00:10:45
|
Revision: 295
http://svn.sourceforge.net/substrate/?rev=295&view=rev
Author: landonf
Date: 2006-09-01 17:10:41 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
r303@bluefish: landonf | 2006-09-01 14:52:05 -0700
Grammar fix
Modified Paths:
--------------
trunk/Tests/NSUnicodeString.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:302
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:303
Modified: trunk/Tests/NSUnicodeString.m
===================================================================
--- trunk/Tests/NSUnicodeString.m 2006-09-02 00:10:31 UTC (rev 294)
+++ trunk/Tests/NSUnicodeString.m 2006-09-02 00:10:41 UTC (rev 295)
@@ -183,7 +183,7 @@
fail_if(string == nil, "-[NSString initWithBytes: length: encoding:] return nil for NSStringEncoding %d.", stringEncoding); \
data = [string dataUsingEncoding: stringEncoding allowLossyConversion: NO]; \
fail_if(data == nil, "-[NSString dataUsingEncoding: allowLossyConversion:] return nil for NSStringEncoding %d.", stringEncoding); \
- fail_unless(memcmp([data bytes], stringEncoding ## _data, sizeof(stringEncoding ## _data)) == 0, "-[NSString dataUsingEncoding: allowLossyConversion:] return data that does not match the original for NSStringEncoding %d.", stringEncoding); \
+ fail_unless(memcmp([data bytes], stringEncoding ## _data, sizeof(stringEncoding ## _data)) == 0, "-[NSString dataUsingEncoding: allowLossyConversion:] returned data that does not match the original for NSStringEncoding %d.", stringEncoding); \
[string release]; \
} \
END_TEST
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-02 00:10:55
|
Revision: 296
http://svn.sourceforge.net/substrate/?rev=296&view=rev
Author: landonf
Date: 2006-09-01 17:10:46 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
r304@bluefish: landonf | 2006-09-01 14:59:27 -0700
UTF-16-LE as the canonical byte ordering was a lie. Apple's runtime returns strings in the host's byte ordering, and now we do the same.
Modified Paths:
--------------
trunk/Foundation/NSUnicodeString.m
trunk/Tests/NSUnicodeString.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:303
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:304
Modified: trunk/Foundation/NSUnicodeString.m
===================================================================
--- trunk/Foundation/NSUnicodeString.m 2006-09-02 00:10:41 UTC (rev 295)
+++ trunk/Foundation/NSUnicodeString.m 2006-09-02 00:10:46 UTC (rev 296)
@@ -427,9 +427,13 @@
case NSProprietaryStringEncoding: /* Fall through to UTF-16 */
/* Canonical encoding for NSString objects (UTF-16). */
case NSUnicodeStringEncoding:
- /* UTF-16-LE is the canonical byte ordering for UTF-16 strings in
- * both Substrate and Apple's Foundation */
+ /* Apple's Foundation returns the string encoded in the host's
+ * byte order. We'll do the same */
+#ifdef WORDS_BIGENDIAN
+ conv = ucnv_open("UTF-16-BE", &err);
+#else
conv = ucnv_open("UTF-16-LE", &err);
+#endif /* WORDS_BIGENDIAN */
allocSize = _length;
break;
Modified: trunk/Tests/NSUnicodeString.m
===================================================================
--- trunk/Tests/NSUnicodeString.m 2006-09-02 00:10:41 UTC (rev 295)
+++ trunk/Tests/NSUnicodeString.m 2006-09-02 00:10:46 UTC (rev 296)
@@ -102,10 +102,16 @@
0xb9, 0x74, 0x69, 0x6e, 0x79
};
-/* English UTF-16-LE "Hello, Universe", assembled by byte
- * UTF-16-LE is the canonical UTF-16 string encoding for both Substrate
- * and Apple's foundation. */
-static const unsigned char NSUnicodeStringEncoding_data[] = {
+/* Apple's NSUnicodeStringEncoding returns a string encodeded in host-byte
+ * order, with the BOM set There is no API for requesting anything else */
+#ifdef WORDS_BIGENDIAN
+# define NSUnicodeStringEncoding_data NSUnicodeStringEncodingBE_data
+#else
+# define NSUnicodeStringEncoding_data NSUnicodeStringEncodingLE_data
+#endif
+
+/* English UTF-16-LE "Hello, Universe", assembled by byte */
+static const unsigned char NSUnicodeStringEncodingLE_data[] = {
0xff, 0xfe, 0x48, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x6f, 0x00,
0x2c, 0x00, 0x20, 0x00, 0x55, 0x00, 0x6e, 0x00, 0x69, 0x00, 0x76, 0x00,
0x65, 0x00, 0x72, 0x00, 0x73, 0x00, 0x65, 0x00, 0x0, 0x0
@@ -214,7 +220,7 @@
[string release];
/* No free, UTF-16-LE */
- string = [[NSString alloc] initWithBytesNoCopy: (void *) NSUnicodeStringEncoding_data length: sizeof(NSUnicodeStringEncoding_data) encoding: NSUnicodeStringEncoding freeWhenDone: NO];
+ string = [[NSString alloc] initWithBytesNoCopy: (void *) NSUnicodeStringEncodingLE_data length: sizeof(NSUnicodeStringEncodingLE_data) encoding: NSUnicodeStringEncoding freeWhenDone: NO];
fail_if(string == nil, "-[NSString initWithBytesNoCopy: length: encoding: freeWhenDone: NO] returned nil with a UTF-16-LE encoded string.");
[string release];
@@ -226,9 +232,9 @@
[string release];
/* Free, UTF-16-LE */
- bytes = malloc(sizeof(NSUnicodeStringEncoding_data));
- memcpy(bytes, NSUnicodeStringEncoding_data, sizeof(NSUnicodeStringEncoding_data));
- string = [[NSString alloc] initWithBytesNoCopy: bytes length: sizeof(NSUnicodeStringEncoding_data) encoding: NSUnicodeStringEncoding freeWhenDone: YES];
+ bytes = malloc(sizeof(NSUnicodeStringEncodingLE_data));
+ memcpy(bytes, NSUnicodeStringEncodingLE_data, sizeof(NSUnicodeStringEncodingLE_data));
+ string = [[NSString alloc] initWithBytesNoCopy: bytes length: sizeof(NSUnicodeStringEncodingLE_data) encoding: NSUnicodeStringEncoding freeWhenDone: YES];
fail_if(string == nil, "-[NSString initWithBytesNoCopy: length: encoding: freeWhenDone: YES] returned nil with a UTF-16-LE encoded string.");
[string release];
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-02 00:10:58
|
Revision: 297
http://svn.sourceforge.net/substrate/?rev=297&view=rev
Author: landonf
Date: 2006-09-01 17:10:54 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
r305@bluefish: landonf | 2006-09-01 15:30:55 -0700
Empty initWithFormat implementation
Modified Paths:
--------------
trunk/Foundation/LFObjCRuntime.h.in
trunk/Foundation/NSString.h
trunk/Foundation/NSString.m
trunk/Tests/NSString.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:304
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:305
Modified: trunk/Foundation/LFObjCRuntime.h.in
===================================================================
--- trunk/Foundation/LFObjCRuntime.h.in 2006-09-02 00:10:46 UTC (rev 296)
+++ trunk/Foundation/LFObjCRuntime.h.in 2006-09-02 00:10:54 UTC (rev 297)
@@ -50,6 +50,9 @@
/* Include stdint.h if available */
@LF_STDINT_INC@
+/* vararg prototypes */
+#include <stdarg.h>
+
#if defined(__WIN32__)
#if defined(LF_BUILDING_libFoundation_LIB) // Building libFoundation
#define LF_EXPORT __declspec(dllexport)
Modified: trunk/Foundation/NSString.h
===================================================================
--- trunk/Foundation/NSString.h 2006-09-02 00:10:46 UTC (rev 296)
+++ trunk/Foundation/NSString.h 2006-09-02 00:10:54 UTC (rev 297)
@@ -39,7 +39,7 @@
#include <Foundation/NSObject.h>
#include <Foundation/NSRange.h>
-@class NSData;
+@class NSData, NSDictionary;
/*!
* @ingroup NSString
@@ -123,6 +123,9 @@
- (id) initWithCString:(const char *)cStr encoding:(NSStringEncoding)encoding;
- (id) initWithBytes:(const void *)bytes length:(unsigned int)len encoding:(NSStringEncoding)encoding;
- (id) initWithBytesNoCopy:(void *)bytes length:(unsigned int)len encoding:(NSStringEncoding)encoding freeWhenDone:(BOOL) shouldFree;
+- (id) initWithFormat:(NSString *)format, ...;
+- (id) initWithFormat:(NSString *)format locale:(NSDictionary *)locale, ...;
+- (id) initWithFormat:(NSString *)format locale:(NSDictionary *)locale arguments:(va_list)args;
/* Encoding */
+ (NSStringEncoding) defaultCStringEncoding;
Modified: trunk/Foundation/NSString.m
===================================================================
--- trunk/Foundation/NSString.m 2006-09-02 00:10:46 UTC (rev 296)
+++ trunk/Foundation/NSString.m 2006-09-02 00:10:54 UTC (rev 297)
@@ -225,8 +225,61 @@
return self;
}
+/*!
+ * Initialize the receiver with format.
+ *
+ * The receiver will be initialized using the supplied printf-style format
+ * string. This method is implemented by calling initWithFormat:locale:arguments
+ * with a nil locale.
+ *
+ * @param format Format string. If nil, raises NSInvalidArgumentException.
+ * @return Newly initialized string.
+ */
+- (id) initWithFormat:(NSString *)format, ... {
+ va_list ap;
+ va_start(ap, format);
+ [self initWithFormat: format locale: nil arguments: ap];
+ va_end(ap);
+ return self;
+}
+
/*!
+ * Initialize the receiver with format and locale.
+ *
+ * The receiver will be initialized using the supplied printf-style format
+ * string, according to locale. If locale is nil,
+ * +[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] will be used.
+ * @param format Format string. If nil, raises NSInvalidArgumentException.
+ * @param locale Locale dictionary. If nil, [[NSUserDefaults standardUserDefaults] dictionaryRepresentation] will be used.
+ * @return Newly initialized string.
+ */
+- (id) initWithFormat:(NSString *)format locale:(NSDictionary *)locale, ... {
+ va_list ap;
+
+ va_start(ap, locale);
+ [self initWithFormat: format locale: locale arguments: ap];
+ va_end(ap);
+ return self;
+}
+
+
+/*!
+ * Initialize the receiver with format, locale, and va_list arguments.
+ *
+ * The receiver will be initialized using the supplied printf-style format
+ * string, according to locale. If locale is nil,
+ * +[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] will be used.
+ * @param format Format string. If nil, raises NSInvalidArgumentException.
+ * @param locale Locale dictionary. If nil, [[NSUserDefaults standardUserDefaults] dictionaryRepresentation] will be used.
+ * @param args Format string arguments (va_list).
+ * @return Newly initialized string.
+ */
+- (id) initWithFormat:(NSString *)format locale:(NSDictionary *)locale arguments:(va_list)args {
+ /* TODO Implement Me ... */
+}
+
+/*!
* @}
* Allocation and Initialization.
*/
Modified: trunk/Tests/NSString.m
===================================================================
--- trunk/Tests/NSString.m 2006-09-02 00:10:46 UTC (rev 296)
+++ trunk/Tests/NSString.m 2006-09-02 00:10:54 UTC (rev 297)
@@ -178,6 +178,15 @@
}
END_TEST
+START_TEST (test_initWithFormatLocale) {
+ NSString *string;
+
+ string = [[NSString alloc] initWithFormat: @"%@ %s" locale: nil, @"Hello, ", "World!"];
+ fail_if(string == nil, "-[NSString initWithFormat: locale:] returned nil");
+ fail_unless(memcmp([string UTF8String], TEST_STRING, [string length]), "-[NSString initWithFormat: locale:] didn't handle our format correctly (Expected: %s, got: %s)", TEST_STRING, [string UTF8String]);
+}
+END_TEST
+
START_TEST (test_cStringUsingEncoding) {
NSString *string;
const char *cStr;
@@ -244,6 +253,7 @@
tcase_add_test(tc_init, test_initWithCStringEncoding);
tcase_add_test(tc_init, test_initWithBytes);
tcase_add_test(tc_init, test_initWithBytesNoCopyLengthEncodingFreeWhenDone);
+ tcase_add_test(tc_init, test_initWithFormatLocale);
TCase *tc_subclass = tcase_create("Subclassing");
tcase_add_checked_fixture(tc_subclass, setUp, tearDown);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-02 00:11:05
|
Revision: 298
http://svn.sourceforge.net/substrate/?rev=298&view=rev
Author: landonf
Date: 2006-09-01 17:11:00 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
r306@bluefish: landonf | 2006-09-01 16:09:39 -0700
Add initWithString, flesh out the initWithFormat implementation a tad
Modified Paths:
--------------
trunk/Foundation/NSString.h
trunk/Foundation/NSString.m
trunk/Tests/NSString.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:305
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:306
Modified: trunk/Foundation/NSString.h
===================================================================
--- trunk/Foundation/NSString.h 2006-09-02 00:10:54 UTC (rev 297)
+++ trunk/Foundation/NSString.h 2006-09-02 00:11:00 UTC (rev 298)
@@ -120,7 +120,11 @@
/* Initialization */
+ (id) string;
+ (id) stringWithCString:(const char *)cStr encoding:(NSStringEncoding)encoding;
++ (id) stringWithString:(NSString *)string;
+
+- (id) initWithString:(NSString *)string;
- (id) initWithCString:(const char *)cStr encoding:(NSStringEncoding)encoding;
+
- (id) initWithBytes:(const void *)bytes length:(unsigned int)len encoding:(NSStringEncoding)encoding;
- (id) initWithBytesNoCopy:(void *)bytes length:(unsigned int)len encoding:(NSStringEncoding)encoding freeWhenDone:(BOOL) shouldFree;
- (id) initWithFormat:(NSString *)format, ...;
Modified: trunk/Foundation/NSString.m
===================================================================
--- trunk/Foundation/NSString.m 2006-09-02 00:10:54 UTC (rev 297)
+++ trunk/Foundation/NSString.m 2006-09-02 00:11:00 UTC (rev 298)
@@ -156,12 +156,39 @@
}
/*!
+ * Allocate and initialize the receiver by copying the characters from the provided string.
+ *
+ * @param string Source string.
+ * @return Newly allocation and initialized NSString.
+ */
++ (id) stringWithString:(NSString *)string {
+ return [[[self alloc] initWithString: string] autorelease];
+}
+
+/*!
+ * Initialize the receiver by copying the characters from the provided string.
+ *
+ * @param string Source string.
+ * @return Initialized NSString.
+ */
+- (id) initWithString:(NSString *)string {
+ unsigned int length;
+ unichar *buffer;
+
+ length = [string length];
+ buffer = NSZoneMalloc(NULL, length * sizeof(unichar));
+ [string getCharacters: buffer];
+ /* Length required here is byte length, not character length. Ugh */
+ return [self initWithBytesNoCopy: buffer length: length * sizeof(unichar) encoding: NSUnicodeStringEncoding freeWhenDone: YES];
+}
+
+/*!
* Initialize the receiver with the supplied C string, encoded according to encoding.
* @param cStr NULL-terminated C string.
* @param encoding Character encoding for the C string.
* @return Newly initialized NSString instance.
*/
-- initWithCString:(const char *)cStr encoding:(NSStringEncoding)encoding {
+- (id) initWithCString:(const char *)cStr encoding:(NSStringEncoding)encoding {
return [self initWithBytes: cStr length: strlen(cStr) encoding: encoding];
}
@@ -274,9 +301,14 @@
* @param locale Locale dictionary. If nil, [[NSUserDefaults standardUserDefaults] dictionaryRepresentation] will be used.
* @param args Format string arguments (va_list).
* @return Newly initialized string.
+ * @todo Avoid copying the newly created string when self is a concrete implementation subclass of NSString.
*/
- (id) initWithFormat:(NSString *)format locale:(NSDictionary *)locale arguments:(va_list)args {
- /* TODO Implement Me ... */
+ NSString *string;
+
+ /* All subclasses get the formatting implementation from NSUnicodeString. */
+ string = [[NSUnicodeString alloc] initWithFormat: format locale: locale arguments: args];
+ return [self initWithString: string];
}
/*!
Modified: trunk/Tests/NSString.m
===================================================================
--- trunk/Tests/NSString.m 2006-09-02 00:10:54 UTC (rev 297)
+++ trunk/Tests/NSString.m 2006-09-02 00:11:00 UTC (rev 298)
@@ -143,11 +143,23 @@
}
END_TEST
+START_TEST (test_cls_stringWithString) {
+ NSString *string = @"Hello, World!";
+ NSString *copy;
+
+ copy = [NSString stringWithString: @"Hello, World!"];
+ fail_if(copy == nil);
+
+ fail_unless(strcmp([copy UTF8String], [string UTF8String]) == 0, "+[NSString stringWithString] returned unexpected string (Expected: %s, got: %s).", [string UTF8String], [copy UTF8String]);
+}
+END_TEST
+
START_TEST (test_initWithBytes) {
NSString *string;
string = [[NSString alloc] initWithBytes: TEST_STRING length: sizeof(TEST_STRING) - 1 encoding: NSASCIIStringEncoding];
fail_if(string == nil, "-[NSString initWithBytes: length: encoding:] returned nil");
+ [string release];
}
END_TEST
@@ -156,6 +168,7 @@
string = [[NSString alloc] initWithCString: TEST_STRING encoding: NSUTF8StringEncoding];
fail_if(string == nil, "-[NSString initWithCString: encoding:] returned nil");
+ [string release];
}
END_TEST
@@ -178,12 +191,25 @@
}
END_TEST
+START_TEST (test_initWithString) {
+ NSString *string = @"Hello, World!";
+ NSString *copy;
+
+ copy = [[NSString alloc] initWithString: @"Hello, World!"];
+ fail_if(copy == nil);
+
+ fail_unless(strcmp([copy UTF8String], [string UTF8String]) == 0, "-[NSString initWithString] returned unexpected string (Expected: %s, got: %s).", [string UTF8String], [copy UTF8String]);
+ [copy release];
+}
+END_TEST
+
START_TEST (test_initWithFormatLocale) {
NSString *string;
string = [[NSString alloc] initWithFormat: @"%@ %s" locale: nil, @"Hello, ", "World!"];
fail_if(string == nil, "-[NSString initWithFormat: locale:] returned nil");
fail_unless(memcmp([string UTF8String], TEST_STRING, [string length]), "-[NSString initWithFormat: locale:] didn't handle our format correctly (Expected: %s, got: %s)", TEST_STRING, [string UTF8String]);
+ [string release];
}
END_TEST
@@ -250,9 +276,11 @@
suite_add_tcase(s, tc_init);
tcase_add_test(tc_init, test_cls_string);
tcase_add_test(tc_init, test_cls_stringWithCString);
+ tcase_add_test(tc_init, test_cls_stringWithString);
tcase_add_test(tc_init, test_initWithCStringEncoding);
tcase_add_test(tc_init, test_initWithBytes);
tcase_add_test(tc_init, test_initWithBytesNoCopyLengthEncodingFreeWhenDone);
+ tcase_add_test(tc_init, test_initWithString);
tcase_add_test(tc_init, test_initWithFormatLocale);
TCase *tc_subclass = tcase_create("Subclassing");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-02 00:11:14
|
Revision: 299
http://svn.sourceforge.net/substrate/?rev=299&view=rev
Author: landonf
Date: 2006-09-01 17:11:08 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
r307@bluefish: landonf | 2006-09-01 17:09:54 -0700
LFUnicodeFormatString implementation skeleton
Modified Paths:
--------------
trunk/Foundation/Makefile.in
trunk/Tests/Foundation.c
trunk/Tests/Foundation.h
trunk/Tests/Makefile.in
Added Paths:
-----------
trunk/Foundation/LFUnicodeFormatString.h
trunk/Foundation/LFUnicodeFormatString.m
trunk/Tests/NSUnicodeFormatString.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:306
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:307
Added: trunk/Foundation/LFUnicodeFormatString.h
===================================================================
--- trunk/Foundation/LFUnicodeFormatString.h (rev 0)
+++ trunk/Foundation/LFUnicodeFormatString.h 2006-09-02 00:11:08 UTC (rev 299)
@@ -0,0 +1,45 @@
+/*
+ * LFUnicodeFormatString.h
+ * vi:ts=4:sw=4:expandtab:
+ *
+ * Copyright (C) 2006 Landon Fuller <la...@op...>
+ * All rights reserved.
+ *
+ * Author: Landon Fuller <la...@op...>
+ *
+ * This file is part of libFoundation.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ *
+ * We disclaim all warranties with regard to this software, including all
+ * implied warranties of merchantability and fitness, in no event shall
+ * we be liable for any special, indirect or consequential damages or any
+ * damages whatsoever resulting from loss of use, data or profits, whether in
+ * an action of contract, negligence or other tortious action, arising out of
+ * or in connection with the use or performance of this software.
+ */
+
+#ifndef __LFUnicodeFormatString_h__
+#define __LFUnicodeFormatString_h__
+
+/*!
+ * @file
+ * @internal
+ * @brief UTF-16 NSString implementation
+ * @brief UTF-16 Format String Parsing
+ */
+
+#include <Foundation/NSUnicodeString.h>
+
+/*!
+ * @ingroup LFUnicodeFormatString
+ * @{
+ */
+
+/*! @} */
+
+#endif /* __LFUnicodeFormatString_h__ */
Added: trunk/Foundation/LFUnicodeFormatString.m
===================================================================
--- trunk/Foundation/LFUnicodeFormatString.m (rev 0)
+++ trunk/Foundation/LFUnicodeFormatString.m 2006-09-02 00:11:08 UTC (rev 299)
@@ -0,0 +1,44 @@
+/*
+ * LFUnicodeFormatString.m
+ * vi:ts=4:sw=4:expandtab:
+ *
+ * Copyright (C) 2006 Landon Fuller
+ * All rights reserved.
+ *
+ * Author: Landon Fuller <la...@op...>
+ *
+ * This file is part of libFoundation.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ *
+ * We disclaim all warranties with regard to this software, including all
+ * implied warranties of merchantability and fitness, in no event shall
+ * we be liable for any special, indirect or consequential damages or any
+ * damages whatsoever resulting from loss of use, data or profits, whether in
+ * an action of contract, negligence or other tortious action, arising out of
+ * or in connection with the use or performance of this software.
+ */
+
+/*!
+ * @file
+ * @internal
+ * @brief UTF-16 Format String Parsing
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/*!
+ * @defgroup LFUnicodeFormatString UTF-16 Format String Parsing
+ * @internal
+ * @ingroup NSString
+ * @{
+ */
+
+
+/*! @} */
Modified: trunk/Foundation/Makefile.in
===================================================================
--- trunk/Foundation/Makefile.in 2006-09-02 00:11:00 UTC (rev 298)
+++ trunk/Foundation/Makefile.in 2006-09-02 00:11:08 UTC (rev 299)
@@ -42,12 +42,13 @@
NSRange.m \
NSProcessInfo.m \
NSString.m \
+ NSSimpleCString.m \
NSUnicodeString.m \
- NSSimpleCString.m \
NSZone.m \
LFStackException.m \
LFGNUException.m \
LFHash.c \
+ LFUnicodeFormatString.m \
s_lock.c \
$(TAS_SRC)
@@ -67,6 +68,7 @@
LFStackException.o \
LFGNUException.o \
LFHash.o \
+ LFUnicodeFormatString.o \
s_lock.o \
$(TAS_OBJS)
Modified: trunk/Tests/Foundation.c
===================================================================
--- trunk/Tests/Foundation.c 2006-09-02 00:11:00 UTC (rev 298)
+++ trunk/Tests/Foundation.c 2006-09-02 00:11:08 UTC (rev 299)
@@ -46,6 +46,7 @@
srunner_add_suite(sr, NSString_suite());
srunner_add_suite(sr, NSSimpleString_suite());
srunner_add_suite(sr, NSUnicodeString_suite());
+ srunner_add_suite(sr, NSUnicodeFormatString_suite());
srunner_add_suite(sr, NSAutoreleasePool_suite());
srunner_add_suite(sr, NSData_suite());
srunner_add_suite(sr, NSMutableData_suite());
Modified: trunk/Tests/Foundation.h
===================================================================
--- trunk/Tests/Foundation.h 2006-09-02 00:11:00 UTC (rev 298)
+++ trunk/Tests/Foundation.h 2006-09-02 00:11:08 UTC (rev 299)
@@ -34,6 +34,7 @@
Suite *NSProcessInfo_suite(void);
Suite *NSString_suite(void);
Suite *NSSimpleString_suite(void);
+Suite *NSUnicodeFormatString_suite(void);
Suite *NSUnicodeString_suite(void);
Suite *NSRange_suite(void);
Suite *NSGeometry_suite(void);
Modified: trunk/Tests/Makefile.in
===================================================================
--- trunk/Tests/Makefile.in 2006-09-02 00:11:00 UTC (rev 298)
+++ trunk/Tests/Makefile.in 2006-09-02 00:11:08 UTC (rev 299)
@@ -12,10 +12,22 @@
FOUNDATION_LIB?= -L../Foundation -lFoundation
LDFLAGS+= $(LIBS) $(OBJC_LIBS) @CHECK_LIBS@ $(FOUNDATION_LIB)
-FOUNDATION_OBJS= Foundation.o NSAutoreleasePool.o NSException.o NSZone.o \
- NSObjectAllocation.o NSObject.o NSProcessInfo.o \
- NSString.o NSSimpleString.o NSUnicodeString.o NSRange.o \
- NSGeometry.o NSData.o NSMutableData.o NSConcreteData.o \
+FOUNDATION_OBJS= Foundation.o \
+ NSAutoreleasePool.o \
+ NSException.o \
+ NSZone.o \
+ NSObjectAllocation.o \
+ NSObject.o \
+ NSProcessInfo.o \
+ NSString.o \
+ NSSimpleString.o \
+ NSUnicodeString.o \
+ NSUnicodeFormatString.o \
+ NSRange.o \
+ NSGeometry.o \
+ NSData.o \
+ NSMutableData.o \
+ NSConcreteData.o \
NSByteOrder.o
SPINLOCK_OBJS= s_lock.o
Added: trunk/Tests/NSUnicodeFormatString.m
===================================================================
--- trunk/Tests/NSUnicodeFormatString.m (rev 0)
+++ trunk/Tests/NSUnicodeFormatString.m 2006-09-02 00:11:08 UTC (rev 299)
@@ -0,0 +1,55 @@
+/*
+ * NSUnicodeFormatString.m vi:ts=4:sw=4:expandtab:
+ * Foundation Unit Tests
+ *
+ * Copyright (C) 2005 - 2006 Landon Fuller <la...@op...>
+ * All rights reserved.
+ *
+ * This file is part of libFoundation.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ *
+ * We disclaim all warranties with regard to this software, including all
+ * implied warranties of merchantability and fitness, in no event shall
+ * we be liable for any special, indirect or consequential damages or any
+ * damages whatsoever resulting from loss of use, data or profits, whether in
+ * an action of contract, negligence or other tortious action, arising out of
+ * or in connection with the use or performance of this software.
+ */
+
+#include <check.h>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Foundation/NSString.h>
+
+/*
+ * Tests that are specific to the NSString format string handling.
+ */
+
+static NSAutoreleasePool *releasePool;
+
+static void setUp(void) {
+ releasePool = [[NSAutoreleasePool alloc] init];
+}
+
+static void tearDown(void) {
+ [releasePool release];
+}
+
+Suite *NSUnicodeFormatString_suite(void) {
+ Suite *s = suite_create("NSUnicodeFormatString");
+
+ TCase *tc_strings = tcase_create("Strings");
+ tcase_add_checked_fixture(tc_strings, setUp, tearDown);
+ suite_add_tcase(s, tc_strings);
+ // tcase_add_test(tc_strings, test_cString);
+
+ return (s);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-02 01:33:08
|
Revision: 301
http://svn.sourceforge.net/substrate/?rev=301&view=rev
Author: landonf
Date: 2006-09-01 18:33:04 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
Minor fixes for getCharacters, etc.
Modified Paths:
--------------
trunk/Foundation/NSSimpleCString.m
trunk/Foundation/NSUnicodeString.m
trunk/Tests/NSUnicodeFormatString.m
trunk/Tests/NSUnicodeString.m
Modified: trunk/Foundation/NSSimpleCString.m
===================================================================
--- trunk/Foundation/NSSimpleCString.m 2006-09-02 00:49:19 UTC (rev 300)
+++ trunk/Foundation/NSSimpleCString.m 2006-09-02 01:33:04 UTC (rev 301)
@@ -84,6 +84,8 @@
}
- (unichar) characterAtIndex:(unsigned int) index {
+ if (index > _numBytes - 1)
+ [NSException raise: NSRangeException format: @"index out of bounds"];
/* ASCII can be directly mapped to UTF-16 */
return (unichar) _bytes[index];
}
Modified: trunk/Foundation/NSUnicodeString.m
===================================================================
--- trunk/Foundation/NSUnicodeString.m 2006-09-02 00:49:19 UTC (rev 300)
+++ trunk/Foundation/NSUnicodeString.m 2006-09-02 01:33:04 UTC (rev 301)
@@ -37,6 +37,7 @@
#include <Foundation/NSData.h>
#include <Foundation/NSException.h>
+#include <string.h>
/*!
* @defgroup NSUnicodeString UTF-16 NSString Implementation
@@ -359,6 +360,19 @@
* @{
*/
+- (void) getCharacters:(unichar *) buffer range:(NSRange) aRange {
+ if (aRange.location + aRange.length > _length)
+ [NSException raise: NSRangeException format: @"range out of bounds"];
+
+ memcpy(buffer, _string + aRange.location, aRange.length);
+}
+
+- (unichar)characterAtIndex:(unsigned)index {
+ if (index > _length - 1)
+ [NSException raise: NSRangeException format: @"index out of bounds"];
+ return _string[index];
+}
+
- (unsigned int) length {
return _length;
}
Modified: trunk/Tests/NSUnicodeFormatString.m
===================================================================
--- trunk/Tests/NSUnicodeFormatString.m 2006-09-02 00:49:19 UTC (rev 300)
+++ trunk/Tests/NSUnicodeFormatString.m 2006-09-02 01:33:04 UTC (rev 301)
@@ -28,6 +28,7 @@
#endif
#include <Foundation/NSString.h>
+#include <Foundation/NSAutoreleasePool.h>
/*
* Tests that are specific to the NSString format string handling.
Modified: trunk/Tests/NSUnicodeString.m
===================================================================
--- trunk/Tests/NSUnicodeString.m 2006-09-02 00:49:19 UTC (rev 300)
+++ trunk/Tests/NSUnicodeString.m 2006-09-02 01:33:04 UTC (rev 301)
@@ -255,6 +255,20 @@
}
END_TEST
+START_TEST (test_getCharacters) {
+ NSString *string = [[NSString alloc] initWithBytes: NSUnicodeStringEncoding_data length: sizeof(NSUnicodeStringEncoding_data) encoding: NSUnicodeStringEncoding];
+ unichar *chars;
+
+ chars = malloc([string length] * sizeof(unichar));
+ [string getCharacters: chars];
+
+ /* chars + 1 skips the BOM */
+ fail_unless(memcmp(chars + 1, NSUnicodeStringEncoding_data, [string length]), "-[NSString getCharacters:] returned unexpected data: '%s'", [string UTF8String]);
+ free(chars);
+ [string release];
+}
+END_TEST
+
Suite *NSUnicodeString_suite(void) {
Suite *s = suite_create("NSUnicodeString");
@@ -280,8 +294,13 @@
TCase *tc_conv = tcase_create("Conversion");
tcase_add_checked_fixture(tc_conv, setUp, tearDown);
- suite_add_tcase(s, tc_conv);
+ suite_add_tcase(s, tc_conv);
tcase_add_test(tc_conv, test_dataUsingEncodingStringEncodingAllowLossyConversion);
+ TCase *tc_access = tcase_create("Accessing");
+ tcase_add_checked_fixture(tc_access, setUp, tearDown);
+ suite_add_tcase(s, tc_access);
+ tcase_add_test(tc_access, test_getCharacters);
+
return (s);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|