Index: src/OFApplication.h ================================================================== --- src/OFApplication.h +++ src/OFApplication.h @@ -203,10 +203,12 @@ * * @param sandbox The sandbox to activate */ + (void)activateSandbox: (OFSandbox *)sandbox; #endif + +- init OF_UNAVAILABLE; /*! * @brief Gets argc and argv. * * @param argc A pointer where a pointer to argc should be stored Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -66,10 +66,11 @@ # define SA_RESTART 0 # endif #endif @interface OFApplication () +- (instancetype)OF_init OF_METHOD_FAMILY(init); - (void)OF_setArgumentCount: (int *)argc andArgumentValues: (char **[])argv; #ifdef OF_WINDOWS - (void)OF_setArgumentCount: (int)argc andWideArgumentValues: (wchar_t *[])argv; @@ -128,11 +129,11 @@ "with OF_APPLICATION_DELEGATE().\n", class_getName(cls), class_getName(cls)); exit(1); } - app = [[OFApplication alloc] init]; + app = [[OFApplication alloc] OF_init]; [app OF_setArgumentCount: argc andArgumentValues: argv]; #ifdef OF_WINDOWS @@ -198,11 +199,11 @@ { [app activateSandbox: sandbox]; } #endif -- init +- OF_init { self = [super init]; @try { void *pool; Index: src/OFDeflateStream.h ================================================================== --- src/OFDeflateStream.h +++ src/OFDeflateStream.h @@ -86,9 +86,9 @@ * * @param stream The underlying stream to which compressed data is written or * from which compressed data is read * @return A initialized OFDeflateStream */ -- initWithStream: (OFStream *)stream; +- initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END Index: src/OFGZIPStream.h ================================================================== --- src/OFGZIPStream.h +++ src/OFGZIPStream.h @@ -73,9 +73,10 @@ uint16_t _extraLength; uint32_t _CRC32, _uncompressedSize; } + (instancetype)streamWithStream: (OFStream *)stream; -- initWithStream: (OFStream *)stream; +- init OF_UNAVAILABLE; +- initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END Index: src/OFGZIPStream.m ================================================================== --- src/OFGZIPStream.m +++ src/OFGZIPStream.m @@ -28,10 +28,15 @@ @implementation OFGZIPStream + (instancetype)streamWithStream: (OFStream *)stream { return [[[self alloc] initWithStream: stream] autorelease]; } + +- init +{ + OF_INVALID_INIT_METHOD +} - initWithStream: (OFStream *)stream { self = [super init]; Index: src/OFHMAC.h ================================================================== --- src/OFHMAC.h +++ src/OFHMAC.h @@ -41,18 +41,20 @@ * @param hashClass The class of the hashing algorithm * @return A new, autoreleased OFHMAC */ + (instancetype)HMACWithHashClass: (Class )hashClass; +- init OF_UNAVAILABLE; + /*! * @brief Initialized an already allocated OFHMAC with the specified hashing * algorithm. * * @param hashClass The class of the hashing algorithm * @return An initialized OFHMAC */ -- initWithHashClass: (Class )hashClass; +- initWithHashClass: (Class )hashClass OF_DESIGNATED_INITIALIZER; /*! * @brief Sets the key for the HMAC. * * @note This resets the HMAC! Index: src/OFHMAC.m ================================================================== --- src/OFHMAC.m +++ src/OFHMAC.m @@ -24,10 +24,15 @@ + (instancetype)HMACWithHashClass: (Class )class { return [[[self alloc] initWithHashClass: class] autorelease]; } + +- init +{ + OF_INVALID_INIT_METHOD +} - initWithHashClass: (Class )class { self = [super init]; Index: src/OFHTTPCookie.h ================================================================== --- src/OFHTTPCookie.h +++ src/OFHTTPCookie.h @@ -101,7 +101,7 @@ * @param name The name of the cookie * @param value The value of the cookie * @return An initialized OFHTTPCookie */ - initWithName: (OFString *)name - value: (OFString *)value; + value: (OFString *)value OF_DESIGNATED_INITIALIZER; @end Index: src/OFINICategory+Private.h ================================================================== --- src/OFINICategory+Private.h +++ src/OFINICategory+Private.h @@ -20,13 +20,13 @@ OF_ASSUME_NONNULL_BEGIN @class OFStream; @interface OFINICategory () -- (instancetype)OF_init; +- (instancetype)OF_init OF_METHOD_FAMILY(init); - (void)OF_parseLine: (OFString *)line; - (bool)OF_writeToStream: (OFStream *)stream encoding: (of_string_encoding_t)encoding first: (bool)first; @end OF_ASSUME_NONNULL_END Index: src/OFINIFile.h ================================================================== --- src/OFINIFile.h +++ src/OFINIFile.h @@ -73,11 +73,11 @@ * @param encoding The encoding of the specified file * * @return An initialized OFINIFile with the contents of the specified file */ - initWithPath: (OFString *)path - encoding: (of_string_encoding_t)encoding; + encoding: (of_string_encoding_t)encoding OF_DESIGNATED_INITIALIZER; /*! * @brief Returns an @ref OFINICategory for the category with the specified * name. * Index: src/OFIntrospection.h ================================================================== --- src/OFIntrospection.h +++ src/OFIntrospection.h @@ -212,9 +212,9 @@ * @brief Initializes an already allocated OFIntrospection with the specified * class. * * @return An initialized OFIntrospection */ -- initWithClass: (Class)class_; +- initWithClass: (Class)class_ OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END Index: src/OFMapTable.h ================================================================== --- src/OFMapTable.h +++ src/OFMapTable.h @@ -135,11 +135,11 @@ * table * @return An initialized OFMapTable */ - initWithKeyFunctions: (of_map_table_functions_t)keyFunctions objectFunctions: (of_map_table_functions_t)objectFunctions - capacity: (size_t)capacity; + capacity: (size_t)capacity OF_DESIGNATED_INITIALIZER; /*! * @brief Returns the number of objects in the map table. * * @return The number of objects in the map table Index: src/OFMapTable.m ================================================================== --- src/OFMapTable.m +++ src/OFMapTable.m @@ -68,11 +68,12 @@ @interface OFMapTableEnumerator () - (instancetype)OF_initWithMapTable: (OFMapTable *)mapTable buckets: (struct of_map_table_bucket **)buckets capacity: (uint32_t)capacity - mutationsPointer: (unsigned long *)mutationsPtr; + mutationsPointer: (unsigned long *)mutationsPtr + OF_METHOD_FAMILY(init); @end @interface OFMapTableKeyEnumerator: OFMapTableEnumerator @end Index: src/OFMessagePackExtension.h ================================================================== --- src/OFMessagePackExtension.h +++ src/OFMessagePackExtension.h @@ -64,9 +64,9 @@ * @param type The MessagePack extension type * @param data The data for the extension * @return An initialized OFMessagePackRepresentation */ - initWithType: (int8_t)type - data: (OFDataArray *)data; + data: (OFDataArray *)data OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END Index: src/OFOptionsParser.h ================================================================== --- src/OFOptionsParser.h +++ src/OFOptionsParser.h @@ -130,11 +130,12 @@ * accepted options, terminated with an option whose short * option is `\0` and long option is `nil`. * * @return An initialized OFOptionsParser */ -- initWithOptions: (const of_options_parser_option_t *)options; +- initWithOptions: (const of_options_parser_option_t *)options + OF_DESIGNATED_INITIALIZER; /*! * @brief Returns the next option. * * If the option is only available as a long option, `-` is returned. Index: src/OFProcess.h ================================================================== --- src/OFProcess.h +++ src/OFProcess.h @@ -171,11 +171,12 @@ */ - initWithProgram: (OFString *)program programName: (OFString *)programName arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments environment: (nullable OFDictionary - OF_GENERIC(OFString *, OFString *) *)environment; + OF_GENERIC(OFString *, OFString *) *)environment + OF_DESIGNATED_INITIALIZER; /*! * @brief Closes the write direction of the process. * * This method needs to be called for some programs before data can be read, Index: src/OFSettings.h ================================================================== --- src/OFSettings.h +++ src/OFSettings.h @@ -60,11 +60,12 @@ * * @param applicationName The name of the application whose settings should be * accessed * @return An initialized OFSettings instance */ -- initWithApplicationName: (OFString *)applicationName; +- initWithApplicationName: (OFString *)applicationName + OF_DESIGNATED_INITIALIZER; /*! * @brief Sets the specified path to the specified string. * * @param string The string to set Index: src/OFStdIOStream+Private.h ================================================================== --- src/OFStdIOStream+Private.h +++ src/OFStdIOStream+Private.h @@ -17,9 +17,9 @@ #import "OFStdIOStream.h" OF_ASSUME_NONNULL_BEGIN @interface OFStdIOStream () -- (instancetype)OF_initWithFileDescriptor: (int)fd; +- (instancetype)OF_initWithFileDescriptor: (int)fd OF_METHOD_FAMILY(init); @end OF_ASSUME_NONNULL_END Index: src/OFString_UTF8+Private.h ================================================================== --- src/OFString_UTF8+Private.h +++ src/OFString_UTF8+Private.h @@ -19,9 +19,9 @@ OF_ASSUME_NONNULL_BEGIN @interface OFString_UTF8 () - (instancetype)OF_initWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength - storage: (char *)storage; + storage: (char *)storage OF_METHOD_FAMILY(init); @end OF_ASSUME_NONNULL_END Index: src/OFTarArchive.h ================================================================== --- src/OFTarArchive.h +++ src/OFTarArchive.h @@ -60,11 +60,11 @@ * specified stream. * * @param stream A stream from which the tar archive will be read * @return An initialized OFTarArchive */ -- initWithStream: (OFStream *)stream; +- initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER; #ifdef OF_HAVE_FILES /*! * @brief Initializes an already allocated OFTarArchive object with the * specified file. Index: src/OFTarArchive.m ================================================================== --- src/OFTarArchive.m +++ src/OFTarArchive.m @@ -49,21 +49,17 @@ } #ifdef OF_HAVE_FILES - initWithPath: (OFString *)path { - self = [super init]; - + OFFile *file = [[OFFile alloc] initWithPath: path + mode: @"rb"]; @try { - _stream = [[OFFile alloc] initWithPath: path - mode: @"rb"]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; + return [self initWithStream: file]; + } @finally { + [file release]; + } } #endif - (void)dealloc { Index: src/OFTarArchiveEntry+Private.h ================================================================== --- src/OFTarArchiveEntry+Private.h +++ src/OFTarArchiveEntry+Private.h @@ -18,10 +18,10 @@ OF_ASSUME_NONNULL_BEGIN @interface OFTarArchiveEntry () - (instancetype)OF_initWithHeader: (char[_Nonnull 512])header - stream: (OFStream *)stream; + stream: (OFStream *)stream OF_METHOD_FAMILY(init); - (void)OF_skip; @end OF_ASSUME_NONNULL_END Index: src/OFTarArchiveEntry.h ================================================================== --- src/OFTarArchiveEntry.h +++ src/OFTarArchiveEntry.h @@ -111,8 +111,10 @@ /*! * The device major (if the file is a device). */ @property (readonly) uint32_t deviceMinor; + +- init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END Index: src/OFTarArchiveEntry.m ================================================================== --- src/OFTarArchiveEntry.m +++ src/OFTarArchiveEntry.m @@ -54,10 +54,15 @@ @synthesize fileName = _fileName, mode = _mode, size = _size; @synthesize modificationDate = _modificationDate, type = _type; @synthesize targetFileName = _targetFileName; @synthesize owner = _owner, group = _group; @synthesize deviceMajor = _deviceMajor, deviceMinor = _deviceMinor; + +- init +{ + OF_INVALID_INIT_METHOD +} - (instancetype)OF_initWithHeader: (char[512])header stream: (OFStream *)stream { self = [super init]; Index: src/OFThreadPool.h ================================================================== --- src/OFThreadPool.h +++ src/OFThreadPool.h @@ -77,11 +77,11 @@ * number of threads. * * @param size The number of threads for the pool * @return An initialized OFThreadPool with the specified number of threads */ -- initWithSize: (size_t)size; +- initWithSize: (size_t)size OF_DESIGNATED_INITIALIZER; /*! * @brief Execute the specified selector on the specified target with the * specified object as soon as a thread is ready. * Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -286,11 +286,10 @@ #ifdef OF_HAVE_FILES - (void)parseFile: (OFString *)path { OFFile *file = [[OFFile alloc] initWithPath: path mode: @"rb"]; - @try { [self parseStream: file]; } @finally { [file release]; } Index: src/OFZIPArchive.h ================================================================== --- src/OFZIPArchive.h +++ src/OFZIPArchive.h @@ -77,11 +77,11 @@ * specified seekable stream. * * @param stream A seekable stream from which the ZIP archive will be read * @return An initialized OFZIPArchive */ -- initWithSeekableStream: (OFSeekableStream *)stream; +- initWithSeekableStream: (OFSeekableStream *)stream OF_DESIGNATED_INITIALIZER; #ifdef OF_HAVE_FILES /*! * @brief Initializes an already allocated OFZIPArchive object with the * specified file. Index: src/OFZIPArchive.m ================================================================== --- src/OFZIPArchive.m +++ src/OFZIPArchive.m @@ -171,24 +171,17 @@ } #ifdef OF_HAVE_FILES - initWithPath: (OFString *)path { - self = [super init]; - + OFFile *file = [[OFFile alloc] initWithPath: path + mode: @"rb"]; @try { - _stream = [[OFFile alloc] initWithPath: path - mode: @"rb"]; - - [self OF_readZIPInfo]; - [self OF_readEntries]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; + return [self initWithSeekableStream: file]; + } @finally { + [file release]; + } } #endif - (void)dealloc { Index: src/OFZIPArchiveEntry+Private.h ================================================================== --- src/OFZIPArchiveEntry+Private.h +++ src/OFZIPArchiveEntry+Private.h @@ -20,9 +20,9 @@ @interface OFZIPArchiveEntry () @property (readonly) uint16_t OF_lastModifiedFileTime, OF_lastModifiedFileDate; @property (readonly) int64_t OF_localFileHeaderOffset; -- (instancetype)OF_initWithStream: (OFStream *)stream; +- (instancetype)OF_initWithStream: (OFStream *)stream OF_METHOD_FAMILY(init); @end OF_ASSUME_NONNULL_END Index: src/OFZIPArchiveEntry.h ================================================================== --- src/OFZIPArchiveEntry.h +++ src/OFZIPArchiveEntry.h @@ -172,10 +172,12 @@ * The general purpose bit flag of the entry. * * See the ZIP specification for details. */ @property (readonly) uint16_t generalPurposeBitFlag; + +- init OF_UNAVAILABLE; /*! * @brief Returns the last modification date of the entry's file. * * @return The last modification date of the entry's file Index: src/OFZIPArchiveEntry.m ================================================================== --- src/OFZIPArchiveEntry.m +++ src/OFZIPArchiveEntry.m @@ -152,10 +152,15 @@ @synthesize versionSpecificAttributes = _versionSpecificAttributes; @synthesize generalPurposeBitFlag = _generalPurposeBitFlag; @synthesize OF_lastModifiedFileTime = _lastModifiedFileTime; @synthesize OF_lastModifiedFileDate = _lastModifiedFileDate; @synthesize OF_localFileHeaderOffset = _localFileHeaderOffset; + +- init +{ + OF_INVALID_INIT_METHOD +} - (instancetype)OF_initWithStream: (OFStream *)stream { self = [super init]; Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -219,10 +219,23 @@ # define OF_SUBCLASSING_RESTRICTED \ __attribute__((__objc_subclassing_restricted__)) #else # define OF_SUBCLASSING_RESTRICTED #endif + +#if __has_attribute(__objc_method_family__) +# define OF_METHOD_FAMILY(f) __attribute__((__objc_method_family__(f))) +#else +# define OF_METHOD_FAMILY(f) +#endif + +#if __has_attribute(__objc_designated_initializer__) +# define OF_DESIGNATED_INITIALIZER \ + __attribute__((__objc_designated_initializer__)) +#else +# define OF_DESIGNATED_INITIALIZER +#endif #ifdef __GNUC__ # ifdef OF_X86_64 # define OF_X86_64_ASM # endif