︙ | | | ︙ | |
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#import "OFArray.h"
#import "autorelease.h"
#import "macros.h"
@implementation OFMethod
#if defined(OF_OBJFW_RUNTIME)
- _initWithMethod: (struct objc_method*)method
{
self = [super init];
@try {
selector = (SEL)&method->sel;
name = [[OFString alloc]
initWithCString: sel_getName(selector)
encoding: OF_STRING_ENCODING_ASCII];
typeEncoding = method->sel.types;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
#elif defined(OF_APPLE_RUNTIME)
- _initWithMethod: (Method)method
{
self = [super init];
@try {
selector = method_getName(method);
name = [[OFString alloc]
initWithCString: sel_getName(selector)
|
|
|
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#import "OFArray.h"
#import "autorelease.h"
#import "macros.h"
@implementation OFMethod
#if defined(OF_OBJFW_RUNTIME)
- OF_initWithMethod: (struct objc_method*)method
{
self = [super init];
@try {
selector = (SEL)&method->sel;
name = [[OFString alloc]
initWithCString: sel_getName(selector)
encoding: OF_STRING_ENCODING_ASCII];
typeEncoding = method->sel.types;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
#elif defined(OF_APPLE_RUNTIME)
- OF_initWithMethod: (Method)method
{
self = [super init];
@try {
selector = method_getName(method);
name = [[OFString alloc]
initWithCString: sel_getName(selector)
|
︙ | | | ︙ | |
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
|
return [OFString stringWithFormat: @"<OFMethod: %@ [%s]>",
name, typeEncoding];
}
@end
@implementation OFInstanceVariable
#if defined(OF_OBJFW_RUNTIME)
- _initWithIvar: (struct objc_ivar*)ivar
{
self = [super init];
@try {
name = [[OFString alloc]
initWithCString: ivar->name
encoding: OF_STRING_ENCODING_ASCII];
typeEncoding = ivar->type;
offset = ivar->offset;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
#elif defined(OF_APPLE_RUNTIME)
- _initWithIvar: (Ivar)ivar
{
self = [super init];
@try {
name = [[OFString alloc]
initWithCString: ivar_getName(ivar)
encoding: OF_STRING_ENCODING_ASCII];
|
|
|
|
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
|
return [OFString stringWithFormat: @"<OFMethod: %@ [%s]>",
name, typeEncoding];
}
@end
@implementation OFInstanceVariable
#if defined(OF_OBJFW_RUNTIME)
- OF_initWithIvar: (struct objc_ivar*)ivar
{
self = [super init];
@try {
name = [[OFString alloc]
initWithCString: ivar->name
encoding: OF_STRING_ENCODING_ASCII];
typeEncoding = ivar->type;
offset = ivar->offset;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
#elif defined(OF_APPLE_RUNTIME)
- OF_initWithIvar: (Ivar)ivar
{
self = [super init];
@try {
name = [[OFString alloc]
initWithCString: ivar_getName(ivar)
encoding: OF_STRING_ENCODING_ASCII];
|
︙ | | | ︙ | |
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
for (methodList = object_getClass(class)->methodlist;
methodList != NULL; methodList = methodList->next) {
int i;
for (i = 0; i < methodList->count; i++) {
void *pool = objc_autoreleasePoolPush();
OFMethod *method = [[OFMethod alloc]
_initWithMethod: &methodList->methods[i]];
[classMethods addObject: [method autorelease]];
objc_autoreleasePoolPop(pool);
}
}
for (methodList = class->methodlist; methodList != NULL;
methodList = methodList->next) {
int i;
for (i = 0; i < methodList->count; i++) {
void *pool = objc_autoreleasePoolPush();
OFMethod *method = [[OFMethod alloc]
_initWithMethod: &methodList->methods[i]];
[instanceMethods addObject:
[method autorelease]];
objc_autoreleasePoolPop(pool);
}
}
if (class->ivars != NULL) {
unsigned i;
for (i = 0; i < class->ivars->count; i++) {
void *pool = objc_autoreleasePoolPush();
OFInstanceVariable *ivar;
ivar = [[OFInstanceVariable alloc]
_initWithIvar: &class->ivars->ivars[i]];
[instanceVariables addObject:
[ivar autorelease]];
objc_autoreleasePoolPop(pool);
}
}
#elif defined(OF_APPLE_RUNTIME)
methodList = class_copyMethodList(object_getClass(class),
&count);
@try {
for (i = 0; i < count; i++) {
void *pool = objc_autoreleasePoolPush();
[classMethods addObject: [[[OFMethod alloc]
_initWithMethod: methodList[i]]
autorelease]];
objc_autoreleasePoolPop(pool);
}
} @finally {
free(methodList);
}
methodList = class_copyMethodList(class, &count);
@try {
for (i = 0; i < count; i++) {
void *pool = objc_autoreleasePoolPush();
[instanceMethods addObject: [[[OFMethod alloc]
_initWithMethod: methodList[i]]
autorelease]];
objc_autoreleasePoolPop(pool);
}
} @finally {
free(methodList);
}
ivarList = class_copyIvarList(class, &count);
@try {
for (i = 0; i < count; i++) {
void *pool = objc_autoreleasePoolPush();
[instanceVariables addObject:
[[[OFInstanceVariable alloc]
_initWithIvar: ivarList[i]] autorelease]];
objc_autoreleasePoolPop(pool);
}
} @finally {
free(ivarList);
}
#endif
|
|
|
|
|
|
|
|
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
for (methodList = object_getClass(class)->methodlist;
methodList != NULL; methodList = methodList->next) {
int i;
for (i = 0; i < methodList->count; i++) {
void *pool = objc_autoreleasePoolPush();
OFMethod *method = [[OFMethod alloc]
OF_initWithMethod: &methodList->methods[i]];
[classMethods addObject: [method autorelease]];
objc_autoreleasePoolPop(pool);
}
}
for (methodList = class->methodlist; methodList != NULL;
methodList = methodList->next) {
int i;
for (i = 0; i < methodList->count; i++) {
void *pool = objc_autoreleasePoolPush();
OFMethod *method = [[OFMethod alloc]
OF_initWithMethod: &methodList->methods[i]];
[instanceMethods addObject:
[method autorelease]];
objc_autoreleasePoolPop(pool);
}
}
if (class->ivars != NULL) {
unsigned i;
for (i = 0; i < class->ivars->count; i++) {
void *pool = objc_autoreleasePoolPush();
OFInstanceVariable *ivar;
ivar = [[OFInstanceVariable alloc]
OF_initWithIvar: &class->ivars->ivars[i]];
[instanceVariables addObject:
[ivar autorelease]];
objc_autoreleasePoolPop(pool);
}
}
#elif defined(OF_APPLE_RUNTIME)
methodList = class_copyMethodList(object_getClass(class),
&count);
@try {
for (i = 0; i < count; i++) {
void *pool = objc_autoreleasePoolPush();
[classMethods addObject: [[[OFMethod alloc]
OF_initWithMethod: methodList[i]]
autorelease]];
objc_autoreleasePoolPop(pool);
}
} @finally {
free(methodList);
}
methodList = class_copyMethodList(class, &count);
@try {
for (i = 0; i < count; i++) {
void *pool = objc_autoreleasePoolPush();
[instanceMethods addObject: [[[OFMethod alloc]
OF_initWithMethod: methodList[i]]
autorelease]];
objc_autoreleasePoolPop(pool);
}
} @finally {
free(methodList);
}
ivarList = class_copyIvarList(class, &count);
@try {
for (i = 0; i < count; i++) {
void *pool = objc_autoreleasePoolPush();
[instanceVariables addObject:
[[[OFInstanceVariable alloc]
OF_initWithIvar: ivarList[i]] autorelease]];
objc_autoreleasePoolPop(pool);
}
} @finally {
free(ivarList);
}
#endif
|
︙ | | | ︙ | |
︙ | | | ︙ | |
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
{
if (self == [OFMutableDictionary_hashtable class]) {
dictionary = [OFDictionary_hashtable class];
[self inheritMethodsFromClass: dictionary];
}
}
- (void)_resizeForCount: (size_t)newCount
{
size_t fullness = newCount * 4 / size;
struct of_dictionary_hashtable_bucket **newData;
uint32_t i, newSize;
if (newCount > UINT32_MAX)
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
|
|
|
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
{
if (self == [OFMutableDictionary_hashtable class]) {
dictionary = [OFDictionary_hashtable class];
[self inheritMethodsFromClass: dictionary];
}
}
- (void)OF_resizeForCount: (size_t)newCount
{
size_t fullness = newCount * 4 / size;
struct of_dictionary_hashtable_bucket **newData;
uint32_t i, newSize;
if (newCount > UINT32_MAX)
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
|
︙ | | | ︙ | |
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
}
[self freeMemory: data];
data = newData;
size = newSize;
}
- (void)_setObject: (id)object
forKey: (id)key
copyKey: (BOOL)copyKey
{
uint32_t i, hash, last;
id old;
if (key == nil || object == nil)
@throw [OFInvalidArgumentException
exceptionWithClass: [self class]
|
|
|
|
|
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
}
[self freeMemory: data];
data = newData;
size = newSize;
}
- (void)OF_setObject: (id)object
forKey: (id)key
copyKey: (BOOL)copyKey
{
uint32_t i, hash, last;
id old;
if (key == nil || object == nil)
@throw [OFInvalidArgumentException
exceptionWithClass: [self class]
|
︙ | | | ︙ | |
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
}
/* Key not in dictionary */
if (i >= last || data[i] == NULL || data[i] == DELETED ||
![data[i]->key isEqual: key]) {
struct of_dictionary_hashtable_bucket *bucket;
[self _resizeForCount: count + 1];
mutations++;
last = size;
for (i = hash & (size - 1); i < last && data[i] != NULL &&
data[i] != DELETED; i++);
|
|
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
}
/* Key not in dictionary */
if (i >= last || data[i] == NULL || data[i] == DELETED ||
![data[i]->key isEqual: key]) {
struct of_dictionary_hashtable_bucket *bucket;
[self OF_resizeForCount: count + 1];
mutations++;
last = size;
for (i = hash & (size - 1); i < last && data[i] != NULL &&
data[i] != DELETED; i++);
|
︙ | | | ︙ | |
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
data[i]->object = [object retain];
[old release];
}
- (void)setObject: (id)object
forKey: (id)key
{
[self _setObject: object
forKey: key
copyKey: YES];
}
- (void)removeObjectForKey: (id)key
{
uint32_t i, hash, last;
if (key == nil)
|
|
|
|
|
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
data[i]->object = [object retain];
[old release];
}
- (void)setObject: (id)object
forKey: (id)key
{
[self OF_setObject: object
forKey: key
copyKey: YES];
}
- (void)removeObjectForKey: (id)key
{
uint32_t i, hash, last;
if (key == nil)
|
︙ | | | ︙ | |
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
[data[i]->key release];
[data[i]->object release];
[self freeMemory: data[i]];
data[i] = DELETED;
count--;
mutations++;
[self _resizeForCount: count];
return;
}
}
if (i < last)
return;
|
|
|
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
[data[i]->key release];
[data[i]->object release];
[self freeMemory: data[i]];
data[i] = DELETED;
count--;
mutations++;
[self OF_resizeForCount: count];
return;
}
}
if (i < last)
return;
|
︙ | | | ︙ | |
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
[data[i]->key release];
[data[i]->object release];
[self freeMemory: data[i]];
data[i] = DELETED;
count--;
mutations++;
[self _resizeForCount: count];
return;
}
}
}
- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
|
|
|
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
[data[i]->key release];
[data[i]->object release];
[self freeMemory: data[i]];
data[i] = DELETED;
count--;
mutations++;
[self OF_resizeForCount: count];
return;
}
}
}
- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
|
︙ | | | ︙ | |
︙ | | | ︙ | |
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
id object;
/*
* We can't just copy the dictionary as the specified set might
* be a counted set, but we're just a normal set.
*/
while ((object = [enumerator nextObject]) != nil)
[dictionary _setObject: one
forKey: object
copyKey: NO];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
|
|
|
|
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
id object;
/*
* We can't just copy the dictionary as the specified set might
* be a counted set, but we're just a normal set.
*/
while ((object = [enumerator nextObject]) != nil)
[dictionary OF_setObject: one
forKey: object
copyKey: NO];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
|
︙ | | | ︙ | |
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
@try {
void *pool = objc_autoreleasePoolPush();
OFNumber *one = [OFNumber numberWithSize: 1];
id *objects = [array objects];
size_t i, count = [array count];
for (i = 0; i < count; i++)
[dictionary _setObject: one
forKey: objects[i]
copyKey: NO];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
|
|
|
|
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
@try {
void *pool = objc_autoreleasePoolPush();
OFNumber *one = [OFNumber numberWithSize: 1];
id *objects = [array objects];
size_t i, count = [array count];
for (i = 0; i < count; i++)
[dictionary OF_setObject: one
forKey: objects[i]
copyKey: NO];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
|
︙ | | | ︙ | |
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
139
140
141
142
143
144
145
146
147
148
149
|
@try {
void *pool = objc_autoreleasePoolPush();
OFNumber *one = [OFNumber numberWithSize: 1];
size_t i;
for (i = 0; i < count; i++)
[dictionary _setObject: one
forKey: objects[i]
copyKey: NO];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- initWithObject: (id)firstObject
arguments: (va_list)arguments
{
self = [self init];
@try {
void *pool = objc_autoreleasePoolPush();
OFNumber *one = [OFNumber numberWithSize: 1];
id object;
[dictionary _setObject: one
forKey: firstObject
copyKey: NO];
while ((object = va_arg(arguments, id)) != nil)
[dictionary _setObject: one
forKey: object
copyKey: NO];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
|
|
|
|
|
|
|
|
|
|
|
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
139
140
141
142
143
144
145
146
147
148
149
|
@try {
void *pool = objc_autoreleasePoolPush();
OFNumber *one = [OFNumber numberWithSize: 1];
size_t i;
for (i = 0; i < count; i++)
[dictionary OF_setObject: one
forKey: objects[i]
copyKey: NO];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- initWithObject: (id)firstObject
arguments: (va_list)arguments
{
self = [self init];
@try {
void *pool = objc_autoreleasePoolPush();
OFNumber *one = [OFNumber numberWithSize: 1];
id object;
[dictionary OF_setObject: one
forKey: firstObject
copyKey: NO];
while ((object = va_arg(arguments, id)) != nil)
[dictionary OF_setObject: one
forKey: object
copyKey: NO];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
|
︙ | | | ︙ | |
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
one = [OFNumber numberWithSize: 1];
enumerator = [[element elementsForNamespace:
OF_SERIALIZATION_NS] objectEnumerator];
while ((child = [enumerator nextObject]) != nil) {
void *pool2 = objc_autoreleasePoolPush();
[dictionary _setObject: one
forKey: [child objectByDeserializing]
copyKey: NO];
objc_autoreleasePoolPop(pool2);
}
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
|
|
|
|
|
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
one = [OFNumber numberWithSize: 1];
enumerator = [[element elementsForNamespace:
OF_SERIALIZATION_NS] objectEnumerator];
while ((child = [enumerator nextObject]) != nil) {
void *pool2 = objc_autoreleasePoolPush();
[dictionary OF_setObject: one
forKey: [child objectByDeserializing]
copyKey: NO];
objc_autoreleasePoolPop(pool2);
}
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
|
︙ | | | ︙ | |
︙ | | | ︙ | |
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
OF_ENSURE(write(cancelFD[1], "", 1) > 0);
#else
OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
sizeof(cancelAddr)) > 0);
#endif
}
- (void)_addFileDescriptorForReading: (int)fd
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (void)_addFileDescriptorForWriting: (int)fd
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (void)_removeFileDescriptorForReading: (int)fd
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (void)_removeFileDescriptorForWriting: (int)fd
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (void)_processQueue
{
[mutex lock];
@try {
OFStream **queueObjects = [queue objects];
int *queueInfoCArray = [queueInfo cArray];
int *queueFDsCArray = [queueFDs cArray];
size_t i, count = [queue count];
|
|
>
>
>
>
>
>
|
|
<
<
<
<
<
<
|
|
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
OF_ENSURE(write(cancelFD[1], "", 1) > 0);
#else
OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
sizeof(cancelAddr)) > 0);
#endif
}
- (void)OF_addFileDescriptorForReading: (int)fd
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (void)OF_addFileDescriptorForWriting: (int)fd
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (void)OF_removeFileDescriptorForReading: (int)fd
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (void)OF_removeFileDescriptorForWriting: (int)fd
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (void)OF_processQueue
{
[mutex lock];
@try {
OFStream **queueObjects = [queue objects];
int *queueInfoCArray = [queueInfo cArray];
int *queueFDsCArray = [queueFDs cArray];
size_t i, count = [queue count];
|
︙ | | | ︙ | |
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
FDToStream[fd] = nil;
}
switch (action) {
case QUEUE_ADD | QUEUE_READ:
[readStreams addObject: stream];
[self _addFileDescriptorForReading: fd];
break;
case QUEUE_ADD | QUEUE_WRITE:
[writeStreams addObject: stream];
[self _addFileDescriptorForWriting: fd];
break;
case QUEUE_REMOVE | QUEUE_READ:
[readStreams removeObjectIdenticalTo: stream];
[self _removeFileDescriptorForReading: fd];
break;
case QUEUE_REMOVE | QUEUE_WRITE:
[writeStreams removeObjectIdenticalTo: stream];
[self _removeFileDescriptorForWriting: fd];
break;
default:
assert(0);
}
}
|
|
|
|
|
|
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
FDToStream[fd] = nil;
}
switch (action) {
case QUEUE_ADD | QUEUE_READ:
[readStreams addObject: stream];
[self OF_addFileDescriptorForReading: fd];
break;
case QUEUE_ADD | QUEUE_WRITE:
[writeStreams addObject: stream];
[self OF_addFileDescriptorForWriting: fd];
break;
case QUEUE_REMOVE | QUEUE_READ:
[readStreams removeObjectIdenticalTo: stream];
[self OF_removeFileDescriptorForReading: fd];
break;
case QUEUE_REMOVE | QUEUE_WRITE:
[writeStreams removeObjectIdenticalTo: stream];
[self OF_removeFileDescriptorForWriting: fd];
break;
default:
assert(0);
}
}
|
︙ | | | ︙ | |
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
|
OF_ENSURE(write(cancelFD[1], "", 1) > 0);
#else
OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
sizeof(cancelAddr)) > 0);
#endif
}
- (BOOL)_processCache
{
OFStream **objects = [readStreams objects];
size_t i, count = [readStreams count];
BOOL foundInCache = NO;
for (i = 0; i < count; i++) {
if ([objects[i] pendingBytes] > 0 &&
![objects[i] _isWaitingForDelimiter]) {
void *pool = objc_autoreleasePoolPush();
[delegate streamIsReadyForReading: objects[i]];
foundInCache = YES;
objc_autoreleasePoolPop(pool);
}
}
|
|
|
|
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
|
OF_ENSURE(write(cancelFD[1], "", 1) > 0);
#else
OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
sizeof(cancelAddr)) > 0);
#endif
}
- (BOOL)OF_processCache
{
OFStream **objects = [readStreams objects];
size_t i, count = [readStreams count];
BOOL foundInCache = NO;
for (i = 0; i < count; i++) {
if ([objects[i] pendingBytes] > 0 &&
![objects[i] OF_isWaitingForDelimiter]) {
void *pool = objc_autoreleasePoolPush();
[delegate streamIsReadyForReading: objects[i]];
foundInCache = YES;
objc_autoreleasePoolPop(pool);
}
}
|
︙ | | | ︙ | |
︙ | | | ︙ | |
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
|
if ((kernelQueue = kqueue()) == -1)
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
changeList = [[OFDataArray alloc] initWithItemSize:
sizeof(struct kevent)];
[self _addFileDescriptorForReading: cancelFD[0]];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
close(kernelQueue);
[changeList release];
[super dealloc];
}
- (void)_addFileDescriptorForReading: (int)fd
{
struct kevent event;
EV_SET(&event, fd, EVFILT_READ, EV_ADD, 0, 0, 0);
[changeList addItem: &event];
}
- (void)_addFileDescriptorForWriting: (int)fd
{
struct kevent event;
EV_SET(&event, fd, EVFILT_WRITE, EV_ADD, 0, 0, 0);
[changeList addItem: &event];
}
- (void)_removeFileDescriptorForReading: (int)fd
{
struct kevent event;
EV_SET(&event, fd, EVFILT_READ, EV_DELETE, 0, 0, 0);
[changeList addItem: &event];
}
- (void)_removeFileDescriptorForWriting: (int)fd
{
struct kevent event;
EV_SET(&event, fd, EVFILT_WRITE, EV_DELETE, 0, 0, 0);
[changeList addItem: &event];
}
- (BOOL)observeWithTimeout: (double)timeout
{
void *pool = objc_autoreleasePoolPush();
struct timespec timespec;
struct kevent eventList[EVENTLIST_SIZE];
int i, events, realEvents = 0;
timespec.tv_sec = timeout;
timespec.tv_nsec = (timeout - timespec.tv_sec) * 1000000000;
[self _processQueue];
if ([self _processCache]) {
objc_autoreleasePoolPop(pool);
return YES;
}
objc_autoreleasePoolPop(pool);
events = kevent(kernelQueue, [changeList cArray],
|
|
|
|
|
|
|
|
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
|
if ((kernelQueue = kqueue()) == -1)
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
changeList = [[OFDataArray alloc] initWithItemSize:
sizeof(struct kevent)];
[self OF_addFileDescriptorForReading: cancelFD[0]];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
close(kernelQueue);
[changeList release];
[super dealloc];
}
- (void)OF_addFileDescriptorForReading: (int)fd
{
struct kevent event;
EV_SET(&event, fd, EVFILT_READ, EV_ADD, 0, 0, 0);
[changeList addItem: &event];
}
- (void)OF_addFileDescriptorForWriting: (int)fd
{
struct kevent event;
EV_SET(&event, fd, EVFILT_WRITE, EV_ADD, 0, 0, 0);
[changeList addItem: &event];
}
- (void)OF_removeFileDescriptorForReading: (int)fd
{
struct kevent event;
EV_SET(&event, fd, EVFILT_READ, EV_DELETE, 0, 0, 0);
[changeList addItem: &event];
}
- (void)OF_removeFileDescriptorForWriting: (int)fd
{
struct kevent event;
EV_SET(&event, fd, EVFILT_WRITE, EV_DELETE, 0, 0, 0);
[changeList addItem: &event];
}
- (BOOL)observeWithTimeout: (double)timeout
{
void *pool = objc_autoreleasePoolPush();
struct timespec timespec;
struct kevent eventList[EVENTLIST_SIZE];
int i, events, realEvents = 0;
timespec.tv_sec = timeout;
timespec.tv_nsec = (timeout - timespec.tv_sec) * 1000000000;
[self OF_processQueue];
if ([self OF_processCache]) {
objc_autoreleasePoolPop(pool);
return YES;
}
objc_autoreleasePoolPop(pool);
events = kevent(kernelQueue, [changeList cArray],
|
︙ | | | ︙ | |
︙ | | | ︙ | |
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#endif
[thread handleTermination];
thread->running = OF_THREAD_WAITING_FOR_JOIN;
[OFTLSKey callAllDestructors];
[OFAutoreleasePool _releaseAll];
[thread release];
return 0;
}
@implementation OFThread
|
|
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#endif
[thread handleTermination];
thread->running = OF_THREAD_WAITING_FOR_JOIN;
[OFTLSKey callAllDestructors];
[OFAutoreleasePool OF_releaseAll];
[thread release];
return 0;
}
@implementation OFThread
|
︙ | | | ︙ | |
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
[thread handleTermination];
thread->running = OF_THREAD_WAITING_FOR_JOIN;
}
[OFTLSKey callAllDestructors];
[OFAutoreleasePool _releaseAll];
[thread release];
of_thread_exit();
}
+ (void)_createMainThread
{
mainThread = [[OFThread alloc] init];
mainThread->thread = of_thread_current();
if (!of_tlskey_set(threadSelfKey, mainThread))
@throw [OFInitializationFailedException
exceptionWithClass: self];
|
|
|
|
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
[thread handleTermination];
thread->running = OF_THREAD_WAITING_FOR_JOIN;
}
[OFTLSKey callAllDestructors];
[OFAutoreleasePool OF_releaseAll];
[thread release];
of_thread_exit();
}
+ (void)OF_createMainThread
{
mainThread = [[OFThread alloc] init];
mainThread->thread = of_thread_current();
if (!of_tlskey_set(threadSelfKey, mainThread))
@throw [OFInitializationFailedException
exceptionWithClass: self];
|
︙ | | | ︙ | |
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
}
- (OFRunLoop*)runLoop
{
return [[runLoop retain] autorelease];
}
- (void)_setRunLoop: (OFRunLoop*)runLoop_
{
OFRunLoop *old = runLoop;
runLoop = [runLoop_ retain];
[old release];
}
- (void)dealloc
|
|
|
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
}
- (OFRunLoop*)runLoop
{
return [[runLoop retain] autorelease];
}
- (void)OF_setRunLoop: (OFRunLoop*)runLoop_
{
OFRunLoop *old = runLoop;
runLoop = [runLoop_ retain];
[old release];
}
- (void)dealloc
|
︙ | | | ︙ | |
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
}
initialized = YES;
return self;
}
- _initWithoutCreatingMutex
{
return [super init];
}
- (void)lock
{
if (!of_mutex_lock(&mutex))
|
|
|
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
}
initialized = YES;
return self;
}
- OF_initWithoutCreatingMutex
{
return [super init];
}
- (void)lock
{
if (!of_mutex_lock(&mutex))
|
︙ | | | ︙ | |
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
[super dealloc];
}
@end
@implementation OFRecursiveMutex
- init
{
self = [super _initWithoutCreatingMutex];
if (!of_rmutex_new(&rmutex)) {
Class c = [self class];
[self release];
@throw [OFInitializationFailedException exceptionWithClass: c];
}
|
|
|
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
[super dealloc];
}
@end
@implementation OFRecursiveMutex
- init
{
self = [super OF_initWithoutCreatingMutex];
if (!of_rmutex_new(&rmutex)) {
Class c = [self class];
[self release];
@throw [OFInitializationFailedException exceptionWithClass: c];
}
|
︙ | | | ︙ | |
︙ | | | ︙ | |
138
139
140
141
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
|
@implementation OFXMLParser
+ (void)initialize
{
size_t i;
const SEL selectors_[] = {
@selector(_parseOutsideTagWithBuffer:i:last:),
@selector(_parseTagOpenedWithBuffer:i:last:),
@selector(_parseInProcessingInstructionsWithBuffer:i:last:),
@selector(_parseInTagNameWithBuffer:i:last:),
@selector(_parseInCloseTagNameWithBuffer:i:last:),
@selector(_parseInTagWithBuffer:i:last:),
@selector(_parseInAttributeNameWithBuffer:i:last:),
@selector(_parseExpectDelimiterWithBuffer:i:last:),
@selector(_parseInAttributeValueWithBuffer:i:last:),
@selector(_parseExpectCloseWithBuffer:i:last:),
@selector(_parseExpectSpaceOrCloseWithBuffer:i:last:),
@selector(_parseInExclamationMarkWithBuffer:i:last:),
@selector(_parseInCDATAOpeningWithBuffer:i:last:),
@selector(_parseInCDATA1WithBuffer:i:last:),
@selector(_parseInCDATA2WithBuffer:i:last:),
@selector(_parseInCommentOpeningWithBuffer:i:last:),
@selector(_parseInComment1WithBuffer:i:last:),
@selector(_parseInComment2WithBuffer:i:last:),
@selector(_parseInDoctypeWithBuffer:i:last:),
};
memcpy(selectors, selectors_, sizeof(selectors_));
for (i = 0; i < OF_XMLPARSER_NUM_STATES; i++) {
if (![self instancesRespondToSelector: selectors[i]])
@throw [OFInitializationFailedException
exceptionWithClass: self];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138
139
140
141
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
|
@implementation OFXMLParser
+ (void)initialize
{
size_t i;
const SEL selectors_[] = {
@selector(OF_parseOutsideTagWithBuffer:i:last:),
@selector(OF_parseTagOpenedWithBuffer:i:last:),
@selector(OF_parseInProcessingInstructionsWithBuffer:i:last:),
@selector(OF_parseInTagNameWithBuffer:i:last:),
@selector(OF_parseInCloseTagNameWithBuffer:i:last:),
@selector(OF_parseInTagWithBuffer:i:last:),
@selector(OF_parseInAttributeNameWithBuffer:i:last:),
@selector(OF_parseExpectDelimiterWithBuffer:i:last:),
@selector(OF_parseInAttributeValueWithBuffer:i:last:),
@selector(OF_parseExpectCloseWithBuffer:i:last:),
@selector(OF_parseExpectSpaceOrCloseWithBuffer:i:last:),
@selector(OF_parseInExclamationMarkWithBuffer:i:last:),
@selector(OF_parseInCDATAOpeningWithBuffer:i:last:),
@selector(OF_parseInCDATA1WithBuffer:i:last:),
@selector(OF_parseInCDATA2WithBuffer:i:last:),
@selector(OF_parseInCommentOpeningWithBuffer:i:last:),
@selector(OF_parseInComment1WithBuffer:i:last:),
@selector(OF_parseInComment2WithBuffer:i:last:),
@selector(OF_parseInDoctypeWithBuffer:i:last:),
};
memcpy(selectors, selectors_, sizeof(selectors_));
for (i = 0; i < OF_XMLPARSER_NUM_STATES; i++) {
if (![self instancesRespondToSelector: selectors[i]])
@throw [OFInitializationFailedException
exceptionWithClass: self];
|
︙ | | | ︙ | |
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
/*
* The following methods handle the different states of the parser. They are
* looked up in +[initialize] and put in a lookup table to speed things up.
* One dispatch for every character would be way too slow!
*/
/* Not in a tag */
- (void)_parseOutsideTagWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
size_t length;
if ((finishedParsing || [previous count] < 1) && buffer[*i] != ' ' &&
buffer[*i] != '\t' && buffer[*i] != '\n' && buffer[*i] != '\r' &&
buffer[*i] != '<')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
|
|
|
|
|
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
/*
* The following methods handle the different states of the parser. They are
* looked up in +[initialize] and put in a lookup table to speed things up.
* One dispatch for every character would be way too slow!
*/
/* Not in a tag */
- (void)OF_parseOutsideTagWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
size_t length;
if ((finishedParsing || [previous count] < 1) && buffer[*i] != ' ' &&
buffer[*i] != '\t' && buffer[*i] != '\n' && buffer[*i] != '\r' &&
buffer[*i] != '<')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
|
︙ | | | ︙ | |
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_TAG_OPENED;
}
/* Tag was just opened */
- (void)_parseTagOpenedWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (finishedParsing && buffer[*i] != '!' && buffer[*i] != '?')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
switch (buffer[*i]) {
case '?':
|
|
|
|
|
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_TAG_OPENED;
}
/* Tag was just opened */
- (void)OF_parseTagOpenedWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (finishedParsing && buffer[*i] != '!' && buffer[*i] != '?')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
switch (buffer[*i]) {
case '?':
|
︙ | | | ︙ | |
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
acceptProlog = NO;
(*i)--;
break;
}
}
/* <?xml […]?> */
- (BOOL)_parseXMLProcessingInstructions: (OFString*)pi
{
const char *cString;
size_t i, last, length;
int piState = 0;
OFString *attribute = nil;
OFMutableString *value = nil;
char piDelimiter = 0;
|
|
|
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
acceptProlog = NO;
(*i)--;
break;
}
}
/* <?xml […]?> */
- (BOOL)OF_parseXMLProcessingInstructions: (OFString*)pi
{
const char *cString;
size_t i, last, length;
int piState = 0;
OFString *attribute = nil;
OFMutableString *value = nil;
char piDelimiter = 0;
|
︙ | | | ︙ | |
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
|
if (piState != 0)
return NO;
return YES;
}
/* Inside processing instructions */
- (void)_parseInProcessingInstructionsWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] == '?')
level = 1;
else if (level == 1 && buffer[*i] == '>') {
void *pool = objc_autoreleasePoolPush();
OFString *pi;
cache_append(cache, buffer + *last, encoding, *i - *last);
pi = transform_string(cache, 1, NO, nil);
if ([pi isEqual: @"xml"] || [pi hasPrefix: @"xml "] ||
[pi hasPrefix: @"xml\t"] || [pi hasPrefix: @"xml\r"] ||
[pi hasPrefix: @"xml\n"])
if (![self _parseXMLProcessingInstructions: pi])
@throw [OFMalformedXMLException
exceptionWithClass: [self class]
parser: self];
[delegate parser: self
foundProcessingInstructions: pi];
objc_autoreleasePoolPop(pool);
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
} else
level = 0;
}
/* Inside a tag, no name yet */
- (void)_parseInTagNameWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
const char *cacheCString, *tmp;
size_t length, cacheLength;
OFString *cacheString;
if (buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' &&
|
|
|
|
|
|
|
|
|
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
|
if (piState != 0)
return NO;
return YES;
}
/* Inside processing instructions */
- (void)OF_parseInProcessingInstructionsWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] == '?')
level = 1;
else if (level == 1 && buffer[*i] == '>') {
void *pool = objc_autoreleasePoolPush();
OFString *pi;
cache_append(cache, buffer + *last, encoding, *i - *last);
pi = transform_string(cache, 1, NO, nil);
if ([pi isEqual: @"xml"] || [pi hasPrefix: @"xml "] ||
[pi hasPrefix: @"xml\t"] || [pi hasPrefix: @"xml\r"] ||
[pi hasPrefix: @"xml\n"])
if (![self OF_parseXMLProcessingInstructions: pi])
@throw [OFMalformedXMLException
exceptionWithClass: [self class]
parser: self];
[delegate parser: self
foundProcessingInstructions: pi];
objc_autoreleasePoolPop(pool);
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
} else
level = 0;
}
/* Inside a tag, no name yet */
- (void)OF_parseInTagNameWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
const char *cacheCString, *tmp;
size_t length, cacheLength;
OFString *cacheString;
if (buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' &&
|
︙ | | | ︙ | |
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
|
objc_autoreleasePoolPop(pool);
[cache removeAllItems];
*last = *i + 1;
}
/* Inside a close tag, no name yet */
- (void)_parseInCloseTagNameWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
const char *cacheCString, *tmp;
size_t length, cacheLength;
OFString *cacheString;
OFString *ns;
|
|
|
|
|
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
|
objc_autoreleasePoolPop(pool);
[cache removeAllItems];
*last = *i + 1;
}
/* Inside a close tag, no name yet */
- (void)OF_parseInCloseTagNameWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
const char *cacheCString, *tmp;
size_t length, cacheLength;
OFString *cacheString;
OFString *ns;
|
︙ | | | ︙ | |
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
|
: OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE);
if ([previous count] == 0)
finishedParsing = YES;
}
/* Inside a tag, name found */
- (void)_parseInTagWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
OFString *ns;
OFXMLAttribute **attributesObjects;
size_t j, attributesCount;
if (buffer[*i] != '>' && buffer[*i] != '/') {
|
|
|
|
|
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
|
: OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE);
if ([previous count] == 0)
finishedParsing = YES;
}
/* Inside a tag, name found */
- (void)OF_parseInTagWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
OFString *ns;
OFXMLAttribute **attributesObjects;
size_t j, attributesCount;
if (buffer[*i] != '>' && buffer[*i] != '/') {
|
︙ | | | ︙ | |
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
|
*last = *i + 1;
state = (buffer[*i] == '/'
? OF_XMLPARSER_EXPECT_CLOSE
: OF_XMLPARSER_OUTSIDE_TAG);
}
/* Looking for attribute name */
- (void)_parseInAttributeNameWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
OFMutableString *cacheString;
const char *cacheCString, *tmp;
size_t length, cacheLength;
if (buffer[*i] != '=')
|
|
|
|
|
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
|
*last = *i + 1;
state = (buffer[*i] == '/'
? OF_XMLPARSER_EXPECT_CLOSE
: OF_XMLPARSER_OUTSIDE_TAG);
}
/* Looking for attribute name */
- (void)OF_parseInAttributeNameWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
OFMutableString *cacheString;
const char *cacheCString, *tmp;
size_t length, cacheLength;
if (buffer[*i] != '=')
|
︙ | | | ︙ | |
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
|
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_EXPECT_DELIM;
}
/* Expecting delimiter */
- (void)_parseExpectDelimiterWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
*last = *i + 1;
if (buffer[*i] == ' ' || buffer[*i] == '\t' || buffer[*i] == '\n' ||
buffer[*i] == '\r')
return;
if (buffer[*i] != '\'' && buffer[*i] != '"')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
delimiter = buffer[*i];
state = OF_XMLPARSER_IN_ATTR_VALUE;
}
/* Looking for attribute value */
- (void)_parseInAttributeValueWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
OFString *attributeValue;
size_t length;
if (buffer[*i] != delimiter)
return;
|
|
|
|
|
|
|
|
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
|
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_EXPECT_DELIM;
}
/* Expecting delimiter */
- (void)OF_parseExpectDelimiterWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
*last = *i + 1;
if (buffer[*i] == ' ' || buffer[*i] == '\t' || buffer[*i] == '\n' ||
buffer[*i] == '\r')
return;
if (buffer[*i] != '\'' && buffer[*i] != '"')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
delimiter = buffer[*i];
state = OF_XMLPARSER_IN_ATTR_VALUE;
}
/* Looking for attribute value */
- (void)OF_parseInAttributeValueWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
OFString *attributeValue;
size_t length;
if (buffer[*i] != delimiter)
return;
|
︙ | | | ︙ | |
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
|
attributeName = attributePrefix = nil;
*last = *i + 1;
state = OF_XMLPARSER_IN_TAG;
}
/* Expecting closing '>' */
- (void)_parseExpectCloseWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] == '>') {
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
} else
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
}
/* Expecting closing '>' or space */
- (void)_parseExpectSpaceOrCloseWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] == '>') {
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
} else if (buffer[*i] != ' ' && buffer[*i] != '\t' &&
buffer[*i] != '\n' && buffer[*i] != '\r')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
}
/* In <! */
- (void)_parseInExclamationMarkWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (finishedParsing && buffer[*i] != '-')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
if (buffer[*i] == '-')
state = OF_XMLPARSER_IN_COMMENT_OPENING;
|
|
|
|
|
|
|
|
|
|
|
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
|
attributeName = attributePrefix = nil;
*last = *i + 1;
state = OF_XMLPARSER_IN_TAG;
}
/* Expecting closing '>' */
- (void)OF_parseExpectCloseWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] == '>') {
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
} else
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
}
/* Expecting closing '>' or space */
- (void)OF_parseExpectSpaceOrCloseWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] == '>') {
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
} else if (buffer[*i] != ' ' && buffer[*i] != '\t' &&
buffer[*i] != '\n' && buffer[*i] != '\r')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
}
/* In <! */
- (void)OF_parseInExclamationMarkWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (finishedParsing && buffer[*i] != '-')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
if (buffer[*i] == '-')
state = OF_XMLPARSER_IN_COMMENT_OPENING;
|
︙ | | | ︙ | |
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
|
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
*last = *i + 1;
}
/* CDATA */
- (void)_parseInCDATAOpeningWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] != "CDATA["[level])
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
if (++level == 6) {
state = OF_XMLPARSER_IN_CDATA_1;
level = 0;
}
*last = *i + 1;
}
- (void)_parseInCDATA1WithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] == ']')
level++;
else
level = 0;
if (level == 2)
state = OF_XMLPARSER_IN_CDATA_2;
}
- (void)_parseInCDATA2WithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
OFString *CDATA;
if (buffer[*i] != '>') {
state = OF_XMLPARSER_IN_CDATA_1;
level = (buffer[*i] == ']' ? 1 : 0);
|
|
|
|
|
|
|
|
|
|
|
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
|
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
*last = *i + 1;
}
/* CDATA */
- (void)OF_parseInCDATAOpeningWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] != "CDATA["[level])
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
if (++level == 6) {
state = OF_XMLPARSER_IN_CDATA_1;
level = 0;
}
*last = *i + 1;
}
- (void)OF_parseInCDATA1WithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] == ']')
level++;
else
level = 0;
if (level == 2)
state = OF_XMLPARSER_IN_CDATA_2;
}
- (void)OF_parseInCDATA2WithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
OFString *CDATA;
if (buffer[*i] != '>') {
state = OF_XMLPARSER_IN_CDATA_1;
level = (buffer[*i] == ']' ? 1 : 0);
|
︙ | | | ︙ | |
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
|
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
}
/* Comment */
- (void)_parseInCommentOpeningWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] != '-')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
*last = *i + 1;
state = OF_XMLPARSER_IN_COMMENT_1;
level = 0;
}
- (void)_parseInComment1WithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] == '-')
level++;
else
level = 0;
if (level == 2)
state = OF_XMLPARSER_IN_COMMENT_2;
}
- (void)_parseInComment2WithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
OFString *comment;
if (buffer[*i] != '>')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
|
|
|
|
|
|
|
|
|
|
|
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
|
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
}
/* Comment */
- (void)OF_parseInCommentOpeningWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] != '-')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
*last = *i + 1;
state = OF_XMLPARSER_IN_COMMENT_1;
level = 0;
}
- (void)OF_parseInComment1WithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if (buffer[*i] == '-')
level++;
else
level = 0;
if (level == 2)
state = OF_XMLPARSER_IN_COMMENT_2;
}
- (void)OF_parseInComment2WithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
void *pool;
OFString *comment;
if (buffer[*i] != '>')
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
|
︙ | | | ︙ | |
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
|
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
}
/* In <!DOCTYPE ...> */
- (void)_parseInDoctypeWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if ((level < 6 && buffer[*i] != "OCTYPE"[level]) ||
(level == 6 && buffer[*i] != ' ' && buffer[*i] != '\t' &&
buffer[*i] != '\n' && buffer[*i] != '\r'))
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
|
|
|
|
|
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
|
[cache removeAllItems];
*last = *i + 1;
state = OF_XMLPARSER_OUTSIDE_TAG;
}
/* In <!DOCTYPE ...> */
- (void)OF_parseInDoctypeWithBuffer: (const char*)buffer
i: (size_t*)i
last: (size_t*)last
{
if ((level < 6 && buffer[*i] != "OCTYPE"[level]) ||
(level == 6 && buffer[*i] != ' ' && buffer[*i] != '\t' &&
buffer[*i] != '\n' && buffer[*i] != '\r'))
@throw [OFMalformedXMLException exceptionWithClass: [self class]
parser: self];
|
︙ | | | ︙ | |