substrate-commits Mailing List for Objective-C Substrate
Brought to you by:
landonf
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(27) |
Sep
(18) |
Oct
|
Nov
|
Dec
(1) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <la...@us...> - 2007-05-05 21:53:37
|
Revision: 306
http://svn.sourceforge.net/substrate/?rev=306&view=rev
Author: landonf
Date: 2007-05-05 14:53:31 -0700 (Sat, 05 May 2007)
Log Message:
-----------
Note cocotron
Modified Paths:
--------------
www/index.html
Modified: www/index.html
===================================================================
--- www/index.html 2006-12-30 18:39:28 UTC (rev 305)
+++ www/index.html 2007-05-05 21:53:31 UTC (rev 306)
@@ -18,6 +18,13 @@
<li><a href="#hist">History</a></li>
</ul>
+ <a name="news"><h2>News</h2></a>
+ <p>
+ In development for a number of years, <a href="http://www.cocotron.org">Cocotron</a> has
+ been released, beating Substrate to the punch. Thus, little reason exists to continue development on the
+ Substrate project.
+ </p>
+
<a name="about"><h2>About</h2></a>
<p>
Substrate is a light-weight standalone library which
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-12-30 18:39:30
|
Revision: 305
http://svn.sourceforge.net/substrate/?rev=305&view=rev
Author: landonf
Date: 2006-12-30 10:39:28 -0800 (Sat, 30 Dec 2006)
Log Message:
-----------
s/Past//g
Modified Paths:
--------------
www/index.html
Modified: www/index.html
===================================================================
--- www/index.html 2006-09-02 06:26:53 UTC (rev 304)
+++ www/index.html 2006-12-30 18:39:28 UTC (rev 305)
@@ -70,14 +70,9 @@
mailing list.
</p>
<p>
- Current Substrate developers are:
+ Substrate developers:
<ul>
<li>Landon Fuller (landonf [at] opendarwin [dot] org)</li>
- </ul>
- </p>
- <p>
- Past contributors include:
- <ul>
<li>David Leimbach (leimy [at] opendarwin [dot] org)</li>
<li>Felix Kronlage (fkr [at] opendarwin [dot] org)</li>
<li>Will Barton (wbb4 [at] opendarwin [dot] org)</li>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-02 06:26:55
|
Revision: 304
http://svn.sourceforge.net/substrate/?rev=304&view=rev
Author: landonf
Date: 2006-09-01 23:26:53 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
Properly initialize the _capacity instance method in NSMutableData's initWithBytesNoCopy:
Modified Paths:
--------------
trunk/Foundation/NSConcreteData.m
Modified: trunk/Foundation/NSConcreteData.m
===================================================================
--- trunk/Foundation/NSConcreteData.m 2006-09-02 05:58:49 UTC (rev 303)
+++ trunk/Foundation/NSConcreteData.m 2006-09-02 06:26:53 UTC (rev 304)
@@ -173,15 +173,24 @@
* @{
*/
+- (id) initWithBytesNoCopy:(void*)bytes length:(unsigned int)length freeWhenDone:(BOOL)freeWhenDone {
+ self = [super initWithBytesNoCopy: bytes length: length freeWhenDone: freeWhenDone];
+ if (!self)
+ return nil;
+
+ _capacity = length;
+ return self;
+}
+
- (id) initWithCapacity:(unsigned int)capacity {
- self = [self init];
+ self = [super init];
if (!self)
return nil;
/* Initialize with 0 length and the specified capacity */
_length = 0;
_capacity = capacity;
- _bytes = malloc(capacity);
+ _bytes = NSZoneMalloc(NULL, capacity);
if (!_bytes) {
[self release];
return nil;
@@ -216,8 +225,12 @@
- (void) _growCapacity:(unsigned int)capacity {
/* Requested length is larger than our capacity.
* We need to realloc. */
- void *new = NSZoneRealloc(NULL, _bytes, capacity);
- _bytes = new;
+ if (_capacity == 0) {
+ _bytes = NSZoneMalloc(NULL, capacity);
+ } else {
+ void *new = NSZoneRealloc(NULL, _bytes, capacity);
+ _bytes = new;
+ }
_capacity = capacity;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-02 05:58:52
|
Revision: 303
http://svn.sourceforge.net/substrate/?rev=303&view=rev
Author: landonf
Date: 2006-09-01 22:58:49 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
Make sure we always initialize memory, newly allocated or not
Modified Paths:
--------------
trunk/Foundation/NSConcreteData.m
Modified: trunk/Foundation/NSConcreteData.m
===================================================================
--- trunk/Foundation/NSConcreteData.m 2006-09-02 05:51:51 UTC (rev 302)
+++ trunk/Foundation/NSConcreteData.m 2006-09-02 05:58:49 UTC (rev 303)
@@ -222,10 +222,14 @@
}
- (void) setLength:(unsigned int)length {
- if (length > _capacity) {
+ /* Grow our capacity */
+ if (length > _capacity)
[self _growCapacity: length];
+
+ /* Initialize our (possibly new) memory */
+ if (length > _length)
memset(_bytes + _length, 0, length - _length);
- }
+
_length = length;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-02 05:51:56
|
Revision: 302
http://svn.sourceforge.net/substrate/?rev=302&view=rev
Author: landonf
Date: 2006-09-01 22:51:51 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
Fix a heap stomper -- ucnv_toUChars() wants the buffer length in characters, not bytes.
Modified Paths:
--------------
trunk/Foundation/NSUnicodeString.m
Modified: trunk/Foundation/NSUnicodeString.m
===================================================================
--- trunk/Foundation/NSUnicodeString.m 2006-09-02 01:33:04 UTC (rev 301)
+++ trunk/Foundation/NSUnicodeString.m 2006-09-02 05:51:51 UTC (rev 302)
@@ -99,54 +99,49 @@
- (id) initWithBytes:(const void *)bytes length:(unsigned int)length encoding:(NSStringEncoding)encoding {
UConverter *conv;
UErrorCode err = U_ZERO_ERROR;
- size_t allocSize;
self = [super init];
if (!self)
return nil;
+ /* Default to same number of characters as source bytes */
+ _length = length;
+
/* 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 * sizeof(UChar);
break;
/* 8-bit EUC encoding for Japanese. */
case NSJapaneseEUCStringEncoding:
conv = ucnv_open("EUC-JP", &err);
- allocSize = length * sizeof(UChar);
break;
/* 8-bit Unicode encoding (UTF-8). */
case NSUTF8StringEncoding:
conv = ucnv_open("UTF-8", &err);
- allocSize = length * sizeof(UChar);
break;
/* 8-bit ISO Latin 1 Encoding. */
case NSISOLatin1StringEncoding:
conv = ucnv_open("latin1", &err);
- allocSize = length * sizeof(UChar);
break;
/* 7-bit non-lossy Unicode encoding (UTF-7). */
case NSNonLossyASCIIStringEncoding:
conv = ucnv_open("UTF-7", &err);
- allocSize = length * sizeof(UChar);
break;
/* 8-bit Japanese Shift_JIS Encoding. */
case NSShiftJISStringEncoding:
conv = ucnv_open("Shift_JIS", &err);
- allocSize = length * sizeof(UChar);
break;
/* 8-bit ISO Latin 2 Encoding. */
case NSISOLatin2StringEncoding:
conv = ucnv_open("latin2", &err);
- allocSize = length * sizeof(UChar);
break;
case NSProprietaryStringEncoding: /* Fall through to UTF-16 */
@@ -169,49 +164,41 @@
conv = ucnv_open("UTF-16", &err);
break;
}
- allocSize = length;
break;
/* Microsoft Windows codepage 1251 for Cryillic characters. */
case NSWindowsCP1251StringEncoding:
conv = ucnv_open("windows-1251", &err);
- allocSize = length * sizeof(UChar);
break;
/* Microsoft Windows codepage 1252 (WinLatin1). */
case NSWindowsCP1252StringEncoding:
conv = ucnv_open("windows-1252", &err);
- allocSize = length * sizeof(UChar);
break;
/* Microsoft Windows codepage 1253, for Greek characters. */
case NSWindowsCP1253StringEncoding:
conv = ucnv_open("windows-1253", &err);
- allocSize = length * sizeof(UChar);
break;
/* Microsoft Windows codepage 1254, for Turkish characters. */
case NSWindowsCP1254StringEncoding:
conv = ucnv_open("windows-1254", &err);
- allocSize = length * sizeof(UChar);
break;
/* Microsoft Windows codepage 1250 (WinLatin2). */
case NSWindowsCP1250StringEncoding:
conv = ucnv_open("windows-1250", &err);
- allocSize = length * sizeof(UChar);
break;
/* ISO 2022 Japanese for e-mail. */
case NSISO2022JPStringEncoding:
conv = ucnv_open("ISO-2022-JP", &err);
- allocSize = length * sizeof(UChar);
break;
/* Legacy Mac Roman Encoding. */
case NSMacOSRomanStringEncoding:
conv = ucnv_open("macintosh", &err);
- allocSize = length * sizeof(UChar);
break;
/* Unhandled encodings */
@@ -241,25 +228,24 @@
}
/* Do the conversion */
- _string = NSZoneMalloc(NULL, allocSize);
+ _string = NSZoneMalloc(NULL, _length * sizeof(UChar));
while (1) {
- size_t newAllocSize;
+ unsigned int newLength;
err = U_ZERO_ERROR;
- _length = ucnv_toUChars(conv, _string, allocSize, bytes, length, &err);
- newAllocSize = _length * sizeof(UChar);
+ newLength = ucnv_toUChars(conv, _string, _length, bytes, length, &err);
if (U_SUCCESS(err)) {
/* Don't bother calling realloc for very small differences */
- if (newAllocSize != allocSize && newAllocSize - allocSize >= 5)
- _string = NSZoneRealloc(NULL, _string, newAllocSize);
- allocSize = newAllocSize;
+ if (newLength != _length && newLength - _length >= 5)
+ _string = NSZoneRealloc(NULL, _string, newLength * sizeof(UChar));
+ _length = newLength;
break;
}
if (err == U_BUFFER_OVERFLOW_ERROR) {
- allocSize = newAllocSize;
- _string = NSZoneRealloc(NULL, _string, allocSize);
+ _length = newLength;
+ _string = NSZoneRealloc(NULL, _string, _length * sizeof(UChar));
continue;
} else {
[NSException raise: NSCharacterConversionException format: @"Failure in IBM ICU's ucnv_toUChars()"];
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.
|
|
From: <la...@us...> - 2006-09-02 00:49:22
|
Revision: 300
http://svn.sourceforge.net/substrate/?rev=300&view=rev
Author: landonf
Date: 2006-09-01 17:49:19 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
Drop old makefile
Removed Paths:
-------------
trunk/Foundation/libFoundation.make.in
Deleted: trunk/Foundation/libFoundation.make.in
===================================================================
--- trunk/Foundation/libFoundation.make.in 2006-09-02 00:11:08 UTC (rev 299)
+++ trunk/Foundation/libFoundation.make.in 2006-09-02 00:49:19 UTC (rev 300)
@@ -1,92 +0,0 @@
-# libFoundation.make.in
-#
-# Copyright (C) 1995, 1996, 1997, 1998 Ovidiu Predescu and Mircea Oancea.
-# All rights reserved.
-#
-# Author: Ovidiu Predescu <ov...@ne...>
-# Date: February 1998
-#
-# 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.
-#
-
-ifeq ($(FOUNDATION_LIB),fd)
-
-FND_DEFINE = -DLIB_FOUNDATION_LIBRARY=1 -DFD_WITH_GSMAKE=1 -DGNUSTEP=1
-FND_LDFLAGS =
-FND_LIBS = -lFoundation
-
-GNUSTEP_DEFINE = -DGNUSTEP=1 -DWITH_GSTEP_MAKE=1
-
-SUMMARY_VERSION = $(GNUSTEP_MAKE_MAJOR_VERSION).$(GNUSTEP_MAKE_MINOR_VERSION)
-
-# All versions but the ones listed look for headers in xxx/Library/Headers
-ifneq ($(SUMMARY_VERSION),1.3)
- ifneq ($(SUMMARY_VERSION),1.4)
- ifneq ($(SUMMARY_VERSION),1.5)
- ifneq ($(SUMMARY_VERSION),1.6)
-LIBFOUNDATION_HEADER_TARGET_FLAG = \
- -I$(GNUSTEP_SYSTEM_ROOT)/Library/Headers/libFoundation/$(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS)/$(OBJC_RUNTIME)
- endif
- endif
- endif
-endif
-
-# Old versions (the ones listead above) look for headers in xxx/Library/Headers
-ifeq ($(LIBFOUNDATION_HEADER_TARGET_FLAG),)
-LIBFOUNDATION_HEADER_TARGET_FLAG = \
- -I$(GNUSTEP_SYSTEM_ROOT)/Headers/libFoundation/$(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS)/$(OBJC_RUNTIME)
-endif
-
-AUXILIARY_CPPFLAGS += $(LIBFOUNDATION_HEADER_TARGET_FLAG)
-
-# If gc=yes was passed and libFoundation was compiled with Boehm's
-# GC support, use the appropriate libraries
-
-ifeq ($(gc), yes)
- ifeq ($(LIBFOUNDATION_WITH_GC), yes)
- OBJC_LIBS = -lobjc $(LIBFOUNDATION_GC_LIBRARY)
- ifeq ($(leak), yes)
- AUXILIARY_CPPFLAGS += -DLIB_FOUNDATION_LEAK_GC=1
- else
- AUXILIARY_CPPFLAGS += -DLIB_FOUNDATION_BOEHM_GC=1
- endif
- endif
-endif
-
-ifeq ($(LIBFOUNDATION_MAKE),)
- LIBFOUNDATION_MAKE = yes
-
- # If libFoundation is built with support for Boehm's garbage collector we
- # should pass in addition to GC library to linker.
-
- ifeq ($(gc), yes)
- LIBFOUNDATION_WITH_GC = yes
- else
- LIBFOUNDATION_WITH_GC = no
- endif
- # LIBFOUNDATION_WITH_GC = @WITH_GC@
-
- GC_LIB = @GC_LIB@
-
- ifeq ($(LIBFOUNDATION_WITH_GC), yes)
- ifneq ($(GC_LIB),)
- LIBFOUNDATION_GC_LIBRARY = -l$(GC_LIB)
- LIBRARIES_FOUNDATION_DEPENDS_UPON = -l$(GC_LIB)
- endif # GC_LIB != ""
- endif # LIBFOUNDATION_WITH_GC
-endif # LIBFOUNDATION_MAKE!=yes
-
-endif # ($(FOUNDATION_LIB),fd)
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 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: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: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: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: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: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-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-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 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 02:44:33
|
Revision: 289
http://svn.sourceforge.net/substrate/?rev=289&view=rev
Author: landonf
Date: 2006-08-31 19:44:30 -0700 (Thu, 31 Aug 2006)
Log Message:
-----------
Another const missing. Will it ever end?
Modified Paths:
--------------
trunk/Foundation/NSString.m
Modified: trunk/Foundation/NSString.m
===================================================================
--- trunk/Foundation/NSString.m 2006-09-01 00:37:19 UTC (rev 288)
+++ trunk/Foundation/NSString.m 2006-09-01 02:44:30 UTC (rev 289)
@@ -287,7 +287,7 @@
* receiver is deallocated.
* @todo Unimplemented.
*/
-- (char *) cString {
+- (const char *) cString {
/* TODO Unimplemented */
return NULL;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-01 00:37:23
|
Revision: 288
http://svn.sourceforge.net/substrate/?rev=288&view=rev
Author: landonf
Date: 2006-08-31 17:37:19 -0700 (Thu, 31 Aug 2006)
Log Message:
-----------
Use target, not host, variables in autoconf.
Bump the optimization cflags up to -O2.
Modified Paths:
--------------
trunk/platform.m4
Modified: trunk/platform.m4
===================================================================
--- trunk/platform.m4 2006-09-01 00:08:24 UTC (rev 287)
+++ trunk/platform.m4 2006-09-01 00:37:19 UTC (rev 288)
@@ -199,7 +199,7 @@
AC_DEFUN(OD_CPU_NATURAL_ALIGNMENT,[
AC_MSG_CHECKING([correct structure alignment])
- case $host_cpu in
+ case $target_cpu in
i?86)
# 4 bytes is the minimum correct alignment
#
@@ -291,7 +291,7 @@
AC_MSG_RESULT([$CPU_NATURAL_ALIGNMENT])
if test x"$CPU_NATURAL_ALIGNMENT" = x"unknown"; then
- AC_MSG_ERROR([natural data alignment for $host_cpu is unknown. Please see the OpenDarwin libFoundation documentation for information on porting libFoundation to a new architecture.])
+ AC_MSG_ERROR([natural data alignment for $target_cpu is unknown. Please see the OpenDarwin libFoundation documentation for information on porting libFoundation to a new architecture.])
fi
AC_DEFINE_UNQUOTED([CPU_NATURAL_ALIGNMENT], [$CPU_NATURAL_ALIGNMENT], [Define to the largest alignment boundry size required on the host platform.])
])
@@ -412,7 +412,7 @@
ECHO_VERSION='`echo ${LIB_VERSION}`'
TCL_LIB_VERSIONS_OK=ok
CFLAGS_DEBUG=-g
- CFLAGS_OPTIMIZE=-O
+ CFLAGS_OPTIMIZE=-O2
if test "$GCC" = "yes" ; then
CFLAGS_WARNING="-Wall -Wno-implicit-int"
else
@@ -430,7 +430,7 @@
LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH"
PLAT_OBJS=""
- case $host_os in
+ case $target_os in
aix5.*)
if test "${TCL_THREADS}" = "1" -a "$GCC" != "yes" ; then
# AIX requires the _r compiler when gcc isn't being used
@@ -638,7 +638,7 @@
EXTRA_CFLAGS="-mabi=n32"
LDFLAGS="-mabi=n32"
else
- case $host_os in
+ case $target_os in
irix6.3)
# Use to build 6.2 compatible binaries on 6.3.
EXTRA_CFLAGS="-n32 -D_OLD_TERMIOS"
@@ -651,7 +651,7 @@
fi
;;
irix646.*)
- # XXX This host_os value probably won't match, but I don't have any Irix machines to test with.
+ # XXX This target_os value probably won't match, but I don't have any Irix machines to test with.
SHLIB_CFLAGS=""
SHLIB_LD="ld -n32 -shared -rdata_shared"
SHLIB_LD_LIBS='${LIBS}'
@@ -678,7 +678,7 @@
SHLIB_LD="${CC} -shared"
LDFLAGS="-rdynamic"
- case $host_cpu in
+ case $target_cpu in
alpha*)
EXTRA_CFLAGS="-mieee"
;;
@@ -691,7 +691,7 @@
SHLIB_LD="${CC} -shared"
LDFLAGS="-rdynamic"
- case $host_cpu in
+ case $target_cpu in
alpha*)
EXTRA_CFLAGS="-mieee"
;;
@@ -766,7 +766,7 @@
EXTRA_CFLAGS="-pthread"
LDFLAGS="$LDFLAGS -pthread"
fi
- case $host_os in
+ case $target_os in
freebsd3.*)
# FreeBSD-3 doesn't handle version numbers with dots.
UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}${DBGX}.a'
@@ -781,7 +781,6 @@
SHLIB_LD_EXTRAS="-compatibility_version \${DYLIB_COMPAT_VERSION} -current_version \${LIB_VERSION} -install_name \${DYLIB_INSTALL_DIR}/\${LIB_FILE}"
SHLIB_LD_LIBS='${LIBS}'
SHLIB_SUFFIX=".dylib"
- CFLAGS_OPTIMIZE="-Os"
LD_LIBRARY_PATH_VAR="DYLD_LIBRARY_PATH"
# for compatibility with autoconf vers 2.13 :
HACK=""
@@ -993,7 +992,7 @@
if test x"$SHLIB_SUFFIX" != "x" ; then
if test "$GCC" = "yes" ; then
- case $host_os in
+ case $target_os in
aix*)
;;
bsdi*)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <la...@us...> - 2006-09-01 00:08:27
|
Revision: 287
http://svn.sourceforge.net/substrate/?rev=287&view=rev
Author: landonf
Date: 2006-08-31 17:08:24 -0700 (Thu, 31 Aug 2006)
Log Message:
-----------
Merge in latest spinlock implementation from Postgres
Modified Paths:
--------------
trunk/Foundation/s_lock.c
trunk/Foundation/s_lock.h
Modified: trunk/Foundation/s_lock.c
===================================================================
--- trunk/Foundation/s_lock.c 2006-08-31 22:59:15 UTC (rev 286)
+++ trunk/Foundation/s_lock.c 2006-09-01 00:08:24 UTC (rev 287)
@@ -30,7 +30,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/lmgr/s_lock.c,v 1.35 2004/12/31 22:01:05 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/s_lock.c,v 1.40.2.2 2006/05/11 21:58:29 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -68,6 +68,7 @@
#include <Foundation/s_lock.h>
#include <Foundation/port.h>
+/* A few postgresql defines and macros */
/*
* The random() function is expected to yield values between 0 and
* MAX_RANDOM_VALUE. Currently, all known implementations yield
@@ -78,7 +79,12 @@
* considerably inferior to --- random().
*/
#define MAX_RANDOM_VALUE (0x7FFFFFFF)
+#define Min(x, y) ((x) < (y) ? (x) : (y))
+#define Max(x, y) ((x) > (y) ? (x) : (y))
+
+static int spins_per_delay = DEFAULT_SPINS_PER_DELAY;
+
/*
* s_lock_stuck() - complain about a stuck spinlock
*/
@@ -104,44 +110,52 @@
lf_s_lock(volatile slock_t *lock, const char *file, int line)
{
/*
- * We loop tightly for awhile, then delay using pg_usleep() and try
- * again. Preferably, "awhile" should be a small multiple of the
- * maximum time we expect a spinlock to be held. 100 iterations seems
- * about right. In most multi-CPU scenarios, the spinlock is probably
- * held by a process on another CPU and will be released before we
- * finish 100 iterations. However, on a uniprocessor, the tight loop
- * is just a waste of cycles, so don't iterate thousands of times.
+ * We loop tightly for awhile, then delay using pg_usleep() and try again.
+ * Preferably, "awhile" should be a small multiple of the maximum time we
+ * expect a spinlock to be held. 100 iterations seems about right as an
+ * initial guess. However, on a uniprocessor the loop is a waste of
+ * cycles, while in a multi-CPU scenario it's usually better to spin a bit
+ * longer than to call the kernel, so we try to adapt the spin loop count
+ * depending on whether we seem to be in a uniprocessor or multiprocessor.
*
+ * Note: you might think MIN_SPINS_PER_DELAY should be just 1, but you'd
+ * be wrong; there are platforms where that can result in a "stuck
+ * spinlock" failure. This has been seen particularly on Alphas; it seems
+ * that the first TAS after returning from kernel space will always fail
+ * on that hardware.
+ *
* Once we do decide to block, we use randomly increasing pg_usleep()
- * delays. The first delay is 10 msec, then the delay randomly
- * increases to about one second, after which we reset to 10 msec and
- * start again. The idea here is that in the presence of heavy
- * contention we need to increase the delay, else the spinlock holder
- * may never get to run and release the lock. (Consider situation
- * where spinlock holder has been nice'd down in priority by the
- * scheduler --- it will not get scheduled until all would-be
- * acquirers are sleeping, so if we always use a 10-msec sleep, there
- * is a real possibility of starvation.) But we can't just clamp the
- * delay to an upper bound, else it would take a long time to make a
- * reasonable number of tries.
+ * delays. The first delay is 1 msec, then the delay randomly increases to
+ * about one second, after which we reset to 1 msec and start again. The
+ * idea here is that in the presence of heavy contention we need to
+ * increase the delay, else the spinlock holder may never get to run and
+ * release the lock. (Consider situation where spinlock holder has been
+ * nice'd down in priority by the scheduler --- it will not get scheduled
+ * until all would-be acquirers are sleeping, so if we always use a 1-msec
+ * sleep, there is a real possibility of starvation.) But we can't just
+ * clamp the delay to an upper bound, else it would take a long time to
+ * make a reasonable number of tries.
*
* We time out and declare error after NUM_DELAYS delays (thus, exactly
- * that many tries). With the given settings, this will usually take
- * 3 or so minutes. It seems better to fix the total number of tries
- * (and thus the probability of unintended failure) than to fix the
- * total time spent.
+ * that many tries). With the given settings, this will usually take 2 or
+ * so minutes. It seems better to fix the total number of tries (and thus
+ * the probability of unintended failure) than to fix the total time
+ * spent.
*
- * The pg_usleep() delays are measured in centiseconds (0.01 sec) because
- * 10 msec is a common resolution limit at the OS level.
+ * The pg_usleep() delays are measured in milliseconds because 1 msec is a
+ * common resolution limit at the OS level for newer platforms. On older
+ * platforms the resolution limit is usually 10 msec, in which case the
+ * total delay before timeout will be a bit more.
*/
-#define SPINS_PER_DELAY 100
+#define MIN_SPINS_PER_DELAY 10
+#define MAX_SPINS_PER_DELAY 1000
#define NUM_DELAYS 1000
-#define MIN_DELAY_CSEC 1
-#define MAX_DELAY_CSEC 100
+#define MIN_DELAY_MSEC 1
+#define MAX_DELAY_MSEC 1000
int spins = 0;
int delays = 0;
- int cur_delay = MIN_DELAY_CSEC;
+ int cur_delay = 0;
#ifndef WIN32
struct timeval delay;
#endif
@@ -151,21 +165,21 @@
/* CPU-specific delay each time through the loop */
SPIN_DELAY();
- /* Block the process every SPINS_PER_DELAY tries */
- if (++spins > SPINS_PER_DELAY)
+ /* Block the process every spins_per_delay tries */
+ if (++spins >= spins_per_delay)
{
if (++delays > NUM_DELAYS)
s_lock_stuck(lock, file, line);
- if (cur_delay > 0) {
+ if (cur_delay == 0) /* first time to delay? */
+ cur_delay = MIN_DELAY_MSEC;
#ifndef WIN32
- delay.tv_sec = (cur_delay * 10000L) / 1000000L;
- delay.tv_usec = (cur_delay * 10000L) % 1000000L;
- (void) select(0, NULL, NULL, NULL, &delay);
+ delay.tv_sec = 0;
+ delay.tv_usec = cur_delay * 1000L;
+ (void) select(0, NULL, NULL, NULL, &delay);
#else
- SleepEx(((cur_delay * 10000L) < 500 ? 1 : ((cur_delay * 10000L) + 500) / 1000), FALSE);
+ SleepEx(cur_delay, FALSE)
#endif
- }
#if defined(S_LOCK_TEST)
fprintf(stdout, "*");
@@ -174,17 +188,78 @@
/* increase delay by a random fraction between 1X and 2X */
cur_delay += (int) (cur_delay *
- (((double) random()) / ((double) MAX_RANDOM_VALUE)) + 0.5);
+ (((double) random()) / ((double) MAX_RANDOM_VALUE)) + 0.5);
/* wrap back to minimum delay when max is exceeded */
- if (cur_delay > MAX_DELAY_CSEC)
- cur_delay = MIN_DELAY_CSEC;
+ if (cur_delay > MAX_DELAY_MSEC)
+ cur_delay = MIN_DELAY_MSEC;
spins = 0;
}
}
+
+ /*
+ * If we were able to acquire the lock without delaying, it's a good
+ * indication we are in a multiprocessor. If we had to delay, it's a sign
+ * (but not a sure thing) that we are in a uniprocessor. Hence, we
+ * decrement spins_per_delay slowly when we had to delay, and increase it
+ * rapidly when we didn't. It's expected that spins_per_delay will
+ * converge to the minimum value on a uniprocessor and to the maximum
+ * value on a multiprocessor.
+ *
+ * Note: spins_per_delay is local within our current process. We want to
+ * average these observations across multiple backends, since it's
+ * relatively rare for this function to even get entered, and so a single
+ * backend might not live long enough to converge on a good value. That
+ * is handled by the two routines below.
+ */
+ if (cur_delay == 0)
+ {
+ /* we never had to delay */
+ if (spins_per_delay < MAX_SPINS_PER_DELAY)
+ spins_per_delay = Min (spins_per_delay + 100, MAX_SPINS_PER_DELAY);
+ }
+ else
+ {
+ if (spins_per_delay > MIN_SPINS_PER_DELAY)
+ spins_per_delay = Max (spins_per_delay - 1, MIN_SPINS_PER_DELAY);
+ }
}
+
/*
+ * Set local copy of spins_per_delay during backend startup.
+ *
+ * NB: this has to be pretty fast as it is called while holding a spinlock
+ */
+LF_PRIVATE void
+set_spins_per_delay(int shared_spins_per_delay)
+{
+ spins_per_delay = shared_spins_per_delay;
+}
+
+/*
+ * Update shared estimate of spins_per_delay during backend exit.
+ *
+ * NB: this has to be pretty fast as it is called while holding a spinlock
+ */
+LF_PRIVATE int
+update_spins_per_delay(int shared_spins_per_delay)
+{
+ /*
+ * We use an exponential moving average with a relatively slow adaption
+ * rate, so that noise in any one backend's result won't affect the shared
+ * value too much. As long as both inputs are within the allowed range,
+ * the result must be too, so we need not worry about clamping the result.
+ *
+ * We deliberately truncate rather than rounding; this is so that single
+ * adjustments inside a backend can affect the shared estimate (see the
+ * asymmetric adjustment rules above).
+ */
+ return (shared_spins_per_delay * 15 + spins_per_delay) / 16;
+}
+
+
+/*
* Various TAS implementations that cannot live in s_lock.h as no inline
* definition exists (yet).
* In the future, get rid of tas.[cso] and fold it into this file.
@@ -204,7 +279,12 @@
*/
-#if defined(__m68k__)
+/*
+ * Note: all the if-tests here probably ought to be testing gcc version
+ * rather than platform, but I don't have adequate info to know what to
+ * write. Ideally we'd flush all this in favor of the inline version.
+ */
+#if defined(__m68k__) && !defined(__linux__)
/* really means: extern int tas(slock_t* **lock); */
static void
tas_dummy()
@@ -212,7 +292,7 @@
__asm__ __volatile__(
#if defined(__NetBSD__) && defined(__ELF__)
/* no underscore for label and % for registers */
- "\
+ "\
.global tas \n\
tas: \n\
movel %sp@(0x4),%a0 \n\
@@ -224,7 +304,7 @@
moveq #0,%d0 \n\
rts \n"
#else
- "\
+ "\
.global _tas \n\
_tas: \n\
movel sp@(0x4),a0 \n\
@@ -236,39 +316,9 @@
moveq #0,d0 \n\
rts \n"
#endif /* __NetBSD__ && __ELF__ */
-);
+ );
}
-#endif /* __m68k__ */
-
-
-#if defined(__mips__) && !defined(__sgi)
-static void
-tas_dummy()
-{
- __asm__ __volatile__(
- "\
-.global tas \n\
-tas: \n\
- .frame $sp, 0, $31 \n\
- .set push \n\
- .set mips2 \n\
- ll $14, 0($4) \n\
- or $15, $14, 1 \n\
- sc $15, 0($4) \n\
- .set pop \n\
- beq $15, 0, fail\n\
- bne $14, 0, fail\n\
- li $2, 0 \n\
- .livereg 0x2000FF0E,0x00000FFF \n\
- j $31 \n\
-fail: \n\
- li $2, 1 \n\
- j $31 \n\
-");
-}
-#endif /* __mips__ && !__sgi */
-
-
+#endif /* __m68k__ && !__linux__ */
#else /* not __GNUC__ */
/*
@@ -309,15 +359,6 @@
tas_dummy() /* really means: extern int tas(slock_t
* *lock); */
{
-
-#ifdef SUNOS4_CC
- asm(".seg \"data\"");
- asm(".seg \"text\"");
-#else
- asm(".section \"data\"");
- asm(".section \"text\"");
-#endif
-
asm("_tas:");
/*
Modified: trunk/Foundation/s_lock.h
===================================================================
--- trunk/Foundation/s_lock.h 2006-08-31 22:59:15 UTC (rev 286)
+++ trunk/Foundation/s_lock.h 2006-09-01 00:08:24 UTC (rev 287)
@@ -86,7 +86,7 @@
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
- * $PostgreSQL: pgsql/src/include/storage/s_lock.h,v 1.133 2004/12/31 22:03:42 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/storage/s_lock.h,v 1.142 2005/10/11 20:41:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -123,7 +123,7 @@
*/
-#if defined(__i386__) || defined(__x86_64__) /* AMD Opteron */
+#ifdef __i386__
#define HAS_TEST_AND_SET
typedef unsigned char slock_t;
@@ -135,7 +135,11 @@
{
register slock_t _res = 1;
- /* Use a non-locking test before asserting the bus lock */
+ /*
+ * Use a non-locking test before asserting the bus lock. Note that the
+ * extra test appears to be a small loss on some x86 platforms and a small
+ * win on others; it's by no means clear that we should keep it.
+ */
__asm__ __volatile__(
" cmpb $0,%1 \n"
" jne 1f \n"
@@ -180,10 +184,52 @@
" rep; nop \n");
}
-#endif /* __i386__ || __x86_64__ */
+#endif /* __i386__ */
-#if defined(__ia64__) || defined(__ia64) /* __ia64 used by ICC compiler? */
+#ifdef __x86_64__ /* AMD Opteron, Intel EM64T */
+#define HAS_TEST_AND_SET
+
+typedef unsigned char slock_t;
+
+#define TAS(lock) tas(lock)
+
+static __inline__ int
+tas(volatile slock_t *lock)
+{
+ register slock_t _res = 1;
+
+ /*
+ * On Opteron, using a non-locking test before the locking instruction
+ * is a huge loss. On EM64T, it appears to be a wash or small loss,
+ * so we needn't bother to try to distinguish the sub-architectures.
+ */
+ __asm__ __volatile__(
+ " lock \n"
+ " xchgb %0,%1 \n"
+: "+q"(_res), "+m"(*lock)
+:
+: "memory", "cc");
+ return (int) _res;
+}
+
+#define SPIN_DELAY() spin_delay()
+
+static __inline__ void
+spin_delay(void)
+{
+ /*
+ * Adding a PAUSE in the spin delay loop is demonstrably a no-op on
+ * Opteron, but it may be of some use on EM64T, so we keep it.
+ */
+ __asm__ __volatile__(
+ " rep; nop \n");
+}
+
+#endif /* __x86_64__ */
+
+
+#if defined(__ia64__) || defined(__ia64)
/* Intel Itanium */
#define HAS_TEST_AND_SET
@@ -191,6 +237,8 @@
#define TAS(lock) tas(lock)
+#ifndef __INTEL_COMPILER
+
static __inline__ int
tas(volatile slock_t *lock)
{
@@ -204,6 +252,19 @@
return (int) ret;
}
+#else /* __INTEL_COMPILER */
+
+static __inline__ int
+tas(volatile slock_t *lock)
+{
+ int ret;
+
+ ret = _InterlockedExchange(lock,1); /* this is a xchg asm macro */
+
+ return ret;
+}
+
+#endif /* __INTEL_COMPILER */
#endif /* __ia64__ || __ia64 */
@@ -328,7 +389,7 @@
#endif /* powerpc */
-#if defined(__mc68000__) && defined(__linux__)
+#if (defined(__mc68000__) || defined(__m68k__)) && defined(__linux__)
#define HAS_TEST_AND_SET
typedef unsigned char slock_t;
@@ -350,7 +411,7 @@
return rv;
}
-#endif /* defined(__mc68000__) && defined(__linux__) */
+#endif /* (__mc68000__ || __m68k__) && __linux__ */
#if defined(__vax__)
@@ -453,20 +514,64 @@
#endif /* __alpha || __alpha__ */
-/* These live in s_lock.c, but only for gcc */
+#if defined(__mips__) && !defined(__sgi)
+/* Note: on SGI we use the OS' mutex ABI, see below */
+/* Note: R10000 processors require a separate SYNC */
+#define HAS_TEST_AND_SET
+typedef unsigned int slock_t;
-#if defined(__m68k__)
-#define HAS_TEST_AND_SET
+#define TAS(lock) tas(lock)
-typedef unsigned char slock_t;
-#endif
+static __inline__ int
+tas(volatile slock_t *lock)
+{
+ register volatile slock_t *_l = lock;
+ register int _res;
+ register int _tmp;
+ __asm__ __volatile__(
+ " .set push \n"
+ " .set mips2 \n"
+ " .set noreorder \n"
+ " .set nomacro \n"
+ " ll %0, %2 \n"
+ " or %1, %0, 1 \n"
+ " sc %1, %2 \n"
+ " xori %1, 1 \n"
+ " or %0, %0, %1 \n"
+ " sync \n"
+ " .set pop "
+: "=&r" (_res), "=&r" (_tmp), "+R" (*_l)
+:
+: "memory");
+ return _res;
+}
-#if defined(__mips__) && !defined(__sgi)
+/* MIPS S_UNLOCK is almost standard but requires a "sync" instruction */
+#define S_UNLOCK(lock) \
+do \
+{ \
+ __asm__ __volatile__( \
+ " .set push \n" \
+ " .set mips2 \n" \
+ " .set noreorder \n" \
+ " .set nomacro \n" \
+ " sync \n" \
+ " .set pop "); \
+ *((volatile slock_t *) (lock)) = 0; \
+} while (0)
+
+#endif /* __mips__ && !__sgi */
+
+
+/* These live in s_lock.c, but only for gcc */
+
+
+#if defined(__m68k__) && !defined(__linux__)
#define HAS_TEST_AND_SET
-typedef unsigned int slock_t;
+typedef unsigned char slock_t;
#endif
@@ -492,9 +597,9 @@
tas(volatile slock_t *s_lock)
{
/* UNIVEL wants %mem in column 1, so we don't pg_indent this file */
-%mem lf_s_lock
+%mem s_lock
pushl %ebx
- movl lf_s_lock, %ebx
+ movl s_lock, %ebx
movl $255, %eax
lock
xchgb %al, (%ebx)
@@ -713,7 +818,7 @@
/* Blow up if we didn't have any way to do spinlocks */
#ifndef HAS_TEST_AND_SET
-#error libFoundation does not have native spinlock support on this platform. Please report this to lib...@op....
+#error Substrate does not have native spinlock support on this platform. Please report this to sub...@li....
#endif
/*
@@ -757,4 +862,10 @@
*/
extern void lf_s_lock(volatile slock_t *lock, const char *file, int line);
+/* Support for dynamic adjustment of spins_per_delay */
+#define DEFAULT_SPINS_PER_DELAY 100
+
+extern void set_spins_per_delay(int shared_spins_per_delay);
+extern int update_spins_per_delay(int shared_spins_per_delay);
+
#endif /* S_LOCK_H */
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:59:20
|
Revision: 286
http://svn.sourceforge.net/substrate/?rev=286&view=rev
Author: landonf
Date: 2006-08-31 15:59:15 -0700 (Thu, 31 Aug 2006)
Log Message:
-----------
Most const mismatches.
Modified Paths:
--------------
trunk/Foundation/NSConcreteData.m
trunk/Foundation/NSData.h
trunk/Foundation/NSData.m
Modified: trunk/Foundation/NSConcreteData.m
===================================================================
--- trunk/Foundation/NSConcreteData.m 2006-08-31 22:49:53 UTC (rev 285)
+++ trunk/Foundation/NSConcreteData.m 2006-08-31 22:59:15 UTC (rev 286)
@@ -61,7 +61,7 @@
* @{
*/
-- (void *) bytes {
+- (const void *) bytes {
return _bytes;
}
@@ -128,7 +128,7 @@
return nil;
_length = length;
- _bytes = bytes;
+ _bytes = bytes;
_freeWhenDone = freeWhenDone;
return self;
}
Modified: trunk/Foundation/NSData.h
===================================================================
--- trunk/Foundation/NSData.h 2006-08-31 22:49:53 UTC (rev 285)
+++ trunk/Foundation/NSData.h 2006-08-31 22:59:15 UTC (rev 286)
@@ -50,13 +50,13 @@
/* Allocating and Initializing an NSData Object */
+ (id) data;
+ (id) dataWithBytes:(const void *)bytes length:(unsigned int)length;
-+ (id) dataWithBytesNoCopy:(const void *)bytes length:(unsigned)length;
-+ (id) dataWithBytesNoCopy:(const void *)bytes length:(unsigned)length freeWhenDone:(BOOL)freeWhenDone;
++ (id) dataWithBytesNoCopy:(void *)bytes length:(unsigned)length;
++ (id) dataWithBytesNoCopy:(void *)bytes length:(unsigned)length freeWhenDone:(BOOL)freeWhenDone;
+ (id) dataWithData:(NSData *)aData;
- (id) initWithBytes:(const void *)bytes length:(unsigned)length;
-- (id) initWithBytesNoCopy:(const void *)bytes length:(unsigned int)length;
-- (id) initWithBytesNoCopy:(const void *)bytes length:(unsigned)length freeWhenDone:(BOOL)freeWhenDone;
+- (id) initWithBytesNoCopy:(void *)bytes length:(unsigned int)length;
+- (id) initWithBytesNoCopy:(void *)bytes length:(unsigned)length freeWhenDone:(BOOL)freeWhenDone;
- (id) initWithData:(NSData *)aData;
/* Accessing Data */
Modified: trunk/Foundation/NSData.m
===================================================================
--- trunk/Foundation/NSData.m 2006-08-31 22:49:53 UTC (rev 285)
+++ trunk/Foundation/NSData.m 2006-08-31 22:59:15 UTC (rev 286)
@@ -104,7 +104,7 @@
* @param length Number of bytes.
* @return Newly allocated and initialized NSData object.
*/
-+ (id) dataWithBytesNoCopy:(const void *)bytes length:(unsigned)length {
++ (id) dataWithBytesNoCopy:(void *)bytes length:(unsigned)length {
return [self dataWithBytesNoCopy: bytes length: length freeWhenDone: YES];
}
@@ -119,7 +119,7 @@
* on deallocation. Bytes must have been allocated with malloc.
* @return Newly allocated and initialized NSData object.
*/
-+ (id) dataWithBytesNoCopy:(const void *)bytes length:(unsigned)length freeWhenDone:(BOOL)freeWhenDone {
++ (id) dataWithBytesNoCopy:(void *)bytes length:(unsigned)length freeWhenDone:(BOOL)freeWhenDone {
return [[[self alloc] initWithBytesNoCopy: bytes length: length freeWhenDone: freeWhenDone] autorelease];
}
@@ -159,7 +159,7 @@
* @param length Number of bytes.
* @return Newly initialized NSData object.
*/
-- (id) initWithBytesNoCopy:(const void *)bytes length:(unsigned int)length {
+- (id) initWithBytesNoCopy:(void *)bytes length:(unsigned int)length {
return [self initWithBytesNoCopy: bytes length: length freeWhenDone: YES];
}
@@ -173,7 +173,7 @@
* on deallocation. Bytes must have been allocated with malloc.
* @return Newly initialized NSData object.
*/
-- (id) initWithBytesNoCopy:(const void *)bytes length:(unsigned)length freeWhenDone:(BOOL)freeWhenDone {
+- (id) initWithBytesNoCopy:(void *)bytes length:(unsigned)length freeWhenDone:(BOOL)freeWhenDone {
self = [self init];
if (!self)
return nil;
@@ -385,7 +385,7 @@
return self;
}
-- (id) initWithBytesNoCopy:(const void *)bytes length:(unsigned)length freeWhenDone:(BOOL)freeWhenDone {
+- (id) initWithBytesNoCopy:(void *)bytes length:(unsigned)length freeWhenDone:(BOOL)freeWhenDone {
self = [self init];
if (!self)
return nil;
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:49:56
|
Revision: 285
http://svn.sourceforge.net/substrate/?rev=285&view=rev
Author: landonf
Date: 2006-08-31 15:49:53 -0700 (Thu, 31 Aug 2006)
Log Message:
-----------
Read-only -const- pointer
Modified Paths:
--------------
trunk/Foundation/NSData.m
Modified: trunk/Foundation/NSData.m
===================================================================
--- trunk/Foundation/NSData.m 2006-08-31 22:42:00 UTC (rev 284)
+++ trunk/Foundation/NSData.m 2006-08-31 22:49:53 UTC (rev 285)
@@ -203,7 +203,7 @@
* Returns a read-only pointer to the receiver's data.
* @return Read-only pointer.
*/
-- (void *) bytes {
+- (const void *) bytes {
[self _subclassResponsibility: _cmd];
return nil;
}
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:42:03
|
Revision: 284
http://svn.sourceforge.net/substrate/?rev=284&view=rev
Author: landonf
Date: 2006-08-31 15:42:00 -0700 (Thu, 31 Aug 2006)
Log Message:
-----------
Need signal.h for SIGTRAP and kill
Modified Paths:
--------------
trunk/Foundation/LFStackException.m
Modified: trunk/Foundation/LFStackException.m
===================================================================
--- trunk/Foundation/LFStackException.m 2006-08-31 22:35:54 UTC (rev 283)
+++ trunk/Foundation/LFStackException.m 2006-08-31 22:42:00 UTC (rev 284)
@@ -66,6 +66,7 @@
#include <assert.h>
#include <stdlib.h>
#include <pthread.h>
+#include <signal.h>
#include <setjmp.h>
/* Number of exception handlers to store in each bucket.
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: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 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/LFStackException.m
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/Foundation/Makefile.in
===================================================================
--- trunk/Foundation/Makefile.in 2006-08-31 22:26:13 UTC (rev 281)
+++ trunk/Foundation/Makefile.in 2006-08-31 22:26:28 UTC (rev 282)
@@ -45,8 +45,8 @@
NSUnicodeString.m \
NSSimpleCString.m \
NSZone.m \
- LFObjCExceptionStack.m \
- LFObjCGNUException.m \
+ LFStackException.m \
+ LFGNUException.m \
LFHash.c \
s_lock.c \
$(TAS_SRC)
@@ -64,8 +64,8 @@
NSUnicodeString.o \
NSSimpleCString.o \
NSZone.o \
- LFObjCExceptionStack.o \
- LFObjCGNUException.o \
+ LFStackException.o \
+ LFGNUException.o \
LFHash.o \
s_lock.o \
$(TAS_OBJS)
Modified: trunk/Foundation/NSConcreteData.m
===================================================================
--- trunk/Foundation/NSConcreteData.m 2006-08-31 22:26:13 UTC (rev 281)
+++ trunk/Foundation/NSConcreteData.m 2006-08-31 22:26:28 UTC (rev 282)
@@ -89,13 +89,12 @@
/* Try to instantiate new object -- on failure,
* release our malloc'd buffer and rethrow
* the exception */
- @try {
+ NS_DURING
[self getBytes: buffer range: range];
- }
- @catch (id e) {
+ NS_HANDLER
NSZoneFree(NULL, buffer);
- LFObjC_ExceptionThrow(e);
- }
+ [localException raise];
+ NS_ENDHANDLER
/* Instantiated NSData instances will free buffer upon deallocation */
return [NSData dataWithBytesNoCopy: buffer length: range.length];
Modified: trunk/Foundation/NSException.h
===================================================================
--- trunk/Foundation/NSException.h 2006-08-31 22:26:13 UTC (rev 281)
+++ trunk/Foundation/NSException.h 2006-08-31 22:26:28 UTC (rev 282)
@@ -34,6 +34,7 @@
#include <Foundation/NSObject.h>
#include <Foundation/NSString.h>
+#include <Foundation/NSObjCRuntime.h>
#include <stdarg.h>
#include <setjmp.h>
@@ -83,8 +84,8 @@
*/
typedef void NSUncaughtExceptionHandler (NSException *exception);
-void NSSetUncaughtExceptionHandler(NSUncaughtExceptionHandler *handler);
-NSUncaughtExceptionHandler *NSGetUncaughtExceptionHandler(void);
+LF_EXPORT void NSSetUncaughtExceptionHandler(NSUncaughtExceptionHandler *handler);
+LF_EXPORT NSUncaughtExceptionHandler *NSGetUncaughtExceptionHandler(void);
/*
* Exception handling for the Apple runtime, and old-style exceptions
@@ -101,18 +102,20 @@
void *pointers[4]; /* The exception is stored in the first pointer */
} LFObjCLocalExceptionData;
-void _NSAddHandler (LFObjCLocalExceptionData *excData);
-void _NSRemoveHandler (LFObjCLocalExceptionData *excData);
-NSException *_NSExceptionFromHandler (LFObjCLocalExceptionData *excData);
+LF_EXPORT void _NSAddHandler (LFObjCLocalExceptionData *excData);
+LF_EXPORT void _NSRemoveHandler (LFObjCLocalExceptionData *excData);
+LF_EXPORT NSException *_NSExceptionObjectFromHandler (LFObjCLocalExceptionData *excData);
+void _NSExceptionThrow (id e);
-#ifdef LF_OBJC_LANGUAGE_EXCEPTIONS
/* New-style Exception Handling */
+#ifdef OBJC_EXCEPTIONS
# define NS_DURING @try {
# define NS_HANDLER } @catch (NSException *localException) {
# define NS_ENDHANDLER }
# define NS_VALUERETURN(val, type) return (val);
# define NS_VOIDRETURN return;
#else
+
/* Old-style Exception Handling */
# define NS_DURING { \
LFObjCLocalExceptionData _localHandler; \
@@ -122,7 +125,7 @@
#define NS_HANDLER \
_NSRemoveHandler(&_localHandler); \
} else { \
- NSException *localException = _NSExceptionFromHandler(&_localHandler);
+ NSException *localException = _NSExceptionObjectFromHandler(&_localHandler);
#define NS_ENDHANDLER \
localException = nil; /* Avoid compiler warning */ \
@@ -137,7 +140,6 @@
_NSRemoveHandler(&_localHandler); \
return; \
}
+#endif /* !OBJC_EXCEPTIONS */
-#endif /* !LF_OBJC_LANGUAGE_EXCEPTIONS */
-
#endif /* __NSException_h__ */
Modified: trunk/Foundation/NSException.m
===================================================================
--- trunk/Foundation/NSException.m 2006-08-31 22:26:13 UTC (rev 281)
+++ trunk/Foundation/NSException.m 2006-08-31 22:26:28 UTC (rev 282)
@@ -245,7 +245,11 @@
* Raise the receiver.
*/
- (void) raise {
- LFObjC_ExceptionThrow(self);
+#ifdef OBJC_EXCEPTIONS
+ @throw self;
+#else
+ _NSExceptionThrow(self);
+#endif
}
Modified: trunk/Foundation/port.h
===================================================================
--- trunk/Foundation/port.h 2006-08-31 22:26:13 UTC (rev 281)
+++ trunk/Foundation/port.h 2006-08-31 22:26:28 UTC (rev 282)
@@ -31,16 +31,16 @@
#endif
#ifndef HAVE_SRANDOM
-LF_PRIVATE void srandom(unsigned int seed);
+void srandom(unsigned int seed);
#endif
#ifndef HAVE_RANDOM
-LF_PRIVATE long random(void);
+long random(void);
#endif
#ifndef HAVE_LRAND48
-LF_PRIVATE long lrand48(void);
-LF_PRIVATE long srand48(long seed);
+long lrand48(void);
+long srand48(long seed);
#endif
#endif /* PORT_H */
Modified: trunk/Mk/autoconf.mk.in
===================================================================
--- trunk/Mk/autoconf.mk.in 2006-08-31 22:26:13 UTC (rev 281)
+++ trunk/Mk/autoconf.mk.in 2006-08-31 22:26:28 UTC (rev 282)
@@ -17,6 +17,7 @@
OBJC_LIBS = @OBJC_LIBS@
OBJC_NSCONSTANTSTRING_CFLAGS = @OBJC_NSCONSTANTSTRING_CFLAGS@
OBJC_EXCEPTIONS_CFLAGS = @OBJC_EXCEPTIONS_CFLAGS@
+OBJC_EXCEPTIONS_DEFINE = @OBJC_EXCEPTIONS_DEFINE@
OBJC_NOCFCONSTANTSTRING_CFLAGS = @OBJC_NOCFCONSTANTSTRING_CFLAGS@
ICU_CFLAGS = @ICU_CFLAGS@
Modified: trunk/aclocal.m4
===================================================================
--- trunk/aclocal.m4 2006-08-31 22:26:13 UTC (rev 281)
+++ trunk/aclocal.m4 2006-08-31 22:26:28 UTC (rev 282)
@@ -301,7 +301,7 @@
#------------------------------------------------------------------------
# OD_OBJC_EXCEPTIONS --
#
-# Check if -fobjc-exceptions is supported
+# If enabled, use Obj-C exceptions (-fobjc-exceptions)
#
# Arguments:
# None.
@@ -312,13 +312,16 @@
#
# Results:
# Result is cached.
-# If supported, OBJC_EXCEPTIONS_CFLAGS is substituted
+# Substitutes OBJC_EXCEPTIONS_DEFINE and OBJC_EXCEPTIONS_CFLAGS
+# If enabled, OBJC_EXCEPTIONS is defined to 1.
#------------------------------------------------------------------------
AC_DEFUN([OD_OBJC_EXCEPTIONS],[
AC_REQUIRE([AC_PROG_OBJC])
AC_LANG_PUSH([Objective C])
+ AC_ARG_ENABLE([objc-exceptions], AC_HELP_STRING([--enable-objc-exceptions], [Enable runtime support for Objective-C language exceptions. New-style language exceptions are not binary-compatible with old-style exception handling when using the GNU runtime. Defaults to yes.]), [ac_cv_objc_exceptions=$enableval], [ac_cv_objc_exceptions=yes])
+
AC_MSG_CHECKING([if Objective-C compiler supports -fobjc-exceptions])
AC_CACHE_VAL(ac_cv_objc_fobjc_exceptions, [
OBJCFLAGS_OLD="${OBJCFLAGS}"
@@ -335,13 +338,22 @@
])
AC_MSG_RESULT(${ac_cv_objc_fobjc_exceptions})
- if test x"$ac_cv_objc_fobjc_exceptions" = "xyes"; then
+ # Can we even enable exceptions?
+ if test x"$ac_cv_objc_exceptions" = "xyes" && test x"$ac_cv_objc_fobc_exceptions" = "xno"; then
+ AC_MSG_WARN([Objective-C exception support requires gcc 4.0 or later. Using old-style exceptions instead. If you are using the GNU runtime and later upgrade to gcc 4.0, old-style exceptions are NOT binary compatible with new-style Objective-C exceptions.])
+ fi
+
+ # 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_CFLAGS="-fobjc-exceptions"
+ OBJC_EXCEPTIONS_DEFINE="#define OBJC_EXCEPTIONS 1"
else
- AC_MSG_ERROR([Objective-C exception support is required. You will need to upgrade your GNU Objective-C compiler to 4.0 or later.])
+ OBJC_EXCEPTIONS_CFLAGS=""
+ OBJC_EXCEPTIONS_DEFINE=""
fi
AC_SUBST([OBJC_EXCEPTIONS_CFLAGS])
+ AC_SUBST([OBJC_EXCEPTIONS_DEFINE])
AC_LANG_POP([Objective C])
])
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2006-08-31 22:26:13 UTC (rev 281)
+++ trunk/configure.ac 2006-08-31 22:26:28 UTC (rev 282)
@@ -59,6 +59,11 @@
OD_OBJC_EXCEPTIONS
# Check whether -fno-constant-cfstrings is supported
OD_OBJC_NOCFCONSTANTSTRING
+if test x"$OBJC_EXCEPTIONS_DEFINE" != "x"; then
+ AC_MSG_NOTICE([Objective-C exception handling: @try @catch @throw])
+else
+ AC_MSG_NOTICE([Exception handling: NS_DURING NS_HANDLER])
+fi
AC_CACHE_SAVE
# Headers
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|