ObjFW  Check-in [07b3d0e8de]

Overview
Comment:Add -[finalize] to all classes which would require it once we have GC.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 07b3d0e8de09f34f948feee9dc97d7b5cfb96f09aa09bda6399624461721f244
User & Date: js on 2011-04-24 21:50:04
Other Links: manifest | tags
Context
2011-04-25
00:18
Add +[OFDataArray dataArrayWithContentsOfURL:]. check-in: 9c4d3e34cd user: js tags: trunk
2011-04-24
21:50
Add -[finalize] to all classes which would require it once we have GC. check-in: 07b3d0e8de user: js tags: trunk
18:30
Add _NSPrintForDebugger. check-in: ff381fe8ba user: js tags: trunk
Changes

Modified src/OFFile.m from [521d39c7c0] to [45991e6e84].

682
683
684
685
686
687
688








689
690
691
692
693
694
695
- (void)dealloc
{
	if (closable && fileDescriptor != -1)
		close(fileDescriptor);

	[super dealloc];
}








@end

@implementation OFFileSingleton
- initWithPath: (OFString*)path
	  mode: (OFString*)mode
{
	Class c = isa;







>
>
>
>
>
>
>
>







682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
- (void)dealloc
{
	if (closable && fileDescriptor != -1)
		close(fileDescriptor);

	[super dealloc];
}

- (void)finalize
{
	if (closable && fileDescriptor != -1)
		close(fileDescriptor);

	[super finalize];
}
@end

@implementation OFFileSingleton
- initWithPath: (OFString*)path
	  mode: (OFString*)mode
{
	Class c = isa;

Modified src/OFObject.h from [71473f3fce] to [ae7d2dccfa].

407
408
409
410
411
412
413






414
415
416
417
418
419
420

/**
 * Deallocates the object and also frees all memory in its memory pool.
 *
 * It is also called when the retain count reaches zero.
 */
- (void)dealloc;






@end

/**
 * \brief A protocol for the creation of copies.
 */
@protocol OFCopying <OFObject>
/**







>
>
>
>
>
>







407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426

/**
 * Deallocates the object and also frees all memory in its memory pool.
 *
 * It is also called when the retain count reaches zero.
 */
- (void)dealloc;

/**
 * If a garbage collector is added in the future, this method will be called
 * before it disposes of the object, for example to close files.
 */
- (void)finalize;
@end

/**
 * \brief A protocol for the creation of copies.
 */
@protocol OFCopying <OFObject>
/**

Modified src/OFObject.m from [e4b8e27eb3] to [e69c1ca6c9].

811
812
813
814
815
816
817



























818
819
820
821
822
823
824
		free(*iter);

	if (PRE_IVAR->memoryChunks != NULL)
		free(PRE_IVAR->memoryChunks);

	free((char*)self - PRE_IVAR_ALIGN);
}




























/* Required to use properties with the Apple runtime */
- copyWithZone: (void*)zone
{
	if (zone != NULL)
		@throw [OFNotImplementedException newWithClass: isa
						      selector: _cmd];







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
		free(*iter);

	if (PRE_IVAR->memoryChunks != NULL)
		free(PRE_IVAR->memoryChunks);

	free((char*)self - PRE_IVAR_ALIGN);
}

- (void)finalize
{
	Class class;
	void (*last)(id, SEL) = NULL;
	void **iter;

	for (class = isa; class != Nil; class = class_getSuperclass(class)) {
		void (*destruct)(id, SEL);

		if ([class instancesRespondToSelector: cxx_destruct]) {
			if ((destruct = (void(*)(id, SEL))[class
			    instanceMethodForSelector: cxx_destruct]) != last)
				destruct(self, cxx_destruct);

			last = destruct;
		} else
			break;
	}

	iter = PRE_IVAR->memoryChunks + PRE_IVAR->memoryChunksSize;
	while (iter-- > PRE_IVAR->memoryChunks)
		free(*iter);

	if (PRE_IVAR->memoryChunks != NULL)
		free(PRE_IVAR->memoryChunks);
}

/* Required to use properties with the Apple runtime */
- copyWithZone: (void*)zone
{
	if (zone != NULL)
		@throw [OFNotImplementedException newWithClass: isa
						      selector: _cmd];

Modified src/OFPlugin.m from [ce104d5d58] to [0f2a144c82].

80
81
82
83
84
85
86







87
{
	of_plugin_handle_t h = handle;

	[super dealloc];

	dlclose(h);
}







@end







>
>
>
>
>
>
>

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{
	of_plugin_handle_t h = handle;

	[super dealloc];

	dlclose(h);
}

- (void)finalize
{
	dlclose(handle);

	[super finalize];
}
@end

Modified src/OFStreamObserver.m from [5e763c88de] to [4fa877dddd].

148
149
150
151
152
153
154








155
156
157
158
159
160
161
#ifdef OF_HAVE_POLL
	[FDToStream release];
	[FDs release];
#endif

	[super dealloc];
}









- (id <OFStreamObserverDelegate>)delegate
{
	return [[(id)delegate retain] autorelease];
}

- (void)setDelegate: (id <OFStreamObserverDelegate>)delegate_







>
>
>
>
>
>
>
>







148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifdef OF_HAVE_POLL
	[FDToStream release];
	[FDs release];
#endif

	[super dealloc];
}

- (void)finalize
{
	close(cancelFD[0]);
	close(cancelFD[1]);

	[super finalize];
}

- (id <OFStreamObserverDelegate>)delegate
{
	return [[(id)delegate retain] autorelease];
}

- (void)setDelegate: (id <OFStreamObserverDelegate>)delegate_

Modified src/OFStreamSocket.m from [773bb7067f] to [a5c51abdbf].

164
165
166
167
168
169
170








171
- (void)dealloc
{
	if (sock != INVALID_SOCKET)
		[self close];

	[super dealloc];
}








@end







>
>
>
>
>
>
>
>

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
- (void)dealloc
{
	if (sock != INVALID_SOCKET)
		[self close];

	[super dealloc];
}

- (void)finalize
{
	if (sock != INVALID_SOCKET)
		[self close];

	[super finalize];
}
@end

Modified src/OFThread.m from [2f72c3fe38] to [8a0ae17cde].

301
302
303
304
305
306
307
















308
309
310
311
312
313
314
		of_thread_detach(thread);

	[object release];
	[returnValue release];

	[super dealloc];
}
















