Skip to content

Commit b49edf6

Browse files
committed
Replace all non-cyclic NSAutoreleasepools with @autoreleasepool
1 parent 7f35608 commit b49edf6

32 files changed

+2755
-2859
lines changed

Frameworks/PostgresKit/Source/PGPostgresConnection.m

+50-52
Original file line numberDiff line numberDiff line change
@@ -297,64 +297,62 @@ - (BOOL)cancelCurrentQuery:(NSError **)error
297297
*/
298298
- (void)_pollConnection:(NSNumber *)isReset
299299
{
300-
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
301-
302-
BOOL reset = isReset && [isReset boolValue];
303-
304-
int sock = PQsocket(_connection);
305-
306-
if (sock == -1) {
307-
[pool release];
308-
return;
309-
}
310-
311-
struct pollfd fdinfo[1];
312-
313-
fdinfo[0].fd = sock;
314-
fdinfo[0].events = POLLIN|POLLOUT;
315-
316-
PostgresPollingStatusType status;
317-
318-
do
319-
{
320-
status = reset ? PQresetPoll(_connection) : PQconnectPoll(_connection);
321-
322-
if (status == PGRES_POLLING_READING || status == PGRES_POLLING_WRITING) {
323-
if (poll(fdinfo, 1, -1) < 0) break;
324-
}
325-
}
326-
while (status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED);
327-
328-
if (status == PGRES_POLLING_OK && [self isConnected]) {
329-
330-
// Increase error verbosity
331-
PQsetErrorVerbosity(_connection, PQERRORS_VERBOSE);
332-
333-
// Set notice processor
334-
PQsetNoticeProcessor(_connection, _PGPostgresConnectionNoticeProcessor, self);
335-
336-
// Register or clear type extensions
337-
NSInteger success = reset ? PQclearTypes(_connection) : PQinitTypes(_connection);
338-
339-
if (!success) {
340-
NSLog(@"PostgresKit: Error: Failed to initialise or clear type extensions. Connection might return unexpected results!");
300+
@autoreleasepool {
301+
BOOL reset = isReset && [isReset boolValue];
302+
303+
int sock = PQsocket(_connection);
304+
305+
if (sock == -1) {
306+
[pool release];
307+
return;
341308
}
342-
343-
[self _loadDatabaseParameters];
344-
345-
if (reset) {
346-
if (_delegate && [_delegate respondsToSelector:@selector(connectionReset:)]) {
347-
[_delegate performSelectorOnMainThread:@selector(connectionReset:) withObject:self waitUntilDone:NO];
309+
310+
struct pollfd fdinfo[1];
311+
312+
fdinfo[0].fd = sock;
313+
fdinfo[0].events = POLLIN|POLLOUT;
314+
315+
PostgresPollingStatusType status;
316+
317+
do
318+
{
319+
status = reset ? PQresetPoll(_connection) : PQconnectPoll(_connection);
320+
321+
if (status == PGRES_POLLING_READING || status == PGRES_POLLING_WRITING) {
322+
if (poll(fdinfo, 1, -1) < 0) break;
348323
}
349324
}
350-
else {
351-
if (_delegate && [_delegate respondsToSelector:@selector(connectionEstablished:)]) {
352-
[_delegate performSelectorOnMainThread:@selector(connectionEstablished:) withObject:self waitUntilDone:NO];
325+
while (status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED);
326+
327+
if (status == PGRES_POLLING_OK && [self isConnected]) {
328+
329+
// Increase error verbosity
330+
PQsetErrorVerbosity(_connection, PQERRORS_VERBOSE);
331+
332+
// Set notice processor
333+
PQsetNoticeProcessor(_connection, _PGPostgresConnectionNoticeProcessor, self);
334+
335+
// Register or clear type extensions
336+
NSInteger success = reset ? PQclearTypes(_connection) : PQinitTypes(_connection);
337+
338+
if (!success) {
339+
NSLog(@"PostgresKit: Error: Failed to initialise or clear type extensions. Connection might return unexpected results!");
340+
}
341+
342+
[self _loadDatabaseParameters];
343+
344+
if (reset) {
345+
if (_delegate && [_delegate respondsToSelector:@selector(connectionReset:)]) {
346+
[_delegate performSelectorOnMainThread:@selector(connectionReset:) withObject:self waitUntilDone:NO];
347+
}
348+
}
349+
else {
350+
if (_delegate && [_delegate respondsToSelector:@selector(connectionEstablished:)]) {
351+
[_delegate performSelectorOnMainThread:@selector(connectionEstablished:) withObject:self waitUntilDone:NO];
352+
}
353353
}
354354
}
355355
}
356-
357-
[pool release];
358356
}
359357

360358
/**

Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.m

+22-24
Original file line numberDiff line numberDiff line change
@@ -138,32 +138,30 @@ - (id)valueForParameter:(NSString *)parameter
138138
*/
139139
- (void)_loadParameters:(id)object
140140
{
141-
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
142-
143-
pthread_mutex_lock(&_readLock);
144-
145-
NSArray *parameters = (NSArray *)object;
146-
147-
if (!_parameters) {
148-
_parameters = [[NSMutableDictionary alloc] initWithCapacity:[parameters count]];
149-
}
150-
151-
for (NSString *parameter in parameters)
152-
{
153-
const char *value = PQparameterStatus([_connection postgresConnection], [parameter UTF8String]);
154-
155-
if (!value) continue;
156-
157-
NSString *stringValue = [NSString stringWithUTF8String:value];
141+
@autoreleasepool {
142+
pthread_mutex_lock(&_readLock);
158143

159-
id paramObject = [self _isBooleanParameterValue:stringValue] ? (id)[NSNumber numberWithBool:[self _booleanForParameterValue:stringValue]] : stringValue;
160-
161-
[_parameters setObject:paramObject forKey:parameter];
144+
NSArray *parameters = (NSArray *)object;
145+
146+
if (!_parameters) {
147+
_parameters = [[NSMutableDictionary alloc] initWithCapacity:[parameters count]];
148+
}
149+
150+
for (NSString *parameter in parameters)
151+
{
152+
const char *value = PQparameterStatus([_connection postgresConnection], [parameter UTF8String]);
153+
154+
if (!value) continue;
155+
156+
NSString *stringValue = [NSString stringWithUTF8String:value];
157+
158+
id paramObject = [self _isBooleanParameterValue:stringValue] ? (id)[NSNumber numberWithBool:[self _booleanForParameterValue:stringValue]] : stringValue;
159+
160+
[_parameters setObject:paramObject forKey:parameter];
161+
}
162+
163+
pthread_mutex_unlock(&_readLock);
162164
}
163-
164-
pthread_mutex_unlock(&_readLock);
165-
166-
[pool release];
167165
}
168166

169167
/**

0 commit comments

Comments
 (0)