From 1fb20d579113845d2d8a7e0810fa5c75eb4fce12 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Fri, 18 Apr 2025 21:29:58 +0000 Subject: [PATCH] Use ARC functions for RR FossilOrigin-Name: d80ebb2ce13b075e0e67dfb391cd120f2bf99f6ad5492c50d4e71e59dcbd1ac1 --- src/SL3Connection.m | 11 ++++++----- src/SL3PreparedStatement.m | 18 +++++++----------- src/exceptions/SL3BindObjectFailedException.m | 19 ++++++++++--------- .../SL3ClearBindingsFailedException.m | 11 ++++++----- src/exceptions/SL3Exception.m | 9 +++++---- .../SL3ExecuteStatementFailedException.m | 11 ++++++----- src/exceptions/SL3OpenFailedException.m | 11 ++++++----- .../SL3PrepareStatementFailedException.m | 13 +++++++------ .../SL3ResetStatementFailedException.m | 11 ++++++----- 9 files changed, 59 insertions(+), 55 deletions(-) diff --git a/src/SL3Connection.m b/src/SL3Connection.m index 12474f6..c05b925 100644 --- a/src/SL3Connection.m +++ b/src/SL3Connection.m @@ -26,12 +26,13 @@ @implementation SL3Connection + (instancetype)connectionWithIRI: (OFIRI *)IRI { - return [[[self alloc] initWithIRI: IRI] autorelease]; + return objc_autoreleaseReturnValue([[self alloc] initWithIRI: IRI]); } + (instancetype)connectionWithIRI: (OFIRI *)IRI flags: (int)flags { - return [[[self alloc] initWithIRI: IRI flags: flags] autorelease]; + return objc_autoreleaseReturnValue([[self alloc] initWithIRI: IRI + flags: flags]); } - (instancetype)initWithIRI: (OFIRI *)IRI @@ -54,7 +55,7 @@ flags: flags errorCode: code]; } @catch (id e) { - [self release]; + objc_release(self); @throw e; } @@ -70,9 +71,9 @@ - (SL3PreparedStatement *)prepareStatement: (OFConstantString *)SQLStatement { - return [[[SL3PreparedStatement alloc] + return objc_autoreleaseReturnValue([[SL3PreparedStatement alloc] sl3_initWithConnection: self - SQLStatement: SQLStatement] autorelease]; + SQLStatement: SQLStatement]); } - (void)executeStatement: (OFConstantString *)SQLStatement diff --git a/src/SL3PreparedStatement.m b/src/SL3PreparedStatement.m index 6ee424c..ae49bf7 100644 --- a/src/SL3PreparedStatement.m +++ b/src/SL3PreparedStatement.m @@ -25,12 +25,6 @@ #import "SL3PrepareStatementFailedException.h" #import "SL3ResetStatementFailedException.h" -static void -releaseObject(void *object) -{ - [(id)object release]; -} - @implementation SL3PreparedStatement - (instancetype)sl3_initWithConnection: (SL3Connection *)connection SQLStatement: (OFConstantString *)SQLStatement @@ -48,9 +42,9 @@ releaseObject(void *object) SQLStatement: SQLStatement errorCode: code]; - _connection = [connection retain]; + _connection = objc_retain(connection); } @catch (id e) { - [self release]; + objc_release(self); @throw e; } @@ -60,7 +54,7 @@ releaseObject(void *object) - (void)dealloc { sqlite3_finalize(_stmt); - [_connection release]; + objc_release(_connection); [super dealloc]; } @@ -87,13 +81,15 @@ bindObject(SL3PreparedStatement *statement, int column, id object) OFString *copy = [object copy]; code = sqlite3_bind_text64(statement->_stmt, column, - copy.UTF8String, copy.UTF8StringLength, releaseObject, + copy.UTF8String, copy.UTF8StringLength, + (void (*)(void *))(void (*)(void))objc_release, SQLITE_UTF8); } else if ([object isKindOfClass: [OFData class]]) { OFData *copy = [object copy]; code = sqlite3_bind_blob64(statement->_stmt, column, copy.items, - copy.count * copy.itemSize, releaseObject); + copy.count * copy.itemSize, + (void (*)(void *))(void (*)(void))objc_release); } else if ([object isEqual: [OFNull null]]) code = sqlite3_bind_null(statement->_stmt, column); else diff --git a/src/exceptions/SL3BindObjectFailedException.m b/src/exceptions/SL3BindObjectFailedException.m index ecbacd3..b06a736 100644 --- a/src/exceptions/SL3BindObjectFailedException.m +++ b/src/exceptions/SL3BindObjectFailedException.m @@ -32,10 +32,11 @@ statement: (SL3PreparedStatement *)statement errorCode: (int)errorCode { - return [[[self alloc] initWithObject: object - column: column - statement: statement - errorCode: errorCode] autorelease]; + return objc_autoreleaseReturnValue( + [[self alloc] initWithObject: object + column: column + statement: statement + errorCode: errorCode]); } - (instancetype)initWithConnection: (SL3Connection *)connection @@ -53,10 +54,10 @@ errorCode: errorCode]; @try { - _object = [object retain]; - _statement = [statement retain]; + _object = objc_retain(object); + _statement = objc_retain(statement); } @catch (id e) { - [self release]; + objc_release(self); @throw e; } @@ -65,8 +66,8 @@ - (void)dealloc { - [_object release]; - [_statement release]; + objc_release(_object); + objc_release(_statement); [super dealloc]; } diff --git a/src/exceptions/SL3ClearBindingsFailedException.m b/src/exceptions/SL3ClearBindingsFailedException.m index 7d1eacc..42c423e 100644 --- a/src/exceptions/SL3ClearBindingsFailedException.m +++ b/src/exceptions/SL3ClearBindingsFailedException.m @@ -30,8 +30,9 @@ + (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement errorCode: (int)errorCode { - return [[[self alloc] initWithStatement: statement - errorCode: errorCode] autorelease]; + return objc_autoreleaseReturnValue( + [[self alloc] initWithStatement: statement + errorCode: errorCode]); } - (instancetype)initWithConnection: (SL3Connection *)connection @@ -47,9 +48,9 @@ errorCode: errorCode]; @try { - _statement = [statement retain]; + _statement = objc_retain(statement); } @catch (id e) { - [self release]; + objc_release(self); @throw e; } @@ -58,7 +59,7 @@ - (void)dealloc { - [_statement release]; + objc_release(_statement); [super dealloc]; } diff --git a/src/exceptions/SL3Exception.m b/src/exceptions/SL3Exception.m index 251015f..a62631a 100644 --- a/src/exceptions/SL3Exception.m +++ b/src/exceptions/SL3Exception.m @@ -29,8 +29,9 @@ + (instancetype)exceptionWithConnection: (SL3Connection *)connection errorCode: (int)errorCode { - return [[[self alloc] initWithConnection: connection - errorCode: errorCode] autorelease]; + return objc_autoreleaseReturnValue( + [[self alloc] initWithConnection: connection + errorCode: errorCode]); } - (instancetype)init @@ -43,7 +44,7 @@ { self = [super init]; - _connection = [connection retain]; + _connection = objc_retain(connection); _errorCode = errorCode; return self; @@ -51,7 +52,7 @@ - (void)dealloc { - [_connection release]; + objc_release(_connection); [super dealloc]; } diff --git a/src/exceptions/SL3ExecuteStatementFailedException.m b/src/exceptions/SL3ExecuteStatementFailedException.m index 0322085..11c4884 100644 --- a/src/exceptions/SL3ExecuteStatementFailedException.m +++ b/src/exceptions/SL3ExecuteStatementFailedException.m @@ -24,8 +24,9 @@ + (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement errorCode: (int)errorCode { - return [[[self alloc] initWithStatement: statement - errorCode: errorCode] autorelease]; + return objc_autoreleaseReturnValue( + [[self alloc] initWithStatement: statement + errorCode: errorCode]); } - (instancetype)initWithStatement: (SL3PreparedStatement *)statement @@ -35,9 +36,9 @@ errorCode: errorCode]; @try { - _statement = [statement retain]; + _statement = objc_retain(statement); } @catch (id e) { - [self release]; + objc_release(self); @throw e; } @@ -46,7 +47,7 @@ - (void)dealloc { - [_statement release]; + objc_release(_statement); [super dealloc]; } diff --git a/src/exceptions/SL3OpenFailedException.m b/src/exceptions/SL3OpenFailedException.m index dacdf68..9288913 100644 --- a/src/exceptions/SL3OpenFailedException.m +++ b/src/exceptions/SL3OpenFailedException.m @@ -31,9 +31,10 @@ flags: (int)flags errorCode: (int)errorCode { - return [[[self alloc] initWithIRI: IRI - flags: flags - errorCode: errorCode] autorelease]; + return objc_autoreleaseReturnValue( + [[self alloc] initWithIRI: IRI + flags: flags + errorCode: errorCode]); } - (instancetype)initWithConnection: (SL3Connection *)connection @@ -53,7 +54,7 @@ _IRI = [IRI copy]; _flags = flags; } @catch (id e) { - [self release]; + objc_release(self); @throw e; } @@ -62,7 +63,7 @@ - (void)dealloc { - [_IRI release]; + objc_release(_IRI); [super dealloc]; } diff --git a/src/exceptions/SL3PrepareStatementFailedException.m b/src/exceptions/SL3PrepareStatementFailedException.m index 4ed0de5..68b85d4 100644 --- a/src/exceptions/SL3PrepareStatementFailedException.m +++ b/src/exceptions/SL3PrepareStatementFailedException.m @@ -31,9 +31,10 @@ SQLStatement: (OFConstantString *)SQLStatement errorCode: (int)errorCode { - return [[[self alloc] initWithConnection: connection - SQLStatement: SQLStatement - errorCode: errorCode] autorelease]; + return objc_autoreleaseReturnValue( + [[self alloc] initWithConnection: connection + SQLStatement: SQLStatement + errorCode: errorCode]); } - (instancetype)initWithConnection: (SL3Connection *)connection @@ -50,9 +51,9 @@ errorCode: errorCode]; @try { - _SQLStatement = [SQLStatement retain]; + _SQLStatement = objc_retain(SQLStatement); } @catch (id e) { - [self release]; + objc_release(self); @throw e; } @@ -61,7 +62,7 @@ - (void)dealloc { - [_SQLStatement release]; + objc_release(_SQLStatement); [super dealloc]; } diff --git a/src/exceptions/SL3ResetStatementFailedException.m b/src/exceptions/SL3ResetStatementFailedException.m index 16a6b69..e7ab9a7 100644 --- a/src/exceptions/SL3ResetStatementFailedException.m +++ b/src/exceptions/SL3ResetStatementFailedException.m @@ -30,8 +30,9 @@ + (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement errorCode: (int)errorCode { - return [[[self alloc] initWithStatement: statement - errorCode: errorCode] autorelease]; + return objc_autoreleaseReturnValue( + [[self alloc] initWithStatement: statement + errorCode: errorCode]); } - (instancetype)initWithConnection: (SL3Connection *)connection @@ -47,9 +48,9 @@ errorCode: errorCode]; @try { - _statement = [statement retain]; + _statement = objc_retain(statement); } @catch (id e) { - [self release]; + objc_release(self); @throw e; } @@ -58,7 +59,7 @@ - (void)dealloc { - [_statement release]; + objc_release(_statement); [super dealloc]; }