ObjFW  Check-in [a6f520157a]

Overview
Comment:A few minor cleanups
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a6f520157a28638e9251809bc38be38c80e718adf5f45db957cb31e0e785e5dc
User & Date: js on 2023-08-08 15:32:43
Other Links: manifest | tags
Context
2023-08-08
21:06
Make OFDate a proper class cluster check-in: 3865cc5695 user: js tags: trunk
15:32
A few minor cleanups check-in: a6f520157a user: js tags: trunk
09:41
Rename OFConcreteData -> OFAdjacentData check-in: f886f21ad5 user: js tags: trunk
Changes

Modified src/OFArray.m from [b025a39cbb] to [baf90bc720].

106
107
108
109
110
111
112
113

114
115
116
117
118
119
120
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120







-
+







}
@end

@implementation OFArray
+ (void)initialize
{
	if (self == [OFArray class])
		placeholder.isa = [OFPlaceholderArray class];
		object_setClass((id)&placeholder, [OFPlaceholderArray class]);
}

+ (instancetype)alloc
{
	if (self == [OFArray class])
		return (id)&placeholder;

154
155
156
157
158
159
160
161


162
163
164
165
166
167
168
154
155
156
157
158
159
160

161
162
163
164
165
166
167
168
169







-
+
+







{
	return [[[self alloc] initWithObjects: objects
					count: count] autorelease];
}

- (instancetype)init
{
	if ([self isMemberOfClass: [OFArray class]]) {
	if ([self isMemberOfClass: [OFArray class]] ||
	    [self isMemberOfClass: [OFMutableArray class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
		} @catch (id e) {
			[self release];
			@throw e;
		}

Modified src/OFBlock.m from [d7b2cab799] to [4c4dfcbe66].

160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187



188
189
190
191
192
193
194
195
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184



185
186
187

188
189
190
191
192
193
194







-
+

















-
-
-
+
+
+
-







struct class _NSConcreteGlobalBlock_metaclass;
struct class _NSConcreteMallocBlock_metaclass;
# endif
#endif

static struct {
	Class isa;
} alloc_failed_exception;
} allocFailedException;

#ifndef OF_HAVE_ATOMIC_OPS
# define numSpinlocks 8	/* needs to be a power of 2 */
# define SPINLOCK_HASH(p) ((uintptr_t)p >> 4) & (numSpinlocks - 1)
static OFSpinlock blockSpinlocks[numSpinlocks];
static OFSpinlock byrefSpinlocks[numSpinlocks];
#endif

void *
_Block_copy(const void *block_)
{
	struct Block *block = (struct Block *)block_;

	if ([(id)block isMemberOfClass: (Class)&_NSConcreteStackBlock]) {
		struct Block *copy;

		if ((copy = malloc(block->descriptor->size)) == NULL) {
			alloc_failed_exception.isa =
			    [OFAllocFailedException class];
			@throw (OFAllocFailedException *)
			object_setClass((id)&allocFailedException,
			    [OFAllocFailedException class]);
			@throw (OFAllocFailedException *)&allocFailedException;
			    &alloc_failed_exception;
		}
		memcpy(copy, block, block->descriptor->size);

		object_setClass((id)copy, (Class)&_NSConcreteMallocBlock);
		copy->flags++;

		if (block->flags & OFBlockHasCopyDispose)
267
268
269
270
271
272
273
274
275


276
277

278
279
280
281
282
283
284
266
267
268
269
270
271
272


273
274
275

276
277
278
279
280
281
282
283







-
-
+
+

-
+







		struct Byref *src = (struct Byref *)src_;
		struct Byref **dst = (struct Byref **)dst_;

		src = src->forwarding;

		if ((src->flags & OFBlockRefCountMask) == 0) {
			if ((*dst = malloc(src->size)) == NULL) {
				alloc_failed_exception.isa =
				    [OFAllocFailedException class];
				object_setClass((id)&allocFailedException,
				    [OFAllocFailedException class]);
				@throw (OFAllocFailedException *)
				    &alloc_failed_exception;
				    &allocFailedException;
			}

			memcpy(*dst, src, src->size);
			(*dst)->flags =
			    ((*dst)->flags & ~OFBlockRefCountMask) | 1;
			(*dst)->forwarding = *dst;

Modified src/OFCharacterSet.m from [272d843979] to [66a03fcc07].

75
76
77
78
79
80
81
82

83
84
85


86
87
88
89
90
91
92
75
76
77
78
79
80
81

82



83
84
85
86
87
88
89
90
91







-
+
-
-
-
+
+







	OF_DEALLOC_UNSUPPORTED
}
@end

@implementation OFCharacterSet
+ (void)initialize
{
	if (self != [OFCharacterSet class])
	if (self == [OFCharacterSet class])
		return;

	placeholder.isa = [OFPlaceholderCharacterSet class];
		object_setClass((id)&placeholder,
		    [OFPlaceholderCharacterSet class]);
}

+ (instancetype)alloc
{
	if (self == [OFCharacterSet class])
		return (id)&placeholder;

Modified src/OFColor.m from [2f23670cfa] to [321947787c].

120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134







-
+








@implementation OFColor
+ (void)initialize
{
	if (self != [OFColor class])
		return;

	placeholder.isa = [OFColorPlaceholder class];
	object_setClass((id)&placeholder, [OFColorPlaceholder class]);
#ifdef OF_OBJFW_RUNTIME
	colorTag =
	    objc_registerTaggedPointerClass([OFTaggedPointerColor class]);
#endif
}

+ (instancetype)of_alloc

Modified src/OFCountedSet.m from [2550c38e59] to [0a786b110f].

90
91
92
93
94
95
96

97

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
105
106
107
108
















109
110
111
112
113
114
115







+
-
+










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







}
@end

@implementation OFCountedSet
+ (void)initialize
{
	if (self == [OFCountedSet class])
		object_setClass((id)&placeholder,
		placeholder.isa = [OFCountedSetPlaceholder class];
		    [OFCountedSetPlaceholder class]);
}

+ (instancetype)alloc
{
	if (self == [OFCountedSet class])
		return (id)&placeholder;

	return [super alloc];
}

- (instancetype)init
{
	if ([self isMemberOfClass: [OFCountedSet class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
		} @catch (id e) {
			[self release];
			@throw e;
		}

		abort();
	}

	return [super init];
}

- (size_t)countForObject: (id)object
{
	OF_UNRECOGNIZED_SELECTOR
}

- (OFString *)description
{

Modified src/OFData.m from [daaae842d6] to [466d9af03d].

125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
125
126
127
128
129
130
131

132
133
134
135
136
137
138
139







-
+







}
@end

@implementation OFData
+ (void)initialize
{
	if (self == [OFData class])
		placeholder.isa = [OFDataPlaceholder class];
		object_setClass((id)&placeholder, [OFDataPlaceholder class]);
}

+ (instancetype)alloc
{
	if (self == [OFData class])
		return (id)&placeholder;

205
206
207
208
209
210
211
212


213
214
215
216
217
218
219
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219
220







-
+
+







+ (instancetype)dataWithBase64EncodedString: (OFString *)string
{
	return [[[self alloc] initWithBase64EncodedString: string] autorelease];
}

- (instancetype)init
{
	if ([self isMemberOfClass: [OFData class]]) {
	if ([self isMemberOfClass: [OFData class]] ||
	    [self isMemberOfClass: [OFMutableData class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
		} @catch (id e) {
			[self release];
			@throw e;
		}

Modified src/OFDate.m from [8b8a822187] to [abe4f98453].

340
341
342
343
344
345
346
347

348
349
350
351
352
353
354
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354







-
+







#ifdef OF_WINDOWS
	HMODULE module;
#endif

	if (self != [OFDate class])
		return;

	placeholder.isa = [OFDatePlaceholder class];
	object_setClass((id)&placeholder, [OFDatePlaceholder class]);

#if (!defined(HAVE_GMTIME_R) || !defined(HAVE_LOCALTIME_R)) && \
    defined(OF_HAVE_THREADS)
	mutex = [[OFMutex alloc] init];
	atexit(releaseMutex);
#endif

Modified src/OFDictionary.m from [34eb84dfb7] to [ca10e7bcfe].

125
126
127
128
129
130
131

132

133
134
135
136
137
138
139
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140







+
-
+







}
@end

@implementation OFDictionary
+ (void)initialize
{
	if (self == [OFDictionary class])
		object_setClass((id)&placeholder,
		placeholder.isa = [OFDictionaryPlaceholder class];
		    [OFDictionaryPlaceholder class]);
}

+ (instancetype)alloc
{
	if (self == [OFDictionary class])
		return (id)&placeholder;

183
184
185
186
187
188
189
190


191
192
193
194
195
196
197
184
185
186
187
188
189
190

191
192
193
194
195
196
197
198
199







-
+
+







	va_end(arguments);

	return ret;
}

- (instancetype)init
{
	if ([self isMemberOfClass: [OFDictionary class]]) {
	if ([self isMemberOfClass: [OFDictionary class]] ||
	    [self isMemberOfClass: [OFMutableDictionary class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
		} @catch (id e) {
			[self release];
			@throw e;
		}

Modified src/OFMutableArray.m from [0c37234313] to [84ae5a66bf].

144
145
146
147
148
149
150

151

152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167















168
169
170
171
172
173
174







+
-
+















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







}
@end

@implementation OFMutableArray
+ (void)initialize
{
	if (self == [OFMutableArray class])
		object_setClass((id)&placeholder,
		placeholder.isa = [OFMutableArrayPlaceholder class];
		    [OFMutableArrayPlaceholder class]);
}

+ (instancetype)alloc
{
	if (self == [OFMutableArray class])
		return (id)&placeholder;

	return [super alloc];
}

+ (instancetype)arrayWithCapacity: (size_t)capacity
{
	return [[[self alloc] initWithCapacity: capacity] autorelease];
}

- (instancetype)init
{
	if ([self isMemberOfClass: [OFMutableArray class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
			abort();
		} @catch (id e) {
			[self release];
			@throw e;
		}
	}

	return [super init];
}

- (instancetype)initWithCapacity: (size_t)capacity
{
	OF_INVALID_INIT_METHOD
}

- (id)copy
{

Modified src/OFMutableData.m from [cdf5f88dbb] to [88129bd097].

115
116
117
118
119
120
121

122

123
124
125
126
127
128
129
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
130







+
-
+







}
@end

@implementation OFMutableData
+ (void)initialize
{
	if (self == [OFMutableData class])
		object_setClass((id)&placeholder,
		placeholder.isa = [OFMutableDataPlaceholder class];
		    [OFMutableDataPlaceholder class]);
}

+ (instancetype)alloc
{
	if (self == [OFMutableData class])
		return (id)&placeholder;

Modified src/OFMutableDictionary.m from [4bd030691a] to [e4cbf1d035].

106
107
108
109
110
111
112

113

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
106
107
108
109
110
111
112
113

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
















130
131
132
133
134
135
136







+
-
+















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







}
@end

@implementation OFMutableDictionary
+ (void)initialize
{
	if (self == [OFMutableDictionary class])
		object_setClass((id)&placeholder,
		placeholder.isa = [OFMutableDictionaryPlaceholder class];
		    [OFMutableDictionaryPlaceholder class]);
}

+ (instancetype)alloc
{
	if (self == [OFMutableDictionary class])
		return (id)&placeholder;

	return [super alloc];
}

+ (instancetype)dictionaryWithCapacity: (size_t)capacity
{
	return [[[self alloc] initWithCapacity: capacity] autorelease];
}

- (instancetype)init
{
	if ([self isMemberOfClass: [OFMutableDictionary class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
		} @catch (id e) {
			[self release];
			@throw e;
		}

		abort();
	}

	return [super init];
}

- (instancetype)initWithCapacity: (size_t)capacity
{
	OF_INVALID_INIT_METHOD
}

- (void)setObject: (id)object forKey: (id)key
{

Modified src/OFMutableSet.m from [f395937f21] to [7b6fef28d7].

94
95
96
97
98
99
100

101

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117















118
119
120
121
122
123
124







+
-
+















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







}
@end

@implementation OFMutableSet
+ (void)initialize
{
	if (self == [OFMutableSet class])
		object_setClass((id)&placeholder,
		placeholder.isa = [OFMutableSetPlaceholder class];
		    [OFMutableSetPlaceholder class]);
}

+ (instancetype)alloc
{
	if (self == [OFMutableSet class])
		return (id)&placeholder;

	return [super alloc];
}

+ (instancetype)setWithCapacity: (size_t)capacity
{
	return [[[self alloc] initWithCapacity: capacity] autorelease];
}

- (instancetype)init
{
	if ([self isMemberOfClass: [OFMutableSet class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
			abort();
		} @catch (id e) {
			[self release];
			@throw e;
		}
	}

	return [super init];
}

- (instancetype)initWithCapacity: (size_t)capacity
{
	OF_INVALID_INIT_METHOD
}

- (id)copy
{

Modified src/OFMutableString.m from [6babdf726b] to [5c70d53726].

207
208
209
210
211
212
213

214

215
216
217
218
219
220
221
207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
222







+
-
+







}
@end

@implementation OFMutableString
+ (void)initialize
{
	if (self == [OFMutableString class])
		object_setClass((id)&placeholder,
		placeholder.isa = [OFMutableStringPlaceholder class];
		    [OFMutableStringPlaceholder class]);
}

+ (instancetype)alloc
{
	if (self == [OFMutableString class])
		return (id)&placeholder;

Modified src/OFNumber.m from [b9b4334494] to [c9137e7e6f].

480
481
482
483
484
485
486
487

488
489
490
491
492
493
494
480
481
482
483
484
485
486

487
488
489
490
491
492
493
494







-
+








@implementation OFNumber
+ (void)initialize
{
	if (self != [OFNumber class])
		return;

	placeholder.isa = [OFNumberPlaceholder class];
	object_setClass((id)&placeholder, [OFNumberPlaceholder class]);

#ifdef OF_OBJFW_RUNTIME
	numberTag =
	    objc_registerTaggedPointerClass([OFTaggedPointerNumber class]);
#endif
}

Modified src/OFObject.m from [e705635cfb] to [663f9433ab].

339
340
341
342
343
344
345

346

347
348
349
350
351
352
353
339
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354







+
-
+







		extraAlignment = ((instanceSize + extraAlignment - 1) &
		    ~(extraAlignment - 1)) - extraAlignment;

	instance = calloc(1, PRE_IVARS_ALIGN + instanceSize +
	    extraAlignment + extraSize);

	if OF_UNLIKELY (instance == nil) {
		object_setClass((id)&allocFailedException,
		allocFailedException.isa = [OFAllocFailedException class];
		    [OFAllocFailedException class]);
		@throw (id)&allocFailedException;
	}

	((struct PreIvars *)instance)->retainCount = 1;

#if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS)
	if OF_UNLIKELY (OFSpinlockNew(

Modified src/OFSet.m from [bebf07d610] to [4cf2dc29e8].

15
16
17
18
19
20
21

22
23
24
25
26
27
28
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29







+








#include "config.h"

#include <stdlib.h>

#import "OFSet.h"
#import "OFArray.h"
#import "OFCountedSet.h"
#import "OFMapTableSet.h"
#import "OFNull.h"
#import "OFString.h"

static struct {
	Class isa;
} placeholder;
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106







-
+







}
@end

@implementation OFSet
+ (void)initialize
{
	if (self == [OFSet class])
		placeholder.isa = [OFSetPlaceholder class];
		object_setClass((id)&placeholder, [OFSetPlaceholder class]);
}

+ (instancetype)alloc
{
	if (self == [OFSet class])
		return (id)&placeholder;

138
139
140
141
142
143
144
145



146
147
148
149
150
151
152
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155







-
+
+
+







{
	return [[[self alloc] initWithObjects: objects
					count: count] autorelease];
}

- (instancetype)init
{
	if ([self isMemberOfClass: [OFSet class]]) {
	if ([self isMemberOfClass: [OFSet class]] ||
	    [self isMemberOfClass: [OFMutableSet class]] ||
	    [self isMemberOfClass: [OFCountedSet class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
		} @catch (id e) {
			[self release];
			@throw e;
		}

Modified src/OFString.m from [a697442a34] to [9aebf03e60].

614
615
616
617
618
619
620
621

622
623
624
625
626
627
628
614
615
616
617
618
619
620

621
622
623
624
625
626
627
628







-
+








@implementation OFString
+ (void)initialize
{
	if (self != [OFString class])
		return;

	placeholder.isa = [OFStringPlaceholder class];
	object_setClass((id)&placeholder, [OFStringPlaceholder class]);

#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) || defined(HAVE_USELOCALE)
	if ((cLocale = newlocale(LC_ALL_MASK, "C", NULL)) == NULL)
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
#endif
}
799
800
801
802
803
804
805
806


807
808
809
810
811
812
813
799
800
801
802
803
804
805

806
807
808
809
810
811
812
813
814







-
+
+







{
	return [[[self alloc] initWithContentsOfIRI: IRI
					   encoding: encoding] autorelease];
}

- (instancetype)init
{
	if ([self isMemberOfClass: [OFString class]]) {
	if ([self isMemberOfClass: [OFString class]] ||
	    [self isMemberOfClass: [OFMutableString class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
		} @catch (id e) {
			[self release];
			@throw e;
		}