Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -25,13 +25,22 @@ /** * Creates a new OFArray whose items all have the same size. * * \param is The size of each element in the OFArray - * \return A new allocated and initialized OFArray + * \return A new autoreleased OFArray + */ ++ arrayWithItemSize: (size_t)is; + +/* + * Creates a new OFArray optimized for big arrays whose items all have the same + * size, which means memory is allocated in pages rather than in bytes. + * + * \param is The size of each element in the OFArray + * \return A new autoreleased OFArray */ -+ newWithItemSize: (size_t)is; ++ bigArrayWithItemSize: (size_t)is; /** * Initializes an already allocated OFArray whose items all have the same size. * * \param is The size of each element in the OFArray @@ -89,48 +98,16 @@ * \param nitems The number of items to remove */ - removeNItems: (size_t)nitems; @end -/** - * The OFBigArray class is nearly the same as the OFArray class, but it - * allocates the memory rather in pages than in bytes. - * This is faster, but needs more memory. It is especially useful if you want - * to store large hunks of data. - */ @interface OFBigArray: OFArray { size_t size; } -/** - * Initializes an already allocated OFBigArray whose items all have the same - * size. - * - * \param is The size of each element in the OFBigArray - * \return An initialized OFBigArray - */ - initWithItemSize: (size_t)is; - -/** - * Adds an item to the OFBigArray. - * - * \param item An arbitrary item - */ - add: (void*)item; - -/** - * Adds items from a C array to the OFBigArray. - * - * \param nitems The number of items to add - * \param carray A C array containing the items to add - */ - addNItems: (size_t)nitems fromCArray: (void*)carray; - -/** - * Removes a specified amount of the last items from the OFBigArray. - * - * \param nitems The number of items to remove - */ - removeNItems: (size_t)nitems; @end Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -22,13 +22,18 @@ static size_t lastpagebyte = 0; extern int getpagesize(void); @implementation OFArray -+ newWithItemSize: (size_t)is ++ arrayWithItemSize: (size_t)is +{ + return [[[self alloc] initWithItemSize: is] autorelease]; +} + ++ bigArrayWithItemSize: (size_t)is { - return [[self alloc] initWithItemSize: is]; + return [[[OFBigArray alloc] initWithItemSize: is] autorelease]; } - initWithItemSize: (size_t)is { if ((self = [super init])) { Index: src/OFAutoreleasePool.m ================================================================== --- src/OFAutoreleasePool.m +++ src/OFAutoreleasePool.m @@ -107,11 +107,11 @@ } - addToPool: (OFObject*)obj { if (objects == nil) - objects = [OFArray newWithItemSize: sizeof(char*)]; + objects = [[OFArray alloc] initWithItemSize: sizeof(char*)]; [objects add: &obj]; return self; } Index: src/OFExceptions.h ================================================================== --- src/OFExceptions.h +++ src/OFExceptions.h @@ -11,10 +11,12 @@ #import "OFObject.h" /** * The OFException class is the base class for all exceptions in ObjFW. + * + * IMPORTANT: Exceptions do NOT use OFAutoreleasePools!! */ @interface OFException: OFObject { Class class; char *string; Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -30,14 +30,14 @@ } /** * \param path The path to the file to open as a C string * \param mode The mode in which the file should be opened as a C string - * \return A new OFFile + * \return A new autoreleased OFFile */ -+ newWithPath: (const char*)path - andMode: (const char*)mode; ++ fileWithPath: (const char*)path + andMode: (const char*)mode; /** * Changes the mode of a file. * * Not available on Windows. * Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -22,15 +22,15 @@ #import "OFFile.h" #import "OFExceptions.h" @implementation OFFile -+ newWithPath: (const char*)path - andMode: (const char*)mode ++ fileWithPath: (const char*)path + andMode: (const char*)mode { - return [[self alloc] initWithPath: path - andMode: mode]; + return [[[self alloc] initWithPath: path + andMode: mode] autorelease]; } + (void)changeModeOfFile: (const char*)path toMode: (mode_t)mode { @@ -181,6 +181,14 @@ { return [self writeNItems: strlen(str) ofSize: 1 fromBuffer: (const uint8_t*)str]; } + +- close +{ + fclose(fp); + fp = NULL; + + return self; +} @end Index: src/OFHashes.h ================================================================== --- src/OFHashes.h +++ src/OFHashes.h @@ -24,10 +24,15 @@ uint8_t in[64]; BOOL calculated; } +/** + * \return A new autoreleased MD5 Hash + */ ++ md5Hash; + - init; /** * Adds a buffer to the hash to be calculated. * @@ -55,10 +60,15 @@ uint8_t digest[SHA1_DIGEST_SIZE]; BOOL calculated; } +/** + * \return A new autoreleased SHA1 Hash + */ ++ sha1Hash; + - init; /** * Adds a buffer to the hash to be calculated. * Index: src/OFHashes.m ================================================================== --- src/OFHashes.m +++ src/OFHashes.m @@ -113,10 +113,15 @@ buf[2] += c; buf[3] += d; } @implementation OFMD5Hash ++ md5Hash +{ + return [[[self alloc] init] autorelease]; +} + - init { if ((self = [super init])) { buf[0] = 0x67452301; buf[1] = 0xEFCDAB89; @@ -351,10 +356,15 @@ memcpy(&buffer[j], &buf[i], size - i); } @implementation OFSHA1Hash ++ sha1Hash +{ + return [[[self alloc] init] autorelease]; +} + - init { if ((self = [super init])) { count = 0; state[0] = 0x67452301; Index: src/OFList.h ================================================================== --- src/OFList.h +++ src/OFList.h @@ -25,10 +25,14 @@ { of_list_object_t *first; of_list_object_t *last; BOOL retain_and_release; } +/** + * \return A new autoreleased OFList + */ ++ list; /** * Initializes an already allocated OFList. * * \param enabled Whether release / retain should be called when an object is Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -12,10 +12,15 @@ #import "config.h" #import "OFList.h" @implementation OFList ++ list +{ + return [[[self alloc] init] autorelease]; +} + - init { if ((self = [super init])) { first = NULL; last = NULL; Index: src/OFNumber.h ================================================================== --- src/OFNumber.h +++ src/OFNumber.h @@ -71,33 +71,33 @@ long double longdouble; } value; enum of_number_type type; } -+ newWithChar: (char)char_; -+ newWithShort: (short)short_; -+ newWithInt: (int)int_; -+ newWithLong: (long)long_; -+ newWithUChar: (unsigned char)uchar; -+ newWithUShort: (unsigned short)ushort; -+ newWithUInt: (unsigned int)uint; -+ newWithULong: (unsigned long)ulong; -+ newWithInt8: (int8_t)int8; -+ newWithInt16: (int16_t)int16; -+ newWithInt32: (int32_t)int32; -+ newWithInt64: (int64_t)int64; -+ newWithUInt8: (uint8_t)uint8; -+ newWithUInt16: (uint16_t)uint16; -+ newWithUInt32: (uint32_t)uint32; -+ newWithUInt64: (uint64_t)uint64; -+ newWithSize: (size_t)size; -+ newWithSSize: (ssize_t)ssize; -+ newWithPtrDiff: (ptrdiff_t)ptrdiff; -+ newWithIntPtr: (intptr_t)intptr; -+ newWithFloat: (float)float_; -+ newWithDouble: (double)double_; -+ newWithLongDouble: (long double)longdouble; ++ numberWithChar: (char)char_; ++ numberWithShort: (short)short_; ++ numberWithInt: (int)int_; ++ numberWithLong: (long)long_; ++ numberWithUChar: (unsigned char)uchar; ++ numberWithUShort: (unsigned short)ushort; ++ numberWithUInt: (unsigned int)uint; ++ numberWithULong: (unsigned long)ulong; ++ numberWithInt8: (int8_t)int8; ++ numberWithInt16: (int16_t)int16; ++ numberWithInt32: (int32_t)int32; ++ numberWithInt64: (int64_t)int64; ++ numberWithUInt8: (uint8_t)uint8; ++ numberWithUInt16: (uint16_t)uint16; ++ numberWithUInt32: (uint32_t)uint32; ++ numberWithUInt64: (uint64_t)uint64; ++ numberWithSize: (size_t)size; ++ numberWithSSize: (ssize_t)ssize; ++ numberWithPtrDiff: (ptrdiff_t)ptrdiff; ++ numberWithIntPtr: (intptr_t)intptr; ++ numberWithFloat: (float)float_; ++ numberWithDouble: (double)double_; ++ numberWithLongDouble: (long double)longdouble; - initWithChar: (char)char_; - initWithShort: (short)short_; - initWithInt: (int)int_; - initWithLong: (long)long_; Index: src/OFNumber.m ================================================================== --- src/OFNumber.m +++ src/OFNumber.m @@ -66,123 +66,123 @@ /* Make gcc happy */ \ return 0; \ } @implementation OFNumber -+ newWithChar: (char)char_ -{ - return [[self alloc] initWithChar: char_]; -} - -+ newWithShort: (short)short_ -{ - return [[self alloc] initWithShort: short_]; -} - -+ newWithInt: (int)int_ -{ - return [[self alloc] initWithInt: int_]; -} - -+ newWithLong: (long)long_ -{ - return [[self alloc] initWithLong: long_]; -} - -+ newWithUChar: (unsigned char)uchar -{ - return [[self alloc] initWithUChar: uchar]; -} - -+ newWithUShort: (unsigned short)ushort -{ - return [[self alloc] initWithUShort: ushort]; -} - -+ newWithUInt: (unsigned int)uint -{ - return [[self alloc] initWithUInt: uint]; -} - -+ newWithULong: (unsigned long)ulong -{ - return [[self alloc] initWithULong: ulong]; -} - -+ newWithInt8: (int8_t)int8 -{ - return [[self alloc] initWithInt8: int8]; -} - -+ newWithInt16: (int16_t)int16 -{ - return [[self alloc] initWithInt16: int16]; -} - -+ newWithInt32: (int32_t)int32 -{ - return [[self alloc] initWithInt32: int32]; -} - -+ newWithInt64: (int64_t)int64 -{ - return [[self alloc] initWithInt64: int64]; -} - -+ newWithUInt8: (uint8_t)uint8 -{ - return [[self alloc] initWithUInt8: uint8]; -} - -+ newWithUInt16: (uint16_t)uint16 -{ - return [[self alloc] initWithUInt16: uint16]; -} - -+ newWithUInt32: (uint32_t)uint32 -{ - return [[self alloc] initWithUInt32: uint32]; -} - -+ newWithUInt64: (uint64_t)uint64 -{ - return [[self alloc] initWithUInt64: uint64]; -} - -+ newWithSize: (size_t)size -{ - return [[self alloc] initWithSize: size]; -} - -+ newWithSSize: (ssize_t)ssize -{ - return [[self alloc] initWithSSize: ssize]; -} - -+ newWithPtrDiff: (ptrdiff_t)ptrdiff -{ - return [[self alloc] initWithPtrDiff: ptrdiff]; -} - -+ newWithIntPtr: (intptr_t)intptr -{ - return [[self alloc] initWithIntPtr: intptr]; -} - -+ newWithFloat: (float)float_ -{ - return [[self alloc] initWithFloat: float_]; -} - -+ newWithDouble: (double)double_ -{ - return [[self alloc] initWithDouble: double_]; -} - -+ newWithLongDouble: (long double)longdouble -{ - return [[self alloc] initWithLongDouble: longdouble]; ++ numberWithChar: (char)char_ +{ + return [[[self alloc] initWithChar: char_] autorelease]; +} + ++ numberWithShort: (short)short_ +{ + return [[[self alloc] initWithShort: short_] autorelease]; +} + ++ numberWithInt: (int)int_ +{ + return [[[self alloc] initWithInt: int_] autorelease]; +} + ++ numberWithLong: (long)long_ +{ + return [[[self alloc] initWithLong: long_] autorelease]; +} + ++ numberWithUChar: (unsigned char)uchar +{ + return [[[self alloc] initWithUChar: uchar] autorelease]; +} + ++ numberWithUShort: (unsigned short)ushort +{ + return [[[self alloc] initWithUShort: ushort] autorelease]; +} + ++ numberWithUInt: (unsigned int)uint +{ + return [[[self alloc] initWithUInt: uint] autorelease]; +} + ++ numberWithULong: (unsigned long)ulong +{ + return [[[self alloc] initWithULong: ulong] autorelease]; +} + ++ numberWithInt8: (int8_t)int8 +{ + return [[[self alloc] initWithInt8: int8] autorelease]; +} + ++ numberWithInt16: (int16_t)int16 +{ + return [[[self alloc] initWithInt16: int16] autorelease]; +} + ++ numberWithInt32: (int32_t)int32 +{ + return [[[self alloc] initWithInt32: int32] autorelease]; +} + ++ numberWithInt64: (int64_t)int64 +{ + return [[[self alloc] initWithInt64: int64] autorelease]; +} + ++ numberWithUInt8: (uint8_t)uint8 +{ + return [[[self alloc] initWithUInt8: uint8] autorelease]; +} + ++ numberWithUInt16: (uint16_t)uint16 +{ + return [[[self alloc] initWithUInt16: uint16] autorelease]; +} + ++ numberWithUInt32: (uint32_t)uint32 +{ + return [[[self alloc] initWithUInt32: uint32] autorelease]; +} + ++ numberWithUInt64: (uint64_t)uint64 +{ + return [[[self alloc] initWithUInt64: uint64] autorelease]; +} + ++ numberWithSize: (size_t)size +{ + return [[[self alloc] initWithSize: size] autorelease]; +} + ++ numberWithSSize: (ssize_t)ssize +{ + return [[[self alloc] initWithSSize: ssize] autorelease]; +} + ++ numberWithPtrDiff: (ptrdiff_t)ptrdiff +{ + return [[[self alloc] initWithPtrDiff: ptrdiff] autorelease]; +} + ++ numberWithIntPtr: (intptr_t)intptr +{ + return [[[self alloc] initWithIntPtr: intptr] autorelease]; +} + ++ numberWithFloat: (float)float_ +{ + return [[[self alloc] initWithFloat: float_] autorelease]; +} + ++ numberWithDouble: (double)double_ +{ + return [[[self alloc] initWithDouble: double_] autorelease]; +} + ++ numberWithLongDouble: (long double)longdouble +{ + return [[[self alloc] initWithLongDouble: longdouble] autorelease]; } - initWithChar: (char)char_ { if ((self = [super init])) { Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -48,6 +48,11 @@ * * \param str The C string from which the data is written to the stream * \return The number of bytes written */ - (size_t)writeCString: (const char*)str; + +/** + * Closes the stream. + */ +- close; @end Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -22,37 +22,42 @@ char *string; size_t length; BOOL is_utf8; } +/** + * \return A new autoreleased OFString + */ ++ string; + /** * Creates a new OFString from a C string. * * \param str A C string to initialize the OFString with - * \return A new OFString + * \return A new autoreleased OFString */ -+ newFromCString: (const char*)str; ++ stringWithCString: (const char*)str; /** * Creates a new OFString from a format C string. * See printf for the format syntax. * * \param fmt A C string used as format to initialize the OFString - * \return A new OFString + * \return A new autoreleased OFString */ -+ newFromFormatCString: (const char*)fmt, ...; ++ stringWithFormat: (const char*)fmt, ...; /** * Creates a new OFString from a format C string. * See printf for the format syntax. * * \param fmt A C string used as format to initialize the OFString * \param args The arguments used in the format string - * \return A new OFString + * \return A new autoreleased OFString */ -+ newFromFormatCString: (const char*)fmt - withArguments: (va_list)args; ++ stringWithFormat: (const char*)fmt + andArguments: (va_list)args; /** * Initializes an already allocated OFString. * * \return An initialized OFString @@ -63,31 +68,31 @@ * Initializes an already allocated OFString from a C string. * * \param str A C string to initialize the OFString with * \return An initialized OFString */ -- initFromCString: (const char*)str; +- initWithCString: (const char*)str; /** * Initializes an already allocated OFString from a format C string. * See printf for the format syntax. * * \param fmt A C string used as format to initialize the OFString * \return An initialized OFString */ -- initFromFormatCString: (const char*)fmt, ...; +- initWithFormat: (const char*)fmt, ...; /** * Initializes an already allocated OFString from a format C string. * See printf for the format syntax. * * \param fmt A C string used as format to initialize the OFString * \param args The arguments used in the format string * \return An initialized OFString */ -- initFromFormatCString: (const char*)fmt - withArguments: (va_list)args; +- initWithFormat: (const char*)fmt + andArguments: (va_list)args; /** * \return The OFString as a wide C string */ - (const char*)cString; @@ -98,19 +103,18 @@ - (size_t)length; /** * Clones the OFString, creating a new one. * - * \return A copy of the OFString + * \return A new autoreleased copy of the OFString */ - (OFString*)clone; /** - * Frees the OFString and sets it to the specified OFString. + * Sets the OFString to the specified OFString. * * \param str An OFString to set the OFString to. - * \return The new OFString */ - setTo: (OFString*)str; /** * Compares the OFString to another OFString. Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -101,33 +101,38 @@ return (utf8 ? 1 : 0); } @implementation OFString -+ newFromCString: (const char*)str ++ string +{ + return [[[self alloc] init] autorelease]; +} + ++ stringWithCString: (const char*)str { - return [[self alloc] initFromCString: str]; + return [[[self alloc] initWithCString: str] autorelease]; } -+ newFromFormatCString: (const char*)fmt, ... ++ stringWithFormat: (const char*)fmt, ... { id ret; va_list args; va_start(args, fmt); - ret = [[self alloc] initFromFormatCString: fmt - withArguments: args]; + ret = [[[self alloc] initWithFormat: fmt + andArguments: args] autorelease]; va_end(args); return ret; } -+ newFromFormatCString: (const char*)fmt - withArguments: (va_list)args ++ stringWithFormat: (const char*)fmt + andArguments: (va_list)args { - return [[self alloc] initFromFormatCString: fmt - withArguments: args]; + return [[[self alloc] initWithFormat: fmt + andArguments: args] autorelease]; } - init { if ((self = [super init])) { @@ -137,11 +142,11 @@ } return self; } -- initFromCString: (const char*)str +- initWithCString: (const char*)str { Class c; if ((self = [super init])) { if (str != NULL) { @@ -164,25 +169,25 @@ } return self; } -- initFromFormatCString: (const char*)fmt, ... +- initWithFormat: (const char*)fmt, ... { id ret; va_list args; va_start(args, fmt); - ret = [self initFromFormatCString: fmt - withArguments: args]; + ret = [self initWithFormat: fmt + andArguments: args]; va_end(args); return ret; } -- initFromFormatCString: (const char*)fmt - withArguments: (va_list)args +- initWithFormat: (const char*)fmt + andArguments: (va_list)args { int t; Class c; if ((self = [super init])) { @@ -232,17 +237,39 @@ return length; } - (OFString*)clone { - return [OFString newFromCString: string]; + return [OFString stringWithCString: string]; } - setTo: (OFString*)str { - [self free]; - return (self = [str clone]); + size_t len; + + if (string != NULL) + free(string); + + len = [str length]; + + switch (check_utf8([str cString], len)) { + case 1: + is_utf8 = YES; + break; + case -1: + string = NULL; + length = 0; + is_utf8 = NO; + + @throw [OFInvalidEncodingException newWithClass: [self class]]; + } + + length = len; + string = [self getMemWithSize: length + 1]; + memcpy(string, [str cString], length + 1); + + return self; } - (int)compareTo: (OFString*)str { return strcmp(string, [str cString]); @@ -256,13 +283,10 @@ - appendCString: (const char*)str { char *newstr; size_t newlen, strlength; - if (string == NULL) - return [self setTo: [OFString newFromCString: str]]; - strlength = strlen(str); switch (check_utf8(str, strlength)) { case 1: is_utf8 = YES; Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -46,10 +46,15 @@ #endif struct sockaddr *saddr; socklen_t saddr_len; } +/** + * \return A new autoreleased OFTCPSocket + */ ++ tcpSocket; + /** * Initializes an already allocated OFTCPSocket. * * \return An initialized OFTCPSocket */ Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -23,10 +23,15 @@ #ifndef INVALID_SOCKET #define INVALID_SOCKET -1 #endif @implementation OFTCPSocket ++ tcpSocket +{ + return [[[self alloc] init] autorelease]; +} + #ifdef _WIN32 + (void)initialize { WSADATA wsa; Index: tests/OFArray/OFArray.m ================================================================== --- tests/OFArray/OFArray.m +++ tests/OFArray/OFArray.m @@ -33,11 +33,11 @@ const char *str = "Hallo!"; #define TEST(type) \ puts("Trying to add too much to an array..."); \ - a = [type newWithItemSize: 4096]; \ + a = [[type alloc] initWithItemSize: 4096]; \ CATCH_EXCEPTION([a addNItems: SIZE_MAX \ fromCArray: NULL], \ OFOutOfRangeException) \ \ puts("Trying to add something after that error..."); \ @@ -91,14 +91,14 @@ OFOutOfRangeException); \ \ puts("Trying to access an index that does not exist..."); \ CATCH_EXCEPTION([a item: [a items]], OFOutOfRangeException); \ \ - [a free]; \ + [a release]; \ \ puts("Creating new array and using it to build a string..."); \ - a = [type newWithItemSize: 1]; \ + a = [[type alloc] initWithItemSize: 1]; \ \ for (i = 0; i < strlen(str); i++) \ [a add: (void*)&str[i]]; \ [a add: ""]; \ \ @@ -107,11 +107,11 @@ else { \ puts("Built string does not match!"); \ abort(); \ } \ \ - [a free]; + [a release]; int main() { id a; Index: tests/OFHashes/OFHashes.m ================================================================== --- tests/OFHashes/OFHashes.m +++ tests/OFHashes/OFHashes.m @@ -27,39 +27,37 @@ main() { uint8_t buf[64]; size_t len; - OFMD5Hash *md5 = [OFMD5Hash new]; - OFSHA1Hash *sha1 = [OFSHA1Hash new]; - OFFile *f = [OFFile newWithPath: "testfile" - andMode: "rb"]; + OFMD5Hash *md5 = [OFMD5Hash md5Hash]; + OFSHA1Hash *sha1 = [OFSHA1Hash sha1Hash]; + OFFile *f = [OFFile fileWithPath: "testfile" + andMode: "rb"]; while (![f atEndOfFile]) { len = [f readNBytes: 64 intoBuffer: buf]; [md5 updateWithBuffer: buf ofSize: len]; [sha1 updateWithBuffer: buf ofSize: len]; } - [f free]; + [f close]; if (!memcmp([md5 digest], testfile_md5, MD5_DIGEST_SIZE)) { fputs("\r\033[1;33mTests successful: 1/2\033[0m", stdout); fflush(stdout); } else { puts("\r\033[K\033[1;31mTest 1/2 failed!\033[0m"); return 1; } - [md5 free]; if (!memcmp([sha1 digest], testfile_sha1, SHA1_DIGEST_SIZE)) puts("\r\033[1;32mTests successful: 2/2\033[0m"); else { puts("\r\033[K\033[1;31mTest 2/2 failed!\033[0m"); return 1; } - [sha1 free]; return 0; } Index: tests/OFList/OFList.m ================================================================== --- tests/OFList/OFList.m +++ tests/OFList/OFList.m @@ -57,15 +57,15 @@ { size_t i, j; OFList *list; of_list_object_t *iter; - list = [OFList new]; + list = [OFList list]; - [list append: [OFString newFromCString: strings[0]]]; - [list append: [OFString newFromCString: strings[1]]]; - [list append: [OFString newFromCString: strings[2]]]; + [list append: [OFString stringWithCString: strings[0]]]; + [list append: [OFString stringWithCString: strings[1]]]; + [list append: [OFString stringWithCString: strings[2]]]; for (iter = [list first], i = 0; iter != NULL; iter = iter->next, i++) if (!strcmp([iter->object cString], strings[i])) SUCCESS else @@ -79,17 +79,17 @@ [list remove: [list first]]; CHECK(!strcmp([[list first]->object cString], [[list last]->object cString])) - [list insert: [OFString newFromCString: strings[0]] + [list insert: [OFString stringWithCString: strings[0]] before: [list last]]; - [list insert: [OFString newFromCString: strings[2]] + [list insert: [OFString stringWithCString: strings[2]] after: [list first]->next]; for (iter = [list first], j = 0; iter != NULL; iter = iter->next, j++) CHECK(!strcmp([iter->object cString], strings[j])) puts(""); return 0; } Index: tests/OFString/OFString.m ================================================================== --- tests/OFString/OFString.m +++ tests/OFString/OFString.m @@ -13,10 +13,11 @@ #import #import "OFString.h" #import "OFExceptions.h" +#import "OFAutoreleasePool.h" #import #ifndef _WIN32 #define ZD "%zd" @@ -52,14 +53,15 @@ int main() { size_t i = 0; - OFString *s1 = [OFString newFromCString: "test"]; - OFString *s2 = [OFString newFromCString: ""]; + OFAutoreleasePool *pool = [OFAutoreleasePool new]; + OFString *s1 = [OFString stringWithCString: "test"]; + OFString *s2 = [OFString stringWithCString: ""]; OFString *s3; - OFString *s4 = [OFString new]; + OFString *s4 = [OFString string]; s3 = [s1 clone]; CHECK(![s1 compareTo: s3]) @@ -72,31 +74,28 @@ CHECK(!strcmp([[s1 reverse] cString], "321tset")) CHECK(!strcmp([[s1 upper] cString], "321TSET")) CHECK(!strcmp([[s1 lower] cString], "321tset")) /* Also clears all the memory of the returned C strings */ - [s1 free]; - [s2 free]; - [s3 free]; - [s4 free]; + [pool release]; /* UTF-8 tests */ - CHECK_EXCEPT(s1 = [OFString newFromCString: "\xE0\x80"], + CHECK_EXCEPT(s1 = [OFString stringWithCString: "\xE0\x80"], OFInvalidEncodingException) - CHECK_EXCEPT(s1 = [OFString newFromCString: "\xF0\x80\x80\xC0"], + CHECK_EXCEPT(s1 = [OFString stringWithCString: "\xF0\x80\x80\xC0"], OFInvalidEncodingException) - s1 = [OFString newFromCString: "äöü€𝄞"]; + s1 = [OFString stringWithCString: "äöü€𝄞"]; CHECK(!strcmp([[s1 reverse] cString], "𝄞€üöä")) [s1 free]; /* Format tests */ - s1 = [OFString newFromFormatCString: "%s: %d", "test", 123]; + s1 = [OFString stringWithFormat: "%s: %d", "test", 123]; CHECK(!strcmp([s1 cString], "test: 123")) [s1 appendWithFormatCString: "%02X", 15]; CHECK(!strcmp([s1 cString], "test: 1230F")) puts(""); return 0; } Index: tests/OFTCPSocket/OFTCPSocket.m ================================================================== --- tests/OFTCPSocket/OFTCPSocket.m +++ tests/OFTCPSocket/OFTCPSocket.m @@ -36,12 +36,12 @@ uint16_t port; srand(time(NULL)); @try { - OFTCPSocket *server = [OFTCPSocket new]; - OFTCPSocket *client = [OFTCPSocket new]; + OFTCPSocket *server = [OFTCPSocket tcpSocket]; + OFTCPSocket *client = [OFTCPSocket tcpSocket]; OFTCPSocket *accepted; char buf[7]; puts("== IPv4 =="); port = get_port(); @@ -69,11 +69,11 @@ } #ifdef HAVE_IPV6 memset(buf, 0, 7); - [accepted free]; + [accepted release]; [client close]; [server close]; puts("== IPv6 =="); port = get_port(); @@ -99,15 +99,15 @@ puts("Received INCORRECT string!"); return 1; } #endif - [accepted free]; - [client free]; - [server free]; + [accepted release]; + [client release]; + [server release]; } @catch(OFException *e) { printf("EXCEPTION: %s\n", [e cString]); return 1; } return 0; }