ObjFW  Check-in [972a3ee40d]

Overview
Comment:Remove -[finalize] as ARC will be implemented instead of a GC.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 972a3ee40d5a595d7d8c218ab9cb9b48d2b0495e9c9a8559a1588b7e08638a4b
User & Date: js on 2011-09-10 18:36:45
Other Links: manifest | tags
Context
2011-09-10
19:37
Make OFStreamObserver an abstract class. check-in: b1ffd7732a user: js tags: trunk
18:36
Remove -[finalize] as ARC will be implemented instead of a GC. check-in: 972a3ee40d user: js tags: trunk
17:46
Add -[stringByReplacingOccurrencesOfString:withString:]. check-in: a8b61d68ae user: js tags: trunk
Changes

Modified src/OFAutoreleasePool.h from [490a0d1357] to [0009cc3f48].

69
70
71
72
73
74
75
76
77
78
79
80
81
82

/**
 * \brief Releases all objects in the autorelease pool and deallocates the pool.
 */
- (void)release;

/**
 * \brief Tells the garbage collector that now is a good time to clean up.
 *
 * If there is no garbage collector, calling drain is equivalent to calling
 * release.
 */
- (void)drain;
@end







|
<
<
<



69
70
71
72
73
74
75
76



77
78
79

/**
 * \brief Releases all objects in the autorelease pool and deallocates the pool.
 */
- (void)release;

/**
 * \brief Releases all objects in the autorelease pool and deallocates the pool.



 */
- (void)drain;
@end

Modified src/OFFile.m from [072b46a026] to [478769a586].

679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
- (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;







<
<
<
<
<
<
<
<







679
680
681
682
683
684
685








686
687
688
689
690
691
692
- (void)dealloc
{
	if (closable && fileDescriptor != -1)
		close(fileDescriptor);

	[super dealloc];
}








@end

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

Modified src/OFObject.h from [8c882f215e] to [786dbd8023].

551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
 * \param pointer A pointer to the allocated memory
 */
- (void)freeMemory: (void*)pointer;

/**
 * \brief Deallocates the object.
 *
 * It is automatically called when the retain count reaches zero, but not when
 * the garbage collector disposes of the object (see finalize).
 *
 * This also frees all memory in its memory pool.
 */
- (void)dealloc;

/**
 * \brief A method which is called before the garbage collector disposes of the
 *	  object.
 *
 * This is useful for example to close files if they haven't been closed by the
 * user yet.
 *
 * Note: Currently, there is no garbage collector. This method only exists to
 *	 make it easy to add support for a garbage collector later.
 */
- (void)finalize;
@end

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







|
<




<
<
<
<
<
<
<
<
<
<
<
<







551
552
553
554
555
556
557
558

559
560
561
562












563
564
565
566
567
568
569
 * \param pointer A pointer to the allocated memory
 */
- (void)freeMemory: (void*)pointer;

/**
 * \brief Deallocates the object.
 *
 * It is automatically called when the retain count reaches zero.

 *
 * This also frees all memory in its memory pool.
 */
- (void)dealloc;












@end

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

Modified src/OFObject.m from [b3a44692ae] to [02fc494c69].

1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120

	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];








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1080
1081
1082
1083
1084
1085
1086



























1087
1088
1089
1090
1091
1092
1093

	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];

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

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







<
<
<
<
<
<
<

80
81
82
83
84
85
86







87
{
	of_plugin_handle_t h = handle;

	[super dealloc];

	dlclose(h);
}







@end

Modified src/OFStreamObserver.m from [741b860b9a] to [154bacad74].

152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
	[FDToStream release];
	[FDs release];
#endif

	[super dealloc];
}

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

	[super finalize];
}

- (id <OFStreamObserverDelegate>)delegate
{
	OF_GETTER(delegate, YES)
}

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







<
<
<
<
<
<
<
<







152
153
154
155
156
157
158








159
160
161
162
163
164
165
	[FDToStream release];
	[FDs release];
#endif

	[super dealloc];
}









- (id <OFStreamObserverDelegate>)delegate
{
	OF_GETTER(delegate, YES)
}

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

Modified src/OFStreamSocket.m from [73e9748565] to [35ae964d9d].

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







<
<
<
<
<
<
<
<

164
165
166
167
168
169
170








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

	[super dealloc];
}








@end

Modified src/OFThread.m from [8d6289db16] to [28529a39cf].

354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
		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];







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







354
355
356
357
358
359
360
















361
362
363
364
365
366
367
		of_thread_detach(thread);

	[object release];
	[returnValue release];

	[super dealloc];
}
















@end

@implementation OFTLSKey
+ (void)initialize
{
	if (self == [OFTLSKey class])
		TLSKeys = [[OFList alloc] init];
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
		@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];
}







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







436
437
438
439
440
441
442


















443
444
445
446
447
448
449
		@synchronized (TLSKeys) {
			[TLSKeys removeListObject: listObject];
		}
	}

	[super dealloc];
}


















@end

@implementation OFMutex
+ mutex
{
	return [[[self alloc] init] autorelease];
}
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
	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];
}







<
<
<
<
<
<
<
<
<
<







487
488
489
490
491
492
493










494
495
496
497
498
499
500
	if (initialized)
		if (!of_mutex_free(&mutex))
			@throw [OFMutexStillLockedException newWithClass: isa
								   mutex: self];

	[super dealloc];
}










@end

@implementation OFCondition
+ condition
{
	return [[[self alloc] init] autorelease];
}
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
		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







<
<
<
<
<
<
<
<
<
<
<

541
542
543
544
545
546
547











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

	[super dealloc];
}











@end