summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.fossil-settings/clean-glob1
-rw-r--r--.fossil-settings/ignore-glob1
-rw-r--r--.gitignore1
-rw-r--r--README.md7
-rw-r--r--configure.ac5
-rw-r--r--generators/TableGenerator.m30
-rw-r--r--src/Info.plist.in2
-rw-r--r--src/Makefile8
-rw-r--r--src/OFASN1Enumerated.h13
-rw-r--r--src/OFASN1Enumerated.m26
-rw-r--r--src/OFASN1Integer.h13
-rw-r--r--src/OFASN1Integer.m34
-rw-r--r--src/OFASN1ObjectIdentifier.m14
-rw-r--r--src/OFConstantString.m19
-rw-r--r--src/OFCountedMapTableSet.m9
-rw-r--r--src/OFDNSResolver.m6
-rw-r--r--src/OFDNSResolverSettings.m22
-rw-r--r--src/OFDNSResourceRecord.m7
-rw-r--r--src/OFData+ASN1DERParsing.h (renamed from src/OFData+ASN1DERValue.h)8
-rw-r--r--src/OFData+ASN1DERParsing.m (renamed from src/OFData+ASN1DERValue.m)12
-rw-r--r--src/OFData+MessagePackParsing.h (renamed from src/OFData+MessagePackValue.h)8
-rw-r--r--src/OFData+MessagePackParsing.m (renamed from src/OFData+MessagePackValue.m)35
-rw-r--r--src/OFData.h4
-rw-r--r--src/OFData.m8
-rw-r--r--src/OFDate.m26
-rw-r--r--src/OFFileManager.h8
-rw-r--r--src/OFFileManager.m16
-rw-r--r--src/OFFileURLHandler.m10
-rw-r--r--src/OFHTTPClient.m43
-rw-r--r--src/OFHTTPCookie.m2
-rw-r--r--src/OFHTTPRequest.m8
-rw-r--r--src/OFHTTPResponse.m22
-rw-r--r--src/OFHTTPServer.m34
-rw-r--r--src/OFINICategory.h6
-rw-r--r--src/OFINICategory.m19
-rw-r--r--src/OFINIFileSettings.m8
-rw-r--r--src/OFLHAArchiveEntry.m14
-rw-r--r--src/OFLocale.m15
-rw-r--r--src/OFMutableTarArchiveEntry.h12
-rw-r--r--src/OFMutableTarArchiveEntry.m12
-rw-r--r--src/OFNumber.h443
-rw-r--r--src/OFNumber.m1238
-rw-r--r--src/OFSettings.h6
-rw-r--r--src/OFSettings.m6
-rw-r--r--src/OFString+JSONParsing.h (renamed from src/OFString+JSONValue.h)8
-rw-r--r--src/OFString+JSONParsing.m (renamed from src/OFString+JSONValue.m)24
-rw-r--r--src/OFString+PropertyListParsing.h (renamed from src/OFString+PropertyListValue.h)6
-rw-r--r--src/OFString+PropertyListParsing.m (renamed from src/OFString+PropertyListValue.m)26
-rw-r--r--src/OFString+Serialization.m2
-rw-r--r--src/OFString.h68
-rw-r--r--src/OFString.m207
-rw-r--r--src/OFSystemInfo.m2
-rw-r--r--src/OFTarArchiveEntry.h20
-rw-r--r--src/OFTarArchiveEntry.m53
-rw-r--r--src/OFURL.m12
-rw-r--r--src/OFXMLNode.h34
-rw-r--r--src/OFXMLNode.m18
-rw-r--r--src/bridge/Info.plist.in2
-rw-r--r--src/runtime/Info.plist.in22
-rw-r--r--src/runtime/Makefile1
-rw-r--r--src/runtime/lookup-asm/lookup-asm-x86_64-macho.S2
-rw-r--r--src/socket.m10
-rw-r--r--tests/Info.plist.in4
-rw-r--r--tests/Makefile2
-rw-r--r--tests/OFASN1DERParsingTests.m (renamed from tests/OFASN1DERValueTests.m)358
-rw-r--r--tests/OFArrayTests.m6
-rw-r--r--tests/OFDictionaryTests.m2
-rw-r--r--tests/OFJSONTests.m26
-rw-r--r--tests/OFNumberTests.m56
-rw-r--r--tests/OFPropertyListTests.m38
-rw-r--r--tests/OFSetTests.m6
-rw-r--r--tests/OFStringTests.m79
-rw-r--r--tests/OFURLTests.m5
-rw-r--r--tests/TestsAppDelegate.h4
-rw-r--r--tests/TestsAppDelegate.m2
-rw-r--r--tests/iOS.xcodeproj/project.pbxproj4
-rw-r--r--tests/plugin/Info.plist.in2
-rw-r--r--tests/serialization.xml2
-rw-r--r--utils/ofarc/LHAArchive.m42
-rw-r--r--utils/ofarc/TarArchive.m17
-rw-r--r--utils/ofarc/ZIPArchive.m37
-rw-r--r--utils/ofhttp/OFHTTP.m53
-rw-r--r--utils/ofhttp/ProgressBar.h12
-rw-r--r--utils/ofhttp/ProgressBar.m30
-rw-r--r--utils/ofhttp/lang/de.json1
-rw-r--r--utils/ofsock/OFSock.m2
86 files changed, 1614 insertions, 1934 deletions
diff --git a/.fossil-settings/clean-glob b/.fossil-settings/clean-glob
index f0199b25..15e695bf 100644
--- a/.fossil-settings/clean-glob
+++ b/.fossil-settings/clean-glob
@@ -27,6 +27,7 @@ generators/gen_tables
src/Info.plist
src/bridge/Info.plist
src/objfw-defs.h
+src/runtime/Info.plist
src/runtime/amiga-library-functable.inc
src/runtime/inline.h
tests/DerivedData
diff --git a/.fossil-settings/ignore-glob b/.fossil-settings/ignore-glob
index 68998d11..9457d988 100644
--- a/.fossil-settings/ignore-glob
+++ b/.fossil-settings/ignore-glob
@@ -29,6 +29,7 @@ generators/gen_tables
src/Info.plist
src/bridge/Info.plist
src/objfw-defs.h
+src/runtime/Info.plist
src/runtime/amiga-library-functable.inc
src/runtime/inline.h
tests/DerivedData
diff --git a/.gitignore b/.gitignore
index cf06268c..10372399 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,6 +29,7 @@ generators/gen_tables
src/Info.plist
src/bridge/Info.plist
src/objfw-defs.h
+src/runtime/Info.plist
src/runtime/amiga-library-functable.inc
src/runtime/inline.h
tests/DerivedData
diff --git a/README.md b/README.md
index 86e2b41c..be71b460 100644
--- a/README.md
+++ b/README.md
@@ -121,12 +121,19 @@ other place, you are most likely using a mirror.
you have multiple working directories all backed by the same local
repository.
+ In order to verify the signature of the currently checked out checkin, you
+ can use:
+
+ $ fossil artifact current | gpg --verify
+
<h2 id="cloning-git">Git</h2>
To clone the Git repository, use the following:
$ git clone https://github.com/ObjFW/ObjFW
+ Git commits are not signed, so if you want to check the signature of an
+ individual commit, branch head or tag, please use Fossil.
<h1 id="installation">Installation</h1>
diff --git a/configure.ac b/configure.ac
index b871b9f3..40f6ed18 100644
--- a/configure.ac
+++ b/configure.ac
@@ -414,6 +414,7 @@ AS_IF([test x"$enable_files" != x"no" -a x"$PLUGIN_SUFFIX" != x""], [
AC_SUBST(USE_SRCS_PLUGINS, '${SRCS_PLUGINS}')
AC_SUBST(TESTPLUGIN, "plugin")
AC_DEFINE(OF_HAVE_PLUGINS, 1, [Whether we have plugin support])
+ AC_CONFIG_FILES(tests/plugin/Info.plist)
AS_IF([test x"$build_framework" = x"yes"], [
TESTPLUGIN_LIBS="-F../../src -F../../src/runtime"
@@ -524,6 +525,7 @@ case "$objc_runtime" in
])
AC_SUBST(RUNTIME, "runtime")
+ AC_CONFIG_FILES(src/runtime/Info.plist)
AS_IF([test x"$enable_shared" != x"no"], [
AC_SUBST(OBJFWRT_SHARED_LIB,
@@ -1574,6 +1576,7 @@ AC_CHECK_FUNC(pledge, [
AS_IF([test x"$objc_runtime" = x"Apple runtime"], [
AC_CHECK_HEADER(Foundation/NSObject.h, [
AC_SUBST(BRIDGE, "bridge")
+ AC_CONFIG_FILES(src/bridge/Info.plist)
AS_IF([test x"$enable_shared" != x"no"], [
AC_SUBST(OBJFWBRIDGE_SHARED_LIB,
@@ -1909,9 +1912,7 @@ AC_CONFIG_FILES([
buildsys.mk
extra.mk
src/Info.plist
- src/bridge/Info.plist
tests/Info.plist
- tests/plugin/Info.plist
utils/objfw-config
])
AC_CONFIG_HEADERS([config.h src/objfw-defs.h])
diff --git a/generators/TableGenerator.m b/generators/TableGenerator.m
index e0655a5f..61a7e1dc 100644
--- a/generators/TableGenerator.m
+++ b/generators/TableGenerator.m
@@ -121,18 +121,18 @@ OF_APPLICATION_DELEGATE(TableGenerator)
[OFApplication terminateWithStatus: 1];
}
- codePoint = (of_unichar_t)
- [[components objectAtIndex: 0] hexadecimalValue];
+ codePoint = (of_unichar_t)[[components objectAtIndex: 0]
+ unsignedLongLongValueWithBase: 16];
if (codePoint > 0x10FFFF)
@throw [OFOutOfRangeException exception];
- _uppercaseTable[codePoint] = (of_unichar_t)
- [[components objectAtIndex: 12] hexadecimalValue];
- _lowercaseTable[codePoint] = (of_unichar_t)
- [[components objectAtIndex: 13] hexadecimalValue];
- _titlecaseTable[codePoint] = (of_unichar_t)
- [[components objectAtIndex: 14] hexadecimalValue];
+ _uppercaseTable[codePoint] = (of_unichar_t)[[components
+ objectAtIndex: 12] unsignedLongLongValueWithBase: 16];
+ _lowercaseTable[codePoint] = (of_unichar_t)[[components
+ objectAtIndex: 13] unsignedLongLongValueWithBase: 16];
+ _titlecaseTable[codePoint] = (of_unichar_t)[[components
+ objectAtIndex: 14] unsignedLongLongValueWithBase: 16];
if ([[components objectAtIndex: 5] length] > 0) {
OFArray *decomposed = [[components objectAtIndex: 5]
@@ -149,8 +149,8 @@ OF_APPLICATION_DELEGATE(TableGenerator)
string = [OFMutableString string];
for (OFString *character in decomposed) {
- of_unichar_t unichar =
- (of_unichar_t)character.hexadecimalValue;
+ of_unichar_t unichar = (of_unichar_t)[character
+ unsignedLongLongValueWithBase: 16];
[string appendCharacters: &unichar
length: 1];
@@ -204,14 +204,14 @@ OF_APPLICATION_DELEGATE(TableGenerator)
![[components objectAtIndex: 1] isEqual: @"C"])
continue;
- codePoint = (of_unichar_t)
- [[components objectAtIndex: 0] hexadecimalValue];
+ codePoint = (of_unichar_t)[[components objectAtIndex: 0]
+ unsignedLongLongValueWithBase: 16];
if (codePoint > 0x10FFFF)
@throw [OFOutOfRangeException exception];
- _casefoldingTable[codePoint] = (of_unichar_t)
- [[components objectAtIndex: 2] hexadecimalValue];
+ _casefoldingTable[codePoint] = (of_unichar_t)[[components
+ objectAtIndex: 2] unsignedLongLongValueWithBase: 16];
objc_autoreleasePoolPop(pool2);
}
@@ -267,6 +267,8 @@ OF_APPLICATION_DELEGATE(TableGenerator)
done = false;
}
+
+ objc_autoreleasePoolPop(pool);
}
} while (!done);
}
diff --git a/src/Info.plist.in b/src/Info.plist.in
index 7a4f56f9..981f93ab 100644
--- a/src/Info.plist.in
+++ b/src/Info.plist.in
@@ -7,7 +7,7 @@
<key>CFBundleName</key>
<string>ObjFW</string>
<key>CFBundleIdentifier</key>
- <string>zone.heap.objfw</string>
+ <string>im.nil.objfw</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
diff --git a/src/Makefile b/src/Makefile
index 5e94979d..a10357d0 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -29,9 +29,9 @@ SRCS = OFASN1BitString.m \
OFConstantString.m \
OFCountedSet.m \
OFData.m \
- OFData+ASN1DERValue.m \
+ OFData+ASN1DERParsing.m \
OFData+CryptoHashing.m \
- OFData+MessagePackValue.m \
+ OFData+MessagePackParsing.m \
OFDate.m \
OFDictionary.m \
OFEnumerator.m \
@@ -86,8 +86,8 @@ SRCS = OFASN1BitString.m \
OFStream.m \
OFString.m \
OFString+CryptoHashing.m \
- OFString+JSONValue.m \
- OFString+PropertyListValue.m \
+ OFString+JSONParsing.m \
+ OFString+PropertyListParsing.m \
OFString+Serialization.m \
OFString+URLEncoding.m \
OFString+XMLEscaping.m \
diff --git a/src/OFASN1Enumerated.h b/src/OFASN1Enumerated.h
index c9544d38..8621b12b 100644
--- a/src/OFASN1Enumerated.h
+++ b/src/OFASN1Enumerated.h
@@ -26,21 +26,21 @@ OF_ASSUME_NONNULL_BEGIN
OF_SUBCLASSING_RESTRICTED
@interface OFASN1Enumerated: OFObject
{
- intmax_t _integerValue;
+ long long _longLongValue;
}
/*!
* @brief The integer value.
*/
-@property (readonly, nonatomic) intmax_t integerValue;
+@property (readonly, nonatomic) long long longLongValue;
/*!
* @brief Creates an ASN.1 Enumerated with the specified integer value.
*
- * @param integerValue The integer value of the Enumerated
+ * @param value The `long long` value of the Enumerated
* @return A new, autoreleased OFASN1Enumerated
*/
-+ (instancetype)enumeratedWithIntegerValue: (intmax_t)integerValue;
++ (instancetype)enumeratedWithLongLong: (long long)value;
- (instancetype)init OF_UNAVAILABLE;
@@ -48,11 +48,10 @@ OF_SUBCLASSING_RESTRICTED
* @brief Initializes an already allocated ASN.1 Enumerated with the specified
* integer value.
*
- * @param integerValue The integer value of the Enumerated
+ * @param value The `long long` value of the Enumerated
* @return An initialized OFASN1Enumerated
*/
-- (instancetype)initWithIntegerValue: (intmax_t)integerValue
- OF_DESIGNATED_INITIALIZER;
+- (instancetype)initWithLongLong: (long long)value OF_DESIGNATED_INITIALIZER;
/*!
* @brief Initializes an already allocated ASN.1 Enumerated with the specified
diff --git a/src/OFASN1Enumerated.m b/src/OFASN1Enumerated.m
index d603eecc..bbd80b2d 100644
--- a/src/OFASN1Enumerated.m
+++ b/src/OFASN1Enumerated.m
@@ -23,22 +23,22 @@
#import "OFInvalidArgumentException.h"
-extern intmax_t of_asn1_der_integer_parse(const unsigned char *buffer,
+extern long long of_asn1_der_integer_parse(const unsigned char *buffer,
size_t length);
@implementation OFASN1Enumerated
-@synthesize integerValue = _integerValue;
+@synthesize longLongValue = _longLongValue;
-+ (instancetype)enumeratedWithIntegerValue: (intmax_t)integerValue
++ (instancetype)enumeratedWithLongLong: (long long)value
{
- return [[[self alloc] initWithIntegerValue: integerValue] autorelease];
+ return [[[self alloc] initWithLongLong: value] autorelease];
}
-- (instancetype)initWithIntegerValue: (intmax_t)integerValue
+- (instancetype)initWithLongLong: (long long)value
{
self = [super init];
- _integerValue = integerValue;
+ _longLongValue = value;
return self;
}
@@ -48,7 +48,7 @@ extern intmax_t of_asn1_der_integer_parse(const unsigned char *buffer,
constructed: (bool)constructed
DEREncodedContents: (OFData *)DEREncodedContents
{
- intmax_t integerValue;
+ long long value;
@try {
if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL ||
@@ -58,14 +58,14 @@ extern intmax_t of_asn1_der_integer_parse(const unsigned char *buffer,
if (DEREncodedContents.itemSize != 1)
@throw [OFInvalidArgumentException exception];
- integerValue = of_asn1_der_integer_parse(
+ value = of_asn1_der_integer_parse(
DEREncodedContents.items, DEREncodedContents.count);
} @catch (id e) {
[self release];
@throw e;
}
- return [self initWithIntegerValue: integerValue];
+ return [self initWithLongLong: value];
}
- (instancetype)init
@@ -85,7 +85,7 @@ extern intmax_t of_asn1_der_integer_parse(const unsigned char *buffer,
enumerated = object;
- if (enumerated->_integerValue != _integerValue)
+ if (enumerated->_longLongValue != _longLongValue)
return false;
return true;
@@ -93,12 +93,12 @@ extern intmax_t of_asn1_der_integer_parse(const unsigned char *buffer,
- (uint32_t)hash
{
- return (uint32_t)_integerValue;
+ return (uint32_t)_longLongValue;
}
- (OFString *)description
{
- return [OFString stringWithFormat: @"<OFASN1Enumerated: %jd>",
- _integerValue];
+ return [OFString stringWithFormat: @"<OFASN1Enumerated: %lld>",
+ _longLongValue];
}
@end
diff --git a/src/OFASN1Integer.h b/src/OFASN1Integer.h
index 55acec23..f9ef0f4b 100644
--- a/src/OFASN1Integer.h
+++ b/src/OFASN1Integer.h
@@ -26,21 +26,21 @@ OF_ASSUME_NONNULL_BEGIN
OF_SUBCLASSING_RESTRICTED
@interface OFASN1Integer: OFObject
{
- intmax_t _integerValue;
+ long long _longLongValue;
}
/*!
* @brief The Integer value.
*/
-@property (readonly, nonatomic) intmax_t integerValue;
+@property (readonly, nonatomic) long long longLongValue;
/*!
* @brief Creates an ASN.1 Integer with the specified integer value.
*
- * @param integerValue The integer value of the Integer
+ * @param value The `long long` value of the Integer
* @return A new, autoreleased OFASN1Integer
*/
-+ (instancetype)integerWithIntegerValue: (intmax_t)integerValue;
++ (instancetype)integerWithLongLong: (long long)value;
- (instancetype)init OF_UNAVAILABLE;
@@ -48,11 +48,10 @@ OF_SUBCLASSING_RESTRICTED
* @brief Initializes an already allocated ASN.1 Integer with the specified
* integer value.
*
- * @param integerValue The integer value of the Integer
+ * @param value The `long long` value of the Integer
* @return An initialized OFASN1Integer
*/
-- (instancetype)initWithIntegerValue: (intmax_t)integerValue
- OF_DESIGNATED_INITIALIZER;
+- (instancetype)initWithLongLong: (long long)value OF_DESIGNATED_INITIALIZER;
/*!
* @brief Initializes an already allocated ASN.1 Integer with the specified
diff --git a/src/OFASN1Integer.m b/src/OFASN1Integer.m
index 9ed0aabe..d85b8832 100644
--- a/src/OFASN1Integer.m
+++ b/src/OFASN1Integer.m
@@ -25,14 +25,14 @@
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
-intmax_t
+long long
of_asn1_der_integer_parse(const unsigned char *buffer, size_t length)
{
- uintmax_t value = 0;
+ unsigned long long value = 0;
/* TODO: Support for big numbers */
- if (length > sizeof(uintmax_t) &&
- (length != sizeof(uintmax_t) + 1 || buffer[0] != 0))
+ if (length > sizeof(unsigned long long) &&
+ (length != sizeof(unsigned long long) + 1 || buffer[0] != 0))
@throw [OFOutOfRangeException exception];
if (length >= 2 && ((buffer[0] == 0 && !(buffer[1] & 0x80)) ||
@@ -40,7 +40,7 @@ of_asn1_der_integer_parse(const unsigned char *buffer, size_t length)
@throw [OFInvalidFormatException exception];
if (length >= 1 && buffer[0] & 0x80)
- value = ~(uintmax_t)0;
+ value = ~0ull;
while (length--)
value = (value << 8) | *buffer++;
@@ -49,18 +49,18 @@ of_asn1_der_integer_parse(const unsigned char *buffer, size_t length)
}
@implementation OFASN1Integer
-@synthesize integerValue = _integerValue;
+@synthesize longLongValue = _longLongValue;
-+ (instancetype)integerWithIntegerValue: (intmax_t)integerValue
++ (instancetype)integerWithLongLong: (long long)value
{
- return [[[self alloc] initWithIntegerValue: integerValue] autorelease];
+ return [[[self alloc] initWithLongLong: value] autorelease];
}
-- (instancetype)initWithIntegerValue: (intmax_t)integerValue
+- (instancetype)initWithLongLong: (long long)value
{
self = [super init];
- _integerValue = integerValue;
+ _longLongValue = value;
return self;
}
@@ -70,7 +70,7 @@ of_asn1_der_integer_parse(const unsigned char *buffer, size_t length)
constructed: (bool)constructed
DEREncodedContents: (OFData *)DEREncodedContents
{
- intmax_t integerValue;
+ long long value;
@try {
if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL ||
@@ -80,14 +80,14 @@ of_asn1_der_integer_parse(const unsigned char *buffer, size_t length)
if (DEREncodedContents.itemSize != 1)
@throw [OFInvalidArgumentException exception];
- integerValue = of_asn1_der_integer_parse(
+ value = of_asn1_der_integer_parse(
DEREncodedContents.items, DEREncodedContents.count);
} @catch (id e) {
[self release];
@throw e;
}
- return [self initWithIntegerValue: integerValue];
+ return [self initWithLongLong: value];
}
- (instancetype)init
@@ -107,7 +107,7 @@ of_asn1_der_integer_parse(const unsigned char *buffer, size_t length)
integer = object;
- if (integer->_integerValue != _integerValue)
+ if (integer->_longLongValue != _longLongValue)
return false;
return true;
@@ -115,12 +115,12 @@ of_asn1_der_integer_parse(const unsigned char *buffer, size_t length)
- (uint32_t)hash
{
- return (uint32_t)_integerValue;
+ return (uint32_t)_longLongValue;
}
- (OFString *)description
{
- return [OFString stringWithFormat: @"<OFASN1Integer: %jd>",
- _integerValue];
+ return [OFString stringWithFormat: @"<OFASN1Integer: %lld>",
+ _longLongValue];
}
@end
diff --git a/src/OFASN1ObjectIdentifier.m b/src/OFASN1ObjectIdentifier.m
index a5113182..964f3dbd 100644
--- a/src/OFASN1ObjectIdentifier.m
+++ b/src/OFASN1ObjectIdentifier.m
@@ -46,7 +46,7 @@
if (subidentifiers.count < 1)
@throw [OFInvalidFormatException exception];
- switch ([[subidentifiers objectAtIndex: 0] intMaxValue]) {
+ switch ([[subidentifiers objectAtIndex: 0] longLongValue]) {
case 0:
case 1:
case 2:
@@ -75,7 +75,7 @@
@try {
const unsigned char *items = DEREncodedContents.items;
size_t count = DEREncodedContents.count;
- uintmax_t value = 0;
+ unsigned long long value = 0;
uint_fast8_t bits = 0;
if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL ||
@@ -95,7 +95,7 @@
value = (value << 7) | (items[i] & 0x7F);
bits += 7;
- if (bits > sizeof(uintmax_t) * 8)
+ if (bits > sizeof(unsigned long long) * 8)
@throw [OFOutOfRangeException exception];
if (items[i] & 0x80)
@@ -104,20 +104,20 @@
if (subidentifiers.count == 0) {
if (value < 40)
[subidentifiers addObject:
- [OFNumber numberWithUIntMax: 0]];
+ [OFNumber numberWithInt: 0]];
else if (value < 80) {
[subidentifiers addObject:
- [OFNumber numberWithUIntMax: 1]];
+ [OFNumber numberWithInt: 1]];
value -= 40;
} else {
[subidentifiers addObject:
- [OFNumber numberWithUIntMax: 2]];
+ [OFNumber numberWithInt: 2]];
value -= 80;
}
}
[subidentifiers addObject:
- [OFNumber numberWithUIntMax: value]];
+ [OFNumber numberWithUnsignedLongLong: value]];
value = 0;
bits = 0;
diff --git a/src/OFConstantString.m b/src/OFConstantString.m
index d6a37f5b..ddd85dbb 100644
--- a/src/OFConstantString.m
+++ b/src/OFConstantString.m
@@ -575,25 +575,32 @@ struct {
return self.stringByDeletingLastPathComponent;
}
-- (intmax_t)decimalValue
+- (long long)longLongValue
{
[self finishInitialization];
- return self.decimalValue;
+ return self.longLongValue;
}
-- (uintmax_t)hexadecimalValue
+- (long long)longLongValueWithBase: (int)base
{
[self finishInitialization];
- return self.hexadecimalValue;
+ return [self longLongValueWithBase: base];
}
-- (uintmax_t)octalValue
+- (unsigned long long)unsignedLongLongValue
{
[self finishInitialization];
- return self.octalValue;
+ return self.unsignedLongLongValue;
+}
+
+- (unsigned long long)unsignedLongLongValueWithBase: (int)base
+{
+ [self finishInitialization];
+
+ return [self unsignedLongLongValueWithBase: base];
}
- (float)floatValue
diff --git a/src/OFCountedMapTableSet.m b/src/OFCountedMapTableSet.m
index 3843a573..917f3474 100644
--- a/src/OFCountedMapTableSet.m
+++ b/src/OFCountedMapTableSet.m
@@ -138,8 +138,7 @@
void *pool2 = objc_autoreleasePoolPush();
OFXMLElement *object;
OFXMLAttribute *countAttribute;
- intmax_t signedCount;
- uintmax_t count;
+ unsigned long long count;
object = [objectElement elementsForNamespace:
OF_SERIALIZATION_NS].firstObject;
@@ -149,11 +148,7 @@
if (object == nil || countAttribute == nil)
@throw [OFInvalidFormatException exception];
- signedCount = countAttribute.decimalValue;
- if (signedCount < 0)
- @throw [OFOutOfRangeException exception];
-
- count = signedCount;
+ count = countAttribute.unsignedLongLongValue;
if (count > SIZE_MAX || count > UINTPTR_MAX)
@throw [OFOutOfRangeException exception];
diff --git a/src/OFDNSResolver.m b/src/OFDNSResolver.m
index aa6e39a0..cc1b305b 100644
--- a/src/OFDNSResolver.m
+++ b/src/OFDNSResolver.m
@@ -493,7 +493,7 @@ parseSection(const unsigned char *buffer, size_t length, size_t *i,
/* Header */
- tmp = OF_BSWAP16_IF_LE(_ID.uInt16Value);
+ tmp = OF_BSWAP16_IF_LE(_ID.unsignedShortValue);
[queryData addItems: &tmp
count: 2];
@@ -814,7 +814,7 @@ parseSection(const unsigned char *buffer, size_t length, size_t *i,
/* Random, unused ID */
do {
- ID = [OFNumber numberWithUInt16: of_random16()];
+ ID = [OFNumber numberWithUnsignedShort: of_random16()];
} while ([_queries objectForKey: ID] != nil);
if (query.domainName.UTF8StringLength > 253)
@@ -913,7 +913,7 @@ parseSection(const unsigned char *buffer, size_t length, size_t *i,
/* We can't get the ID to get the context. Ignore packet. */
return true;
- ID = [OFNumber numberWithUInt16: (buffer[0] << 8) | buffer[1]];
+ ID = [OFNumber numberWithUnsignedShort: (buffer[0] << 8) | buffer[1]];
context = [[[_queries objectForKey: ID] retain] autorelease];
if (context == nil)
diff --git a/src/OFDNSResolverSettings.m b/src/OFDNSResolverSettings.m
index 21921a84..942ffb77 100644
--- a/src/OFDNSResolverSettings.m
+++ b/src/OFDNSResolverSettings.m
@@ -34,6 +34,7 @@
#import "OFInvalidFormatException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfMemoryException.h"
+#import "OFOutOfRangeException.h"
#ifdef OF_WINDOWS
# define interface struct
@@ -238,26 +239,37 @@ domainFromHostname(void)
{
@try {
if ([option hasPrefix: @"ndots:"]) {
+ unsigned long long number;
+
option = [option substringWithRange:
of_range(6, option.length - 6)];
+ number = option.unsignedLongLongValue;
+
+ if (number > UINT_MAX)
+ @throw [OFOutOfRangeException exception];
- _minNumberOfDotsInAbsoluteName =
- (unsigned int)option.decimalValue;
+ _minNumberOfDotsInAbsoluteName = (unsigned int)number;
} else if ([option hasPrefix: @"timeout:"]) {
option = [option substringWithRange:
of_range(8, option.length - 8)];
- _timeout = option.decimalValue;
+ _timeout = option.unsignedLongLongValue;
} else if ([option hasPrefix: @"attempts:"]) {
+ unsigned long long number;
+
option = [option substringWithRange:
of_range(9, option.length - 9)];
+ number = option.unsignedLongLongValue;
+
+ if (number > UINT_MAX)
+ @throw [OFOutOfRangeException exception];
- _maxAttempts = (unsigned int)option.decimalValue;
+ _maxAttempts = (unsigned int)number;
} else if ([option hasPrefix: @"reload-period:"]) {
option = [option substringWithRange:
of_range(14, option.length - 14)];
- _configReloadInterval = option.decimalValue;
+ _configReloadInterval = option.unsignedLongLongValue;
} else if ([option isEqual: @"tcp"])
_usesTCP = true;
} @catch (OFInvalidFormatException *e) {
diff --git a/src/OFDNSResourceRecord.m b/src/OFDNSResourceRecord.m
index 26c0fc91..fd596263 100644
--- a/src/OFDNSResourceRecord.m
+++ b/src/OFDNSResourceRecord.m
@@ -81,7 +81,8 @@ of_dns_class_t of_dns_class_parse(OFString *string)
DNSClass = OF_DNS_CLASS_IN;
else {
@try {
- DNSClass = (of_dns_class_t)string.decimalValue;
+ DNSClass = (of_dns_class_t)
+ [string unsignedLongLongValueWithBase: 0];
} @catch (OFInvalidFormatException *e) {
@throw [OFInvalidArgumentException exception];
}
@@ -125,8 +126,8 @@ of_dns_record_type_t of_dns_record_type_parse(OFString *string)
recordType = OF_DNS_RECORD_TYPE_ALL;
else {
@try {
- recordType =
- (of_dns_record_type_t)string.decimalValue;
+ recordType = (of_dns_record_type_t)
+ [string unsignedLongLongValueWithBase: 0];
} @catch (OFInvalidFormatException *e) {
@throw [OFInvalidArgumentException exception];
}
diff --git a/src/OFData+ASN1DERValue.h b/src/OFData+ASN1DERParsing.h
index e5985471..85426768 100644
--- a/src/OFData+ASN1DERValue.h
+++ b/src/OFData+ASN1DERParsing.h
@@ -23,12 +23,12 @@ OF_ASSUME_NONNULL_BEGIN
#ifdef __cplusplus
extern "C" {
#endif
-extern int _OFData_ASN1DERValue_reference;
+extern int _OFData_ASN1DERParsing_reference;
#ifdef __cplusplus
}
#endif
-@interface OFData (ASN1DERValue)
+@interface OFData (ASN1DERParsing)
/*!
* @brief The data interpreted as ASN.1 in DER representation and parsed as an
* object.
@@ -36,7 +36,7 @@ extern int _OFData_ASN1DERValue_reference;
* This is either an OFArray (for a sequence), an OFSet (for a set) or an
* OFASN1Value.
*/
-@property (readonly, nonatomic) id ASN1DERValue;
+@property (readonly, nonatomic) id objectByParsingASN1DER;
/*!
* @brief Parses the ASN.1 DER representation and returns it as an object.
@@ -48,7 +48,7 @@ extern int _OFData_ASN1DERValue_reference;
* if not specified, 0 means no limit (insecure!))
* @return The ASN.1 DER representation as an object
*/
-- (id)ASN1DERValueWithDepthLimit: (size_t)depthLimit;
+- (id)objectByParsingASN1DERWithDepthLimit: (size_t)depthLimit;
@end
OF_ASSUME_NONNULL_END
diff --git a/src/OFData+ASN1DERValue.m b/src/OFData+ASN1DERParsing.m
index 35be4325..a9fbfa13 100644
--- a/src/OFData+ASN1DERValue.m
+++ b/src/OFData+ASN1DERParsing.m
@@ -17,7 +17,7 @@
#include "config.h"
-#import "OFData+ASN1DERValue.h"
+#import "OFData+ASN1DERParsing.h"
#import "OFASN1BitString.h"
#import "OFASN1Boolean.h"
#import "OFASN1Enumerated.h"
@@ -42,7 +42,7 @@ enum {
ASN1_TAG_CONSTRUCTED_MASK = 0x20
};
-int _OFData_ASN1DERValue_reference;
+int _OFData_ASN1DERParsing_reference;
static size_t parseObject(OFData *self, id *object, size_t depthLimit);
@@ -225,13 +225,13 @@ parseObject(OFData *self, id *object, size_t depthLimit)
return bytesConsumed;
}
-@implementation OFData (ASN1DERValue)
-- (id)ASN1DERValue
+@implementation OFData (ASN1DERParsing)
+- (id)objectByParsingASN1DER
{
- return [self ASN1DERValueWithDepthLimit: 32];
+ return [self objectByParsingASN1DERWithDepthLimit: 32];
}
-- (id)ASN1DERValueWithDepthLimit: (size_t)depthLimit
+- (id)objectByParsingASN1DERWithDepthLimit: (size_t)depthLimit
{
void *pool = objc_autoreleasePoolPush();
id object;
diff --git a/src/OFData+MessagePackValue.h b/src/OFData+MessagePackParsing.h
index 1036614d..53f5af04 100644
--- a/src/OFData+MessagePackValue.h
+++ b/src/OFData+MessagePackParsing.h
@@ -22,17 +22,17 @@ OF_ASSUME_NONNULL_BEGIN
#ifdef __cplusplus
extern "C" {
#endif
-extern int _OFData_MessagePackValue_reference;
+extern int _OFData_MessagePackParsing_reference;
#ifdef __cplusplus
}
#endif
-@interface OFData (MessagePackValue)
+@interface OFData (MessagePackParsing)
/*!
* @brief The data interpreted as MessagePack representation and parsed as an
* object.
*/
-@property (readonly, nonatomic) id messagePackValue;
+@property (readonly, nonatomic) id objectByParsingMessagePack;
/*!
* @brief Parses the MessagePack representation and returns it as an object.
@@ -41,7 +41,7 @@ extern int _OFData_MessagePackValue_reference;
* if not specified, 0 means no limit (insecure!))
* @return The MessagePack representation as an object
*/
-- (id)messagePackValueWithDepthLimit: (size_t)depthLimit;
+- (id)objectByParsingMessagePackWithDepthLimit: (size_t)depthLimit;
@end
OF_ASSUME_NONNULL_END
diff --git a/src/OFData+MessagePackValue.m b/src/OFData+MessagePackParsing.m
index 36b8c827..c8c3a5a8 100644
--- a/src/OFData+MessagePackValue.m
+++ b/src/OFData+MessagePackParsing.m
@@ -19,7 +19,7 @@
#include <string.h>
-#import "OFData+MessagePackValue.h"
+#import "OFData+MessagePackParsing.h"
#import "OFArray.h"
#import "OFDate.h"
#import "OFDictionary.h"
@@ -33,7 +33,7 @@
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
-int _OFData_MessagePackValue_reference;
+int _OFData_MessagePackParsing_reference;
static size_t parseObject(const unsigned char *buffer, size_t length,
id *object, size_t depthLimit);
@@ -193,12 +193,12 @@ parseObject(const unsigned char *buffer, size_t length, id *object,
/* positive fixint */
if ((buffer[0] & 0x80) == 0) {
- *object = [OFNumber numberWithUInt8: buffer[0] & 0x7F];
+ *object = [OFNumber numberWithUnsignedChar: buffer[0] & 0x7F];
return 1;
}
/* negative fixint */
if ((buffer[0] & 0xE0) == 0xE0) {
- *object = [OFNumber numberWithInt8:
+ *object = [OFNumber numberWithChar:
((int8_t)(buffer[0] & 0x1F)) - 32];
return 1;
}
@@ -233,50 +233,53 @@ parseObject(const unsigned char *buffer, size_t length, id *object,
if (length < 2)
@throw [OFTruncatedDataException exception];
- *object = [OFNumber numberWithUInt8: buffer[1]];
+ *object = [OFNumber numberWithUnsignedChar: buffer[1]];
return 2;
case 0xCD: /* uint 16 */
if (length < 3)
@throw [OFTruncatedDataException exception];
- *object = [OFNumber numberWithUInt16: readUInt16(buffer + 1)];
+ *object = [OFNumber numberWithUnsignedShort:
+ readUInt16(buffer + 1)];
return 3;
case 0xCE: /* uint 32 */
if (length < 5)
@throw [OFTruncatedDataException exception];
- *object = [OFNumber numberWithUInt32: readUInt32(buffer + 1)];
+ *object = [OFNumber numberWithUnsignedLong:
+ readUInt32(buffer + 1)];
return 5;
case 0xCF: /* uint 64 */
if (length < 9)
@throw [OFTruncatedDataException exception];
- *object = [OFNumber numberWithUInt64: readUInt64(buffer + 1)];
+ *object = [OFNumber numberWithUnsignedLongLong:
+ readUInt64(buffer + 1)];
return 9;
/* Signed integers */
case 0xD0: /* int 8 */
if (length < 2)
@throw [OFTruncatedDataException exception];
- *object = [OFNumber numberWithInt8: buffer[1]];
+ *object = [OFNumber numberWithChar: buffer[1]];
return 2;
case 0xD1: /* int 16 */
if (length < 3)
@throw [OFTruncatedDataException exception];
- *object = [OFNumber numberWithInt16: readUInt16(buffer + 1)];
+ *object = [OFNumber numberWithShort: readUInt16(buffer + 1)];
return 3;
case 0xD2: /* int 32 */
if (length < 5)
@throw [OFTruncatedDataException exception];
- *object = [OFNumber numberWithInt32: readUInt32(buffer + 1)];
+ *object = [OFNumber numberWithLong: readUInt32(buffer + 1)];
return 5;
case 0xD3: /* int 64 */
if (length < 9)
@throw [OFTruncatedDataException exception];
- *object = [OFNumber numberWithInt64: readUInt64(buffer + 1)];
+ *object = [OFNumber numberWithLongLong: readUInt64(buffer + 1)];
return 9;
/* Floating point */
case 0xCA:; /* float 32 */
@@ -542,13 +545,13 @@ parseObject(const unsigned char *buffer, size_t length, id *object,
}
}
-@implementation OFData (MessagePackValue)
-- (id)messagePackValue
+@implementation OFData (MessagePackParsing)
+- (id)objectByParsingMessagePack
{
- return [self messagePackValueWithDepthLimit: 32];
+ return [self objectByParsingMessagePackWithDepthLimit: 32];
}
-- (id)messagePackValueWithDepthLimit: (size_t)depthLimit
+- (id)objectByParsingMessagePackWithDepthLimit: (size_t)depthLimit
{
void *pool = objc_autoreleasePoolPush();
size_t count = self.count;
diff --git a/src/OFData.h b/src/OFData.h
index 1e81a938..a5a63cde 100644
--- a/src/OFData.h
+++ b/src/OFData.h
@@ -327,6 +327,6 @@ enum {
OF_ASSUME_NONNULL_END
#import "OFMutableData.h"
-#import "OFData+ASN1DERValue.h"
+#import "OFData+ASN1DERParsing.h"
#import "OFData+CryptoHashing.h"
-#import "OFData+MessagePackValue.h"
+#import "OFData+MessagePackParsing.h"
diff --git a/src/OFData.m b/src/OFData.m
index 363f64a9..744b54b2 100644
--- a/src/OFData.m
+++ b/src/OFData.m
@@ -48,9 +48,9 @@
void
_references_to_categories_of_OFData(void)
{
- _OFData_ASN1DERValue_reference = 1;
+ _OFData_ASN1DERParsing_reference = 1;
_OFData_CryptoHashing_reference = 1;
- _OFData_MessagePackValue_reference = 1;
+ _OFData_MessagePackParsing_reference = 1;
}
@implementation OFData
@@ -184,7 +184,7 @@ _references_to_categories_of_OFData(void)
- (instancetype)initWithContentsOfFile: (OFString *)path
{
char *buffer = NULL;
- uintmax_t size;
+ unsigned long long size;
@try {
OFFile *file;
@@ -192,7 +192,7 @@ _references_to_categories_of_OFData(void)
size = [[OFFileManager defaultManager]
attributesOfItemAtPath: path].fileSize;
-# if UINTMAX_MAX > SIZE_MAX
+# if ULLONG_MAX > SIZE_MAX
if (size > SIZE_MAX)
@throw [OFOutOfRangeException exception];
# endif
diff --git a/src/OFDate.m b/src/OFDate.m
index 6197b3f3..9d4b2b0f 100644
--- a/src/OFDate.m
+++ b/src/OFDate.m
@@ -487,17 +487,29 @@ tmAndTzToTime(struct tm *tm, int16_t *tz)
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
- void *pool = objc_autoreleasePoolPush();
of_time_interval_t seconds;
- if (![element.name isEqual: @"OFDate"] ||
- ![element.namespace isEqual: OF_SERIALIZATION_NS])
- @throw [OFInvalidArgumentException exception];
+ @try {
+ void *pool = objc_autoreleasePoolPush();
+ unsigned long long value;
- seconds = OF_BSWAP_DOUBLE_IF_LE(OF_INT_TO_DOUBLE_RAW(OF_BSWAP64_IF_LE(
- element.hexadecimalValue)));
+ if (![element.name isEqual: @"OFDate"] ||
+ ![element.namespace isEqual: OF_SERIALIZATION_NS])
+ @throw [OFInvalidArgumentException exception];
- objc_autoreleasePoolPop(pool);
+ value = [element unsignedLongLongValueWithBase: 16];
+
+ if (value > UINT64_MAX)
+ @throw [OFOutOfRangeException exception];
+
+ seconds = OF_BSWAP_DOUBLE_IF_LE(OF_INT_TO_DOUBLE_RAW(
+ OF_BSWAP64_IF_LE(value)));
+
+ objc_autoreleasePoolPop(pool);
+ } @catch (id e) {
+ [self release];
+ @throw e;
+ }
return [self initWithTimeIntervalSince1970: seconds];
}
diff --git a/src/OFFileManager.h b/src/OFFileManager.h
index 446e83fb..d3c14cdc 100644
--- a/src/OFFileManager.h
+++ b/src/OFFileManager.h
@@ -578,7 +578,7 @@ OF_SUBCLASSING_RESTRICTED
*
* Raises an @ref OFUndefinedKeyException if the key is missing.
*/
-@property (readonly, nonatomic) uintmax_t fileSize;
+@property (readonly, nonatomic) unsigned long long fileSize;
/*!
* @brief The @ref of_file_attribute_key_type key from the dictionary.
@@ -593,21 +593,21 @@ OF_SUBCLASSING_RESTRICTED
*
* Raises an @ref OFUndefinedKeyException if the key is missing.
*/
-@property (readonly, nonatomic) uint16_t filePOSIXPermissions;
+@property (readonly, nonatomic) unsigned long filePOSIXPermissions;
/*!
* @brief The @ref of_file_attribute_key_posix_uid key from the dictionary.
*
* Raises an @ref OFUndefinedKeyException if the key is missing.
*/
-@property (readonly, nonatomic) uint32_t filePOSIXUID;
+@property (readonly, nonatomic) unsigned long filePOSIXUID;
/*!
* @brief The @ref of_file_attribute_key_posix_gid key from the dictionary.
*
* Raises an @ref OFUndefinedKeyException if the key is missing.
*/
-@property (readonly, nonatomic) uint32_t filePOSIXGID;
+@property (readonly, nonatomic) unsigned long filePOSIXGID;
/*!
* @brief The @ref of_file_attribute_key_owner key from the dictionary.
diff --git a/src/OFFileManager.m b/src/OFFileManager.m
index 72ec8fb4..04acb7a2 100644
--- a/src/OFFileManager.m
+++ b/src/OFFileManager.m
@@ -938,10 +938,10 @@ attributeForKeyOrException(of_file_attributes_t attributes,
@end
@implementation OFDictionary (FileAttributes)
-- (uintmax_t)fileSize
+- (unsigned long long)fileSize
{
return [attributeForKeyOrException(self, of_file_attribute_key_size)
- uIntMaxValue];
+ unsignedLongLongValue];
}
- (of_file_type_t)fileType
@@ -949,22 +949,22 @@ attributeForKeyOrException(of_file_attributes_t attributes,
return attributeForKeyOrException(self, of_file_attribute_key_type);
}
-- (uint16_t)filePOSIXPermissions
+- (unsigned long)filePOSIXPermissions
{
return [attributeForKeyOrException(self,
- of_file_attribute_key_posix_permissions) uInt16Value];
+ of_file_attribute_key_posix_permissions) unsignedLongValue];
}
-- (uint32_t)filePOSIXUID
+- (unsigned long)filePOSIXUID
{
return [attributeForKeyOrException(self,
- of_file_attribute_key_posix_uid) uInt32Value];
+ of_file_attribute_key_posix_uid) unsignedLongValue];
}
-- (uint32_t)filePOSIXGID
+- (unsigned long)filePOSIXGID
{
return [attributeForKeyOrException(self,
- of_file_attribute_key_posix_gid) uInt32Value];
+ of_file_attribute_key_posix_gid) unsignedLongValue];
}
- (OFString *)fileOwner
diff --git a/src/OFFileURLHandler.m b/src/OFFileURLHandler.m
index 757fae2d..6de10a36 100644
--- a/src/OFFileURLHandler.m
+++ b/src/OFFileURLHandler.m
@@ -411,9 +411,9 @@ setOwnerAndGroupAttributes(of_mutable_file_attributes_t attributes,
of_stat_t *s)
{
#ifdef OF_FILE_MANAGER_SUPPORTS_OWNER
- [attributes setObject: [NSNumber numberWithUInt16: s->st_uid]
+ [attributes setObject: [NSNumber numberWithUnsignedLong: s->st_uid]
forKey: of_file_attribute_key_posix_uid];
- [attributes setObject: [NSNumber numberWithUInt16: s->st_gid]
+ [attributes setObject: [NSNumber numberWithUnsignedLong: s->st_gid]
forKey: of_file_attribute_key_posix_gid];
# ifdef OF_HAVE_THREADS
@@ -620,12 +620,12 @@ setSymbolicLinkDestinationAttribute(of_mutable_file_attributes_t attributes,
if (s.st_size < 0)
@throw [OFOutOfRangeException exception];
- [ret setObject: [NSNumber numberWithUIntMax: s.st_size]
+ [ret setObject: [NSNumber numberWithUnsignedLongLong: s.st_size]
forKey: of_file_attribute_key_size];
setTypeAttribute(ret, &s);
- [ret setObject: [NSNumber numberWithUInt16: s.st_mode & 07777]
+ [ret setObject: [NSNumber numberWithUnsignedLong: s.st_mode]
forKey: of_file_attribute_key_posix_permissions];
setOwnerAndGroupAttributes(ret, &s);
@@ -760,7 +760,7 @@ setSymbolicLinkDestinationAttribute(of_mutable_file_attributes_t attributes,
attributes: (of_file_attributes_t)attributes OF_DIRECT
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
- uint16_t mode = permissions.uInt16Value & 0777;
+ mode_t mode = (mode_t)permissions.unsignedLongValue;
OFString *path = URL.fileSystemRepresentation;
int status;
diff --git a/src/OFHTTPClient.m b/src/OFHTTPClient.m
index cd720322..b01c94fc 100644
--- a/src/OFHTTPClient.m
+++ b/src/OFHTTPClient.m
@@ -79,7 +79,7 @@ OF_DIRECT_MEMBERS
OFHTTPClientRequestHandler *_handler;
OFTCPSocket *_socket;
bool _chunked;
- uintmax_t _toWrite;
+ unsigned long long _toWrite;
bool _atEndOfStream;
}
@@ -93,7 +93,7 @@ OF_DIRECT_MEMBERS
OFTCPSocket *_socket;
bool _hasContentLength, _chunked, _keepAlive;
bool _atEndOfStream, _setAtEndOfStream;
- intmax_t _toRead;
+ long long _toRead;
}
@property (nonatomic, setter=of_setKeepAlive:) bool of_keepAlive;
@@ -445,6 +445,8 @@ defaultShouldFollow(of_http_request_method_t method, int statusCode)
- (bool)handleFirstLine: (OFString *)line
{
+ long long status;
+
/*
* It's possible that the write succeeds on a connection that is
* keep-alive, but the connection has already been closed by the remote
@@ -464,7 +466,12 @@ defaultShouldFollow(of_http_request_method_t method, int statusCode)
@throw [OFUnsupportedVersionException
exceptionWithVersion: _version];
- _status = (int)[line substringWithRange: of_range(9, 3)].decimalValue;
+ status = [line substringWithRange: of_range(9, 3)].longLongValue;
+
+ if (status < 0 || status > 599)
+ @throw [OFInvalidServerReplyException exception];
+
+ _status = (int)status;
return true;
}
@@ -713,7 +720,7 @@ defaultShouldFollow(of_http_request_method_t method, int statusCode)
URLPort = URL.port;
if (URLPort != nil)
- port = URLPort.uInt16Value;
+ port = URLPort.unsignedShortValue;
sock.delegate = self;
[sock asyncConnectToHost: URL.host
@@ -732,7 +739,6 @@ defaultShouldFollow(of_http_request_method_t method, int statusCode)
@try {
OFDictionary OF_GENERIC(OFString *, OFString *) *headers;
- intmax_t contentLength;
OFString *transferEncoding, *contentLengthString;
_handler = [handler retain];
@@ -749,11 +755,7 @@ defaultShouldFollow(of_http_request_method_t method, int statusCode)
@throw [OFInvalidArgumentException
exception];
- contentLength = contentLengthString.decimalValue;
- if (contentLength < 0)
- @throw [OFOutOfRangeException exception];
-
- _toWrite = contentLength;
+ _toWrite = contentLengthString.unsignedLongLongValue;
} else if (!_chunked)
@throw [OFInvalidArgumentException exception];
} @catch (id e) {
@@ -895,11 +897,13 @@ defaultShouldFollow(of_http_request_method_t method, int statusCode)
_hasContentLength = true;
@try {
- _toRead = contentLength.decimalValue;
+ unsigned long long toRead =
+ contentLength.unsignedLongLongValue;
- if (_toRead < 0)
- @throw [OFInvalidServerReplyException
- exception];
+ if (toRead > LLONG_MAX)
+ @throw [OFOutOfRangeException exception];
+
+ _toRead = (long long)toRead;
} @catch (OFInvalidFormatException *e) {
@throw [OFInvalidServerReplyException exception];
}
@@ -926,7 +930,7 @@ defaultShouldFollow(of_http_request_method_t method, int statusCode)
if (!_chunked) {
size_t ret;
- if (length > (uintmax_t)_toRead)
+ if (length > (unsigned long long)_toRead)
length = (size_t)_toRead;
ret = [_socket readIntoBuffer: buffer
@@ -981,7 +985,7 @@ defaultShouldFollow(of_http_request_method_t method, int statusCode)
return 0;
} else if (_toRead > 0) {
- if (length > (uintmax_t)_toRead)
+ if (length > (unsigned long long)_toRead)
length = (size_t)_toRead;
length = [_socket readIntoBuffer: buffer
@@ -1026,8 +1030,13 @@ defaultShouldFollow(of_http_request_method_t method, int statusCode)
}
@try {
- if ((_toRead = line.hexadecimalValue) < 0)
+ unsigned long long toRead =
+ [line unsignedLongLongValueWithBase: 16];
+
+ if (toRead > LLONG_MAX)
@throw [OFOutOfRangeException exception];
+
+ _toRead = (long long)toRead;
} @catch (OFInvalidFormatException *e) {
@throw [OFInvalidServerReplyException exception];
}
diff --git a/src/OFHTTPCookie.m b/src/OFHTTPCookie.m
index e3c1c3bc..7cf62482 100644
--- a/src/OFHTTPCookie.m
+++ b/src/OFHTTPCookie.m
@@ -38,7 +38,7 @@ handleAttribute(OFHTTPCookie *cookie, OFString *name, OFString *value)
cookie.expires = date;
} else if ([lowercaseName isEqual: @"max-age"]) {
OFDate *date = [OFDate dateWithTimeIntervalSinceNow:
- value.decimalValue];
+ value.unsignedLongLongValue];
cookie.expires = date;
} else if ([lowercaseName isEqual: @"domain"])
cookie.domain = value;
diff --git a/src/OFHTTPRequest.m b/src/OFHTTPRequest.m
index a7521be7..ff0a4646 100644
--- a/src/OFHTTPRequest.m
+++ b/src/OFHTTPRequest.m
@@ -214,16 +214,16 @@ of_http_request_method_from_string(OFString *string)
{
void *pool = objc_autoreleasePoolPush();
OFArray *components = [string componentsSeparatedByString: @"."];
- intmax_t major, minor;
+ unsigned long long major, minor;
of_http_request_protocol_version_t protocolVersion;
if (components.count != 2)
@throw [OFInvalidFormatException exception];
- major = [components.firstObject decimalValue];
- minor = [components.lastObject decimalValue];
+ major = [components.firstObject unsignedLongLongValue];
+ minor = [components.lastObject unsignedLongLongValue];
- if (major < 0 || major > UINT8_MAX || minor < 0 || minor > UINT8_MAX)
+ if (major > UINT8_MAX || minor > UINT8_MAX)
@throw [OFOutOfRangeException exception];
protocolVersion.major = (uint8_t)major;
diff --git a/src/OFHTTPResponse.m b/src/OFHTTPResponse.m
index 719cd97e..d1e4f41a 100644
--- a/src/OFHTTPResponse.m
+++ b/src/OFHTTPResponse.m
@@ -271,16 +271,16 @@ encodingForContentType(OFString *contentType)
{
void *pool = objc_autoreleasePoolPush();
OFArray *components = [string componentsSeparatedByString: @"."];
- intmax_t major, minor;
+ unsigned long long major, minor;
of_http_request_protocol_version_t protocolVersion;
if (components.count != 2)
@throw [OFInvalidFormatException exception];
- major = [components.firstObject decimalValue];
- minor = [components.lastObject decimalValue];
+ major = [components.firstObject unsignedLongLongValue];
+ minor = [components.lastObject unsignedLongLongValue];
- if (major < 0 || major > UINT8_MAX || minor < 0 || minor > UINT8_MAX)
+ if (major > UINT8_MAX || minor > UINT8_MAX)
@throw [OFOutOfRangeException exception];
protocolVersion.major = (uint8_t)major;
@@ -306,7 +306,7 @@ encodingForContentType(OFString *contentType)
- (OFString *)stringWithEncoding: (of_string_encoding_t)encoding
{
void *pool = objc_autoreleasePoolPush();
- OFString *contentType, *contentLength, *ret;
+ OFString *contentType, *contentLengthString, *ret;
OFData *data;
if (encoding == OF_STRING_ENCODING_AUTODETECT &&
@@ -318,9 +318,17 @@ encodingForContentType(OFString *contentType)
data = [self readDataUntilEndOfStream];
- if ((contentLength = [_headers objectForKey: @"Content-Length"]) != nil)
- if (data.count != (size_t)contentLength.decimalValue)
+ contentLengthString = [_headers objectForKey: @"Content-Length"];
+ if (contentLengthString != nil) {
+ unsigned long long contentLength =
+ contentLengthString.unsignedLongLongValue;
+
+ if (contentLength > SIZE_MAX)
+ @throw [OFOutOfRangeException exception];
+
+ if (data.count != (size_t)contentLength)
@throw [OFTruncatedDataException exception];
+ }
ret = [[OFString alloc] initWithCString: (char *)data.items
encoding: encoding
diff --git a/src/OFHTTPServer.m b/src/OFHTTPServer.m
index 3d53d238..95c88626 100644
--- a/src/OFHTTPServer.m
+++ b/src/OFHTTPServer.m
@@ -105,13 +105,13 @@ OF_DIRECT_MEMBERS
{
OFStreamSocket *_socket;
bool _chunked;
- intmax_t _toRead;
+ long long _toRead;
bool _atEndOfStream, _setAtEndOfStream;
}
- (instancetype)initWithSocket: (OFStreamSocket *)sock
chunked: (bool)chunked
- contentLength: (uintmax_t)contentLength;
+ contentLength: (unsigned long long)contentLength;
@end
#ifdef OF_HAVE_THREADS
@@ -415,7 +415,7 @@ normalizedKey(OFString *key)
isEqual: @"chunked"];
OFString *contentLengthString =
[_headers objectForKey: @"Content-Length"];
- intmax_t contentLength = 0;
+ unsigned long long contentLength = 0;
if (contentLengthString != nil) {
if (chunked || contentLengthString.length == 0)
@@ -423,13 +423,10 @@ normalizedKey(OFString *key)
@try {
contentLength =
- contentLengthString.decimalValue;
+ contentLengthString.unsignedLongLongValue;
} @catch (OFInvalidFormatException *e) {
return [self sendErrorAndClose: 400];
}
-
- if (contentLength < 0)
- return [self sendErrorAndClose: 400];
}
if (chunked || contentLengthString != nil) {
@@ -482,8 +479,9 @@ normalizedKey(OFString *key)
@try {
of_range_t range =
of_range(pos + 1, value.length - pos - 1);
- intmax_t portTmp = [value
- substringWithRange: range].decimalValue;
+ unsigned long long portTmp =
+ [value substringWithRange: range]
+ .unsignedLongLongValue;
if (portTmp < 1 || portTmp > UINT16_MAX)
return [self sendErrorAndClose: 400];
@@ -545,7 +543,7 @@ normalizedKey(OFString *key)
URL.scheme = @"http";
URL.host = _host;
if (_port != 80)
- URL.port = [OFNumber numberWithUInt16: _port];
+ URL.port = [OFNumber numberWithUnsignedShort: _port];
if ((pos = [_path rangeOfString: @"?"].location) != OF_NOT_FOUND) {
OFString *path, *query;
@@ -585,14 +583,17 @@ normalizedKey(OFString *key)
@implementation OFHTTPServerRequestBodyStream
- (instancetype)initWithSocket: (OFStreamSocket *)sock
chunked: (bool)chunked
- contentLength: (uintmax_t)contentLength
+ contentLength: (unsigned long long)contentLength
{
self = [super init];
@try {
+ if (contentLength > LLONG_MAX)
+ @throw [OFOutOfRangeException exception];
+
_socket = [sock retain];
_chunked = chunked;
- _toRead = contentLength;
+ _toRead = (long long)contentLength;
if (_chunked && _toRead > 0)
@throw [OFInvalidArgumentException exception];
@@ -633,7 +634,7 @@ normalizedKey(OFString *key)
if (!_chunked) {
size_t ret;
- if (length > (uintmax_t)_toRead)
+ if (length > (unsigned long long)_toRead)
length = (size_t)_toRead;
ret = [_socket readIntoBuffer: buffer
@@ -682,7 +683,7 @@ normalizedKey(OFString *key)
return 0;
} else if (_toRead > 0) {
- if (length > (uintmax_t)_toRead)
+ if (length > (unsigned long long)_toRead)
length = (size_t)_toRead;
length = [_socket readIntoBuffer: buffer
@@ -698,6 +699,7 @@ normalizedKey(OFString *key)
void *pool = objc_autoreleasePoolPush();
OFString *line;
of_range_t range;
+ unsigned long long toRead;
@try {
line = [_socket tryReadLine];
@@ -725,8 +727,10 @@ normalizedKey(OFString *key)
@throw [OFInvalidFormatException exception];
}
- if ((_toRead = line.hexadecimalValue) < 0)
+ toRead = [line unsignedLongLongValueWithBase: 16];
+ if (toRead > LLONG_MAX)
@throw [OFOutOfRangeException exception];
+ _toRead = (long long)toRead;
if (_toRead == 0) {
_setAtEndOfStream = true;
diff --git a/src/OFINICategory.h b/src/OFINICategory.h
index 296b855e..3815373f 100644
--- a/src/OFINICategory.h
+++ b/src/OFINICategory.h
@@ -81,8 +81,8 @@ OF_SUBCLASSING_RESTRICTED
* @return The integer value for the specified key or the specified default
* value if it does not exist
*/
-- (intmax_t)integerForKey: (OFString *)key
- defaultValue: (intmax_t)defaultValue;
+- (long long)integerForKey: (OFString *)key
+ defaultValue: (long long)defaultValue;
/*!
* @brief Returns the bool value for the specified key or the specified default
@@ -163,7 +163,7 @@ OF_SUBCLASSING_RESTRICTED
* @param integer The integer to which the value of the key should be set
* @param key The key for which the new value should be set
*/
-- (void)setInteger: (intmax_t)integer
+- (void)setInteger: (long long)integer
forKey: (OFString *)key;
/*!
diff --git a/src/OFINICategory.m b/src/OFINICategory.m
index 320fe154..f788b9b6 100644
--- a/src/OFINICategory.m
+++ b/src/OFINICategory.m
@@ -209,20 +209,17 @@ unescapeString(OFString *string)
return defaultValue;
}
-- (intmax_t)integerForKey: (OFString *)key
- defaultValue: (intmax_t)defaultValue
+- (long long)integerForKey: (OFString *)key
+ defaultValue: (long long)defaultValue
{
void *pool = objc_autoreleasePoolPush();
OFString *value = [self stringForKey: key
defaultValue: nil];
- intmax_t ret;
+ long long ret;
- if (value != nil) {
- if ([value hasPrefix: @"0x"] || [value hasPrefix: @"$"])
- ret = value.hexadecimalValue;
- else
- ret = value.decimalValue;
- } else
+ if (value != nil)
+ ret = [value longLongValueWithBase: 0];
+ else
ret = defaultValue;
objc_autoreleasePoolPop(pool);
@@ -354,12 +351,12 @@ unescapeString(OFString *string)
objc_autoreleasePoolPop(pool);
}
-- (void)setInteger: (intmax_t)integer
+- (void)setInteger: (long long)integer
forKey: (OFString *)key
{
void *pool = objc_autoreleasePoolPush();
- [self setString: [OFString stringWithFormat: @"%jd", integer]
+ [self setString: [OFString stringWithFormat: @"%lld", integer]
forKey: key];
objc_autoreleasePoolPop(pool);
diff --git a/src/OFINIFileSettings.m b/src/OFINIFileSettings.m
index 142fde1e..47dce942 100644
--- a/src/OFINIFileSettings.m
+++ b/src/OFINIFileSettings.m
@@ -88,7 +88,7 @@
objc_autoreleasePoolPop(pool);
}
-- (void)setInteger: (intmax_t)integer
+- (void)setInteger: (long long)integer
forPath: (OFString *)path
{
void *pool = objc_autoreleasePoolPush();
@@ -186,12 +186,12 @@
return [ret autorelease];
}
-- (intmax_t)integerForPath: (OFString *)path
- defaultValue: (intmax_t)defaultValue
+- (long long)integerForPath: (OFString *)path
+ defaultValue: (long long)defaultValue
{
void *pool = objc_autoreleasePoolPush();
OFString *category, *key;
- intmax_t ret;
+ long long ret;
[self of_getCategory: &category
andKey: &key
diff --git a/src/OFLHAArchiveEntry.m b/src/OFLHAArchiveEntry.m
index eb6b1efb..ba81c079 100644
--- a/src/OFLHAArchiveEntry.m
+++ b/src/OFLHAArchiveEntry.m
@@ -127,7 +127,7 @@ parsePermissionsExtension(OFLHAArchiveEntry *entry, OFData *extension,
[entry->_mode release];
entry->_mode = nil;
- entry->_mode = [[OFNumber alloc] initWithUInt16: mode];
+ entry->_mode = [[OFNumber alloc] initWithUnsignedShort: mode];
}
static void
@@ -151,8 +151,8 @@ parseGIDUIDExtension(OFLHAArchiveEntry *entry, OFData *extension,
[entry->_UID release];
entry->_UID = nil;
- entry->_GID = [[OFNumber alloc] initWithUInt16: GID];
- entry->_UID = [[OFNumber alloc] initWithUInt16: UID];
+ entry->_GID = [[OFNumber alloc] initWithUnsignedShort: GID];
+ entry->_UID = [[OFNumber alloc] initWithUnsignedShort: UID];
}
static void
@@ -655,7 +655,7 @@ getFileNameAndDirectoryName(OFLHAArchiveEntry *entry,
count: sizeof(tmp16)];
[data addItem: "\x50"];
- tmp16 = OF_BSWAP16_IF_BE(_mode.uInt16Value);
+ tmp16 = OF_BSWAP16_IF_BE(_mode.unsignedShortValue);
[data addItems: &tmp16
count: sizeof(tmp16)];
}
@@ -669,11 +669,11 @@ getFileNameAndDirectoryName(OFLHAArchiveEntry *entry,
count: sizeof(tmp16)];
[data addItem: "\x51"];
- tmp16 = OF_BSWAP16_IF_BE(_GID.uInt16Value);
+ tmp16 = OF_BSWAP16_IF_BE(_GID.unsignedShortValue);
[data addItems: &tmp16
count: sizeof(tmp16)];
- tmp16 = OF_BSWAP16_IF_BE(_UID.uInt16Value);
+ tmp16 = OF_BSWAP16_IF_BE(_UID.unsignedShortValue);
[data addItems: &tmp16
count: sizeof(tmp16)];
}
@@ -761,7 +761,7 @@ getFileNameAndDirectoryName(OFLHAArchiveEntry *entry,
{
void *pool = objc_autoreleasePoolPush();
OFString *mode = (_mode == nil ? nil
- : [OFString stringWithFormat: @"%" PRIo16, _mode.uInt16Value]);
+ : [OFString stringWithFormat: @"%ho", _mode.unsignedShortValue]);
OFString *extensions = [_extensions.description
stringByReplacingOccurrencesOfString: @"\n"
withString: @"\n\t"];
diff --git a/src/OFLocale.m b/src/OFLocale.m
index 1d4dd94c..984040c8 100644
--- a/src/OFLocale.m
+++ b/src/OFLocale.m
@@ -215,8 +215,9 @@ evaluateCondition(OFString *condition, OFDictionary *variables)
var = [OFNumber numberWithDouble:
[first doubleValue] + [second doubleValue]];
else if ([token isEqual: @"%"])
- var = [OFNumber numberWithIntMax:
- [first intMaxValue] % [second intMaxValue]];
+ var = [OFNumber numberWithLongLong:
+ [first longLongValue] %
+ [second longLongValue]];
else if ([token isEqual: @"&&"])
var = [OFNumber numberWithBool:
[first boolValue] && [second boolValue]];
@@ -238,7 +239,8 @@ evaluateCondition(OFString *condition, OFDictionary *variables)
![first boolValue]];
else if ([token isEqual: @"is_real"])
var = [OFNumber numberWithBool:
- [first doubleValue] != [first intMaxValue]];
+ ([first doubleValue] !=
+ [first longLongValue])];
else
OF_ENSURE(0);
@@ -510,7 +512,8 @@ evaluateArray(OFArray *array, OFDictionary *variables)
mapPath = [path stringByAppendingPathComponent: @"languages.json"];
@try {
- map = [[OFString stringWithContentsOfFile: mapPath] JSONValue];
+ map = [[OFString stringWithContentsOfFile: mapPath]
+ objectByParsingJSON];
} @catch (OFOpenItemFailedException *e) {
objc_autoreleasePoolPop(pool);
return;
@@ -534,8 +537,8 @@ evaluateArray(OFArray *array, OFDictionary *variables)
languageFile = [path stringByAppendingPathComponent:
[languageFile stringByAppendingString: @".json"]];
- [_localizedStrings addObject:
- [[OFString stringWithContentsOfFile: languageFile] JSONValue]];
+ [_localizedStrings addObject: [[OFString stringWithContentsOfFile:
+ languageFile] objectByParsingJSON]];
objc_autoreleasePoolPop(pool);
}
diff --git a/src/OFMutableTarArchiveEntry.h b/src/OFMutableTarArchiveEntry.h
index f406f298..e5ab79d4 100644
--- a/src/OFMutableTarArchiveEntry.h
+++ b/src/OFMutableTarArchiveEntry.h
@@ -38,22 +38,22 @@ OF_ASSUME_NONNULL_BEGIN
/*!
* @brief The mode of the entry.
*/
-@property (readwrite, nonatomic) uint32_t mode;
+@property (readwrite, nonatomic) unsigned long mode;
/*!
* @brief The UID of the owner.
*/
-@property (readwrite, nonatomic) uint32_t UID;
+@property (readwrite, nonatomic) unsigned long UID;
/*!
* @brief The GID of the group.
*/
-@property (readwrite, nonatomic) uint32_t GID;
+@property (readwrite, nonatomic) unsigned long GID;
/*!
* @brief The size of the file.
*/
-@property (readwrite, nonatomic) uint64_t size;
+@property (readwrite, nonatomic) unsigned long long size;
/*!
* @brief The date of the last modification of the file.
@@ -86,12 +86,12 @@ OF_ASSUME_NONNULL_BEGIN
/*!
* @brief The device major (if the file is a device).
*/
-@property (readwrite, nonatomic) uint32_t deviceMajor;
+@property (readwrite, nonatomic) unsigned long deviceMajor;
/*!
* @brief The device major (if the file is a device).
*/
-@property (readwrite, nonatomic) uint32_t deviceMinor;
+@property (readwrite, nonatomic) unsigned long deviceMinor;
/*!
* @brief Converts the OFMutableTarArchiveEntry to an immutable
diff --git a/src/OFMutableTarArchiveEntry.m b/src/OFMutableTarArchiveEntry.m
index 8f888f7e..b839890e 100644
--- a/src/OFMutableTarArchiveEntry.m
+++ b/src/OFMutableTarArchiveEntry.m
@@ -41,22 +41,22 @@
[old release];
}
-- (void)setMode: (uint32_t)mode
+- (void)setMode: (unsigned long)mode
{
_mode = mode;
}
-- (void)setUID: (uint32_t)UID
+- (void)setUID: (unsigned long)UID
{
_UID = UID;
}
-- (void)setGID: (uint32_t)GID
+- (void)setGID: (unsigned long)GID
{
_GID = GID;
}
-- (void)setSize: (uint64_t)size
+- (void)setSize: (unsigned long long)size
{
_size = size;
}
@@ -94,12 +94,12 @@
[old release];
}
-- (void)setDeviceMajor: (uint32_t)deviceMajor
+- (void)setDeviceMajor: (unsigned long)deviceMajor
{
_deviceMajor = deviceMajor;
}
-- (void)setDeviceMinor: (uint32_t)deviceMinor
+- (void)setDeviceMinor: (unsigned long)deviceMinor
{
_deviceMinor = deviceMinor;
}
diff --git a/src/OFNumber.h b/src/OFNumber.h
index 27a55f20..66f866ac 100644
--- a/src/OFNumber.h
+++ b/src/OFNumber.h
@@ -49,15 +49,10 @@ OF_SUBCLASSING_RESTRICTED
OFJSONRepresentation, OFMessagePackRepresentation>
{
union of_number_value {
- double float_;
- intmax_t signed_;
- uintmax_t unsigned_;
+ double float_;
+ long long signed_;
+ unsigned long long unsigned_;
} _value;
- enum of_number_type {
- OF_NUMBER_TYPE_FLOAT = 1,
- OF_NUMBER_TYPE_SIGNED,
- OF_NUMBER_TYPE_UNSIGNED
- } _type;
const char *_typeEncoding;
}
@@ -117,81 +112,6 @@ OF_SUBCLASSING_RESTRICTED
@property (readonly, nonatomic) unsigned long long unsignedLongLongValue;
/*!
- * @brief The OFNumber as an `int8_t`.
- */
-@property (readonly, nonatomic) int8_t int8Value;
-
-/*!
- * @brief The OFNumber as an `int16_t`.
- */
-@property (readonly, nonatomic) int16_t int16Value;
-
-/*!
- * @brief The OFNumber as an `int32_t`.
- */
-@property (readonly, nonatomic) int32_t int32Value;
-
-/*!
- * @brief The OFNumber as an `int64_t`.
- */
-@property (readonly, nonatomic) int64_t int64Value;
-
-/*!
- * @brief The OFNumber as a `uint8_t`.
- */
-@property (readonly, nonatomic) uint8_t uInt8Value;
-
-/*!
- * @brief The OFNumber as a `uint16_t`.
- */
-@property (readonly, nonatomic) uint16_t uInt16Value;
-
-/*!
- * @brief The OFNumber as a `uint32_t`.
- */
-@property (readonly, nonatomic) uint32_t uInt32Value;
-
-/*!
- * @brief The OFNumber as a `uint64_t`.
- */
-@property (readonly, nonatomic) uint64_t uInt64Value;
-
-/*!
- * @brief The OFNumber as a `size_t`.
- */
-@property (readonly, nonatomic) size_t sizeValue;
-
-/*!
- * @brief The OFNumber as an `ssize_t`.
- */
-@property (readonly, nonatomic) ssize_t sSizeValue;
-
-/*!
- * @brief The OFNumber as an `intmax_t`.
- */
-@property (readonly, nonatomic) intmax_t intMaxValue;
-
-/*!
- * @brief The OFNumber as a `uintmax_t`.
- */
-@property (readonly, nonatomic) uintmax_t uIntMaxValue;
-
-/*!
- * @brief The OFNumber as a `ptrdiff_t`.
- */
-@property (readonly, nonatomic) ptrdiff_t ptrDiffValue;
-
-/*!
- * @brief The OFNumber as an `intptr_t`.
- */
-@property (readonly, nonatomic) intptr_t intPtrValue;
-
-/*!
- * @brief The OFNumber as a `uintptr_t`.
- */
-@property (readonly, nonatomic) uintptr_t uIntPtrValue;
-
-/*!
* @brief The OFNumber as a `float`.
*/
@property (readonly, nonatomic) float floatValue;
@@ -220,226 +140,106 @@ OF_SUBCLASSING_RESTRICTED
/*!
* @brief Creates a new OFNumber with the specified `bool`.
*
- * @param bool_ A `bool` which the OFNumber should contain
+ * @param value The `bool` value which the OFNumber should contain
* @return A new autoreleased OFNumber
*/
-+ (instancetype)numberWithBool: (bool)bool_;
++ (instancetype)numberWithBool: (bool)value;
/*!
* @brief Creates a new OFNumber with the specified `signed char`.
*
- * @param sChar A `signed char` which the OFNumber should contain
+ * @param value The `signed char` value which the OFNumber should contain
* @return A new autoreleased OFNumber
*/
-+ (instancetype)numberWithChar: (signed char)sChar;
++ (instancetype)numberWithChar: (signed char)value;
/*!
* @brief Creates a new OFNumber with the specified `short`.
*
- * @param sShort A `short` which the OFNumber should contain
+ * @param value The `short` value which the OFNumber should contain
* @return A new autoreleased OFNumber
*/
-+ (instancetype)numberWithShort: (short)sShort;
++ (instancetype)numberWithShort: (short)value;
/*!
* @brief Creates a new OFNumber with the specified `int`.
*
- * @param sInt An `int` which the OFNumber should contain
+ * @param value The `int` value which the OFNumber should contain
* @return A new autoreleased OFNumber
*/
-+ (instancetype)numberWithInt: (int)sInt;
++ (instancetype)numberWithInt: (int)value;
/*!
* @brief Creates a new OFNumber with the specified `long`.
*
- * @param sLong A `long` which the OFNumber should contain
+ * @param value The `long` value which the OFNumber should contain
* @return A new autoreleased OFNumber
*/
-+ (instancetype)numberWithLong: (long)sLong;
++ (instancetype)numberWithLong: (long)value;
/*!
* @brief Creates a new OFNumber with the specified `long long`.
*
- * @param sLongLong A `long long` which the OFNumber should contain
+ * @param value The `long long` value which the OFNumber should contain
* @return A new autoreleased OFNumber
*/
-+ (instancetype)numberWithLongLong: (long long)sLongLong;
++ (instancetype)numberWithLongLong: (long long)value;
/*!
* @brief Creates a new OFNumber with the specified `unsigned char`.
*
- * @param uChar An `unsigned char` which the OFNumber should contain
+ * @param value The `unsigned char` value which the OFNumber should contain
* @return A new autoreleased OFNumber
*/
-+ (instancetype)numberWithUnsignedChar: (unsigned char)uChar;
++ (instancetype)numberWithUnsignedChar: (unsigned char)value;
/*!
* @brief Creates a new OFNumber with the specified `unsigned short`.
*
- * @param uShort An `unsigned short` which the OFNumber should contain
+ * @param value The `unsigned short` value which the OFNumber should contain
* @return A new autoreleased OFNumber
*/
-+ (instancetype)numberWithUnsignedShort: (unsigned short)uShort;
++ (instancetype)numberWithUnsignedShort: (unsigned short)value;
/*!
* @brief Creates a new OFNumber with the specified `unsigned int`.
*
- * @param uInt An `unsigned int` which the OFNumber should contain
+ * @param value The `unsigned int` value which the OFNumber should contain
* @return A new autoreleased OFNumber
*/
-+ (instancetype)numberWithUnsignedInt: (unsigned int)uInt;
++ (instancetype)numberWithUnsignedInt: (unsigned int)value;
/*!
* @brief Creates a new OFNumber with the specified `unsigned long`.
*
- * @param uLong An `unsigned long` which the OFNumber should contain
+ * @param value The `unsigned long` value which the OFNumber should contain
* @return A new autoreleased OFNumber
*/
-+ (instancetype)numberWithUnsignedLong: (unsigned long)uLong;
++ (instancetype)numberWithUnsignedLong: (unsigned long)value;
/*!
* @brief Creates a new OFNumber with the specified `unsigned long long`.
*
- * @param uLongLong An `unsigned long long` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithUnsignedLongLong: (unsigned long long)uLongLong;
-
-/*!
- * @brief Creates a new OFNumber with the specified `int8_t`.
- *
- * @param int8 An `int8_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithInt8: (int8_t)int8;
-
-/*!
- * @brief Creates a new OFNumber with the specified `int16_t`.
- *
- * @param int16 An `int16_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithInt16: (int16_t)int16;
-
-/*!
- * @brief Creates a new OFNumber with the specified `int32_t`.
- *
- * @param int32 An `int32_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithInt32: (int32_t)int32;
-
-/*!
- * @brief Creates a new OFNumber with the specified `int64_t`.
- *
- * @param int64 An `int64_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithInt64: (int64_t)int64;
-
-/*!
- * @brief Creates a new OFNumber with the specified `uint8_t`.
- *
- * @param uInt8 A `uint8_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithUInt8: (uint8_t)uInt8;
-
-/*!
- * @brief Creates a new OFNumber with the specified `uint16_t`.
- *
- * @param uInt16 A `uint16_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithUInt16: (uint16_t)uInt16;
-
-/*!
- * @brief Creates a new OFNumber with the specified `uint32_t`.
- *
- * @param uInt32 A `uint32_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithUInt32: (uint32_t)uInt32;
-
-/*!
- * @brief Creates a new OFNumber with the specified `uint64_t`.
- *
- * @param uInt64 A `uint64_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithUInt64: (uint64_t)uInt64;
-
-/*!
- * @brief Creates a new OFNumber with the specified `size_t`.
- *
- * @param size A `size_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithSize: (size_t)size;
-
-/*!
- * @brief Creates a new OFNumber with the specified `ssize_t`.
- *
- * @param sSize An `ssize_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithSSize: (ssize_t)sSize;
-
-/*!
- * @brief Creates a new OFNumber with the specified `intmax_t`.
- *
- * @param intMax An `intmax_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithIntMax: (intmax_t)intMax;
-
-/*!
- * @brief Creates a new OFNumber with the specified `uintmax_t`.
- *
- * @param uIntMax A `uintmax_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithUIntMax: (uintmax_t)uIntMax;
-
-/*!
- * @brief Creates a new OFNumber with the specified `ptrdiff_t`.
- *
- * @param ptrDiff A `ptrdiff_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithPtrDiff: (ptrdiff_t)ptrDiff;
-
-/*!
- * @brief Creates a new OFNumber with the specified `intptr_t`.
- *
- * @param intPtr An `intptr_t` which the OFNumber should contain
- * @return A new autoreleased OFNumber
- */
-+ (instancetype)numberWithIntPtr: (intptr_t)intPtr;
-
-/*!
- * @brief Creates a new OFNumber with the specified `uintptr_t`.
- *
- * @param uIntPtr A `uintptr_t` which the OFNumber should contain
+ * @param value The `unsigned long long` value which the OFNumber should contain
* @return A new autoreleased OFNumber
*/
-+ (instancetype)numberWithUIntPtr: (uintptr_t)uIntPtr;
++ (instancetype)numberWithUnsignedLongLong: (unsigned long long)value;
/*!
* @brief Creates a new OFNumber with the specified `float`.
*
- * @param float_ A `float` which the OFNumber should contain
+ * @param value The `float` value which the OFNumber should contain
* @return A new autoreleased OFNumber
*/
-+ (instancetype)numberWithFloat: (float)float_;
++ (instancetype)numberWithFloat: (float)value;
/*!
* @brief Creates a new OFNumber with the specified `double`.
*
- * @param double_ A `double` which the OFNumber should contain
+ * @param value The `double` value which the OFNumber should contain
* @return A new autoreleased OFNumber
*/
-+ (instancetype)numberWithDouble: (double)double_;
++ (instancetype)numberWithDouble: (double)value;
- (instancetype)init OF_UNAVAILABLE;
#ifdef OF_HAVE_UNAVAILABLE
@@ -456,246 +256,113 @@ OF_SUBCLASSING_RESTRICTED
/*!
* @brief Initializes an already allocated OFNumber with the specified `bool`.
*
- * @param bool_ A `bool` which the OFNumber should contain
+ * @param value The `bool` value which the OFNumber should contain
* @return An initialized OFNumber
*/
-- (instancetype)initWithBool: (bool)bool_;
+- (instancetype)initWithBool: (bool)value;
/*!
* @brief Initializes an already allocated OFNumber with the specified
* `signed char`.
*
- * @param sChar A `signed char` which the OFNumber should contain
+ * @param value The `signed char` value which the OFNumber should contain
* @return An initialized OFNumber
*/
-- (instancetype)initWithChar: (signed char)sChar;
+- (instancetype)initWithChar: (signed char)value;
/*!
* @brief Initializes an already allocated OFNumber with the specified `short`.
*
- * @param sShort A `short` which the OFNumber should contain
+ * @param value The `short` value which the OFNumber should contain
* @return An initialized OFNumber
*/
-- (instancetype)initWithShort: (short)sShort;
+- (instancetype)initWithShort: (short)value;
/*!
* @brief Initializes an already allocated OFNumber with the specified `int`.
*
- * @param sInt An `int` which the OFNumber should contain
+ * @param value The `int` value which the OFNumber should contain
* @return An initialized OFNumber
*/
-- (instancetype)initWithInt: (int)sInt;
+- (instancetype)initWithInt: (int)value;
/*!
* @brief Initializes an already allocated OFNumber with the specified `long`.
*
- * @param sLong A `long` which the OFNumber should contain
+ * @param value The `long` value which the OFNumber should contain
* @return An initialized OFNumber
*/
-- (instancetype)initWithLong: (long)sLong;
+- (instancetype)initWithLong: (long)value;
/*!
* @brief Initializes an already allocated OFNumber with the specified
* `long long`.
*
- * @param sLongLong A `long long` which the OFNumber should contain
+ * @param value The `long long` value which the OFNumber should contain
* @return An initialized OFNumber
*/
-- (instancetype)initWithLongLong: (long long)sLongLong;
+- (instancetype)initWithLongLong: (long long)value;
/*!
* @brief Initializes an already allocated OFNumber with the specified
* `unsigned char`.
*
- * @param uChar An `unsigned char` which the OFNumber should contain
+ * @param value The `unsigned char` value which the OFNumber should contain
* @return An initialized OFNumber
*/
-- (instancetype)initWithUnsignedChar: (unsigned char)uChar;
+- (instancetype)initWithUnsignedChar: (unsigned char)value;
/*!
* @brief Initializes an already allocated OFNumber with the specified
* `unsigned short`.
*
- * @param uShort An `unsigned short` which the OFNumber should contain
+ * @param value The `unsigned short` value which the OFNumber should contain
* @return An initialized OFNumber
*/
-- (instancetype)initWithUnsignedShort: (unsigned short)uShort;
+- (instancetype)initWithUnsignedShort: (unsigned short)value;
/*!
* @brief Initializes an already allocated OFNumber with the specified
* `unsigned int`.
*
- * @param uInt An `unsigned int` which the OFNumber should contain
+ * @param value The `unsigned int` value which the OFNumber should contain
* @return An initialized OFNumber
*/
-- (instancetype)initWithUnsignedInt: (unsigned int)uInt;
+- (instancetype)initWithUnsignedInt: (unsigned int)value;
/*!
* @brief Initializes an already allocated OFNumber with the specified
* `unsigned long`.
*
- * @param uLong An `unsigned long` which the OFNumber should contain
+ * @param value The `unsigned long` value which the OFNumber should contain
* @return An initialized OFNumber
*/
-- (instancetype)initWithUnsignedLong: (unsigned long)uLong;
+- (instancetype)initWithUnsignedLong: (unsigned long)value;
/*!
* @brief Initializes an already allocated OFNumber with the specified
* `unsigned long long`.
*
- * @param uLongLong An `unsigned long long` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithUnsignedLongLong: (unsigned long long)uLongLong;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified `int8_t`.
- *
- * @param int8 An `int8_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithInt8: (int8_t)int8;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified
- * `int16_t`.
- *
- * @param int16 An `int16_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithInt16: (int16_t)int16;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified
- * `int32_t`.
- *
- * @param int32 An `int32_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithInt32: (int32_t)int32;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified
- * `int64_t`.
- *
- * @param int64 An `int64_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithInt64: (int64_t)int64;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified
- * `uint8_t`.
- *
- * @param uInt8 A `uint8_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithUInt8: (uint8_t)uInt8;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified
- * `uint16_t`.
- *
- * @param uInt16 A `uint16_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithUInt16: (uint16_t)uInt16;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified
- * `uint32_t`.
- *
- * @param uInt32 A `uint32_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithUInt32: (uint32_t)uInt32;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified
- * `uint64_t`.
- *
- * @param uInt64 A `uint64_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithUInt64: (uint64_t)uInt64;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified `size_t`.
- *
- * @param size A `size_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithSize: (size_t)size;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified
- * `ssize_t`.
- *
- * @param sSize An `ssize_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithSSize: (ssize_t)sSize;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified
- * `intmax_t`.
- *
- * @param intMax An `intmax_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithIntMax: (intmax_t)intMax;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified
- * `uintmax_t`.
- *
- * @param uIntMax A `uintmax_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithUIntMax: (uintmax_t)uIntMax;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified
- * `ptrdiff_t`.
- *
- * @param ptrDiff A `ptrdiff_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithPtrDiff: (ptrdiff_t)ptrDiff;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified
- * `intptr_t`.
- *
- * @param intPtr An `intptr_t` which the OFNumber should contain
- * @return An initialized OFNumber
- */
-- (instancetype)initWithIntPtr: (intptr_t)intPtr;
-
-/*!
- * @brief Initializes an already allocated OFNumber with the specified
- * `uintptr_t`.
- *
- * @param uIntPtr A `uintptr_t` which the OFNumber should contain
+ * @param value The `unsigned long long` value which the OFNumber should contain
* @return An initialized OFNumber
*/
-- (instancetype)initWithUIntPtr: (uintptr_t)uIntPtr;
+- (instancetype)initWithUnsignedLongLong: (unsigned long long)value;
/*!
* @brief Initializes an already allocated OFNumber with the specified `float`.
*
- * @param float_ A `float` which the OFNumber should contain
+ * @param value The `float` value which the OFNumber should contain
* @return An initialized OFNumber
*/
-- (instancetype)initWithFloat: (float)float_;
+- (instancetype)initWithFloat: (float)value;
/*!
* @brief Initializes an already allocated OFNumber with the specified `double`.
*
- * @param double_ A `double` which the OFNumber should contain
+ * @param value The `double` value which the OFNumber should contain
* @return An initialized OFNumber
*/
-- (instancetype)initWithDouble: (double)double_;
+- (instancetype)initWithDouble: (double)value;
@end
OF_ASSUME_NONNULL_END
diff --git a/src/OFNumber.m b/src/OFNumber.m
index bac570db..eb5ba05a 100644
--- a/src/OFNumber.m
+++ b/src/OFNumber.m
@@ -43,330 +43,349 @@
@interface OFNumberSingleton: OFNumber
@end
+#ifdef OF_OBJFW_RUNTIME
+enum {
+ TAG_CHAR,
+ TAG_SHORT,
+ TAG_INT,
+ TAG_LONG,
+ TAG_LONG_LONG,
+ TAG_UNSIGNED_CHAR,
+ TAG_UNSIGNED_SHORT,
+ TAG_UNSIGNED_INT,
+ TAG_UNSIGNED_LONG,
+ TAG_UNSIGNED_LONG_LONG,
+};
+# define TAG_BITS 4
+# define TAG_MASK 0xF
+
+@interface OFTaggedPointerNumber: OFNumberSingleton
+@end
+#endif
+
static struct {
Class isa;
} placeholder;
-static OFNumberSingleton *zeroNumber, *oneNumber, *twoNumber;
-static OFNumberSingleton *trueNumber, *falseNumber;
-
-static void
-initZeroNumber(void)
-{
- zeroNumber = [[OFNumberSingleton alloc] initWithUnsignedChar: 0];
-}
-
-static void
-initOneNumber(void)
-{
- oneNumber = [[OFNumberSingleton alloc] initWithUnsignedChar: 1];
-}
+#define SINGLETON(var, sel, val) \
+ static OFNumberSingleton *var; \
+ \
+ static void \
+ var##Init(void) \
+ { \
+ var = [[OFNumberSingleton alloc] sel val]; \
+ }
+SINGLETON(falseNumber, initWithBool:, false)
+SINGLETON(trueNumber, initWithBool:, true)
+SINGLETON(charZeroNumber, initWithChar:, 0)
+SINGLETON(shortZeroNumber, initWithShort:, 0)
+SINGLETON(intZeroNumber, initWithInt:, 0)
+SINGLETON(longZeroNumber, initWithLong:, 0)
+SINGLETON(longLongZeroNumber, initWithLongLong:, 0)
+SINGLETON(unsignedCharZeroNumber, initWithUnsignedChar:, 0)
+SINGLETON(unsignedShortZeroNumber, initWithUnsignedShort:, 0)
+SINGLETON(unsignedIntZeroNumber, initWithUnsignedInt:, 0)
+SINGLETON(unsignedLongZeroNumber, initWithUnsignedLong:, 0)
+SINGLETON(unsignedLongLongZeroNumber, initWithUnsignedLongLong:, 0)
+SINGLETON(floatZeroNumber, initWithFloat:, 0)
+SINGLETON(doubleZeroNumber, initWithDouble:, 0)
+#undef SINGLETON
+
+#ifdef OF_OBJFW_RUNTIME
+static int numberTag;
+#endif
-static void
-initTwoNumber(void)
+static bool
+isUnsigned(OFNumber *number)
{
- twoNumber = [[OFNumberSingleton alloc] initWithUnsignedChar: 2];
+ switch (*number.objCType) {
+ case 'B':
+ return true;
+ case 'C':
+ return true;
+ case 'S':
+ return true;
+ case 'I':
+ return true;
+ case 'L':
+ return true;
+ case 'Q':
+ return true;
+ default:
+ return false;
+ }
}
-static void
-initTrueNumber(void)
+static bool
+isSigned(OFNumber *number)
{
- trueNumber = [[OFNumberSingleton alloc] initWithBool: true];
+ switch (*number.objCType) {
+ case 'c':
+ return true;
+ case 's':
+ return true;
+ case 'i':
+ return true;
+ case 'l':
+ return true;
+ case 'q':
+ return true;
+ default:
+ return false;
+ }
}
-static void
-initFalseNumber(void)
+static bool
+isFloat(OFNumber *number)
{
- falseNumber = [[OFNumberSingleton alloc] initWithBool: false];
+ switch (*number.objCType) {
+ case 'f':
+ return true;
+ case 'd':
+ return true;
+ default:
+ return false;
+ }
}
@implementation OFNumberPlaceholder
-- (instancetype)initWithBool: (bool)bool_
+- (instancetype)initWithBool: (bool)value
{
- if (bool_) {
- static of_once_t once;
- of_once(&once, initTrueNumber);
+ if (value) {
+ static of_once_t once = OF_ONCE_INIT;
+ of_once(&once, trueNumberInit);
return (id)trueNumber;
} else {
- static of_once_t once;
- of_once(&once, initFalseNumber);
+ static of_once_t once = OF_ONCE_INIT;
+ of_once(&once, falseNumberInit);
return (id)falseNumber;
}
}
-- (instancetype)initWithChar: (signed char)sChar
-{
- if (sChar >= 0)
- return [self initWithUnsignedChar: sChar];
-
- return (id)[[OFNumber of_alloc] initWithChar: sChar];
-}
-
-- (instancetype)initWithShort: (short)sShort
-{
- if (sShort >= 0)
- return [self initWithUnsignedShort: sShort];
- if (sShort >= SCHAR_MIN)
- return [self initWithChar: (signed char)sShort];
-
- return (id)[[OFNumber of_alloc] initWithShort: sShort];
-}
-
-- (instancetype)initWithInt: (int)sInt
-{
- if (sInt >= 0)
- return [self initWithUnsignedInt: sInt];
- if (sInt >= SHRT_MIN)
- return [self initWithShort: (short)sInt];
-
- return (id)[[OFNumber of_alloc] initWithInt: sInt];
-}
-
-- (instancetype)initWithLong: (long)sLong
-{
- if (sLong >= 0)
- return [self initWithUnsignedLong: sLong];
- if (sLong >= INT_MIN)
- return [self initWithShort: (int)sLong];
-
- return (id)[[OFNumber of_alloc] initWithLong: sLong];
-}
-
-- (instancetype)initWithLongLong: (long long)sLongLong
-{
- if (sLongLong >= 0)
- return [self initWithUnsignedLongLong: sLongLong];
- if (sLongLong >= LONG_MIN)
- return [self initWithLong: (long)sLongLong];
-
- return (id)[[OFNumber of_alloc] initWithLongLong: sLongLong];
-}
-
-- (instancetype)initWithUnsignedChar: (unsigned char)uChar
+#ifdef __clang__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
+#endif
+- (instancetype)initWithChar: (signed char)value
{
- switch (uChar) {
- case 0: {
- static of_once_t once = OF_ONCE_INIT;
- of_once(&once, initZeroNumber);
- return (id)zeroNumber;
- }
- case 1: {
+ if (value == 0) {
static of_once_t once = OF_ONCE_INIT;
- of_once(&once, initOneNumber);
- return (id)oneNumber;
- }
- case 2: {
- static of_once_t once = OF_ONCE_INIT;
- of_once(&once, initTwoNumber);
- return (id)twoNumber;
- }
+ of_once(&once, charZeroNumberInit);
+ return (id)charZeroNumber;
+#ifdef OF_OBJFW_RUNTIME
+ } else if ((unsigned char)value <= (UINTPTR_MAX >> TAG_BITS)) {
+ id ret = objc_createTaggedPointer(numberTag,
+ ((uintptr_t)(unsigned char)value << TAG_BITS) | TAG_CHAR);
+
+ if (ret != nil)
+ return ret;
+#endif
}
- return (id)[[OFNumber of_alloc] initWithUnsignedChar: uChar];
-}
-
-- (instancetype)initWithUnsignedShort: (unsigned short)uShort
-{
- if (uShort <= UCHAR_MAX)
- return [self initWithUnsignedChar: (unsigned char)uShort];
-
- return (id)[[OFNumber of_alloc] initWithUnsignedShort: uShort];
-}
-
-- (instancetype)initWithUnsignedInt: (unsigned int)uInt
-{
- if (uInt <= USHRT_MAX)
- return [self initWithUnsignedShort: (unsigned short)uInt];
-
- return (id)[[OFNumber of_alloc] initWithUnsignedInt: uInt];
-}
-
-- (instancetype)initWithUnsignedLong: (unsigned long)uLong
-{
- if (uLong <= UINT_MAX)
- return [self initWithUnsignedInt: (unsigned int)uLong];
-
- return (id)[[OFNumber of_alloc] initWithUnsignedLong: uLong];
-}
-
-- (instancetype)initWithUnsignedLongLong: (unsigned long long)uLongLong
-{
- if (uLongLong <= ULONG_MAX)
- return [self initWithUnsignedLong: (unsigned long)uLongLong];
-
- return (id)[[OFNumber of_alloc] initWithUnsignedLongLong: uLongLong];
-}
-
-- (instancetype)initWithInt8: (int8_t)int8
-{
- if (int8 >= 0)
- return [self initWithUInt8: int8];
-
- return (id)[[OFNumber of_alloc] initWithInt8: int8];
-}
-
-- (instancetype)initWithInt16: (int16_t)int16
-{
- if (int16 >= 0)
- return [self initWithUInt16: int16];
- if (int16 >= INT8_MIN)
- return [self initWithInt8: (int8_t)int16];
-
- return (id)[[OFNumber of_alloc] initWithInt16: int16];
-}
-
-- (instancetype)initWithInt32: (int32_t)int32
-{
- if (int32 >= 0)
- return [self initWithUInt32: int32];
- if (int32 >= INT16_MIN)
- return [self initWithInt16: (int16_t)int32];
-
- return (id)[[OFNumber of_alloc] initWithInt32: int32];
-}
-
-- (instancetype)initWithInt64: (int64_t)int64
-{
- if (int64 >= 0)
- return [self initWithUInt64: int64];
- if (int64 >= INT32_MIN)
- return [self initWithInt32: (int32_t)int64];
-
- return (id)[[OFNumber of_alloc] initWithInt64: int64];
-}
-
-- (instancetype)initWithUInt8: (uint8_t)uInt8
-{
- return (id)[[OFNumber of_alloc] initWithUInt8: uInt8];
+ return (id)[[OFNumber of_alloc] initWithChar: value];
}
-- (instancetype)initWithUInt16: (uint16_t)uInt16
+- (instancetype)initWithShort: (short)value
{
- if (uInt16 <= UINT8_MAX)
- return [self initWithUInt8: (uint8_t)uInt16];
+ if (value == 0) {
+ static of_once_t once = OF_ONCE_INIT;
+ of_once(&once, shortZeroNumberInit);
+ return (id)shortZeroNumber;
+#ifdef OF_OBJFW_RUNTIME
+ } else if ((unsigned short)value <= (UINTPTR_MAX >> TAG_BITS)) {
+ id ret = objc_createTaggedPointer(numberTag,
+ ((uintptr_t)(unsigned short)value << TAG_BITS) | TAG_SHORT);
+
+ if (ret != nil)
+ return ret;
+#endif
+ }
- return (id)[[OFNumber of_alloc] initWithUInt16: uInt16];
+ return (id)[[OFNumber of_alloc] initWithShort: value];
}
-- (instancetype)initWithUInt32: (uint32_t)uInt32
+- (instancetype)initWithInt: (int)value
{
- if (uInt32 <= UINT16_MAX)
- return [self initWithUInt16: (uint16_t)uInt32];
+ if (value == 0) {
+ static of_once_t once = OF_ONCE_INIT;
+ of_once(&once, intZeroNumberInit);
+ return (id)intZeroNumber;
+#ifdef OF_OBJFW_RUNTIME
+ } else if ((unsigned int)value <= (UINTPTR_MAX >> TAG_BITS)) {
+ id ret = objc_createTaggedPointer(numberTag,
+ ((uintptr_t)(unsigned int)value << TAG_BITS) | TAG_INT);
+
+ if (ret != nil)
+ return ret;
+#endif
+ }
- return (id)[[OFNumber of_alloc] initWithUInt32: uInt32];
+ return (id)[[OFNumber of_alloc] initWithInt: value];
}
-- (instancetype)initWithUInt64: (uint64_t)uInt64
+- (instancetype)initWithLong: (long)value
{
- if (uInt64 <= UINT32_MAX)
- return [self initWithUInt32: (uint32_t)uInt64];
+ if (value == 0) {
+ static of_once_t once = OF_ONCE_INIT;
+ of_once(&once, longZeroNumberInit);
+ return (id)longZeroNumber;
+#ifdef OF_OBJFW_RUNTIME
+ } else if ((unsigned long)value <= (UINTPTR_MAX >> TAG_BITS)) {
+ id ret = objc_createTaggedPointer(numberTag,
+ ((uintptr_t)(unsigned long)value << TAG_BITS) | TAG_LONG);
+
+ if (ret != nil)
+ return ret;
+#endif
+ }
- return (id)[[OFNumber of_alloc] initWithUInt64: uInt64];
+ return (id)[[OFNumber of_alloc] initWithLong: value];
}
-- (instancetype)initWithSize: (size_t)size
+- (instancetype)initWithLongLong: (long long)value
{
- if (size <= ULONG_MAX)
- return [self initWithUnsignedLong: (unsigned long)size];
+ if (value == 0) {
+ static of_once_t once = OF_ONCE_INIT;
+ of_once(&once, longLongZeroNumberInit);
+ return (id)longLongZeroNumber;
+#ifdef OF_OBJFW_RUNTIME
+ } else if ((unsigned long long)value <= (UINTPTR_MAX >> TAG_BITS)) {
+ id ret = objc_createTaggedPointer(numberTag,
+ ((uintptr_t)(unsigned long long)value << TAG_BITS) |
+ TAG_LONG_LONG);
+
+ if (ret != nil)
+ return ret;
+#endif
+ }
- return (id)[[OFNumber of_alloc] initWithSize: size];
+ return (id)[[OFNumber of_alloc] initWithLongLong: value];
}
-- (instancetype)initWithSSize: (ssize_t)sSize
+- (instancetype)initWithUnsignedChar: (unsigned char)value
{
- if (sSize >= 0)
- return [self initWithSize: sSize];
- if (sSize <= LONG_MIN)
- return [self initWithLong: (long)sSize];
+ if (value == 0) {
+ static of_once_t once = OF_ONCE_INIT;
+ of_once(&once, unsignedCharZeroNumberInit);
+ return (id)unsignedCharZeroNumber;
+#ifdef OF_OBJFW_RUNTIME
+ } else if (value <= (UINTPTR_MAX >> TAG_BITS)) {
+ id ret = objc_createTaggedPointer(numberTag,
+ ((uintptr_t)value << TAG_BITS) | TAG_UNSIGNED_CHAR);
+
+ if (ret != nil)
+ return ret;
+#endif
+ }
- return (id)[[OFNumber of_alloc] initWithSSize: sSize];
+ return (id)[[OFNumber of_alloc] initWithUnsignedChar: value];
}
-- (instancetype)initWithIntMax: (intmax_t)intMax
+- (instancetype)initWithUnsignedShort: (unsigned short)value
{
- if (intMax >= 0)
- return [self initWithUIntMax: intMax];
- if (intMax <= LLONG_MIN)
- return [self initWithLongLong: (long long)intMax];
+ if (value == 0) {
+ static of_once_t once = OF_ONCE_INIT;
+ of_once(&once, unsignedShortZeroNumberInit);
+ return (id)unsignedShortZeroNumber;
+#ifdef OF_OBJFW_RUNTIME
+ } else if (value <= (UINTPTR_MAX >> TAG_BITS)) {
+ id ret = objc_createTaggedPointer(numberTag,
+ ((uintptr_t)value << TAG_BITS) | TAG_UNSIGNED_SHORT);
+
+ if (ret != nil)
+ return ret;
+#endif
+ }
- return (id)[[OFNumber of_alloc] initWithIntMax: intMax];
+ return (id)[[OFNumber of_alloc] initWithUnsignedShort: value];
}
-- (instancetype)initWithUIntMax: (uintmax_t)uIntMax
+- (instancetype)initWithUnsignedInt: (unsigned int)value
{
- if (uIntMax <= ULLONG_MAX)
- return [self initWithUnsignedLongLong:
- (unsigned long long)uIntMax];
-
- return (id)[[OFNumber of_alloc] initWithUIntMax: uIntMax];
-}
-
-#ifdef __clang__
-/*
- * This warning should probably not exist at all, as it prevents checking
- * whether one type fits into another in a portable way.
- */
-# pragma clang diagnostic push
-# pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
+ if (value == 0) {
+ static of_once_t once = OF_ONCE_INIT;
+ of_once(&once, unsignedIntZeroNumberInit);
+ return (id)unsignedIntZeroNumber;
+#ifdef OF_OBJFW_RUNTIME
+ } else if (value <= (UINTPTR_MAX >> TAG_BITS)) {
+ id ret = objc_createTaggedPointer(numberTag,
+ ((uintptr_t)value << TAG_BITS) | TAG_UNSIGNED_INT);
+
+ if (ret != nil)
+ return ret;
#endif
+ }
-- (instancetype)initWithPtrDiff: (ptrdiff_t)ptrDiff
-{
- if (ptrDiff >= LLONG_MIN && ptrDiff <= LLONG_MAX)
- return [self initWithLongLong: (long long)ptrDiff];
-
- return (id)[[OFNumber of_alloc] initWithPtrDiff: ptrDiff];
+ return (id)[[OFNumber of_alloc] initWithUnsignedInt: value];
}
-- (instancetype)initWithIntPtr: (intptr_t)intPtr
+- (instancetype)initWithUnsignedLong: (unsigned long)value
{
- if (intPtr >= 0)
- return [self initWithUIntPtr: intPtr];
- if (intPtr >= LLONG_MIN)
- return [self initWithLongLong: (long long)intPtr];
+ if (value == 0) {
+ static of_once_t once = OF_ONCE_INIT;
+ of_once(&once, unsignedLongZeroNumberInit);
+ return (id)unsignedLongZeroNumber;
+#ifdef OF_OBJFW_RUNTIME
+ } else if (value <= (UINTPTR_MAX >> TAG_BITS)) {
+ id ret = objc_createTaggedPointer(numberTag,
+ ((uintptr_t)value << TAG_BITS) | TAG_UNSIGNED_LONG);
+
+ if (ret != nil)
+ return ret;
+#endif
+ }
- return (id)[[OFNumber of_alloc] initWithIntPtr: intPtr];
+ return (id)[[OFNumber of_alloc] initWithUnsignedLong: value];
}
-- (instancetype)initWithUIntPtr: (uintptr_t)uIntPtr
+- (instancetype)initWithUnsignedLongLong: (unsigned long long)value
{
- if (uIntPtr <= ULLONG_MAX)
- return [self initWithUnsignedLongLong:
- (unsigned long long)uIntPtr];
+ if (value == 0) {
+ static of_once_t once = OF_ONCE_INIT;
+ of_once(&once, unsignedLongLongZeroNumberInit);
+ return (id)unsignedLongLongZeroNumber;
+#ifdef OF_OBJFW_RUNTIME
+ } else if (value <= (UINTPTR_MAX >> TAG_BITS)) {
+ id ret = objc_createTaggedPointer(numberTag,
+ ((uintptr_t)value << TAG_BITS) | TAG_UNSIGNED_LONG_LONG);
+
+ if (ret != nil)
+ return ret;
+#endif
+ }
- return (id)[[OFNumber of_alloc] initWithUIntPtr: uIntPtr];
+ return (id)[[OFNumber of_alloc] initWithUnsignedLongLong: value];
}
-#ifdef __clang__
-# pragma clang diagnostic pop
-#endif
-
-- (instancetype)initWithFloat: (float)float_
+- (instancetype)initWithFloat: (float)value
{
- if (float_ == (uintmax_t)float_)
- return [self initWithUIntMax: (uintmax_t)float_];
- if (float_ == (intmax_t)float_)
- return [self initWithIntMax: (intmax_t)float_];
+ if (value == 0) {
+ static of_once_t once = OF_ONCE_INIT;
+ of_once(&once, floatZeroNumberInit);
+ return (id)floatZeroNumber;
+ }
- return (id)[[OFNumber of_alloc] initWithFloat: float_];
+ return (id)[[OFNumber of_alloc] initWithFloat: value];
}
-- (instancetype)initWithDouble: (double)double_
+- (instancetype)initWithDouble: (double)value
{
- if (double_ == (uintmax_t)double_)
- return [self initWithUIntMax: (uintmax_t)double_];
- if (double_ == (intmax_t)double_)
- return [self initWithIntMax: (intmax_t)double_];
- if (double_ == (float)double_)
- return [self initWithFloat: (float)double_];
+ if (value == 0) {
+ static of_once_t once = OF_ONCE_INIT;
+ of_once(&once, doubleZeroNumberInit);
+ return (id)doubleZeroNumber;
+ }
- return (id)[[OFNumber of_alloc] initWithDouble: double_];
+ return (id)[[OFNumber of_alloc] initWithDouble: value];
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
return (id)[[OFNumber of_alloc] initWithSerialization: element];
}
+#ifdef __clang__
+# pragma clang diagnostic pop
+#endif
@end
@implementation OFNumberSingleton
@@ -390,164 +409,173 @@ initFalseNumber(void)
}
@end
-@implementation OFNumber
-+ (void)initialize
-{
- if (self == [OFNumber class])
- placeholder.isa = [OFNumberPlaceholder class];
-}
-
-+ (instancetype)of_alloc
-{
- return [super alloc];
-}
-
-+ (instancetype)alloc
-{
- if (self == [OFNumber class])
- return (id)&placeholder;
-
- return [super alloc];
-}
-
-+ (instancetype)numberWithBool: (bool)bool_
-{
- return [[[self alloc] initWithBool: bool_] autorelease];
-}
-
-+ (instancetype)numberWithChar: (signed char)sChar
-{
- return [[[self alloc] initWithChar: sChar] autorelease];
-}
-
-+ (instancetype)numberWithShort: (short)sShort
-{
- return [[[self alloc] initWithShort: sShort] autorelease];
-}
-
-+ (instancetype)numberWithInt: (int)sInt
-{
- return [[[self alloc] initWithInt: sInt] autorelease];
-}
-
-+ (instancetype)numberWithLong: (long)sLong
-{
- return [[[self alloc] initWithLong: sLong] autorelease];
-}
-
-+ (instancetype)numberWithLongLong: (long long)sLongLong
+#ifdef OF_OBJFW_RUNTIME
+@implementation OFTaggedPointerNumber
+- (const char *)objCType
{
- return [[[self alloc] initWithLongLong: sLongLong] autorelease];
+ uintptr_t value = object_getTaggedPointerValue(self);
+
+ switch (value & TAG_MASK) {
+ case TAG_CHAR:
+ return @encode(signed char);
+ case TAG_SHORT:
+ return @encode(short);
+ case TAG_INT:
+ return @encode(int);
+ case TAG_LONG:
+ return @encode(long);
+ case TAG_LONG_LONG:
+ return @encode(long long);
+ case TAG_UNSIGNED_CHAR:
+ return @encode(unsigned char);
+ case TAG_UNSIGNED_SHORT:
+ return @encode(unsigned short);
+ case TAG_UNSIGNED_INT:
+ return @encode(unsigned int);
+ case TAG_UNSIGNED_LONG:
+ return @encode(unsigned long);
+ case TAG_UNSIGNED_LONG_LONG:
+ return @encode(unsigned long long);
+ default:
+ @throw [OFInvalidArgumentException exception];
+ }
}
-+ (instancetype)numberWithUnsignedChar: (unsigned char)uChar
+# define RETURN_VALUE \
+ uintptr_t value = object_getTaggedPointerValue(self); \
+ \
+ switch (value & TAG_MASK) { \
+ case TAG_CHAR: \
+ return (signed char)(unsigned char)(value >> TAG_BITS); \
+ case TAG_SHORT: \
+ return (short)(unsigned short)(value >> TAG_BITS); \
+ case TAG_INT: \
+ return (int)(unsigned int)(value >> TAG_BITS); \
+ case TAG_LONG: \
+ return (long)(unsigned long)(value >> TAG_BITS); \
+ case TAG_LONG_LONG: \
+ return (long long)(unsigned long long)(value >> TAG_BITS); \
+ case TAG_UNSIGNED_CHAR: \
+ return (unsigned char)(value >> TAG_BITS); \
+ case TAG_UNSIGNED_SHORT: \
+ return (unsigned short)(value >> TAG_BITS); \
+ case TAG_UNSIGNED_INT: \
+ return (unsigned int)(value >> TAG_BITS); \
+ case TAG_UNSIGNED_LONG: \
+ return (unsigned long)(value >> TAG_BITS); \
+ case TAG_UNSIGNED_LONG_LONG: \
+ return (unsigned long long)(value >> TAG_BITS); \
+ default: \
+ @throw [OFInvalidArgumentException exception]; \
+ }
+- (long long)longLongValue
{
- return [[[self alloc] initWithUnsignedChar: uChar] autorelease];
+ RETURN_VALUE
}
-+ (instancetype)numberWithUnsignedShort: (unsigned short)uShort
+- (unsigned long long)unsignedLongLongValue
{
- return [[[self alloc] initWithUnsignedShort: uShort] autorelease];
+ RETURN_VALUE
}
-+ (instancetype)numberWithUnsignedInt: (unsigned int)uInt
+- (double)doubleValue
{
- return [[[self alloc] initWithUnsignedInt: uInt] autorelease];
+ RETURN_VALUE
}
+@end
+# undef RETURN_VALUE
+#endif
-+ (instancetype)numberWithUnsignedLong: (unsigned long)uLong
+@implementation OFNumber
++ (void)initialize
{
- return [[[self alloc] initWithUnsignedLong: uLong] autorelease];
-}
+ if (self != [OFNumber class])
+ return;
-+ (instancetype)numberWithUnsignedLongLong: (unsigned long long)uLongLong
-{
- return [[[self alloc] initWithUnsignedLongLong: uLongLong] autorelease];
-}
+ placeholder.isa = [OFNumberPlaceholder class];
-+ (instancetype)numberWithInt8: (int8_t)int8
-{
- return [[[self alloc] initWithInt8: int8] autorelease];
+#ifdef OF_OBJFW_RUNTIME
+ numberTag =
+ objc_registerTaggedPointerClass([OFTaggedPointerNumber class]);
+#endif
}
-+ (instancetype)numberWithInt16: (int16_t)int16
++ (instancetype)of_alloc
{
- return [[[self alloc] initWithInt16: int16] autorelease];
+ return [super alloc];
}
-+ (instancetype)numberWithInt32: (int32_t)int32
++ (instancetype)alloc
{
- return [[[self alloc] initWithInt32: int32] autorelease];
-}
+ if (self == [OFNumber class])
+ return (id)&placeholder;
-+ (instancetype)numberWithInt64: (int64_t)int64
-{
- return [[[self alloc] initWithInt64: int64] autorelease];
+ return [super alloc];
}
-+ (instancetype)numberWithUInt8: (uint8_t)uInt8
++ (instancetype)numberWithBool: (bool)value
{
- return [[[self alloc] initWithUInt8: uInt8] autorelease];
+ return [[[self alloc] initWithBool: value] autorelease];
}
-+ (instancetype)numberWithUInt16: (uint16_t)uInt16
++ (instancetype)numberWithChar: (signed char)value
{
- return [[[self alloc] initWithUInt16: uInt16] autorelease];
+ return [[[self alloc] initWithChar: value] autorelease];
}
-+ (instancetype)numberWithUInt32: (uint32_t)uInt32
++ (instancetype)numberWithShort: (short)value
{
- return [[[self alloc] initWithUInt32: uInt32] autorelease];
+ return [[[self alloc] initWithShort: value] autorelease];
}
-+ (instancetype)numberWithUInt64: (uint64_t)uInt64
++ (instancetype)numberWithInt: (int)value
{
- return [[[self alloc] initWithUInt64: uInt64] autorelease];
+ return [[[self alloc] initWithInt: value] autorelease];
}
-+ (instancetype)numberWithSize: (size_t)size
++ (instancetype)numberWithLong: (long)value
{
- return [[[self alloc] initWithSize: size] autorelease];
+ return [[[self alloc] initWithLong: value] autorelease];
}
-+ (instancetype)numberWithSSize: (ssize_t)sSize
++ (instancetype)numberWithLongLong: (long long)value
{
- return [[[self alloc] initWithSSize: sSize] autorelease];
+ return [[[self alloc] initWithLongLong: value] autorelease];
}
-+ (instancetype)numberWithIntMax: (intmax_t)intMax
++ (instancetype)numberWithUnsignedChar: (unsigned char)value
{
- return [[[self alloc] initWithIntMax: intMax] autorelease];
+ return [[[self alloc] initWithUnsignedChar: value] autorelease];
}
-+ (instancetype)numberWithUIntMax: (uintmax_t)uIntMax
++ (instancetype)numberWithUnsignedShort: (unsigned short)value
{
- return [[[self alloc] initWithUIntMax: uIntMax] autorelease];
+ return [[[self alloc] initWithUnsignedShort: value] autorelease];
}
-+ (instancetype)numberWithPtrDiff: (ptrdiff_t)ptrDiff
++ (instancetype)numberWithUnsignedInt: (unsigned int)value
{
- return [[[self alloc] initWithPtrDiff: ptrDiff] autorelease];
+ return [[[self alloc] initWithUnsignedInt: value] autorelease];
}
-+ (instancetype)numberWithIntPtr: (intptr_t)intPtr
++ (instancetype)numberWithUnsignedLong: (unsigned long)value
{
- return [[[self alloc] initWithIntPtr: intPtr] autorelease];
+ return [[[self alloc] initWithUnsignedLong: value] autorelease];
}
-+ (instancetype)numberWithUIntPtr: (uintptr_t)uIntPtr
++ (instancetype)numberWithUnsignedLongLong: (unsigned long long)value
{
- return [[[self alloc] initWithUIntPtr: uIntPtr] autorelease];
+ return [[[self alloc] initWithUnsignedLongLong: value] autorelease];
}
-+ (instancetype)numberWithFloat: (float)float_
++ (instancetype)numberWithFloat: (float)value
{
- return [[[self alloc] initWithFloat: float_] autorelease];
+ return [[[self alloc] initWithFloat: value] autorelease];
}
-+ (instancetype)numberWithDouble: (double)double_
++ (instancetype)numberWithDouble: (double)value
{
- return [[[self alloc] initWithDouble: double_] autorelease];
+ return [[[self alloc] initWithDouble: value] autorelease];
}
- (instancetype)init
@@ -555,309 +583,161 @@ initFalseNumber(void)
OF_INVALID_INIT_METHOD
}
-- (instancetype)initWithBool: (bool)bool_
+- (instancetype)initWithBool: (bool)value
{
self = [super init];
- _value.unsigned_ = bool_;
- _type = OF_NUMBER_TYPE_UNSIGNED;
+ _value.unsigned_ = value;
_typeEncoding = @encode(bool);
return self;
}
-- (instancetype)initWithChar: (signed char)sChar
+- (instancetype)initWithChar: (signed char)value
{
self = [super init];
- _value.signed_ = sChar;
- _type = OF_NUMBER_TYPE_SIGNED;
+ _value.signed_ = value;
_typeEncoding = @encode(signed char);
return self;
}
-- (instancetype)initWithShort: (short)sShort
+- (instancetype)initWithShort: (short)value
{
self = [super init];
- _value.signed_ = sShort;
- _type = OF_NUMBER_TYPE_SIGNED;
+ _value.signed_ = value;
_typeEncoding = @encode(short);
return self;
}
-- (instancetype)initWithInt: (int)sInt
+- (instancetype)initWithInt: (int)value
{
self = [super init];
- _value.signed_ = sInt;
- _type = OF_NUMBER_TYPE_SIGNED;
+ _value.signed_ = value;
_typeEncoding = @encode(int);
return self;
}
-- (instancetype)initWithLong: (long)sLong
+- (instancetype)initWithLong: (long)value
{
self = [super init];
- _value.signed_ = sLong;
- _type = OF_NUMBER_TYPE_SIGNED;
+ _value.signed_ = value;
_typeEncoding = @encode(long);
return self;
}
-- (instancetype)initWithLongLong: (long long)sLongLong
+- (instancetype)initWithLongLong: (long long)value
{
self = [super init];
- _value.signed_ = sLongLong;
- _type = OF_NUMBER_TYPE_SIGNED;
+ _value.signed_ = value;
_typeEncoding = @encode(long long);
return self;
}
-- (instancetype)initWithUnsignedChar: (unsigned char)uChar
+- (instancetype)initWithUnsignedChar: (unsigned char)value
{
self = [super init];
- _value.unsigned_ = uChar;
- _type = OF_NUMBER_TYPE_UNSIGNED;
+ _value.unsigned_ = value;
_typeEncoding = @encode(unsigned long);
return self;
}
-- (instancetype)initWithUnsignedShort: (unsigned short)uShort
+- (instancetype)initWithUnsignedShort: (unsigned short)value
{
self = [super init];
- _value.unsigned_ = uShort;
- _type = OF_NUMBER_TYPE_UNSIGNED;
+ _value.unsigned_ = value;
_typeEncoding = @encode(unsigned short);
return self;
}
-- (instancetype)initWithUnsignedInt: (unsigned int)uInt
+- (instancetype)initWithUnsignedInt: (unsigned int)value
{
self = [super init];
- _value.unsigned_ = uInt;
- _type = OF_NUMBER_TYPE_UNSIGNED;
+ _value.unsigned_ = value;
_typeEncoding = @encode(unsigned int);
return self;
}
-- (instancetype)initWithUnsignedLong: (unsigned long)uLong
+- (instancetype)initWithUnsignedLong: (unsigned long)value
{
self = [super init];
- _value.unsigned_ = uLong;
- _type = OF_NUMBER_TYPE_UNSIGNED;
+ _value.unsigned_ = value;
_typeEncoding = @encode(unsigned long);
return self;
}
-- (instancetype)initWithUnsignedLongLong: (unsigned long long)uLongLong
+- (instancetype)initWithUnsignedLongLong: (unsigned long long)value
{
self = [super init];
- _value.unsigned_ = uLongLong;
- _type = OF_NUMBER_TYPE_UNSIGNED;
+ _value.unsigned_ = value;
_typeEncoding = @encode(unsigned long long);
return self;
}
-- (instancetype)initWithInt8: (int8_t)int8
-{
- self = [super init];
-
- _value.signed_ = int8;
- _type = OF_NUMBER_TYPE_SIGNED;
- _typeEncoding = @encode(int8_t);
-
- return self;
-}
-
-- (instancetype)initWithInt16: (int16_t)int16
-{
- self = [super init];
-
- _value.signed_ = int16;
- _type = OF_NUMBER_TYPE_SIGNED;
- _typeEncoding = @encode(int16_t);
-
- return self;
-}
-
-- (instancetype)initWithInt32: (int32_t)int32
-{
- self = [super init];
-
- _value.signed_ = int32;
- _type = OF_NUMBER_TYPE_SIGNED;
- _typeEncoding = @encode(int32_t);
-
- return self;
-}
-
-- (instancetype)initWithInt64: (int64_t)int64
-{
- self = [super init];
-
- _value.signed_ = int64;
- _type = OF_NUMBER_TYPE_SIGNED;
- _typeEncoding = @encode(int64_t);
-
- return self;
-}
-
-- (instancetype)initWithUInt8: (uint8_t)uInt8
-{
- self = [super init];
-
- _value.unsigned_ = uInt8;
- _type = OF_NUMBER_TYPE_UNSIGNED;
- _typeEncoding = @encode(uint8_t);
-
- return self;
-}
-
-- (instancetype)initWithUInt16: (uint16_t)uInt16
-{
- self = [super init];
-
- _value.unsigned_ = uInt16;
- _type = OF_NUMBER_TYPE_UNSIGNED;
- _typeEncoding = @encode(uint16_t);
-
- return self;
-}
-
-- (instancetype)initWithUInt32: (uint32_t)uInt32
-{
- self = [super init];
-
- _value.unsigned_ = uInt32;
- _type = OF_NUMBER_TYPE_UNSIGNED;
- _typeEncoding = @encode(uint32_t);
-
- return self;
-}
-
-- (instancetype)initWithUInt64: (uint64_t)uInt64
-{
- self = [super init];
-
- _value.unsigned_ = uInt64;
- _type = OF_NUMBER_TYPE_UNSIGNED;
- _typeEncoding = @encode(uint64_t);
-
- return self;
-}
-
-- (instancetype)initWithSize: (size_t)size
-{
- self = [super init];
-
- _value.unsigned_ = size;
- _type = OF_NUMBER_TYPE_UNSIGNED;
- _typeEncoding = @encode(size_t);
-
- return self;
-}
-
-- (instancetype)initWithSSize: (ssize_t)sSize
-{
- self = [super init];
-
- _value.signed_ = sSize;
- _type = OF_NUMBER_TYPE_SIGNED;
- _typeEncoding = @encode(ssize_t);
-
- return self;
-}
-
-- (instancetype)initWithIntMax: (intmax_t)intMax
+- (instancetype)initWithPtrDiff: (ptrdiff_t)value
{
self = [super init];
- _value.signed_ = intMax;
- _type = OF_NUMBER_TYPE_SIGNED;
- _typeEncoding = @encode(intmax_t);
-
- return self;
-}
-
-- (instancetype)initWithUIntMax: (uintmax_t)uIntMax
-{
- self = [super init];
-
- _value.unsigned_ = uIntMax;
- _type = OF_NUMBER_TYPE_UNSIGNED;
- _typeEncoding = @encode(uintmax_t);
-
- return self;
-}
-
-- (instancetype)initWithPtrDiff: (ptrdiff_t)ptrDiff
-{
- self = [super init];
-
- _value.signed_ = ptrDiff;
- _type = OF_NUMBER_TYPE_SIGNED;
+ _value.signed_ = value;
_typeEncoding = @encode(ptrdiff_t);
return self;
}
-- (instancetype)initWithIntPtr: (intptr_t)intPtr
+- (instancetype)initWithIntPtr: (intptr_t)value
{
self = [super init];
- _value.signed_ = intPtr;
- _type = OF_NUMBER_TYPE_SIGNED;
+ _value.signed_ = value;
_typeEncoding = @encode(intptr_t);
return self;
}
-- (instancetype)initWithUIntPtr: (uintptr_t)uIntPtr
+- (instancetype)initWithUIntPtr: (uintptr_t)value
{
self = [super init];
- _value.unsigned_ = uIntPtr;
- _type = OF_NUMBER_TYPE_UNSIGNED;
+ _value.unsigned_ = value;
_typeEncoding = @encode(uintptr_t);
return self;
}
-- (instancetype)initWithFloat: (float)float_
+- (instancetype)initWithFloat: (float)value
{
self = [super init];
- _value.float_ = float_;
- _type = OF_NUMBER_TYPE_FLOAT;
+ _value.float_ = value;
_typeEncoding = @encode(float);
return self;
}
-- (instancetype)initWithDouble: (double)double_
+- (instancetype)initWithDouble: (double)value
{
self = [super init];
- _value.float_ = double_;
- _type = OF_NUMBER_TYPE_FLOAT;
+ _value.float_ = value;
_typeEncoding = @encode(double);
return self;
@@ -871,7 +751,7 @@ initFalseNumber(void)
void *pool = objc_autoreleasePoolPush();
OFString *typeString;
- if (![element.name isEqual: self.className] ||
+ if (![element.name isEqual: @"OFNumber"] ||
![element.namespace isEqual: OF_SERIALIZATION_NS])
@throw [OFInvalidArgumentException exception];
@@ -885,18 +765,20 @@ initFalseNumber(void)
self = [self initWithBool: false];
else
@throw [OFInvalidArgumentException exception];
- } else if ([typeString isEqual: @"float"])
+ } else if ([typeString isEqual: @"float"]) {
+ unsigned long long value =
+ [element unsignedLongLongValueWithBase: 16];
+
+ if (value > UINT64_MAX)
+ @throw [OFOutOfRangeException exception];
+
self = [self initWithDouble: OF_BSWAP_DOUBLE_IF_LE(
- OF_INT_TO_DOUBLE_RAW(OF_BSWAP64_IF_LE(
- (uint64_t)element.hexadecimalValue)))];
- else if ([typeString isEqual: @"signed"])
- self = [self initWithIntMax: element.doubleValue];
+ OF_INT_TO_DOUBLE_RAW(OF_BSWAP64_IF_LE(value)))];
+ } else if ([typeString isEqual: @"signed"])
+ self = [self initWithLongLong: element.longLongValue];
else if ([typeString isEqual: @"unsigned"])
- /*
- * FIXME: This will fail if the value is bigger than
- * INTMAX_MAX!
- */
- self = [self initWithUIntMax: element.decimalValue];
+ self = [self initWithUnsignedLongLong:
+ element.unsignedLongLongValue];
else
@throw [OFInvalidArgumentException exception];
@@ -917,10 +799,10 @@ initFalseNumber(void)
- (void)getValue: (void *)value
size: (size_t)size
{
- switch (*_typeEncoding) {
-#define CASE(enc, type, field) \
+ switch (*self.objCType) {
+#define CASE(enc, type, property) \
case enc: { \
- type tmp = (type)_value.field; \
+ type tmp = (type)self.property; \
\
if (size != sizeof(type)) \
@throw [OFOutOfRangeException exception]; \
@@ -928,177 +810,111 @@ initFalseNumber(void)
memcpy(value, &tmp, size); \
break; \
}
- CASE('B', bool, unsigned_)
- CASE('c', signed char, signed_)
- CASE('s', short, signed_)
- CASE('i', int, signed_)
- CASE('l', long, signed_)
- CASE('q', long long, signed_)
- CASE('C', unsigned char, unsigned_)
- CASE('S', unsigned short, unsigned_)
- CASE('I', unsigned int, unsigned_)
- CASE('L', unsigned long, unsigned_)
- CASE('Q', unsigned long long, unsigned_)
- CASE('f', float, float_)
- CASE('d', double, float_)
+ CASE('B', bool, unsignedLongLongValue)
+ CASE('c', signed char, longLongValue)
+ CASE('s', short, longLongValue)
+ CASE('i', int, longLongValue)
+ CASE('l', long, longLongValue)
+ CASE('q', long long, longLongValue)
+ CASE('C', unsigned char, unsignedLongLongValue)
+ CASE('S', unsigned short, unsignedLongLongValue)
+ CASE('I', unsigned int, unsignedLongLongValue)
+ CASE('L', unsigned long, unsignedLongLongValue)
+ CASE('Q', unsigned long long, unsignedLongLongValue)
+ CASE('f', float, doubleValue)
+ CASE('d', double, doubleValue)
#undef CASE
default:
@throw [OFInvalidFormatException exception];
}
}
-#define RETURN_AS(t) \
- switch (_type) { \
- case OF_NUMBER_TYPE_FLOAT: \
- return (t)_value.float_; \
- case OF_NUMBER_TYPE_SIGNED: \
- return (t)_value.signed_; \
- case OF_NUMBER_TYPE_UNSIGNED: \
- return (t)_value.unsigned_; \
- default: \
- @throw [OFInvalidFormatException exception]; \
- }
-- (bool)boolValue
-{
- RETURN_AS(bool)
-}
-
-- (signed char)charValue
-{
- RETURN_AS(signed char)
-}
-
-- (short)shortValue
-{
- RETURN_AS(short)
-}
-
-- (int)intValue
-{
- RETURN_AS(int)
-}
-
-- (long)longValue
-{
- RETURN_AS(long)
-}
-
- (long long)longLongValue
{
- RETURN_AS(long long)
-}
-
-- (unsigned char)unsignedCharValue
-{
- RETURN_AS(unsigned char)
-}
-
-- (unsigned short)unsignedShortValue
-{
- RETURN_AS(unsigned short)
-}
-
-- (unsigned int)unsignedIntValue
-{
- RETURN_AS(unsigned int)
-}
-
-- (unsigned long)unsignedLongValue
-{
- RETURN_AS(unsigned long)
+ if (isFloat(self))
+ return _value.float_;
+ else if (isSigned(self))
+ return _value.signed_;
+ else if (isUnsigned(self))
+ return _value.unsigned_;
+ else
+ @throw [OFInvalidFormatException exception];
}
- (unsigned long long)unsignedLongLongValue
{
- RETURN_AS(unsigned long long)
-}
-
-- (int8_t)int8Value
-{
- RETURN_AS(int8_t)
-}
-
-- (int16_t)int16Value
-{
- RETURN_AS(int16_t)
-}
-
-- (int32_t)int32Value
-{
- RETURN_AS(int32_t)
-}
-
-- (int64_t)int64Value
-{
- RETURN_AS(int64_t)
-}
-
-- (uint8_t)uInt8Value
-{
- RETURN_AS(uint8_t)
+ if (isFloat(self))
+ return _value.float_;
+ else if (isSigned(self))
+ return _value.signed_;
+ else if (isUnsigned(self))
+ return _value.unsigned_;
+ else
+ @throw [OFInvalidFormatException exception];
}
-- (uint16_t)uInt16Value
+- (double)doubleValue
{
- RETURN_AS(uint16_t)
+ if (isFloat(self))
+ return _value.float_;
+ else if (isSigned(self))
+ return _value.signed_;
+ else if (isUnsigned(self))
+ return _value.unsigned_;
+ else
+ @throw [OFInvalidFormatException exception];
}
-- (uint32_t)uInt32Value
+- (bool)boolValue
{
- RETURN_AS(uint32_t)
+ return (bool)self.unsignedLongLongValue;
}
-- (uint64_t)uInt64Value
+- (signed char)charValue
{
- RETURN_AS(uint64_t)
+ return (signed char)self.longLongValue;
}
-- (size_t)sizeValue
+- (short)shortValue
{
- RETURN_AS(size_t)
+ return (short)self.longLongValue;
}
-- (ssize_t)sSizeValue
+- (int)intValue
{
- RETURN_AS(ssize_t)
+ return (int)self.longLongValue;
}
-- (intmax_t)intMaxValue
+- (long)longValue
{
- RETURN_AS(intmax_t)
+ return (long)self.longLongValue;
}
-- (uintmax_t)uIntMaxValue
+- (unsigned char)unsignedCharValue
{
- RETURN_AS(uintmax_t)
+ return (unsigned char)self.unsignedLongLongValue;
}
-- (ptrdiff_t)ptrDiffValue
+- (unsigned short)unsignedShortValue
{
- RETURN_AS(ptrdiff_t)
+ return (unsigned short)self.unsignedLongLongValue;
}
-- (intptr_t)intPtrValue
+- (unsigned int)unsignedIntValue
{
- RETURN_AS(intptr_t)
+ return (unsigned int)self.unsignedLongLongValue;
}
-- (uintptr_t)uIntPtrValue
+- (unsigned long)unsignedLongValue
{
- RETURN_AS(uintptr_t)
+ return (unsigned long)self.unsignedLongLongValue;
}
- (float)floatValue
{
- RETURN_AS(float)
+ return (float)self.doubleValue;
}
-- (double)doubleValue
-{
- RETURN_AS(double)
-}
-#undef RETURN_AS
-
- (bool)isEqual: (id)object
{
OFNumber *number;
@@ -1111,8 +927,7 @@ initFalseNumber(void)
number = object;
- if (_type == OF_NUMBER_TYPE_FLOAT ||
- number->_type == OF_NUMBER_TYPE_FLOAT) {
+ if (isFloat(self) || isFloat(number)) {
double value1 = number.doubleValue;
double value2 = self.doubleValue;
@@ -1124,11 +939,10 @@ initFalseNumber(void)
return (value1 == value2);
}
- if (_type == OF_NUMBER_TYPE_SIGNED ||
- number->_type == OF_NUMBER_TYPE_SIGNED)
- return (number.intMaxValue == self.intMaxValue);
+ if (isSigned(self) || isSigned(number))
+ return (number.longLongValue == self.longLongValue);
- return (number.uIntMaxValue == self.uIntMaxValue);
+ return (number.unsignedLongLongValue == self.unsignedLongLongValue);
}
- (of_comparison_result_t)compare: (id <OFComparing>)object
@@ -1140,8 +954,7 @@ initFalseNumber(void)
number = (OFNumber *)object;
- if (_type == OF_NUMBER_TYPE_FLOAT ||
- number->_type == OF_NUMBER_TYPE_FLOAT) {
+ if (isFloat(self) || isFloat(number)) {
double double1 = self.doubleValue;
double double2 = number.doubleValue;
@@ -1151,10 +964,9 @@ initFalseNumber(void)
return OF_ORDERED_ASCENDING;
return OF_ORDERED_SAME;
- } else if (_type == OF_NUMBER_TYPE_SIGNED ||
- number->_type == OF_NUMBER_TYPE_SIGNED) {
- intmax_t int1 = self.intMaxValue;
- intmax_t int2 = number.intMaxValue;
+ } else if (isSigned(self) || isSigned(number)) {
+ long long int1 = self.longLongValue;
+ long long int2 = number.longLongValue;
if (int1 > int2)
return OF_ORDERED_DESCENDING;
@@ -1163,8 +975,8 @@ initFalseNumber(void)
return OF_ORDERED_SAME;
} else {
- uintmax_t uint1 = self.uIntMaxValue;
- uintmax_t uint2 = number.uIntMaxValue;
+ unsigned long long uint1 = self.unsignedLongLongValue;
+ unsigned long long uint2 = number.unsignedLongLongValue;
if (uint1 > uint2)
return OF_ORDERED_DESCENDING;
@@ -1177,12 +989,11 @@ initFalseNumber(void)
- (uint32_t)hash
{
- enum of_number_type type = _type;
uint32_t hash;
OF_HASH_INIT(hash);
- if (type == OF_NUMBER_TYPE_FLOAT) {
+ if (isFloat(self)) {
double d;
if (isnan(self.doubleValue))
@@ -1192,21 +1003,12 @@ initFalseNumber(void)
for (uint_fast8_t i = 0; i < sizeof(double); i++)
OF_HASH_ADD(hash, ((char *)&d)[i]);
- } else if (type == OF_NUMBER_TYPE_SIGNED) {
- intmax_t v = self.intMaxValue * -1;
-
- while (v != 0) {
- OF_HASH_ADD(hash, v & 0xFF);
- v >>= 8;
- }
-
- OF_HASH_ADD(hash, 1);
- } else if (type == OF_NUMBER_TYPE_UNSIGNED) {
- uintmax_t v = self.uIntMaxValue;
+ } else if (isSigned(self) || isUnsigned(self)) {
+ unsigned long long value = self.unsignedLongLongValue;
- while (v != 0) {
- OF_HASH_ADD(hash, v & 0xFF);
- v >>= 8;
+ while (value != 0) {
+ OF_HASH_ADD(hash, value & 0xFF);
+ value >>= 8;
}
} else
@throw [OFInvalidFormatException exception];
@@ -1228,14 +1030,15 @@ initFalseNumber(void)
- (OFString *)stringValue
{
- if (*_typeEncoding == 'B')
- return (_value.unsigned_ ? @"true" : @"false");
- if (_type == OF_NUMBER_TYPE_FLOAT)
- return [OFString stringWithFormat: @"%g", _value.float_];
- if (_type == OF_NUMBER_TYPE_SIGNED)
- return [OFString stringWithFormat: @"%jd", _value.signed_];
- if (_type == OF_NUMBER_TYPE_UNSIGNED)
- return [OFString stringWithFormat: @"%ju", _value.unsigned_];
+ if (*self.objCType == 'B')
+ return (self.boolValue ? @"true" : @"false");
+ if (isFloat(self))
+ return [OFString stringWithFormat: @"%g", self.doubleValue];
+ if (isSigned(self))
+ return [OFString stringWithFormat: @"%lld", self.longLongValue];
+ if (isUnsigned(self))
+ return [OFString stringWithFormat: @"%llu",
+ self.unsignedLongLongValue];
@throw [OFInvalidFormatException exception];
}
@@ -1245,24 +1048,24 @@ initFalseNumber(void)
void *pool = objc_autoreleasePoolPush();
OFXMLElement *element;
- element = [OFXMLElement elementWithName: self.className
+ element = [OFXMLElement elementWithName: @"OFNumber"
namespace: OF_SERIALIZATION_NS
stringValue: self.description];
- if (*_typeEncoding == 'B')
+ if (*self.objCType == 'B')
[element addAttributeWithName: @"type"
stringValue: @"bool"];
- else if (_type == OF_NUMBER_TYPE_FLOAT) {
+ else if (isFloat(self)) {
[element addAttributeWithName: @"type"
stringValue: @"float"];
element.stringValue = [OFString
stringWithFormat: @"%016" PRIx64,
OF_BSWAP64_IF_LE(OF_DOUBLE_TO_INT_RAW(OF_BSWAP_DOUBLE_IF_LE(
- _value.float_)))];
- } else if (_type == OF_NUMBER_TYPE_SIGNED)
+ self.doubleValue)))];
+ } else if (isSigned(self))
[element addAttributeWithName: @"type"
stringValue: @"signed"];
- else if (_type == OF_NUMBER_TYPE_UNSIGNED)
+ else if (isUnsigned(self))
[element addAttributeWithName: @"type"
stringValue: @"unsigned"];
else
@@ -1292,8 +1095,8 @@ initFalseNumber(void)
{
double doubleValue;
- if (*_typeEncoding == 'B')
- return (_value.unsigned_ ? @"true" : @"false");
+ if (*self.objCType == 'B')
+ return (self.boolValue ? @"true" : @"false");
doubleValue = self.doubleValue;
if (isinf(doubleValue)) {
@@ -1312,15 +1115,16 @@ initFalseNumber(void)
- (OFData *)messagePackRepresentation
{
OFMutableData *data;
+ const char *typeEncoding = self.objCType;
- if (*_typeEncoding == 'B') {
- uint8_t type = (_value.unsigned_ ? 0xC3 : 0xC2);
+ if (*typeEncoding == 'B') {
+ uint8_t type = (self.boolValue ? 0xC3 : 0xC2);
data = [OFMutableData dataWithItems: &type
count: 1];
- } else if (*_typeEncoding == 'f') {
+ } else if (*typeEncoding == 'f') {
uint8_t type = 0xCA;
- float tmp = OF_BSWAP_FLOAT_IF_LE(_value.float_);
+ float tmp = OF_BSWAP_FLOAT_IF_LE(self.floatValue);
data = [OFMutableData dataWithItemSize: 1
capacity: 5];
@@ -1328,9 +1132,9 @@ initFalseNumber(void)
[data addItem: &type];
[data addItems: &tmp
count: sizeof(tmp)];
- } else if (*_typeEncoding == 'd') {
+ } else if (*typeEncoding == 'd') {
uint8_t type = 0xCB;
- double tmp = OF_BSWAP_DOUBLE_IF_LE(_value.float_);
+ double tmp = OF_BSWAP_DOUBLE_IF_LE(self.doubleValue);
data = [OFMutableData dataWithItemSize: 1
capacity: 9];
@@ -1338,8 +1142,8 @@ initFalseNumber(void)
[data addItem: &type];
[data addItems: &tmp
count: sizeof(tmp)];
- } else if (_type == OF_NUMBER_TYPE_SIGNED) {
- intmax_t value = self.intMaxValue;
+ } else if (isSigned(self)) {
+ long long value = self.longLongValue;
if (value >= -32 && value < 0) {
uint8_t tmp = 0xE0 | ((uint8_t)(value - 32) & 0x1F);
@@ -1387,8 +1191,8 @@ initFalseNumber(void)
count: sizeof(tmp)];
} else
@throw [OFOutOfRangeException exception];
- } else if (_type == OF_NUMBER_TYPE_UNSIGNED) {
- uintmax_t value = self.uIntMaxValue;
+ } else if (isUnsigned(self)) {
+ unsigned long long value = self.unsignedLongLongValue;
if (value <= 127) {
uint8_t tmp = ((uint8_t)value & 0x7F);
diff --git a/src/OFSettings.h b/src/OFSettings.h
index 4c2d0b55..47109975 100644
--- a/src/OFSettings.h
+++ b/src/OFSettings.h
@@ -83,7 +83,7 @@ OF_ASSUME_NONNULL_BEGIN
* @param integer The integer to set
* @param path The path to store the integer at
*/
-- (void)setInteger: (intmax_t)integer
+- (void)setInteger: (long long)integer
forPath: (OFString *)path;
/*!
@@ -150,8 +150,8 @@ OF_ASSUME_NONNULL_BEGIN
* @param defaultValue The default value to return if the path does not exist
* @return The integer value of the specified path
*/
-- (intmax_t)integerForPath: (OFString *)path
- defaultValue: (intmax_t)defaultValue;
+- (long long)integerForPath: (OFString *)path
+ defaultValue: (long long)defaultValue;
/*!
* @brief Returns the bool for the specified path, or the default value if the
diff --git a/src/OFSettings.m b/src/OFSettings.m
index 7a0d7ee0..46be94b2 100644
--- a/src/OFSettings.m
+++ b/src/OFSettings.m
@@ -70,7 +70,7 @@
OF_UNRECOGNIZED_SELECTOR
}
-- (void)setInteger: (intmax_t)integer
+- (void)setInteger: (long long)integer
forPath: (OFString *)path
{
OF_UNRECOGNIZED_SELECTOR
@@ -112,8 +112,8 @@
OF_UNRECOGNIZED_SELECTOR
}
-- (intmax_t)integerForPath: (OFString *)path
- defaultValue: (intmax_t)defaultValue
+- (long long)integerForPath: (OFString *)path
+ defaultValue: (long long)defaultValue
{
OF_UNRECOGNIZED_SELECTOR
}
diff --git a/src/OFString+JSONValue.h b/src/OFString+JSONParsing.h
index b25e4781..1d1b8ee7 100644
--- a/src/OFString+JSONValue.h
+++ b/src/OFString+JSONParsing.h
@@ -22,12 +22,12 @@ OF_ASSUME_NONNULL_BEGIN
#ifdef __cplusplus
extern "C" {
#endif
-extern int _OFString_JSONValue_reference;
+extern int _OFString_JSONParsing_reference;
#ifdef __cplusplus
}
#endif
-@interface OFString (JSONValue)
+@interface OFString (JSONParsing)
/*!
* @brief The string interpreted as JSON and parsed as an object.
*
@@ -43,7 +43,7 @@ extern int _OFString_JSONValue_reference;
* want your program to terminate due to a message not understood, but
* instead check the returned object using @ref isKindOfClass:.
*/
-@property (readonly, nonatomic) id JSONValue;
+@property (readonly, nonatomic) id objectByParsingJSON;
/*!
* @brief Creates an object from the JSON value of the string.
@@ -65,7 +65,7 @@ extern int _OFString_JSONValue_reference;
*
* @return An object
*/
-- (id)JSONValueWithDepthLimit: (size_t)depthLimit;
+- (id)objectByParsingJSONWithDepthLimit: (size_t)depthLimit;
@end
OF_ASSUME_NONNULL_END
diff --git a/src/OFString+JSONValue.m b/src/OFString+JSONParsing.m
index 6d496750..08a13a1c 100644
--- a/src/OFString+JSONValue.m
+++ b/src/OFString+JSONParsing.m
@@ -24,7 +24,7 @@
#include <assert.h>
-#import "OFString+JSONValue.h"
+#import "OFString+JSONParsing.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFNumber.h"
@@ -32,7 +32,7 @@
#import "OFInvalidJSONException.h"
-int _OFString_JSONValue_reference;
+int _OFString_JSONParsing_reference;
static id nextObject(const char **pointer, const char *stop, size_t *line,
size_t depthLimit);
@@ -528,7 +528,7 @@ parseDictionary(const char **pointer, const char *stop, size_t *line,
static inline OFNumber *
parseNumber(const char **pointer, const char *stop, size_t *line)
{
- bool isHex = (*pointer + 1 < stop && (*pointer)[1] == 'x');
+ bool isNegative = (*pointer < stop && (*pointer)[0] == '-');
bool hasDecimal = false;
size_t i;
OFString *string;
@@ -557,16 +557,16 @@ parseNumber(const char **pointer, const char *stop, size_t *line)
if (hasDecimal)
number = [OFNumber numberWithDouble:
string.doubleValue];
- else if (isHex)
- number = [OFNumber numberWithIntMax:
- string.hexadecimalValue];
else if ([string isEqual: @"Infinity"])
number = [OFNumber numberWithDouble: INFINITY];
else if ([string isEqual: @"-Infinity"])
number = [OFNumber numberWithDouble: -INFINITY];
+ else if (isNegative)
+ number = [OFNumber numberWithLongLong:
+ [string longLongValueWithBase: 0]];
else
- number = [OFNumber numberWithIntMax:
- string.decimalValue];
+ number = [OFNumber numberWithUnsignedLongLong:
+ [string unsignedLongLongValueWithBase: 0]];
} @finally {
[string release];
}
@@ -641,13 +641,13 @@ nextObject(const char **pointer, const char *stop, size_t *line,
}
}
-@implementation OFString (JSONValue)
-- (id)JSONValue
+@implementation OFString (JSONParsing)
+- (id)objectByParsingJSON
{
- return [self JSONValueWithDepthLimit: 32];
+ return [self objectByParsingJSONWithDepthLimit: 32];
}
-- (id)JSONValueWithDepthLimit: (size_t)depthLimit
+- (id)objectByParsingJSONWithDepthLimit: (size_t)depthLimit
{
void *pool = objc_autoreleasePoolPush();
const char *pointer = self.UTF8String;
diff --git a/src/OFString+PropertyListValue.h b/src/OFString+PropertyListParsing.h
index fd0bbb93..1365742a 100644
--- a/src/OFString+PropertyListValue.h
+++ b/src/OFString+PropertyListParsing.h
@@ -22,18 +22,18 @@ OF_ASSUME_NONNULL_BEGIN
#ifdef __cplusplus
extern "C" {
#endif
-extern int _OFString_PropertyListValue_reference;
+extern int _OFString_PropertyListParsing_reference;
#ifdef __cplusplus
}
#endif
-@interface OFString (PropertyListValue)
+@interface OFString (PropertyListParsing)
/*!
* @brief The string interpreted as a property list and parsed as an object.
*
* @note This only supports XML property lists!
*/
-@property (readonly, nonatomic) id propertyListValue;
+@property (readonly, nonatomic) id objectByParsingPropertyList;
@end
OF_ASSUME_NONNULL_END
diff --git a/src/OFString+PropertyListValue.m b/src/OFString+PropertyListParsing.m
index 950ecf0f..bf1caa5c 100644
--- a/src/OFString+PropertyListValue.m
+++ b/src/OFString+PropertyListParsing.m
@@ -17,7 +17,7 @@
#include "config.h"
-#import "OFString+PropertyListValue.h"
+#import "OFString+PropertyListParsing.h"
#import "OFArray.h"
#import "OFData.h"
#import "OFDate.h"
@@ -29,7 +29,7 @@
#import "OFInvalidFormatException.h"
#import "OFUnsupportedVersionException.h"
-int _OFString_PropertyListValue_reference;
+int _OFString_PropertyListParsing_reference;
static id parseElement(OFXMLElement *element);
@@ -125,7 +125,23 @@ parseRealElement(OFXMLElement *element)
static OFNumber *
parseIntegerElement(OFXMLElement *element)
{
- return [OFNumber numberWithIntMax: element.decimalValue];
+ void *pool = objc_autoreleasePoolPush();
+ OFString *stringValue;
+ OFNumber *ret;
+
+ stringValue = element.stringValue.stringByDeletingEnclosingWhitespaces;
+
+ if ([stringValue hasPrefix: @"-"])
+ ret = [OFNumber numberWithLongLong: stringValue.longLongValue];
+ else
+ ret = [OFNumber numberWithUnsignedLongLong:
+ stringValue.unsignedLongLongValue];
+
+ [ret retain];
+
+ objc_autoreleasePoolPop(pool);
+
+ return [ret autorelease];
}
static id
@@ -160,8 +176,8 @@ parseElement(OFXMLElement *element)
@throw [OFInvalidFormatException exception];
}
-@implementation OFString (PropertyListValue)
-- (id)propertyListValue
+@implementation OFString (PropertyListParsing)
+- (id)objectByParsingPropertyList
{
void *pool = objc_autoreleasePoolPush();
OFXMLElement *rootElement = [OFXMLElement elementWithXMLString: self];
diff --git a/src/OFString+Serialization.m b/src/OFString+Serialization.m
index 2cb52a1d..9feabb62 100644
--- a/src/OFString+Serialization.m
+++ b/src/OFString+Serialization.m
@@ -52,7 +52,7 @@ int _OFString_Serialization_reference;
if (version == nil)
@throw [OFInvalidArgumentException exception];
- if (version.decimalValue != 1)
+ if (version.unsignedLongLongValue != 1)
@throw [OFUnsupportedVersionException
exceptionWithVersion: version];
diff --git a/src/OFString.h b/src/OFString.h
index 328bfd6d..a00d7fe6 100644
--- a/src/OFString.h
+++ b/src/OFString.h
@@ -171,43 +171,30 @@ typedef void (^of_string_line_enumeration_block_t)(OFString *line, bool *stop);
@property (readonly, nonatomic) OFString *capitalizedString;
/*!
- * @brief The decimal value of the string as an `intmax_t`.
+ * @brief The decimal value of the string as a `long long`.
*
* Leading and trailing whitespaces are ignored.
*
* If the string contains any non-number characters, an
* @ref OFInvalidFormatException is thrown.
*
- * If the number is too big to fit into an `intmax_t`, an
+ * If the number is too big to fit into a `long long`, an
* @ref OFOutOfRangeException is thrown.
*/
-@property (readonly, nonatomic) intmax_t decimalValue;
+@property (readonly, nonatomic) long long longLongValue;
/*!
- * @brief The hexadecimal value of the string as an `uintmax_t`.
+ * @brief The decimal value of the string as an `unsigned long long`.
*
* Leading and trailing whitespaces are ignored.
*
* If the string contains any non-number characters, an
* @ref OFInvalidFormatException is thrown.
*
- * If the number is too big to fit into an `uintmax_t`, an
+ * If the number is too big to fit into an `unsigned long long`, an
* @ref OFOutOfRangeException is thrown.
*/
-@property (readonly, nonatomic) uintmax_t hexadecimalValue;
-
-/*!
- * @brief The octal value of the string as an `uintmax_t`.
- *
- * Leading and trailing whitespaces are ignored.
- *
- * If the string contains any non-number characters, an
- * @ref OFInvalidFormatException is thrown.
- *
- * If the number is too big to fit into an `uintmax_t`, an
- * @ref OFOutOfRangeException is thrown.
- */
-@property (readonly, nonatomic) uintmax_t octalValue;
+@property (readonly, nonatomic) unsigned long long unsignedLongLongValue;
/*!
* @brief The float value of the string as a float.
@@ -1026,6 +1013,45 @@ typedef void (^of_string_line_enumeration_block_t)(OFString *line, bool *stop);
- (OFString *)substringWithRange: (of_range_t)range;
/*!
+ * @brief The value of the string in the specified base as a `long long`.
+ *
+ * Leading and trailing whitespaces are ignored.
+ *
+ * If the string contains any non-number characters, an
+ * @ref OFInvalidFormatException is thrown.
+ *
+ * If the number is too big to fit into a `long long`, an
+ * @ref OFOutOfRangeException is thrown.
+ *
+ * @param base The base to use. If the base is 0, base 16 is assumed if the
+ * string starts with 0x (after stripping white spaces). If the
+ * string starts with 0, base 8 is assumed. Otherwise, base 10 is
+ * assumed.
+ * @return The value of the string in the specified base
+ */
+- (long long)longLongValueWithBase: (int)base;
+
+/*!
+ * @brief The value of the string in the specified base as an
+ * `unsigned long long`.
+ *
+ * Leading and trailing whitespaces are ignored.
+ *
+ * If the string contains any non-number characters, an
+ * @ref OFInvalidFormatException is thrown.
+ *
+ * If the number is too big to fit into an `unsigned long long`, an
+ * @ref OFOutOfRangeException is thrown.
+ *
+ * @param base The base to use. If the base is 0, base 16 is assumed if the
+ * string starts with 0x (after stripping white spaces). If the
+ * string starts with 0, base 8 is assumed. Otherwise, base 10 is
+ * assumed.
+ * @return The value of the string in the specified base
+ */
+- (unsigned long long)unsignedLongLongValueWithBase: (int)base;
+
+/*!
* @brief Creates a new string by appending another string.
*
* @param string The string to append
@@ -1254,11 +1280,11 @@ OF_ASSUME_NONNULL_END
#include "OFMutableString.h"
#ifdef __OBJC__
# import "OFString+CryptoHashing.h"
-# import "OFString+JSONValue.h"
+# import "OFString+JSONParsing.h"
# ifdef OF_HAVE_FILES
# import "OFString+PathAdditions.h"
# endif
-# import "OFString+PropertyListValue.h"
+# import "OFString+PropertyListParsing.h"
# import "OFString+Serialization.h"
# import "OFString+URLEncoding.h"
# import "OFString+XMLEscaping.h"
diff --git a/src/OFString.m b/src/OFString.m
index 1e10ccde..0adae370 100644
--- a/src/OFString.m
+++ b/src/OFString.m
@@ -17,6 +17,7 @@
#include "config.h"
+#include <ctype.h>
#include <errno.h>
#include <math.h>
#include <stdarg.h>
@@ -126,11 +127,11 @@ void
_references_to_categories_of_OFString(void)
{
_OFString_CryptoHashing_reference = 1;
- _OFString_JSONValue_reference = 1;
+ _OFString_JSONParsing_reference = 1;
#ifdef OF_HAVE_FILES
_OFString_PathAdditions_reference = 1;
#endif
- _OFString_PropertyListValue_reference = 1;
+ _OFString_PropertyListParsing_reference = 1;
_OFString_Serialization_reference = 1;
_OFString_URLEncoding_reference = 1;
_OFString_XMLEscaping_reference = 1;
@@ -990,7 +991,7 @@ decomposedString(OFString *self, const char *const *const *table, size_t size)
encoding: (of_string_encoding_t)encoding
{
char *tmp;
- uintmax_t fileSize;
+ unsigned long long fileSize;
@try {
void *pool = objc_autoreleasePoolPush();
@@ -1008,7 +1009,7 @@ decomposedString(OFString *self, const char *const *const *table, size_t size)
objc_autoreleasePoolPop(pool);
-# if UINTMAX_MAX > SIZE_MAX
+# if ULLONG_MAX > SIZE_MAX
if (fileSize > SIZE_MAX)
@throw [OFOutOfRangeException exception];
#endif
@@ -2313,159 +2314,67 @@ decomposedString(OFString *self, const char *const *const *table, size_t size)
return array;
}
-- (intmax_t)decimalValue
+- (long long)longLongValue
{
- void *pool = objc_autoreleasePoolPush();
- const of_unichar_t *characters = self.characters;
- size_t i = 0, length = self.length;
- intmax_t value = 0;
- bool expectWhitespace = false;
-
- while (length > 0 && of_ascii_isspace(*characters)) {
- characters++;
- length--;
- }
-
- if (length == 0) {
- objc_autoreleasePoolPop(pool);
- return 0;
- }
-
- if (characters[0] == '-' || characters[0] == '+')
- i++;
-
- for (; i < length; i++) {
- if (expectWhitespace) {
- if (of_ascii_isspace(characters[i]))
- continue;
-
- @throw [OFInvalidFormatException exception];
- }
-
- if (characters[i] >= '0' && characters[i] <= '9') {
- if (INTMAX_MAX / 10 < value ||
- INTMAX_MAX - value * 10 < characters[i] - '0')
- @throw [OFOutOfRangeException exception];
-
- value = (value * 10) + (characters[i] - '0');
- } else if (of_ascii_isspace(characters[i]))
- expectWhitespace = true;
- else
- @throw [OFInvalidFormatException exception];
- }
-
- if (characters[0] == '-')
- value *= -1;
-
- objc_autoreleasePoolPop(pool);
-
- return value;
+ return [self longLongValueWithBase: 10];
}
-- (uintmax_t)hexadecimalValue
+- (long long)longLongValueWithBase: (int)base
{
void *pool = objc_autoreleasePoolPush();
- const of_unichar_t *characters = self.characters;
- size_t i = 0, length = self.length;
- uintmax_t value = 0;
- bool expectWhitespace = false, foundValue = false;
-
- while (length > 0 && of_ascii_isspace(*characters)) {
- characters++;
- length--;
- }
-
- if (length == 0) {
- objc_autoreleasePoolPop(pool);
- return 0;
- }
-
- if (length >= 2 && characters[0] == '0' && characters[1] == 'x')
- i = 2;
- else if (length >= 1 && (characters[0] == 'x' || characters[0] == '$'))
- i = 1;
-
- for (; i < length; i++) {
- uintmax_t newValue;
-
- if (expectWhitespace) {
- if (of_ascii_isspace(characters[i]))
- continue;
-
- @throw [OFInvalidFormatException exception];
- }
-
- if (characters[i] >= '0' && characters[i] <= '9') {
- newValue = (value << 4) | (characters[i] - '0');
- foundValue = true;
- } else if (characters[i] >= 'A' && characters[i] <= 'F') {
- newValue = (value << 4) | (characters[i] - 'A' + 10);
- foundValue = true;
- } else if (characters[i] >= 'a' && characters[i] <= 'f') {
- newValue = (value << 4) | (characters[i] - 'a' + 10);
- foundValue = true;
- } else if (characters[i] == 'h' ||
- of_ascii_isspace(characters[i])) {
- expectWhitespace = true;
- continue;
- } else
- @throw [OFInvalidFormatException exception];
+ const char *UTF8String = self.UTF8String;
+ char *endPointer = NULL;
+ long long value;
- if (newValue < value)
- @throw [OFOutOfRangeException exception];
+ errno = 0;
+ value = strtoll(UTF8String, &endPointer, base);
- value = newValue;
- }
+ if ((value == LLONG_MIN || value == LLONG_MAX) && errno == ERANGE)
+ @throw [OFOutOfRangeException exception];
- if (!foundValue)
- @throw [OFInvalidFormatException exception];
+ /* Check if there are any invalid chars left */
+ if (endPointer != NULL)
+ for (; *endPointer != '\0'; endPointer++)
+ /* Use isspace since strtoll uses the same. */
+ if (!isspace((unsigned char)*endPointer))
+ @throw [OFInvalidFormatException exception];
objc_autoreleasePoolPop(pool);
return value;
}
-- (uintmax_t)octalValue
+- (unsigned long long)unsignedLongLongValue
{
- void *pool = objc_autoreleasePoolPush();
- const of_unichar_t *characters = self.characters;
- size_t i = 0, length = self.length;
- uintmax_t value = 0;
- bool expectWhitespace = false;
-
- while (length > 0 && of_ascii_isspace(*characters)) {
- characters++;
- length--;
- }
-
- if (length == 0) {
- objc_autoreleasePoolPop(pool);
- return 0;
- }
+ return [self unsignedLongLongValueWithBase: 10];
+}
- for (; i < length; i++) {
- uintmax_t newValue;
+- (unsigned long long)unsignedLongLongValueWithBase: (int)base
+{
+ void *pool = objc_autoreleasePoolPush();
+ const char *UTF8String = self.UTF8String;
+ char *endPointer = NULL;
+ unsigned long long value;
- if (expectWhitespace) {
- if (of_ascii_isspace(characters[i]))
- continue;
+ /* Use isspace since strtoull uses the same. */
+ while (isspace((unsigned char)*UTF8String))
+ UTF8String++;
- @throw [OFInvalidFormatException exception];
- }
+ if (*UTF8String == '-')
+ @throw [OFInvalidFormatException exception];
- if (characters[i] >= '0' && characters[i] <= '7')
- newValue = (value << 3) | (characters[i] - '0');
- else if (of_ascii_isspace(characters[i])) {
- expectWhitespace = true;
- continue;
- } else
- @throw [OFInvalidFormatException exception];
+ errno = 0;
+ value = strtoull(UTF8String, &endPointer, base);
- if (newValue < value)
- @throw [OFOutOfRangeException exception];
+ if (value == ULLONG_MAX && errno == ERANGE)
+ @throw [OFOutOfRangeException exception];
- value = newValue;
- }
+ /* Check if there are any invalid chars left */
+ if (endPointer != NULL)
+ for (; *endPointer != '\0'; endPointer++)
+ /* Use isspace since strtoull uses the same. */
+ if (!isspace((unsigned char)*endPointer))
+ @throw [OFInvalidFormatException exception];
objc_autoreleasePoolPop(pool);
@@ -2475,8 +2384,6 @@ decomposedString(OFString *self, const char *const *const *table, size_t size)
- (float)floatValue
{
void *pool = objc_autoreleasePoolPush();
-
-#if defined(OF_AMIGAOS_M68K) || defined(OF_MORPHOS)
OFString *stripped = self.stringByDeletingEnclosingWhitespaces;
if ([stripped caseInsensitiveCompare: @"INF"] == OF_ORDERED_SAME ||
@@ -2485,7 +2392,6 @@ decomposedString(OFString *self, const char *const *const *table, size_t size)
if ([stripped caseInsensitiveCompare: @"-INF"] == OF_ORDERED_SAME ||
[stripped caseInsensitiveCompare: @"-INFINITY"] == OF_ORDERED_SAME)
return -INFINITY;
-#endif
#ifdef HAVE_STRTOF_L
const char *UTF8String = self.UTF8String;
@@ -2502,19 +2408,21 @@ decomposedString(OFString *self, const char *const *const *table, size_t size)
char *endPointer = NULL;
float value;
- while (of_ascii_isspace(*UTF8String))
- UTF8String++;
-
+ errno = 0;
#ifdef HAVE_STRTOF_L
value = strtof_l(UTF8String, &endPointer, cLocale);
#else
value = strtof(UTF8String, &endPointer);
#endif
+ if (value == HUGE_VALF && errno == ERANGE)
+ @throw [OFOutOfRangeException exception];
+
/* Check if there are any invalid chars left */
if (endPointer != NULL)
for (; *endPointer != '\0'; endPointer++)
- if (!of_ascii_isspace(*endPointer))
+ /* Use isspace since strtof uses the same. */
+ if (!isspace((unsigned char)*endPointer))
@throw [OFInvalidFormatException exception];
objc_autoreleasePoolPop(pool);
@@ -2525,8 +2433,6 @@ decomposedString(OFString *self, const char *const *const *table, size_t size)
- (double)doubleValue
{
void *pool = objc_autoreleasePoolPush();
-
-#if defined(OF_AMIGAOS_M68K) || defined(OF_MORPHOS)
OFString *stripped = self.stringByDeletingEnclosingWhitespaces;
if ([stripped caseInsensitiveCompare: @"INF"] == OF_ORDERED_SAME ||
@@ -2535,7 +2441,6 @@ decomposedString(OFString *self, const char *const *const *table, size_t size)
if ([stripped caseInsensitiveCompare: @"-INF"] == OF_ORDERED_SAME ||
[stripped caseInsensitiveCompare: @"-INFINITY"] == OF_ORDERED_SAME)
return -INFINITY;
-#endif
#ifdef HAVE_STRTOD_L
const char *UTF8String = self.UTF8String;
@@ -2552,19 +2457,21 @@ decomposedString(OFString *self, const char *const *const *table, size_t size)
char *endPointer = NULL;
double value;
- while (of_ascii_isspace(*UTF8String))
- UTF8String++;
-
+ errno = 0;
#ifdef HAVE_STRTOD_L
value = strtod_l(UTF8String, &endPointer, cLocale);
#else
value = strtod(UTF8String, &endPointer);
#endif
+ if (value == HUGE_VAL && errno == ERANGE)
+ @throw [OFOutOfRangeException exception];
+
/* Check if there are any invalid chars left */
if (endPointer != NULL)
for (; *endPointer != '\0'; endPointer++)
- if (!of_ascii_isspace(*endPointer))
+ /* Use isspace since strtod uses the same. */
+ if (!isspace((unsigned char)*endPointer))
@throw [OFInvalidFormatException exception];
objc_autoreleasePoolPop(pool);
diff --git a/src/OFSystemInfo.m b/src/OFSystemInfo.m
index 6f177b76..7f3d6efc 100644
--- a/src/OFSystemInfo.m
+++ b/src/OFSystemInfo.m
@@ -152,7 +152,7 @@ initOperatingSystemVersion(void)
@try {
OFDictionary *propertyList = [OFString stringWithContentsOfFile:
@"/System/Library/CoreServices/SystemVersion.plist"]
- .propertyListValue;
+ .objectByParsingPropertyList;
operatingSystemVersion = [[propertyList
objectForKey: @"ProductVersion"] copy];
diff --git a/src/OFTarArchiveEntry.h b/src/OFTarArchiveEntry.h
index 7df8a503..76c05c40 100644
--- a/src/OFTarArchiveEntry.h
+++ b/src/OFTarArchiveEntry.h
@@ -53,14 +53,14 @@ typedef enum of_tar_archive_entry_type_t {
@interface OFTarArchiveEntry: OFObject <OFCopying, OFMutableCopying>
{
OFString *_fileName;
- uint32_t _mode;
- uint64_t _size;
- uint32_t _UID, _GID;
+ unsigned long _mode;
+ unsigned long long _size;
+ unsigned long _UID, _GID;
OFDate *_modificationDate;
of_tar_archive_entry_type_t _type;
OFString *_Nullable _targetFileName;
OFString *_Nullable _owner, *_Nullable _group;
- uint32_t _deviceMajor, _deviceMinor;
+ unsigned long _deviceMajor, _deviceMinor;
OF_RESERVE_IVARS(4)
}
@@ -72,22 +72,22 @@ typedef enum of_tar_archive_entry_type_t {
/*!
* @brief The mode of the entry.
*/
-@property (readonly, nonatomic) uint32_t mode;
+@property (readonly, nonatomic) unsigned long mode;
/*!
* @brief The UID of the owner.
*/
-@property (readonly, nonatomic) uint32_t UID;
+@property (readonly, nonatomic) unsigned long UID;
/*!
* @brief The GID of the group.
*/
-@property (readonly, nonatomic) uint32_t GID;
+@property (readonly, nonatomic) unsigned long GID;
/*!
* @brief The size of the file.
*/
-@property (readonly, nonatomic) uint64_t size;
+@property (readonly, nonatomic) unsigned long long size;
/*!
* @brief The date of the last modification of the file.
@@ -120,12 +120,12 @@ typedef enum of_tar_archive_entry_type_t {
/*!
* @brief The device major (if the file is a device).
*/
-@property (readonly, nonatomic) uint32_t deviceMajor;
+@property (readonly, nonatomic) unsigned long deviceMajor;
/*!
* @brief The device major (if the file is a device).
*/
-@property (readonly, nonatomic) uint32_t deviceMinor;
+@property (readonly, nonatomic) unsigned long deviceMinor;
/*!
* @brief Creates a new OFTarArchiveEntry with the specified file name.
diff --git a/src/OFTarArchiveEntry.m b/src/OFTarArchiveEntry.m
index 834559f7..b066c269 100644
--- a/src/OFTarArchiveEntry.m
+++ b/src/OFTarArchiveEntry.m
@@ -53,10 +53,11 @@ stringToBuffer(unsigned char *buffer, OFString *string, size_t length,
buffer[i] = '\0';
}
-static uintmax_t
-octalValueFromBuffer(const unsigned char *buffer, size_t length, uintmax_t max)
+static unsigned long long
+octalValueFromBuffer(const unsigned char *buffer, size_t length,
+ unsigned long long max)
{
- uintmax_t value = 0;
+ unsigned long long value = 0;
if (length == 0)
return 0;
@@ -65,8 +66,8 @@ octalValueFromBuffer(const unsigned char *buffer, size_t length, uintmax_t max)
for (size_t i = 1; i < length; i++)
value = (value << 8) | buffer[i];
} else
- value = stringFromBuffer(buffer, length,
- OF_STRING_ENCODING_ASCII).octalValue;
+ value = [stringFromBuffer(buffer, length,
+ OF_STRING_ENCODING_ASCII) unsignedLongLongValueWithBase: 8];
if (value > max)
@throw [OFOutOfRangeException exception];
@@ -95,18 +96,18 @@ octalValueFromBuffer(const unsigned char *buffer, size_t length, uintmax_t max)
OFString *targetFileName;
_fileName = [stringFromBuffer(header, 100, encoding) copy];
- _mode = (uint32_t)octalValueFromBuffer(
- header + 100, 8, UINT32_MAX);
- _UID = (uint32_t)octalValueFromBuffer(
- header + 108, 8, UINT32_MAX);
- _GID = (uint32_t)octalValueFromBuffer(
- header + 116, 8, UINT32_MAX);
- _size = (uint64_t)octalValueFromBuffer(
- header + 124, 12, UINT64_MAX);
+ _mode = (unsigned long)octalValueFromBuffer(
+ header + 100, 8, ULONG_MAX);
+ _UID = (unsigned long)octalValueFromBuffer(
+ header + 108, 8, ULONG_MAX);
+ _GID = (unsigned long)octalValueFromBuffer(
+ header + 116, 8, ULONG_MAX);
+ _size = (unsigned long long)octalValueFromBuffer(
+ header + 124, 12, ULLONG_MAX);
_modificationDate = [[OFDate alloc]
initWithTimeIntervalSince1970:
(of_time_interval_t)octalValueFromBuffer(
- header + 136, 12, UINTMAX_MAX)];
+ header + 136, 12, ULLONG_MAX)];
_type = header[156];
targetFileName = stringFromBuffer(header + 157, 100, encoding);
@@ -124,10 +125,10 @@ octalValueFromBuffer(const unsigned char *buffer, size_t length, uintmax_t max)
_group = [stringFromBuffer(header + 297, 32, encoding)
copy];
- _deviceMajor = (uint32_t)octalValueFromBuffer(
- header + 329, 8, UINT32_MAX);
- _deviceMinor = (uint32_t)octalValueFromBuffer(
- header + 337, 8, UINT32_MAX);
+ _deviceMajor = (unsigned long)octalValueFromBuffer(
+ header + 329, 8, ULONG_MAX);
+ _deviceMinor = (unsigned long)octalValueFromBuffer(
+ header + 337, 8, ULONG_MAX);
prefix = stringFromBuffer(header + 345, 155, encoding);
if (prefix.length > 0) {
@@ -208,22 +209,22 @@ octalValueFromBuffer(const unsigned char *buffer, size_t length, uintmax_t max)
return _fileName;
}
-- (uint32_t)mode
+- (unsigned long)mode
{
return _mode;
}
-- (uint32_t)UID
+- (unsigned long)UID
{
return _UID;
}
-- (uint32_t)GID
+- (unsigned long)GID
{
return _GID;
}
-- (uint64_t)size
+- (unsigned long long)size
{
return _size;
}
@@ -253,12 +254,12 @@ octalValueFromBuffer(const unsigned char *buffer, size_t length, uintmax_t max)
return _group;
}
-- (uint32_t)deviceMajor
+- (unsigned long)deviceMajor
{
return _deviceMajor;
}
-- (uint32_t)deviceMinor
+- (unsigned long)deviceMinor
{
return _deviceMinor;
}
@@ -294,7 +295,7 @@ octalValueFromBuffer(const unsigned char *buffer, size_t length, uintmax_t max)
encoding: (of_string_encoding_t)encoding
{
unsigned char buffer[512];
- uint64_t modificationDate;
+ unsigned long long modificationDate;
uint16_t checksum = 0;
stringToBuffer(buffer, _fileName, 100, encoding);
@@ -312,7 +313,7 @@ octalValueFromBuffer(const unsigned char *buffer, size_t length, uintmax_t max)
OF_STRING_ENCODING_ASCII);
modificationDate = _modificationDate.timeIntervalSince1970;
stringToBuffer(buffer + 136,
- [OFString stringWithFormat: @"%011" PRIo64 " ", modificationDate],
+ [OFString stringWithFormat: @"%011llo", modificationDate],
12, OF_STRING_ENCODING_ASCII);
/*
diff --git a/src/OFURL.m b/src/OFURL.m
index cc2e57a6..c22ec808 100644
--- a/src/OFURL.m
+++ b/src/OFURL.m
@@ -488,12 +488,12 @@ of_url_verify_escaped(OFString *string, OFCharacterSet *characterSet)
length: UTF8String - tmp2];
if (portString.length == 0 ||
- portString.decimalValue > 65535)
+ portString.unsignedLongLongValue > 65535)
@throw [OFInvalidFormatException
exception];
- _port = [[OFNumber alloc] initWithUInt16:
- (uint16_t)portString.decimalValue];
+ _port = [[OFNumber alloc] initWithUnsignedShort:
+ portString.unsignedLongLongValue];
} else if (*UTF8String != '\0')
@throw [OFInvalidFormatException exception];
@@ -509,11 +509,11 @@ of_url_verify_escaped(OFString *string, OFCharacterSet *characterSet)
portString = [OFString stringWithUTF8String: tmp2];
- if (portString.decimalValue > 65535)
+ if (portString.unsignedLongLongValue > 65535)
@throw [OFInvalidFormatException exception];
- _port = [[OFNumber alloc] initWithUInt16:
- (uint16_t)portString.decimalValue];
+ _port = [[OFNumber alloc] initWithUnsignedShort:
+ portString.unsignedLongLongValue];
} else
_URLEncodedHost = [[OFString alloc]
initWithUTF8String: UTF8String];
diff --git a/src/OFXMLNode.h b/src/OFXMLNode.h
index 48f9c46b..516173cc 100644
--- a/src/OFXMLNode.h
+++ b/src/OFXMLNode.h
@@ -41,14 +41,14 @@ OF_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy) OFString *stringValue;
/*!
- * @brief The contents of the receiver as a decimal value.
+ * @brief The contents of the receiver as a `long long` value.
*/
-@property (readonly, nonatomic) intmax_t decimalValue;
+@property (readonly, nonatomic) long long longLongValue;
/*!
- * @brief The contents of the receiver as a hexadecimal value.
+ * @brief The contents of the receiver as an `unsigned long long` value.
*/
-@property (readonly, nonatomic) uintmax_t hexadecimalValue;
+@property (readonly, nonatomic) unsigned long long unsignedLongLongValue;
/*!
* @brief The contents of the receiver as a float value.
@@ -89,6 +89,32 @@ OF_ASSUME_NONNULL_BEGIN
*/
- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
level: (unsigned int)level;
+
+/*!
+ * @brief The contents of the receiver as a `long long` value in the specified
+ * base.
+ *
+ * @param base The base to use. If the base is 0, base 16 is assumed if the
+ * string starts with 0x (after stripping white spaces). If the
+ * string starts with 0, base 8 is assumed. Otherwise, base 10 is
+ * assumed.
+ * @return The contents of the receiver as a `long long` value in the specified
+ * base
+ */
+- (long long)longLongValueWithBase: (int)base;
+
+/*!
+ * @brief The contents of the receiver as an `unsigned long long` value in the
+ * specified base.
+ *
+ * @param base The base to use. If the base is 0, base 16 is assumed if the
+ * string starts with 0x (after stripping white spaces). If the
+ * string starts with 0, base 8 is assumed. Otherwise, base 10 is
+ * assumed.
+ * @return The contents of the receiver as an `unsigned long long` value in the
+ * specified base
+ */
+- (unsigned long long)unsignedLongLongValueWithBase: (int)base;
@end
OF_ASSUME_NONNULL_END
diff --git a/src/OFXMLNode.m b/src/OFXMLNode.m
index 16501cda..564bb621 100644
--- a/src/OFXMLNode.m
+++ b/src/OFXMLNode.m
@@ -46,14 +46,24 @@
OF_UNRECOGNIZED_SELECTOR
}
-- (intmax_t)decimalValue
+- (long long)longLongValue
{
- return self.stringValue.decimalValue;
+ return self.stringValue.longLongValue;
}
-- (uintmax_t)hexadecimalValue
+- (long long)longLongValueWithBase: (int)base
{
- return self.stringValue.hexadecimalValue;
+ return [self.stringValue longLongValueWithBase: base];
+}
+
+- (unsigned long long)unsignedLongLongValue
+{
+ return self.stringValue.unsignedLongLongValue;
+}
+
+- (unsigned long long)unsignedLongLongValueWithBase: (int)base
+{
+ return [self.stringValue unsignedLongLongValueWithBase: base];
}
- (float)floatValue
diff --git a/src/bridge/Info.plist.in b/src/bridge/Info.plist.in
index 82d9c118..2ddbc84f 100644
--- a/src/bridge/Info.plist.in
+++ b/src/bridge/Info.plist.in
@@ -7,7 +7,7 @@
<key>CFBundleName</key>
<string>ObjFWBridge</string>
<key>CFBundleIdentifier</key>
- <string>zone.heap.objfw.bridge</string>
+ <string>im.nil.objfw.bridge</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
diff --git a/src/runtime/Info.plist.in b/src/runtime/Info.plist.in
new file mode 100644
index 00000000..331f4686
--- /dev/null
+++ b/src/runtime/Info.plist.in
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleExecutable</key>
+ <string>ObjFWRT</string>
+ <key>CFBundleName</key>
+ <string>ObjFWRT</string>
+ <key>CFBundleIdentifier</key>
+ <string>im.nil.objfw.rt</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>FMWK</string>
+ <key>CFBundleVersion</key>
+ <string>@BUNDLE_VERSION@</string>
+ <key>CFBundleShortVersionString</key>
+ <string>@BUNDLE_SHORT_VERSION@</string>
+ <key>MinimumOSVersion</key>
+ <string>9.0</string>
+</dict>
+</plist>
diff --git a/src/runtime/Makefile b/src/runtime/Makefile
index bf070c52..46b9a5e4 100644
--- a/src/runtime/Makefile
+++ b/src/runtime/Makefile
@@ -3,6 +3,7 @@ include ../../extra.mk
SUBDIRS = lookup-asm
SUBDIRS_AFTER = ${LINKLIB}
CLEAN = amiga-library-functable.inc inline.h
+DISTCLEAN = Info.plist
SHARED_LIB = ${OBJFWRT_SHARED_LIB}
STATIC_LIB = ${OBJFWRT_STATIC_LIB}
diff --git a/src/runtime/lookup-asm/lookup-asm-x86_64-macho.S b/src/runtime/lookup-asm/lookup-asm-x86_64-macho.S
index f0209652..8e9d3f83 100644
--- a/src/runtime/lookup-asm/lookup-asm-x86_64-macho.S
+++ b/src/runtime/lookup-asm/lookup-asm-x86_64-macho.S
@@ -59,7 +59,7 @@ Ltagged_pointer_$0:
and dil, 0xE
movzx r8, dil
- mov rax, [rip+_objc_tagged_pointer_classes]
+ mov rax, [rip+_objc_tagged_pointer_classes@GOTPCREL]
mov r8, [rax+r8*4]
mov r8, [r8+64]
diff --git a/src/socket.m b/src/socket.m
index bcc2caa2..0488ec95 100644
--- a/src/socket.m
+++ b/src/socket.m
@@ -376,7 +376,7 @@ of_socket_address_parse_ipv4(OFString *IPv4, uint16_t port)
addr = 0;
for (OFString *component in components) {
- intmax_t number;
+ unsigned long long number;
if (component.length == 0)
@throw [OFInvalidFormatException exception];
@@ -385,9 +385,9 @@ of_socket_address_parse_ipv4(OFString *IPv4, uint16_t port)
whitespaceCharacterSet] != OF_NOT_FOUND)
@throw [OFInvalidFormatException exception];
- number = component.decimalValue;
+ number = component.unsignedLongLongValue;
- if (number < 0 || number > UINT8_MAX)
+ if (number > UINT8_MAX)
@throw [OFInvalidFormatException exception];
addr = (addr << 8) | (number & 0xFF);
@@ -403,13 +403,13 @@ of_socket_address_parse_ipv4(OFString *IPv4, uint16_t port)
static uint16_t
parseIPv6Component(OFString *component)
{
- uintmax_t number;
+ unsigned long long number;
if ([component indexOfCharacterFromSet:
[OFCharacterSet whitespaceCharacterSet]] != OF_NOT_FOUND)
@throw [OFInvalidFormatException exception];
- number = component.hexadecimalValue;
+ number = [component unsignedLongLongValueWithBase: 16];
if (number > UINT16_MAX)
@throw [OFInvalidFormatException exception];
diff --git a/tests/Info.plist.in b/tests/Info.plist.in
index b7c31309..38918663 100644
--- a/tests/Info.plist.in
+++ b/tests/Info.plist.in
@@ -13,9 +13,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleVersion</key>
- <string>@PACKAGE_VERSION@</string>
+ <string>@BUNDLE_VERSION@</string>
<key>CFBundleShortVersionString</key>
- <string>@PACKAGE_VERSION@</string>
+ <string>@BUNDLE_SHORT_VERSION@</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
diff --git a/tests/Makefile b/tests/Makefile
index f9ad1757..063bd9f8 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -11,8 +11,8 @@ DISTCLEAN = Info.plist
PROG_NOINST = tests${PROG_SUFFIX}
STATIC_LIB_NOINST = ${TESTS_STATIC_LIB}
SRCS = ForwardingTests.m \
+ OFASN1DERParsingTests.m \
OFASN1DERRepresentationTests.m \
- OFASN1DERValueTests.m \
OFArrayTests.m \
${OF_BLOCK_TESTS_M} \
OFCharacterSetTests.m \
diff --git a/tests/OFASN1DERValueTests.m b/tests/OFASN1DERParsingTests.m
index 8cf2a033..df836392 100644
--- a/tests/OFASN1DERValueTests.m
+++ b/tests/OFASN1DERParsingTests.m
@@ -19,10 +19,10 @@
#import "TestsAppDelegate.h"
-static OFString *module = @"OFData+ASN1DERValue";
+static OFString *module = @"OFData+ASN1DERParsing";
-@implementation TestsAppDelegate (OFASN1DERValueTests)
-- (void)ASN1DERValueTests
+@implementation TestsAppDelegate (OFASN1DERParsingTests)
+- (void)ASN1DERParsingTests
{
void *pool = objc_autoreleasePoolPush();
OFASN1BitString *bitString;
@@ -33,74 +33,89 @@ static OFString *module = @"OFData+ASN1DERValue";
/* Boolean */
TEST(@"Parsing of boolean",
![[[OFData dataWithItems: "\x01\x01\x00"
- count: 3] ASN1DERValue] booleanValue] &&
+ count: 3] objectByParsingASN1DER]
+ booleanValue] &&
[[[OFData dataWithItems: "\x01\x01\xFF"
- count: 3] ASN1DERValue] booleanValue])
+ count: 3] objectByParsingASN1DER] booleanValue])
EXPECT_EXCEPTION(@"Detection of invalid boolean #1",
- OFInvalidFormatException, [[OFData dataWithItems: "\x01\x01\x01"
- count: 3] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x01\x01\x01"
+ count: 3] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid boolean #2",
- OFInvalidFormatException, [[OFData dataWithItems: "\x01\x02\x00\x00"
- count: 4] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x01\x02\x00\x00"
+ count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid boolean #3",
- OFInvalidFormatException, [[OFData dataWithItems: "\x01\x00"
- count: 2] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x01\x00"
+ count: 2] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated boolean",
- OFTruncatedDataException, [[OFData dataWithItems: "\x01\x01"
- count: 2] ASN1DERValue])
+ OFTruncatedDataException,
+ [[OFData dataWithItems: "\x01\x01"
+ count: 2] objectByParsingASN1DER])
/* Integer */
TEST(@"Parsing of integer",
[[[OFData dataWithItems: "\x02\x00"
- count: 2] ASN1DERValue] integerValue] == 0 &&
+ count: 2] objectByParsingASN1DER]
+ longLongValue] == 0 &&
[[[OFData dataWithItems: "\x02\x01\x01"
- count: 3] ASN1DERValue] integerValue] == 1 &&
+ count: 3] objectByParsingASN1DER]
+ longLongValue] == 1 &&
[[[OFData dataWithItems: "\x02\x02\x01\x04"
- count: 4] ASN1DERValue] integerValue] == 260 &&
+ count: 4] objectByParsingASN1DER]
+ longLongValue] == 260 &&
[[[OFData dataWithItems: "\x02\x01\xFF"
- count: 3] ASN1DERValue] integerValue] == -1 &&
+ count: 3] objectByParsingASN1DER]
+ longLongValue] == -1 &&
[[[OFData dataWithItems: "\x02\x03\xFF\x00\x00"
- count: 5] ASN1DERValue] integerValue] == -65536 &&
- (uintmax_t)[[[OFData dataWithItems: "\x02\x09\x00\xFF\xFF\xFF\xFF"
- "\xFF\xFF\xFF\xFF"
- count: 11] ASN1DERValue]
- integerValue] == UINTMAX_MAX)
+ count: 5] objectByParsingASN1DER]
+ longLongValue] == -65536 &&
+ (unsigned long long)[[[OFData dataWithItems: "\x02\x09\x00\xFF\xFF"
+ "\xFF\xFF\xFF\xFF\xFF"
+ "\xFF"
+ count: 11]
+ objectByParsingASN1DER] longLongValue] == ULLONG_MAX)
EXPECT_EXCEPTION(@"Detection of invalid integer #1",
- OFInvalidFormatException, [[OFData dataWithItems: "\x02\x02\x00\x00"
- count: 4] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x02\x02\x00\x00"
+ count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid integer #2",
- OFInvalidFormatException, [[OFData dataWithItems: "\x02\x02\x00\x7F"
- count: 4] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x02\x02\x00\x7F"
+ count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid integer #3",
- OFInvalidFormatException, [[OFData dataWithItems: "\x02\x02\xFF\x80"
- count: 4] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x02\x02\xFF\x80"
+ count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of out of range integer",
OFOutOfRangeException,
[[OFData dataWithItems: "\x02\x09\x01"
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
- count: 11] ASN1DERValue])
+ count: 11] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated integer",
- OFTruncatedDataException, [[OFData dataWithItems: "\x02\x02\x00"
- count: 3] ASN1DERValue])
+ OFTruncatedDataException,
+ [[OFData dataWithItems: "\x02\x02\x00"
+ count: 3] objectByParsingASN1DER])
/* Bit string */
TEST(@"Parsing of bit string",
(bitString = [[OFData dataWithItems: "\x03\x01\x00"
- count: 3] ASN1DERValue]) &&
+ count: 3] objectByParsingASN1DER]) &&
[bitString.bitStringValue isEqual: [OFData dataWithItems: ""
- count: 0]] &&
+ count: 0]] &&
bitString.bitStringLength == 0 &&
(bitString = [[OFData dataWithItems: "\x03\x0D\x01Hello World\x80"
- count: 15] ASN1DERValue]) &&
+ count: 15] objectByParsingASN1DER]) &&
[bitString.bitStringValue
isEqual: [OFData dataWithItems: "Hello World\x80"
count: 12]] &&
@@ -110,7 +125,7 @@ static OFString *module = @"OFData+ASN1DERValue";
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxx"
- count: 131] ASN1DERValue]) &&
+ count: 131] objectByParsingASN1DER]) &&
[bitString.bitStringValue
isEqual: [OFData dataWithItems: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@@ -120,176 +135,199 @@ static OFString *module = @"OFData+ASN1DERValue";
bitString.bitStringLength == 127 * 8)
EXPECT_EXCEPTION(@"Detection of invalid bit string #1",
- OFInvalidFormatException, [[OFData dataWithItems: "\x03\x00"
- count: 2] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x03\x00"
+ count: 2] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid bit string #2",
- OFInvalidFormatException, [[OFData dataWithItems: "\x03\x01\x01"
- count: 3] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x03\x01\x01"
+ count: 3] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of out of range bit string",
OFOutOfRangeException,
[[OFData dataWithItems: "\x03\x89"
"\x01\x01\x01\x01\x01\x01\x01\x01\x01"
- count: 11] ASN1DERValue])
+ count: 11] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated bit string",
- OFTruncatedDataException, [[OFData dataWithItems: "\x03\x01"
- count: 2] ASN1DERValue])
+ OFTruncatedDataException,
+ [[OFData dataWithItems: "\x03\x01"
+ count: 2] objectByParsingASN1DER])
/* Octet string */
TEST(@"Parsing of octet string",
[[[[OFData dataWithItems: "\x04\x0CHello World!"
- count: 14] ASN1DERValue] octetStringValue]
- isEqual: [OFData dataWithItems: "Hello World!"
- count: 12]] &&
+ count: 14] objectByParsingASN1DER]
+ octetStringValue] isEqual: [OFData dataWithItems: "Hello World!"
+ count: 12]] &&
[[[[OFData dataWithItems: "\x04\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxx"
- count: 131] ASN1DERValue] octetStringValue]
- isEqual: [OFData dataWithItems: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- "xxxxxxxxxxxxxxxxxxxxxxxxxx"
- count: 128]])
+ count: 131] objectByParsingASN1DER]
+ octetStringValue] isEqual:
+ [OFData dataWithItems: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ count: 128]])
EXPECT_EXCEPTION(@"Detection of out of range octet string",
OFOutOfRangeException,
[[OFData dataWithItems: "\x04\x89"
"\x01\x01\x01\x01\x01\x01\x01\x01\x01"
- count: 11] ASN1DERValue])
+ count: 11] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated octet string",
- OFTruncatedDataException, [[OFData dataWithItems: "\x04\x01"
- count: 2] ASN1DERValue])
+ OFTruncatedDataException,
+ [[OFData dataWithItems: "\x04\x01"
+ count: 2] objectByParsingASN1DER])
/* Null */
TEST(@"Parsing of null",
[[[OFData dataWithItems: "\x05\x00"
- count: 2] ASN1DERValue] isEqual: [OFNull null]])
+ count: 2] objectByParsingASN1DER]
+ isEqual: [OFNull null]])
EXPECT_EXCEPTION(@"Detection of invalid null",
- OFInvalidFormatException, [[OFData dataWithItems: "\x05\x01\x00"
- count: 3] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x05\x01\x00"
+ count: 3] objectByParsingASN1DER])
/* Object Identifier */
TEST(@"Parsing of Object Identifier",
(array = [[[OFData dataWithItems: "\x06\x01\x27"
- count: 3] ASN1DERValue]
+ count: 3] objectByParsingASN1DER]
subidentifiers]) && array.count == 2 &&
- [[array objectAtIndex: 0] uIntMaxValue] == 0 &&
- [[array objectAtIndex: 1] uIntMaxValue] == 39 &&
+ [[array objectAtIndex: 0] unsignedLongLongValue] == 0 &&
+ [[array objectAtIndex: 1] unsignedLongLongValue] == 39 &&
(array = [[[OFData dataWithItems: "\x06\x01\x4F"
- count: 3] ASN1DERValue]
+ count: 3] objectByParsingASN1DER]
subidentifiers]) && array.count == 2 &&
- [[array objectAtIndex: 0] uIntMaxValue] == 1 &&
- [[array objectAtIndex: 1] uIntMaxValue] == 39 &&
+ [[array objectAtIndex: 0] unsignedLongLongValue] == 1 &&
+ [[array objectAtIndex: 1] unsignedLongLongValue] == 39 &&
(array = [[[OFData dataWithItems: "\x06\x02\x88\x37"
- count: 4] ASN1DERValue]
+ count: 4] objectByParsingASN1DER]
subidentifiers]) && array.count == 2 &&
- [[array objectAtIndex: 0] uIntMaxValue] == 2 &&
- [[array objectAtIndex: 1] uIntMaxValue] == 999 &&
+ [[array objectAtIndex: 0] unsignedLongLongValue] == 2 &&
+ [[array objectAtIndex: 1] unsignedLongLongValue] == 999 &&
(array = [[[OFData dataWithItems: "\x06\x09\x2A\x86\x48\x86\xF7\x0D"
"\x01\x01\x0B"
- count: 11] ASN1DERValue]
+ count: 11] objectByParsingASN1DER]
subidentifiers]) && array.count == 7 &&
- [[array objectAtIndex: 0] uIntMaxValue] == 1 &&
- [[array objectAtIndex: 1] uIntMaxValue] == 2 &&
- [[array objectAtIndex: 2] uIntMaxValue] == 840 &&
- [[array objectAtIndex: 3] uIntMaxValue] == 113549 &&
- [[array objectAtIndex: 4] uIntMaxValue] == 1 &&
- [[array objectAtIndex: 5] uIntMaxValue] == 1 &&
- [[array objectAtIndex: 6] uIntMaxValue] == 11)
+ [[array objectAtIndex: 0] unsignedLongLongValue] == 1 &&
+ [[array objectAtIndex: 1] unsignedLongLongValue] == 2 &&
+ [[array objectAtIndex: 2] unsignedLongLongValue] == 840 &&
+ [[array objectAtIndex: 3] unsignedLongLongValue] == 113549 &&
+ [[array objectAtIndex: 4] unsignedLongLongValue] == 1 &&
+ [[array objectAtIndex: 5] unsignedLongLongValue] == 1 &&
+ [[array objectAtIndex: 6] unsignedLongLongValue] == 11)
EXPECT_EXCEPTION(@"Detection of invalid Object Identifier #1",
- OFInvalidFormatException, [[OFData dataWithItems: "\x06\x01\x81"
- count: 3] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x06\x01\x81"
+ count: 3] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid Object Identifier #2",
- OFInvalidFormatException, [[OFData dataWithItems: "\x06\x02\x80\x01"
- count: 4] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x06\x02\x80\x01"
+ count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of out of range Object Identifier",
OFOutOfRangeException,
[[OFData dataWithItems: "\x06\x0A\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
"\xFF\x7F"
- count: 12] ASN1DERValue])
+ count: 12] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated Object Identifier",
- OFTruncatedDataException, [[OFData dataWithItems: "\x06\x02\x00"
- count: 3] ASN1DERValue])
+ OFTruncatedDataException,
+ [[OFData dataWithItems: "\x06\x02\x00"
+ count: 3] objectByParsingASN1DER])
/* Enumerated */
TEST(@"Parsing of enumerated",
[[[OFData dataWithItems: "\x0A\x00"
- count: 2] ASN1DERValue] integerValue] == 0 &&
+ count: 2] objectByParsingASN1DER] longLongValue] ==
+ 0 &&
[[[OFData dataWithItems: "\x0A\x01\x01"
- count: 3] ASN1DERValue] integerValue] == 1 &&
+ count: 3] objectByParsingASN1DER] longLongValue] ==
+ 1 &&
[[[OFData dataWithItems: "\x0A\x02\x01\x04"
- count: 4] ASN1DERValue] integerValue] == 260 &&
+ count: 4] objectByParsingASN1DER] longLongValue] ==
+ 260 &&
[[[OFData dataWithItems: "\x0A\x01\xFF"
- count: 3] ASN1DERValue] integerValue] == -1 &&
+ count: 3] objectByParsingASN1DER] longLongValue] ==
+ -1 &&
[[[OFData dataWithItems: "\x0A\x03\xFF\x00\x00"
- count: 5] ASN1DERValue] integerValue] == -65536 &&
- (uintmax_t)[[[OFData dataWithItems: "\x0A\x09\x00\xFF\xFF\xFF\xFF"
- "\xFF\xFF\xFF\xFF"
- count: 11] ASN1DERValue]
- integerValue] == UINTMAX_MAX)
+ count: 5] objectByParsingASN1DER] longLongValue] ==
+ -65536 &&
+ (unsigned long long)[[[OFData dataWithItems: "\x0A\x09\x00\xFF\xFF"
+ "\xFF\xFF\xFF\xFF\xFF"
+ "\xFF"
+ count: 11]
+ objectByParsingASN1DER] longLongValue] == ULLONG_MAX)
EXPECT_EXCEPTION(@"Detection of invalid enumerated #1",
- OFInvalidFormatException, [[OFData dataWithItems: "\x0A\x02\x00\x00"
- count: 4] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x0A\x02\x00\x00"
+ count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid enumerated #2",
- OFInvalidFormatException, [[OFData dataWithItems: "\x0A\x02\x00\x7F"
- count: 4] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x0A\x02\x00\x7F"
+ count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid enumerated #3",
- OFInvalidFormatException, [[OFData dataWithItems: "\x0A\x02\xFF\x80"
- count: 4] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x0A\x02\xFF\x80"
+ count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of out of range enumerated",
OFOutOfRangeException,
[[OFData dataWithItems: "\x0A\x09\x01"
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
- count: 11] ASN1DERValue])
+ count: 11] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated enumerated",
- OFTruncatedDataException, [[OFData dataWithItems: "\x0A\x02\x00"
- count: 3] ASN1DERValue])
+ OFTruncatedDataException,
+ [[OFData dataWithItems: "\x0A\x02\x00"
+ count: 3] objectByParsingASN1DER])
/* UTF-8 string */
TEST(@"Parsing of UTF-8 string",
[[[[OFData dataWithItems: "\x0C\x0EHällo Wörld!"
- count: 16] ASN1DERValue] UTF8StringValue]
- isEqual: @"Hällo Wörld!"] &&
+ count: 16] objectByParsingASN1DER]
+ UTF8StringValue] isEqual: @"Hällo Wörld!"] &&
[[[[OFData dataWithItems: "\x0C\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxx"
- count: 131] ASN1DERValue] UTF8StringValue]
- isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- @"xxxxxxxxxxxxxxxx"])
+ count: 131] objectByParsingASN1DER]
+ UTF8StringValue] isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ @"xxxxxxxxxxx"])
EXPECT_EXCEPTION(@"Detection of out of range UTF-8 string",
OFOutOfRangeException,
[[OFData dataWithItems: "\x0C\x89"
"\x01\x01\x01\x01\x01\x01\x01\x01\x01"
- count: 11] ASN1DERValue])
+ count: 11] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated UTF-8 string",
- OFTruncatedDataException, [[OFData dataWithItems: "\x0C\x01"
- count: 2] ASN1DERValue])
+ OFTruncatedDataException,
+ [[OFData dataWithItems: "\x0C\x01"
+ count: 2] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated length",
- OFTruncatedDataException, [[OFData dataWithItems: "\x0C\x83\x01\x01"
- count: 4] ASN1DERValue])
+ OFTruncatedDataException,
+ [[OFData dataWithItems: "\x0C\x83\x01\x01"
+ count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid / inefficient length #1",
- OFInvalidFormatException, [[OFData dataWithItems: "\x0C\x81\x7F"
- count: 3] ASN1DERValue])
+ OFInvalidFormatException,
+ [[OFData dataWithItems: "\x0C\x81\x7F"
+ count: 3] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid / inefficient length #2",
OFInvalidFormatException,
@@ -297,140 +335,148 @@ static OFString *module = @"OFData+ASN1DERValue";
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxx"
- count: 132] ASN1DERValue])
+ count: 132] objectByParsingASN1DER])
/* Sequence */
TEST(@"Parsing of sequence",
(array = [[OFData dataWithItems: "\x30\x00"
- count: 2] ASN1DERValue]) &&
+ count: 2] objectByParsingASN1DER]) &&
[array isKindOfClass: [OFArray class]] && array.count == 0 &&
(array = [[OFData dataWithItems: "\x30\x09\x02\x01\x7B\x0C\x04Test"
- count: 11] ASN1DERValue]) &&
+ count: 11] objectByParsingASN1DER]) &&
[array isKindOfClass: [OFArray class]] && array.count == 2 &&
- [[array objectAtIndex: 0] integerValue] == 123 &&
+ [[array objectAtIndex: 0] longLongValue] == 123 &&
[[[array objectAtIndex: 1] stringValue] isEqual: @"Test"])
EXPECT_EXCEPTION(@"Detection of truncated sequence #1",
- OFTruncatedDataException, [[OFData dataWithItems: "\x30\x01"
- count: 2] ASN1DERValue])
+ OFTruncatedDataException,
+ [[OFData dataWithItems: "\x30\x01"
+ count: 2] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated sequence #2",
OFTruncatedDataException,
[[OFData dataWithItems: "\x30\x04\x02\x01\x01\x00\x00"
- count: 7] ASN1DERValue])
+ count: 7] objectByParsingASN1DER])
/* Set */
TEST(@"Parsing of set",
(set = [[OFData dataWithItems: "\x31\x00"
- count: 2] ASN1DERValue]) &&
+ count: 2] objectByParsingASN1DER]) &&
[set isKindOfClass: [OFSet class]] && set.count == 0 &&
(set = [[OFData dataWithItems: "\x31\x09\x02\x01\x7B\x0C\x04Test"
- count: 11] ASN1DERValue]) &&
+ count: 11] objectByParsingASN1DER]) &&
[set isKindOfClass: [OFSet class]] && set.count == 2 &&
(enumerator = [set objectEnumerator]) &&
- [[enumerator nextObject] integerValue] == 123 &&
+ [[enumerator nextObject] longLongValue] == 123 &&
[[[enumerator nextObject] stringValue] isEqual: @"Test"])
EXPECT_EXCEPTION(@"Detection of invalid set",
OFInvalidFormatException,
[[OFData dataWithItems: "\x31\x06\x02\x01\x02\x02\x01\x01"
- count: 8] ASN1DERValue])
+ count: 8] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated set #1",
- OFTruncatedDataException, [[OFData dataWithItems: "\x31\x01"
- count: 2] ASN1DERValue])
+ OFTruncatedDataException,
+ [[OFData dataWithItems: "\x31\x01"
+ count: 2] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated set #2",
OFTruncatedDataException,
[[OFData dataWithItems: "\x31\x04\x02\x01\x01\x00\x00"
- count: 7] ASN1DERValue])
+ count: 7] objectByParsingASN1DER])
/* NumericString */
TEST(@"Parsing of NumericString",
[[[[OFData dataWithItems: "\x12\x0B" "12345 67890"
- count: 13] ASN1DERValue] numericStringValue]
- isEqual: @"12345 67890"] &&
+ count: 13] objectByParsingASN1DER]
+ numericStringValue] isEqual: @"12345 67890"] &&
[[[[OFData dataWithItems: "\x12\x81\x80" "0000000000000000000000000"
"0000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000"
"00000000000000000000000"
- count: 131] ASN1DERValue] numericStringValue]
- isEqual: @"00000000000000000000000000000000000000000000000000000000"
- @"00000000000000000000000000000000000000000000000000000000"
- @"0000000000000000"])
+ count: 131] objectByParsingASN1DER]
+ numericStringValue] isEqual: @"000000000000000000000000000000000000"
+ @"000000000000000000000000000000000000"
+ @"000000000000000000000000000000000000"
+ @"00000000000000000000"])
EXPECT_EXCEPTION(@"Detection of invalid NumericString",
OFInvalidEncodingException,
[[OFData dataWithItems: "\x12\x02."
- count: 4] ASN1DERValue])
+ count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of out of range NumericString",
OFOutOfRangeException,
[[OFData dataWithItems: "\x12\x89"
"\x01\x01\x01\x01\x01\x01\x01\x01\x01"
- count: 11] ASN1DERValue])
+ count: 11] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated NumericString",
- OFTruncatedDataException, [[OFData dataWithItems: "\x12\x01"
- count: 2] ASN1DERValue])
+ OFTruncatedDataException,
+ [[OFData dataWithItems: "\x12\x01"
+ count: 2] objectByParsingASN1DER])
/* PrintableString */
TEST(@"Parsing of PrintableString",
[[[[OFData dataWithItems: "\x13\x0CHello World."
- count: 14] ASN1DERValue] printableStringValue]
- isEqual: @"Hello World."] &&
+ count: 14] objectByParsingASN1DER]
+ printableStringValue] isEqual: @"Hello World."] &&
[[[[OFData dataWithItems: "\x13\x81\x80 '()+,-./:=?abcdefghijklmnop"
"qrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '()"
"+,-./:=?abcdefghijklmnopqrstuvwxyzABCDEF"
"GHIJKLMNOPQRSTUVWXYZ"
- count: 131] ASN1DERValue] printableStringValue]
- isEqual: @" '()+,-./:=?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR"
- @"STUVWXYZ '()+,-./:=?abcdefghijklmnopqrstuvwxyzABCDEFGHIJ"
- @"KLMNOPQRSTUVWXYZ"])
+ count: 131] objectByParsingASN1DER]
+ printableStringValue] isEqual: @" '()+,-./:=?abcdefghijklmnopqrstuv"
+ @"wxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '()"
+ @"+,-./:=?abcdefghijklmnopqrstuvwxyz"
+ @"ABCDEFGHIJKLMNOPQRSTUVWXYZ"])
EXPECT_EXCEPTION(@"Detection of invalid PrintableString",
OFInvalidEncodingException,
[[OFData dataWithItems: "\x13\x02;"
- count: 4] ASN1DERValue])
+ count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of out of range PrintableString",
OFOutOfRangeException,
[[OFData dataWithItems: "\x13\x89"
"\x01\x01\x01\x01\x01\x01\x01\x01\x01"
- count: 11] ASN1DERValue])
+ count: 11] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated PrintableString",
- OFTruncatedDataException, [[OFData dataWithItems: "\x13\x01"
- count: 2] ASN1DERValue])
+ OFTruncatedDataException,
+ [[OFData dataWithItems: "\x13\x01"
+ count: 2] objectByParsingASN1DER])
/* IA5String */
TEST(@"Parsing of IA5String",
[[[[OFData dataWithItems: "\x16\x0CHello World!"
- count: 14] ASN1DERValue] IA5StringValue]
- isEqual: @"Hello World!"] &&
+ count: 14] objectByParsingASN1DER]
+ IA5StringValue] isEqual: @"Hello World!"] &&
[[[[OFData dataWithItems: "\x16\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxx"
- count: 131] ASN1DERValue] IA5StringValue]
- isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- @"xxxxxxxxxxxxxxxx"])
+ count: 131] objectByParsingASN1DER]
+ IA5StringValue] isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ @"xxxxxxxx"])
EXPECT_EXCEPTION(@"Detection of invalid IA5String",
OFInvalidEncodingException,
[[OFData dataWithItems: "\x16\x02ä"
- count: 4] ASN1DERValue])
+ count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of out of range IA5String",
OFOutOfRangeException,
[[OFData dataWithItems: "\x16\x89"
"\x01\x01\x01\x01\x01\x01\x01\x01\x01"
- count: 11] ASN1DERValue])
+ count: 11] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated IA5String",
- OFTruncatedDataException, [[OFData dataWithItems: "\x16\x01"
- count: 2] ASN1DERValue])
+ OFTruncatedDataException,
+ [[OFData dataWithItems: "\x16\x01"
+ count: 2] objectByParsingASN1DER])
objc_autoreleasePoolPop(pool);
}
diff --git a/tests/OFArrayTests.m b/tests/OFArrayTests.m
index 336f58f9..3300777d 100644
--- a/tests/OFArrayTests.m
+++ b/tests/OFArrayTests.m
@@ -422,10 +422,10 @@ static OFString *c_ary[] = {
TEST(@"-[valueForKey:]",
[[[arrayClass arrayWithObjects: @"foo", @"bar", @"quxqux", nil]
valueForKey: @"length"] isEqual:
- [arrayClass arrayWithObjects: [OFNumber numberWithSize: 3],
- [OFNumber numberWithSize: 3], [OFNumber numberWithSize: 6], nil]] &&
+ [arrayClass arrayWithObjects: [OFNumber numberWithInt: 3],
+ [OFNumber numberWithInt: 3], [OFNumber numberWithInt: 6], nil]] &&
[[[arrayClass arrayWithObjects: @"1", @"2", nil]
- valueForKey: @"@count"] isEqual: [OFNumber numberWithSize: 2]])
+ valueForKey: @"@count"] isEqual: [OFNumber numberWithInt: 2]])
m[0] = [mutableArrayClass arrayWithObjects:
[OFMutableURL URLWithString: @"http://foo.bar/"],
diff --git a/tests/OFDictionaryTests.m b/tests/OFDictionaryTests.m
index 4fc626ad..75b1d420 100644
--- a/tests/OFDictionaryTests.m
+++ b/tests/OFDictionaryTests.m
@@ -182,7 +182,7 @@ static OFString *values[] = {
TEST(@"-[valueForKey:]",
[[mutDict valueForKey: keys[0]] isEqual: values[0]] &&
[[mutDict valueForKey: @"@count"] isEqual:
- [OFNumber numberWithSize: 2]])
+ [OFNumber numberWithInt: 2]])
EXPECT_EXCEPTION(@"Catching -[setValue:forKey:] on immutable "
@"dictionary", OFUndefinedKeyException,
diff --git a/tests/OFJSONTests.m b/tests/OFJSONTests.m
index 9ee278b4..6ef2f114 100644
--- a/tests/OFJSONTests.m
+++ b/tests/OFJSONTests.m
@@ -38,7 +38,7 @@ static OFString *module = @"OFJSON";
nil],
nil];
- TEST(@"-[JSONValue] #1", [s.JSONValue isEqual: d])
+ TEST(@"-[objectByParsingJSON] #1", [s.objectByParsingJSON isEqual: d])
TEST(@"-[JSONRepresentation]", [[d JSONRepresentation] isEqual:
@"{\"x\":[0.5,15,null,\"foo\",false],\"foo\":\"b\\na\\r\"}"])
@@ -52,18 +52,18 @@ static OFString *module = @"OFJSON";
[[d JSONRepresentationWithOptions: OF_JSON_REPRESENTATION_JSON5]
isEqual: @"{x:[0.5,15,null,\"foo\",false],foo:\"b\\\na\\r\"}"])
- EXPECT_EXCEPTION(@"-[JSONValue] #2", OFInvalidJSONException,
- [@"{" JSONValue])
- EXPECT_EXCEPTION(@"-[JSONValue] #3", OFInvalidJSONException,
- [@"]" JSONValue])
- EXPECT_EXCEPTION(@"-[JSONValue] #4", OFInvalidJSONException,
- [@"bar" JSONValue])
- EXPECT_EXCEPTION(@"-[JSONValue] #5", OFInvalidJSONException,
- [@"[\"a\" \"b\"]" JSONValue])
+ EXPECT_EXCEPTION(@"-[objectByParsingJSON] #2", OFInvalidJSONException,
+ [@"{" objectByParsingJSON])
+ EXPECT_EXCEPTION(@"-[objectByParsingJSON] #3", OFInvalidJSONException,
+ [@"]" objectByParsingJSON])
+ EXPECT_EXCEPTION(@"-[objectByParsingJSON] #4", OFInvalidJSONException,
+ [@"bar" objectByParsingJSON])
+ EXPECT_EXCEPTION(@"-[objectByParsingJSON] #5", OFInvalidJSONException,
+ [@"[\"a\" \"b\"]" objectByParsingJSON])
- TEST(@"-[JSONValue] #6",
+ TEST(@"-[objectByParsingJSON] #6",
[@"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
- .JSONValue isEqual: [OFArray arrayWithObject:
+ .objectByParsingJSON isEqual: [OFArray arrayWithObject:
[OFArray arrayWithObject: [OFArray arrayWithObject:
[OFArray arrayWithObject: [OFArray arrayWithObject:
[OFArray arrayWithObject: [OFArray arrayWithObject:
@@ -81,9 +81,9 @@ static OFString *module = @"OFJSON";
[OFArray arrayWithObject:
[OFDictionary dictionary]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]])
- EXPECT_EXCEPTION(@"-[JSONValue] #7", OFInvalidJSONException,
+ EXPECT_EXCEPTION(@"-[objectByParsingJSON] #7", OFInvalidJSONException,
[@"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
- JSONValue])
+ objectByParsingJSON])
objc_autoreleasePoolPop(pool);
}
diff --git a/tests/OFNumberTests.m b/tests/OFNumberTests.m
index 22bfe8b3..694c2403 100644
--- a/tests/OFNumberTests.m
+++ b/tests/OFNumberTests.m
@@ -27,11 +27,11 @@ static OFString *module = @"OFNumber";
void *pool = objc_autoreleasePoolPush();
OFNumber *num;
- TEST(@"+[numberWithIntMax:]",
- (num = [OFNumber numberWithIntMax: 123456789]))
+ TEST(@"+[numberWithLongLong:]",
+ (num = [OFNumber numberWithLongLong: 123456789]))
TEST(@"-[isEqual:]",
- [num isEqual: [OFNumber numberWithUInt32: 123456789]])
+ [num isEqual: [OFNumber numberWithLong: 123456789]])
TEST(@"-[hash]", num.hash == 0x82D8BC42)
@@ -39,6 +39,56 @@ static OFString *module = @"OFNumber";
TEST(@"-[doubleValue]", num.doubleValue == 123456789.L)
+ TEST(@"signed char minimum & maximum unmodified",
+ (num = [OFNumber numberWithChar: SCHAR_MIN]) &&
+ num.charValue == SCHAR_MIN &&
+ (num = [OFNumber numberWithChar: SCHAR_MAX]) &&
+ num.charValue == SCHAR_MAX)
+
+ TEST(@"short minimum & maximum unmodified",
+ (num = [OFNumber numberWithShort: SHRT_MIN]) &&
+ num.shortValue == SHRT_MIN &&
+ (num = [OFNumber numberWithShort: SHRT_MAX]) &&
+ num.shortValue == SHRT_MAX)
+
+ TEST(@"int minimum & maximum unmodified",
+ (num = [OFNumber numberWithInt: INT_MIN]) &&
+ num.intValue == INT_MIN &&
+ (num = [OFNumber numberWithInt: INT_MAX]) &&
+ num.intValue == INT_MAX)
+
+ TEST(@"long minimum & maximum unmodified",
+ (num = [OFNumber numberWithLong: LONG_MIN]) &&
+ num.longValue == LONG_MIN &&
+ (num = [OFNumber numberWithLong: LONG_MAX]) &&
+ num.longValue == LONG_MAX)
+
+ TEST(@"long long minimum & maximum unmodified",
+ (num = [OFNumber numberWithLongLong: LLONG_MIN]) &&
+ num.longLongValue == LLONG_MIN &&
+ (num = [OFNumber numberWithLongLong: LLONG_MAX]) &&
+ num.longLongValue == LLONG_MAX)
+
+ TEST(@"unsigned char maximum unmodified",
+ (num = [OFNumber numberWithUnsignedChar: UCHAR_MAX]) &&
+ num.unsignedCharValue == UCHAR_MAX)
+
+ TEST(@"unsigned short maximum unmodified",
+ (num = [OFNumber numberWithUnsignedShort: USHRT_MAX]) &&
+ num.unsignedShortValue == USHRT_MAX)
+
+ TEST(@"unsigned int maximum unmodified",
+ (num = [OFNumber numberWithUnsignedInt: UINT_MAX]) &&
+ num.unsignedIntValue == UINT_MAX)
+
+ TEST(@"unsigned long maximum unmodified",
+ (num = [OFNumber numberWithUnsignedLong: ULONG_MAX]) &&
+ num.unsignedLongValue == ULONG_MAX)
+
+ TEST(@"unsigned long long maximum unmodified",
+ (num = [OFNumber numberWithUnsignedLongLong: ULLONG_MAX]) &&
+ num.unsignedLongLongValue == ULLONG_MAX)
+
objc_autoreleasePoolPop(pool);
}
@end
diff --git a/tests/OFPropertyListTests.m b/tests/OFPropertyListTests.m
index 30063715..2625774f 100644
--- a/tests/OFPropertyListTests.m
+++ b/tests/OFPropertyListTests.m
@@ -70,49 +70,51 @@ static OFString *PLIST3 = PLIST(
[OFNumber numberWithInt: -10],
nil];
- TEST(@"-[propertyListValue:] #1",
- [PLIST1.propertyListValue isEqual: @"Hello"])
+ TEST(@"-[objectByParsingPropertyList:] #1",
+ [PLIST1.objectByParsingPropertyList isEqual: @"Hello"])
- TEST(@"-[propertyListValue:] #2",
- [PLIST2.propertyListValue isEqual: array])
+ TEST(@"-[objectByParsingPropertyList:] #2",
+ [PLIST2.objectByParsingPropertyList isEqual: array])
- TEST(@"-[propertyListValue:] #3",
- [PLIST3.propertyListValue isEqual:
+ TEST(@"-[objectByParsingPropertyList:] #3",
+ [PLIST3.objectByParsingPropertyList isEqual:
[OFDictionary dictionaryWithKeysAndObjects:
@"array", array,
@"foo", @"bar",
nil]])
- EXPECT_EXCEPTION(@"-[propertyListValue] detecting unsupported version",
+ EXPECT_EXCEPTION(@"Detecting unsupported version",
OFUnsupportedVersionException,
[[PLIST(@"<string/>") stringByReplacingOccurrencesOfString: @"1.0"
withString: @"1.1"]
- propertyListValue])
+ objectByParsingPropertyList])
EXPECT_EXCEPTION(
- @"-[propertyListValue] detecting invalid format #1",
+ @"-[objectByParsingPropertyList] detecting invalid format #1",
OFInvalidFormatException,
- [PLIST(@"<string x='b'/>") propertyListValue])
+ [PLIST(@"<string x='b'/>") objectByParsingPropertyList])
EXPECT_EXCEPTION(
- @"-[propertyListValue] detecting invalid format #2",
+ @"-[objectByParsingPropertyList] detecting invalid format #2",
OFInvalidFormatException,
- [PLIST(@"<string xmlns='foo'/>") propertyListValue])
+ [PLIST(@"<string xmlns='foo'/>") objectByParsingPropertyList])
EXPECT_EXCEPTION(
- @"-[propertyListValue] detecting invalid format #3",
+ @"-[objectByParsingPropertyList] detecting invalid format #3",
OFInvalidFormatException,
- [PLIST(@"<dict count='0'/>") propertyListValue])
+ [PLIST(@"<dict count='0'/>") objectByParsingPropertyList])
EXPECT_EXCEPTION(
- @"-[propertyListValue] detecting invalid format #4",
+ @"-[objectByParsingPropertyList] detecting invalid format #4",
OFInvalidFormatException,
- [PLIST(@"<dict><key/><string/><key/></dict>") propertyListValue])
+ [PLIST(@"<dict><key/><string/><key/></dict>")
+ objectByParsingPropertyList])
EXPECT_EXCEPTION(
- @"-[propertyListValue] detecting invalid format #5",
+ @"-[objectByParsingPropertyList] detecting invalid format #5",
OFInvalidFormatException,
- [PLIST(@"<dict><key x='x'/><string/></dict>") propertyListValue])
+ [PLIST(@"<dict><key x='x'/><string/></dict>")
+ objectByParsingPropertyList])
objc_autoreleasePoolPop(pool);
}
diff --git a/tests/OFSetTests.m b/tests/OFSetTests.m
index 41c9a10c..4f34e701 100644
--- a/tests/OFSetTests.m
+++ b/tests/OFSetTests.m
@@ -278,10 +278,10 @@ static OFString *module = nil;
TEST(@"-[valueForKey:]",
[(set1 = [[setClass setWithObjects: @"a", @"ab", @"abc", @"b", nil]
valueForKey: @"length"]) isEqual: [setClass setWithObjects:
- [OFNumber numberWithSize: 1], [OFNumber numberWithSize: 2],
- [OFNumber numberWithSize: 3], nil]] &&
+ [OFNumber numberWithInt: 1], [OFNumber numberWithInt: 2],
+ [OFNumber numberWithInt: 3], nil]] &&
[[set1 valueForKey: @"@count"] isEqual:
- [OFNumber numberWithSize: 3]])
+ [OFNumber numberWithInt: 3]])
objc_autoreleasePoolPop(pool);
}
diff --git a/tests/OFStringTests.m b/tests/OFStringTests.m
index 4844dd1f..eccd1417 100644
--- a/tests/OFStringTests.m
+++ b/tests/OFStringTests.m
@@ -1069,24 +1069,29 @@ static uint16_t sutf16str[] = {
# endif
#endif
- TEST(@"-[decimalValue]",
- C(@"1234").decimalValue == 1234 &&
- C(@"\r\n+123 ").decimalValue == 123 &&
- C(@"-500\t").decimalValue == -500 &&
- C(@"\t\t\r\n").decimalValue == 0)
-
- TEST(@"-[hexadecimalValue]",
- C(@"123f").hexadecimalValue == 0x123f &&
- C(@"\t\n0xABcd\r").hexadecimalValue == 0xABCD &&
- C(@" xbCDE").hexadecimalValue == 0xBCDE &&
- C(@"$CdEf").hexadecimalValue == 0xCDEF &&
- C(@"\rFeh ").hexadecimalValue == 0xFE &&
- C(@"\r\t").hexadecimalValue == 0)
-
- TEST(@"-[octalValue]",
- C(@"1234567").octalValue == 01234567 &&
- C(@"\r\n123").octalValue == 0123 &&
- C(@"765\t").octalValue == 0765 && C(@"\t\t\r\n").octalValue == 0)
+ TEST(@"-[longLongValue]",
+ C(@"1234").longLongValue == 1234 &&
+ C(@"\r\n+123 ").longLongValue == 123 &&
+ C(@"-500\t").longLongValue == -500 &&
+ [C(@"-0x10\t") longLongValueWithBase: 0] == -0x10 &&
+ C(@"\t\t\r\n").longLongValue == 0 &&
+ [C(@"123f") longLongValueWithBase: 16] == 0x123f &&
+ [C(@"\t\n0xABcd\r") longLongValueWithBase: 0] == 0xABCD &&
+ [C(@"1234567") longLongValueWithBase: 8] == 01234567 &&
+ [C(@"\r\n0123") longLongValueWithBase: 0] == 0123 &&
+ [C(@"765\t") longLongValueWithBase: 8] == 0765 &&
+ [C(@"\t\t\r\n") longLongValueWithBase: 8] == 0)
+
+ TEST(@"-[unsignedLongLongValue]",
+ C(@"1234").unsignedLongLongValue == 1234 &&
+ C(@"\r\n+123 ").unsignedLongLongValue == 123 &&
+ C(@"\t\t\r\n").unsignedLongLongValue == 0 &&
+ [C(@"123f") unsignedLongLongValueWithBase: 16] == 0x123f &&
+ [C(@"\t\n0xABcd\r") unsignedLongLongValueWithBase: 0] == 0xABCD &&
+ [C(@"1234567") unsignedLongLongValueWithBase: 8] == 01234567 &&
+ [C(@"\r\n0123") unsignedLongLongValueWithBase: 0] == 0123 &&
+ [C(@"765\t") unsignedLongLongValueWithBase: 8] == 0765 &&
+ [C(@"\t\t\r\n") unsignedLongLongValueWithBase: 8] == 0)
/*
* These test numbers can be generated without rounding if we have IEEE
@@ -1109,7 +1114,7 @@ static uint16_t sutf16str[] = {
# define EXPECTED -0.123456789
# else
/*
- * Solaris' strtod() has weird rounding on x86, but not on x86_64/
+ * Solaris' strtod() has weird rounding on x86, but not on x86_64.
* AmigaOS 3 with libnix has weird rounding as well.
*/
# define INPUT @"\t-0.125 "
@@ -1124,21 +1129,17 @@ static uint16_t sutf16str[] = {
#undef INPUT
#undef EXPECTED
- EXPECT_EXCEPTION(@"Detect invalid characters in -[decimalValue] #1",
- OFInvalidFormatException, [C(@"abc") decimalValue])
- EXPECT_EXCEPTION(@"Detect invalid characters in -[decimalValue] #2",
- OFInvalidFormatException, [C(@"0a") decimalValue])
- EXPECT_EXCEPTION(@"Detect invalid characters in -[decimalValue] #3",
- OFInvalidFormatException, [C(@"0 1") decimalValue])
-
- EXPECT_EXCEPTION(@"Detect invalid chars in -[hexadecimalValue] #1",
- OFInvalidFormatException, [C(@"0xABCDEFG") hexadecimalValue])
- EXPECT_EXCEPTION(@"Detect invalid chars in -[hexadecimalValue] #2",
- OFInvalidFormatException, [C(@"0x") hexadecimalValue])
- EXPECT_EXCEPTION(@"Detect invalid chars in -[hexadecimalValue] #3",
- OFInvalidFormatException, [C(@"$") hexadecimalValue])
- EXPECT_EXCEPTION(@"Detect invalid chars in -[hexadecimalValue] #4",
- OFInvalidFormatException, [C(@"$ ") hexadecimalValue])
+ EXPECT_EXCEPTION(@"Detect invalid chars in -[longLongValue] #1",
+ OFInvalidFormatException, [C(@"abc") longLongValue])
+ EXPECT_EXCEPTION(@"Detect invalid chars in -[longLongValue] #2",
+ OFInvalidFormatException, [C(@"0a") longLongValue])
+ EXPECT_EXCEPTION(@"Detect invalid chars in -[longLongValue] #3",
+ OFInvalidFormatException, [C(@"0 1") longLongValue])
+ EXPECT_EXCEPTION(@"Detect invalid chars in -[longLongValue] #4",
+ OFInvalidFormatException,
+ [C(@"0xABCDEFG") longLongValueWithBase: 0])
+ EXPECT_EXCEPTION(@"Detect invalid chars in -[longLongValue] #5",
+ OFInvalidFormatException, [C(@"0x") longLongValueWithBase: 0])
EXPECT_EXCEPTION(@"Detect invalid chars in -[floatValue] #1",
OFInvalidFormatException, [C(@"0.0a") floatValue])
@@ -1166,17 +1167,17 @@ static uint16_t sutf16str[] = {
OFInvalidFormatException, [C(@"0,0") doubleValue])
#endif
- EXPECT_EXCEPTION(@"Detect out of range in -[decimalValue]",
+ EXPECT_EXCEPTION(@"Detect out of range in -[longLongValue]",
OFOutOfRangeException,
- [C(@"12345678901234567890123456789012345678901234567890"
+ [C(@"-12345678901234567890123456789012345678901234567890"
@"12345678901234567890123456789012345678901234567890")
- decimalValue])
+ longLongValueWithBase: 16])
- EXPECT_EXCEPTION(@"Detect out of range in -[hexadecimalValue]",
+ EXPECT_EXCEPTION(@"Detect out of range in -[unsignedLongLongValue]",
OFOutOfRangeException,
[C(@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF")
- hexadecimalValue])
+ unsignedLongLongValueWithBase: 16])
TEST(@"-[characters]", (ua = C(@"fööbär🀺").characters) &&
!memcmp(ua, ucstr + 1, sizeof(ucstr) - 8))
diff --git a/tests/OFURLTests.m b/tests/OFURLTests.m
index ee4491b6..5ab854e7 100644
--- a/tests/OFURLTests.m
+++ b/tests/OFURLTests.m
@@ -156,9 +156,8 @@ static OFString *url_str = @"ht%3atp://us%3Aer:p%40w@ho%3Ast:1234/"
TEST(@"-[host]", [u1.host isEqual: @"ho:st"] &&
[u6.host isEqual: @"12:34::56:abcd"] &&
[u7.host isEqual: @"12:34::56:abcd"])
- TEST(@"-[port]", [u1.port isEqual: [OFNumber numberWithUInt16: 1234]] &&
- [u4 port] == nil &&
- [u7.port isEqual: [OFNumber numberWithUInt16: 234]])
+ TEST(@"-[port]", u1.port.unsignedShortValue == 1234 &&
+ [u4 port] == nil && u7.port.unsignedShortValue == 234)
TEST(@"-[path]",
[u1.path isEqual: @"/pa?th"] && [u4.path isEqual: @"/etc/passwd"])
TEST(@"-[pathComponents]",
diff --git a/tests/TestsAppDelegate.h b/tests/TestsAppDelegate.h
index b2500e16..b4aea7f7 100644
--- a/tests/TestsAppDelegate.h
+++ b/tests/TestsAppDelegate.h
@@ -70,8 +70,8 @@
inModule: (OFString *)module;
@end
-@interface TestsAppDelegate (OFASN1DERValueTests)
-- (void)ASN1DERValueTests;
+@interface TestsAppDelegate (OFASN1DERParsingTests)
+- (void)ASN1DERParsingTests;
@end
@interface TestsAppDelegate (OFASN1DERRepresentationTests)
diff --git a/tests/TestsAppDelegate.m b/tests/TestsAppDelegate.m
index df1e4d3c..851263be 100644
--- a/tests/TestsAppDelegate.m
+++ b/tests/TestsAppDelegate.m
@@ -380,7 +380,7 @@ main(int argc, char *argv[])
#endif
[self JSONTests];
[self propertyListTests];
- [self ASN1DERValueTests];
+ [self ASN1DERParsingTests];
[self ASN1DERRepresentationTests];
#if defined(OF_HAVE_PLUGINS)
[self pluginTests];
diff --git a/tests/iOS.xcodeproj/project.pbxproj b/tests/iOS.xcodeproj/project.pbxproj
index b3f122c3..fb726a1d 100644
--- a/tests/iOS.xcodeproj/project.pbxproj
+++ b/tests/iOS.xcodeproj/project.pbxproj
@@ -306,7 +306,7 @@
"$(PROJECT_DIR)",
);
OTHER_LDFLAGS = "-ObjC";
- PRODUCT_BUNDLE_IDENTIFIER = zone.heap.objfw.tests;
+ PRODUCT_BUNDLE_IDENTIFIER = im.nil.objfw.tests;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
};
@@ -326,7 +326,7 @@
"$(PROJECT_DIR)",
);
OTHER_LDFLAGS = "-ObjC";
- PRODUCT_BUNDLE_IDENTIFIER = zone.heap.objfw.tests;
+ PRODUCT_BUNDLE_IDENTIFIER = im.nil.objfw.tests;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
};
diff --git a/tests/plugin/Info.plist.in b/tests/plugin/Info.plist.in
index a3e92425..31d2e3a0 100644
--- a/tests/plugin/Info.plist.in
+++ b/tests/plugin/Info.plist.in
@@ -7,7 +7,7 @@
<key>CFBundleName</key>
<string>TestPlugin</string>
<key>CFBundleIdentifier</key>
- <string>zone.heap.objfw.testplugin</string>
+ <string>im.nil.objfw.tests.plugin</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
diff --git a/tests/serialization.xml b/tests/serialization.xml
index 43fb1b10..2a716f29 100644
--- a/tests/serialization.xml
+++ b/tests/serialization.xml
@@ -17,7 +17,7 @@
<OFArray>
<OFString>Qu&quot;xbar
test</OFString>
- <OFNumber type='unsigned'>1234</OFNumber>
+ <OFNumber type='signed'>1234</OFNumber>
<OFNumber type='float'>40934a456d5cfaad</OFNumber>
<OFMutableString>asd</OFMutableString>
<OFDate>40934a456d5cfaad</OFDate>
diff --git a/utils/ofarc/LHAArchive.m b/utils/ofarc/LHAArchive.m
index 96a5be1b..a5ebecd6 100644
--- a/utils/ofarc/LHAArchive.m
+++ b/utils/ofarc/LHAArchive.m
@@ -47,6 +47,9 @@ setPermissions(OFString *path, OFLHAArchiveEntry *entry)
if (mode == nil)
return;
+ mode = [OFNumber numberWithUnsignedShort:
+ mode.unsignedShortValue & 0777];
+
of_file_attributes_t attributes = [OFDictionary
dictionaryWithObject: mode
forKey: of_file_attribute_key_posix_permissions];
@@ -145,24 +148,24 @@ setModificationDate(OFString *path, OFLHAArchiveEntry *entry)
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_compressed_size",
- [@"["
- @" 'Compressed: ',"
- @" ["
- @" {'size == 1': '1 byte'},"
- @" {'': '%[size] bytes'}"
- @" ]"
- @"]" JSONValue],
+ @"["
+ @" 'Compressed: ',"
+ @" ["
+ @" {'size == 1': '1 byte'},"
+ @" {'': '%[size] bytes'}"
+ @" ]"
+ @"]".objectByParsingJSON,
@"size", compressedSize)];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_uncompressed_size",
- [@"["
- @" 'Uncompressed: ',"
- @" ["
- @" {'size == 1': '1 byte'},"
- @" {'': '%[size] bytes'}"
- @" ]"
- @"]" JSONValue],
+ @"["
+ @" 'Uncompressed: ',"
+ @" ["
+ @" {'size == 1': '1 byte'},"
+ @" {'': '%[size] bytes'}"
+ @" ]"
+ @"]".objectByParsingJSON,
@"size", uncompressedSize)];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@@ -181,7 +184,7 @@ setModificationDate(OFString *path, OFLHAArchiveEntry *entry)
if (entry.mode != nil) {
OFString *modeString = [OFString
stringWithFormat:
- @"%" PRIo16, entry.mode.uInt16Value];
+ @"%ho", entry.mode.unsignedShortValue];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(@"list_mode",
@@ -469,16 +472,16 @@ outer_loop_end:
entry = [OFMutableLHAArchiveEntry entryWithFileName: fileName];
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
- entry.mode = [OFNumber numberWithUInt16:
+ entry.mode = [OFNumber numberWithUnsignedLong:
attributes.filePOSIXPermissions];
#endif
entry.date = attributes.fileModificationDate;
#ifdef OF_FILE_MANAGER_SUPPORTS_OWNER
entry.UID =
- [OFNumber numberWithUInt16: attributes.filePOSIXUID];
+ [OFNumber numberWithUnsignedLong: attributes.filePOSIXUID];
entry.GID =
- [OFNumber numberWithUInt16: attributes.filePOSIXGID];
+ [OFNumber numberWithUnsignedLong: attributes.filePOSIXGID];
entry.owner = attributes.fileOwner;
entry.group = attributes.fileGroup;
#endif
@@ -489,7 +492,8 @@ outer_loop_end:
output = [_archive streamForWritingEntry: entry];
if ([type isEqual: of_file_type_regular]) {
- uintmax_t written = 0, size = attributes.fileSize;
+ unsigned long long written = 0;
+ unsigned long long size = attributes.fileSize;
int8_t percent = -1, newPercent;
OFFile *input = [OFFile fileWithPath: fileName
diff --git a/utils/ofarc/TarArchive.m b/utils/ofarc/TarArchive.m
index e2d3ef07..4cef7554 100644
--- a/utils/ofarc/TarArchive.m
+++ b/utils/ofarc/TarArchive.m
@@ -35,8 +35,9 @@ static void
setPermissions(OFString *path, OFTarArchiveEntry *entry)
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
+ OFNumber *mode = [OFNumber numberWithUnsignedShort: entry.mode & 0777];
of_file_attributes_t attributes = [OFDictionary
- dictionaryWithObject: [OFNumber numberWithUInt16: entry.mode]
+ dictionaryWithObject: mode
forKey: of_file_attribute_key_posix_permissions];
[[OFFileManager defaultManager] setAttributes: attributes
@@ -126,13 +127,13 @@ setModificationDate(OFString *path, OFTarArchiveEntry *entry)
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(@"list_size",
- [@"["
- @" 'Size: ',"
- @" ["
- @" {'size == 1': '1 byte'},"
- @" {'': '%[size] bytes'}"
- @" ]"
- @"]" JSONValue],
+ @"["
+ @" 'Size: ',"
+ @" ["
+ @" {'size == 1': '1 byte'},"
+ @" {'': '%[size] bytes'}"
+ @" ]"
+ @"]".objectByParsingJSON,
@"size", size)];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(@"list_mode",
diff --git a/utils/ofarc/ZIPArchive.m b/utils/ofarc/ZIPArchive.m
index d6cf6196..61820410 100644
--- a/utils/ofarc/ZIPArchive.m
+++ b/utils/ofarc/ZIPArchive.m
@@ -44,11 +44,12 @@ setPermissions(OFString *path, OFZIPArchiveEntry *entry)
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
if ((entry.versionMadeBy >> 8) ==
OF_ZIP_ARCHIVE_ENTRY_ATTR_COMPAT_UNIX) {
- uint16_t mode = entry.versionSpecificAttributes >> 16;
+ OFNumber *mode = [OFNumber numberWithUnsignedShort:
+ (entry.versionSpecificAttributes >> 16) & 0777];
of_file_attribute_key_t key =
of_file_attribute_key_posix_permissions;
of_file_attributes_t attributes = [OFDictionary
- dictionaryWithObject: [OFNumber numberWithUInt16: mode]
+ dictionaryWithObject: mode
forKey: key];
[[OFFileManager defaultManager] setAttributes: attributes
@@ -138,24 +139,24 @@ setModificationDate(OFString *path, OFZIPArchiveEntry *entry)
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_compressed_size",
- [@"["
- @" 'Compressed: ',"
- @" ["
- @" {'size == 1': '1 byte'},"
- @" {'': '%[size] bytes'}"
- @" ]"
- @"]" JSONValue],
+ @"["
+ @" 'Compressed: ',"
+ @" ["
+ @" {'size == 1': '1 byte'},"
+ @" {'': '%[size] bytes'}"
+ @" ]"
+ @"]".objectByParsingJSON,
@"size", compressedSize)];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_uncompressed_size",
- [@"["
- @" 'Uncompressed: ',"
- @" ["
- @" {'size == 1': '1 byte'},"
- @" {'': '%[size] bytes'}"
- @" ]"
- @"]" JSONValue],
+ @"["
+ @" 'Uncompressed: ',"
+ @" ["
+ @" {'size == 1': '1 byte'},"
+ @" {'': '%[size] bytes'}"
+ @" ]"
+ @"]".objectByParsingJSON,
@"size", uncompressedSize)];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@@ -421,7 +422,7 @@ outer_loop_end:
of_file_attributes_t attributes;
bool isDirectory = false;
OFMutableZIPArchiveEntry *entry;
- uintmax_t size;
+ unsigned long long size;
OFStream *output;
components = localFileName.pathComponents;
@@ -458,7 +459,7 @@ outer_loop_end:
output = [_archive streamForWritingEntry: entry];
if (!isDirectory) {
- uintmax_t written = 0;
+ unsigned long long written = 0;
int8_t percent = -1, newPercent;
OFFile *input = [OFFile fileWithPath: fileName
diff --git a/utils/ofhttp/OFHTTP.m b/utils/ofhttp/OFHTTP.m
index 47fb7f5c..4fc7f682 100644
--- a/utils/ofhttp/OFHTTP.m
+++ b/utils/ofhttp/OFHTTP.m
@@ -28,6 +28,9 @@
#import "OFHTTPResponse.h"
#import "OFLocale.h"
#import "OFOptionsParser.h"
+#ifdef OF_HAVE_PLUGINS
+# import "OFPlugin.h"
+#endif
#import "OFSandbox.h"
#import "OFStdIOStream.h"
#import "OFSystemInfo.h"
@@ -69,7 +72,7 @@
OFHTTPClient *_HTTPClient;
char *_buffer;
OFStream *_output;
- intmax_t _received, _length, _resumedFrom;
+ unsigned long long _received, _length, _resumedFrom;
ProgressBar *_progressBar;
}
@@ -274,6 +277,17 @@ fileNameFromContentDisposition(OFString *contentDisposition)
}
@implementation OFHTTP
+#ifdef OF_HAVE_PLUGINS
++ (void)initialize
+{
+ if (self != [OFHTTP class])
+ return;
+
+ /* Opportunistically try loading ObjOpenSSL and ignore any errors. */
+ of_dlopen(@"objopenssl", OF_RTLD_LAZY);
+}
+#endif
+
- (instancetype)init
{
self = [super init];
@@ -334,7 +348,8 @@ fileNameFromContentDisposition(OFString *contentDisposition)
mode: @"r"];
@try {
- uintmax_t fileSize = [[OFFileManager defaultManager]
+ unsigned long long fileSize =
+ [[OFFileManager defaultManager]
attributesOfItemAtPath: path].fileSize;
contentLength =
@@ -376,14 +391,14 @@ fileNameFromContentDisposition(OFString *contentDisposition)
rangeOfString: @":"
options: OF_STRING_SEARCH_BACKWARDS].location;
OFString *host;
- intmax_t port;
+ unsigned long long port;
if (pos == OF_NOT_FOUND)
@throw [OFInvalidFormatException exception];
host = [proxy substringWithRange: of_range(0, pos)];
- port = [proxy substringWithRange:
- of_range(pos + 1, proxy.length - pos - 1)].decimalValue;
+ port = [proxy substringWithRange: of_range(pos + 1,
+ proxy.length - pos - 1)].unsignedLongLongValue;
if (port > UINT16_MAX)
@throw [OFOutOfRangeException exception];
@@ -721,8 +736,11 @@ fileNameFromContentDisposition(OFString *contentDisposition)
[_progressBar release];
_progressBar = nil;
- if (!_quiet)
- [of_stdout writeString: @"\n Error!\n"];
+ if (!_quiet) {
+ [of_stdout writeString: @"\n "];
+ [of_stdout writeLine: OF_LOCALIZED(@"download_error",
+ @"Error!")];
+ }
URL = [_URLs objectAtIndex: _URLIndex - 1];
[of_stderr writeLine: OF_LOCALIZED(
@@ -785,7 +803,7 @@ fileNameFromContentDisposition(OFString *contentDisposition)
type = OF_LOCALIZED(@"type_unknown", @"unknown");
if (lengthString != nil) {
- _length = lengthString.decimalValue;
+ _length = lengthString.unsignedLongLongValue;
if (_resumedFrom + _length >= GIBIBYTE) {
lengthString = [OFString stringWithFormat:
@@ -812,12 +830,12 @@ fileNameFromContentDisposition(OFString *contentDisposition)
lengthString = [OFString stringWithFormat:
@"%jd", _resumedFrom + _length];
lengthString = OF_LOCALIZED(@"size_bytes",
- [@"["
- @" ["
- @" {'num == 1': '1 byte'},"
- @" {'': '%[num] bytes'}"
- @" ]"
- @"]" JSONValue],
+ @"["
+ @" ["
+ @" {'num == 1': '1 byte'},"
+ @" {'': '%[num] bytes'}"
+ @" ]"
+ @"]".objectByParsingJSON,
@"num", lengthString);
}
} else
@@ -1010,14 +1028,15 @@ next:
if (_continue) {
@try {
- uintmax_t size = [[OFFileManager defaultManager]
+ unsigned long long size =
+ [[OFFileManager defaultManager]
attributesOfItemAtPath: _currentFileName].fileSize;
OFString *range;
- if (size > INTMAX_MAX)
+ if (size > ULLONG_MAX)
@throw [OFOutOfRangeException exception];
- _resumedFrom = (intmax_t)size;
+ _resumedFrom = (unsigned long long)size;
range = [OFString stringWithFormat: @"bytes=%jd-",
_resumedFrom];
diff --git a/utils/ofhttp/ProgressBar.h b/utils/ofhttp/ProgressBar.h
index cae2f995..66bd3806 100644
--- a/utils/ofhttp/ProgressBar.h
+++ b/utils/ofhttp/ProgressBar.h
@@ -20,19 +20,23 @@
@class OFDate;
@class OFTimer;
+#define BPS_WINDOW_SIZE 10
+
@interface ProgressBar: OFObject
{
- intmax_t _received, _lastReceived, _length, _resumedFrom;
+ unsigned long long _received, _lastReceived, _length, _resumedFrom;
OFDate *_startDate, *_lastReceivedDate;
OFTimer *_drawTimer, *_BPSTimer;
bool _stopped;
float _BPS;
double _ETA;
+ float _BPSWindow[BPS_WINDOW_SIZE];
+ size_t _BPSWindowIndex, _BPSWindowLength;
}
-- (instancetype)initWithLength: (intmax_t)length
- resumedFrom: (intmax_t)resumedFrom;
-- (void)setReceived: (intmax_t)received;
+- (instancetype)initWithLength: (unsigned long long)length
+ resumedFrom: (unsigned long long)resumedFrom;
+- (void)setReceived: (unsigned long long)received;
- (void)draw;
- (void)calculateBPSAndETA;
- (void)stop;
diff --git a/utils/ofhttp/ProgressBar.m b/utils/ofhttp/ProgressBar.m
index 225705dd..f02e836b 100644
--- a/utils/ofhttp/ProgressBar.m
+++ b/utils/ofhttp/ProgressBar.m
@@ -33,8 +33,8 @@
#define UPDATE_INTERVAL 0.1
@implementation ProgressBar
-- (instancetype)initWithLength: (intmax_t)length
- resumedFrom: (intmax_t)resumedFrom
+- (instancetype)initWithLength: (unsigned long long)length
+ resumedFrom: (unsigned long long)resumedFrom
{
self = [super init];
@@ -78,7 +78,7 @@
[super dealloc];
}
-- (void)setReceived: (intmax_t)received
+- (void)setReceived: (unsigned long long)received
{
_received = received;
}
@@ -204,12 +204,12 @@
OFString *num = [OFString stringWithFormat:
@"%jd", _resumedFrom + _received];
[of_stdout writeString: OF_LOCALIZED(@"progress_bytes",
- [@"["
- @" ["
- @" {'num == 1': '1 byte '},"
- @" {'': '%[num] bytes'}"
- @" ]"
- @"]" JSONValue],
+ @"["
+ @" ["
+ @" {'num == 1': '1 byte '},"
+ @" {'': '%[num] bytes'}"
+ @" ]"
+ @"]".objectByParsingJSON,
@"num", num)];
}
@@ -256,8 +256,18 @@
- (void)calculateBPSAndETA
{
- _BPS = (float)(_received - _lastReceived) /
+ _BPSWindow[_BPSWindowIndex++ % BPS_WINDOW_SIZE] =
+ (float)(_received - _lastReceived) /
-(float)_lastReceivedDate.timeIntervalSinceNow;
+
+ if (_BPSWindowLength < BPS_WINDOW_SIZE)
+ _BPSWindowLength++;
+
+ _BPS = 0;
+ for (size_t i = 0; i < _BPSWindowLength; i++)
+ _BPS += _BPSWindow[i];
+ _BPS /= _BPSWindowLength;
+
_ETA = (double)(_length - _received) / _BPS;
_lastReceived = _received;
diff --git a/utils/ofhttp/lang/de.json b/utils/ofhttp/lang/de.json
index 400b1dda..4bafc260 100644
--- a/utils/ofhttp/lang/de.json
+++ b/utils/ofhttp/lang/de.json
@@ -68,6 +68,7 @@
"%[prog]: Fehler beim Download von <%[url]>!\n",
" HTTP Status-Code: %[code]"
],
+ "download_error": "Fehler!",
"download_failed_exception": [
"%[prog]: Fehler beim Download von <%[url]>!\n",
" %[exception]"
diff --git a/utils/ofsock/OFSock.m b/utils/ofsock/OFSock.m
index 9ea66cc6..c4c69013 100644
--- a/utils/ofsock/OFSock.m
+++ b/utils/ofsock/OFSock.m
@@ -62,7 +62,7 @@ streamFromString(OFString *string)
}
[sock connectToHost: URL.host
- port: URL.port.uInt16Value];
+ port: URL.port.shortValue];
return [OFPair pairWithFirstObject: sock
secondObject: sock];