@end

@implementation OFTLSKey
+ (void)initialize
{
	if (self == [OFTLSKey class])
		TLSKeys = [[OFList alloc] init];







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
		of_thread_detach(thread);

	[object release];
	[returnValue release];

	[super dealloc];
}

- (void)finalize
{
	if (running == OF_THREAD_RUNNING)
		@throw [OFThreadStillRunningException newWithClass: isa
							    thread: self];

	/*
	 * We should not be running anymore, but call detach in order to free
	 * the resources.
	 */
	if (running == OF_THREAD_WAITING_FOR_JOIN)
		of_thread_detach(thread);

	[super finalize];
}
@end

@implementation OFTLSKey
+ (void)initialize
{
	if (self == [OFTLSKey class])
		TLSKeys = [[OFList alloc] init];
383
384
385
386
387
388
389


















390
391
392
393
394
395
396
		@synchronized (TLSKeys) {
			[TLSKeys removeListObject: listObject];
		}
	}

	[super dealloc];
}


















@end

@implementation OFMutex
+ mutex
{
	return [[[self alloc] init] autorelease];
}







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
		@synchronized (TLSKeys) {
			[TLSKeys removeListObject: listObject];
		}
	}

	[super dealloc];
}

- (void)finalize
{
	if (destructor != NULL)
		destructor(self);

	if (initialized)
		of_tlskey_free(key);

	/* In case we called [self release] in init */
	if (listObject != NULL) {
		@synchronized (TLSKeys) {
			[TLSKeys removeListObject: listObject];
		}
	}

	[super finalize];
}
@end

@implementation OFMutex
+ mutex
{
	return [[[self alloc] init] autorelease];
}
434
435
436
437
438
439
440










441
442
443
444
445
446
447
	if (initialized)
		if (!of_mutex_free(&mutex))
			@throw [OFMutexStillLockedException newWithClass: isa
								   mutex: self];

	[super dealloc];
}










@end

@implementation OFCondition
+ condition
{
	return [[[self alloc] init] autorelease];
}







>
>
>
>
>
>
>
>
>
>







468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
	if (initialized)
		if (!of_mutex_free(&mutex))
			@throw [OFMutexStillLockedException newWithClass: isa
								   mutex: self];

	[super dealloc];
}

- (void)finalize
{
	if (initialized)
		if (!of_mutex_free(&mutex))
			@throw [OFMutexStillLockedException newWithClass: isa
								   mutex: self];

	[super finalize];
}
@end

@implementation OFCondition
+ condition
{
	return [[[self alloc] init] autorelease];
}
488
489
490
491
492
493
494











495
		if (!of_condition_free(&condition))
			@throw [OFConditionStillWaitingException
			    newWithClass: isa
			       condition: self];

	[super dealloc];
}











@end







>
>
>
>
>
>
>
>
>
>
>

532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
		if (!of_condition_free(&condition))
			@throw [OFConditionStillWaitingException
			    newWithClass: isa
			       condition: self];

	[super dealloc];
}

- (void)finalize
{
	if (conditionInitialized)
		if (!of_condition_free(&condition))
			@throw [OFConditionStillWaitingException
			    newWithClass: isa
			       condition: self];

	[super finalize];
}
@end