ObjFW  Check-in [abb7536cdd]

Overview
Comment:Make -[finishInitialization] thread-safe.

This way, it's possible to use the same constant string from multiple
threads without having to make sure it's initialized first.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: abb7536cdd3afdf50682836f5f6f1337687fe1ab41f8310b42b12d60020f5ab3
User & Date: js on 2013-05-01 20:35:40
Other Links: manifest | tags
Context
2013-05-01
21:05
OFRunLoop: Work correctly for threads && !sockets. check-in: 56ec27cbdf user: js tags: trunk
20:35
Make -[finishInitialization] thread-safe. check-in: abb7536cdd user: js tags: trunk
20:31
Fix -Wcast-align check for recent Clang versions. check-in: 874faa49a7 user: js tags: trunk
Changes

Modified src/OFConstantString.m from [9a6d67963b] to [8447dff468].

142
143
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
	free(class);
	objc_registerClassPair((Class)&_OFConstantStringClassReference);
#endif
}

- (void)finishInitialization
{

	struct of_string_utf8_ivars *ivars;




	if ((ivars = calloc(1, sizeof(*ivars))) == NULL)
		@throw [OFOutOfMemoryException
		    exceptionWithClass: [self class]
			 requestedSize: sizeof(*ivars)];

	ivars->cString = _cString;
	ivars->cStringLength = _cStringLength;

	switch (of_string_utf8_check(ivars->cString, ivars->cStringLength,

	    &ivars->length)) {
	case 1:
		ivars->isUTF8 = true;
		break;
	case -1:
		free(ivars);
		@throw [OFInvalidEncodingException
		    exceptionWithClass: [self class]];
	}

	_cString = (char*)ivars;
	object_setClass(self, [OFString_const class]);

}

+ alloc
{
	[self doesNotRecognizeSelector: _cmd];
	abort();
}







>
|

>
>
>
|
|
|
|

|
|

|
>
|
|
|
|
|
|
|
|
|

|
|
>







142
143
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
	free(class);
	objc_registerClassPair((Class)&_OFConstantStringClassReference);
#endif
}

- (void)finishInitialization
{
	@synchronized (self) {
		struct of_string_utf8_ivars *ivars;

		if (object_getClass(self) == [OFString_const class])
			return;

		if ((ivars = calloc(1, sizeof(*ivars))) == NULL)
			@throw [OFOutOfMemoryException
			    exceptionWithClass: [self class]
				 requestedSize: sizeof(*ivars)];

		ivars->cString = _cString;
		ivars->cStringLength = _cStringLength;

		switch (of_string_utf8_check(ivars->cString,
		    ivars->cStringLength,
			&ivars->length)) {
			case 1:
				ivars->isUTF8 = true;
				break;
			case -1:
				free(ivars);
				@throw [OFInvalidEncodingException
				    exceptionWithClass: [self class]];
		}

		_cString = (char*)ivars;
		object_setClass(self, [OFString_const class]);
	}
}

+ alloc
{
	[self doesNotRecognizeSelector: _cmd];
	abort();
}