Modified ObjFW.xcodeproj/project.pbxproj
from [0481245247]
to [f8de28e17c].
︙ | | |
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
+
+
|
4BB25E89139C388A00F574EA /* OFObject+Serialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BB25E83139C388A00F574EA /* OFObject+Serialization.m */; };
4BB25E8A139C388A00F574EA /* OFString+Serialization.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BB25E84139C388A00F574EA /* OFString+Serialization.h */; settings = {ATTRIBUTES = (Public, ); }; };
4BB25E8B139C388A00F574EA /* OFString+Serialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BB25E85139C388A00F574EA /* OFString+Serialization.m */; };
4BB25E8C139C388A00F574EA /* OFXMLElement+Serialization.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BB25E86139C388A00F574EA /* OFXMLElement+Serialization.h */; settings = {ATTRIBUTES = (Public, ); }; };
4BB25E8D139C388A00F574EA /* OFXMLElement+Serialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BB25E87139C388A00F574EA /* OFXMLElement+Serialization.m */; };
4BB524C1143D1E4E0085FBCC /* OFProcess.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BB524BF143D1E4E0085FBCC /* OFProcess.h */; settings = {ATTRIBUTES = (Public, ); }; };
4BB524C2143D1E4E0085FBCC /* OFProcess.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BB524C0143D1E4E0085FBCC /* OFProcess.m */; settings = {ATTRIBUTES = (Public, ); }; };
4BC090441584F6760040640F /* OFInvalidJSONException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC090421584F6760040640F /* OFInvalidJSONException.h */; settings = {ATTRIBUTES = (Public, ); }; };
4BC090451584F6760040640F /* OFInvalidJSONException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BC090431584F6760040640F /* OFInvalidJSONException.m */; };
4BD653C5143B8489006182F0 /* OFTCPSocket+SOCKS5.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD653C3143B8489006182F0 /* OFTCPSocket+SOCKS5.h */; };
4BD653C6143B8489006182F0 /* OFTCPSocket+SOCKS5.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BD653C4143B8489006182F0 /* OFTCPSocket+SOCKS5.m */; };
4BD98C03133814220048DD5B /* objfw-defs.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD98C011338140B0048DD5B /* objfw-defs.h */; settings = {ATTRIBUTES = (Public, ); }; };
4BDF37B51338055600F9A81A /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BDF37B41338055600F9A81A /* config.h */; };
4BF33AFB133807590059CEF7 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B3D23761337FBC800DD29B8 /* ObjFW.framework */; };
4BF33AFC133807A20059CEF7 /* OFArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF66E1235358D0076B512 /* OFArrayTests.m */; };
4BF33AFD133807A20059CEF7 /* OFBlockTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BE5F0E412DF4259005C7A0C /* OFBlockTests.m */; };
|
︙ | | |
659
660
661
662
663
664
665
666
667
668
669
670
671
672
|
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
|
+
+
|
4BB25E87139C388A00F574EA /* OFXMLElement+Serialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFXMLElement+Serialization.m"; path = "src/OFXMLElement+Serialization.m"; sourceTree = "<group>"; };
4BB50DCF12F863C700C9393F /* of_asprintf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = of_asprintf.h; path = src/of_asprintf.h; sourceTree = SOURCE_ROOT; };
4BB50DD012F863C700C9393F /* of_asprintf.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = of_asprintf.m; path = src/of_asprintf.m; sourceTree = SOURCE_ROOT; };
4BB524BF143D1E4E0085FBCC /* OFProcess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFProcess.h; path = src/OFProcess.h; sourceTree = "<group>"; };
4BB524C0143D1E4E0085FBCC /* OFProcess.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFProcess.m; path = src/OFProcess.m; sourceTree = "<group>"; };
4BBA36C411406AB700CBA3AC /* atomic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = atomic.h; path = src/atomic.h; sourceTree = "<group>"; };
4BBA36C511406AB700CBA3AC /* macros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = macros.h; path = src/macros.h; sourceTree = "<group>"; };
4BC090421584F6760040640F /* OFInvalidJSONException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFInvalidJSONException.h; path = src/exceptions/OFInvalidJSONException.h; sourceTree = "<group>"; };
4BC090431584F6760040640F /* OFInvalidJSONException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFInvalidJSONException.m; path = src/exceptions/OFInvalidJSONException.m; sourceTree = "<group>"; };
4BD653C3143B8489006182F0 /* OFTCPSocket+SOCKS5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFTCPSocket+SOCKS5.h"; path = "src/OFTCPSocket+SOCKS5.h"; sourceTree = "<group>"; };
4BD653C4143B8489006182F0 /* OFTCPSocket+SOCKS5.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFTCPSocket+SOCKS5.m"; path = "src/OFTCPSocket+SOCKS5.m"; sourceTree = "<group>"; };
4BD86D801237A6C600ED9912 /* OFBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFBlock.h; path = src/OFBlock.h; sourceTree = SOURCE_ROOT; };
4BD86D811237A6C600ED9912 /* OFBlock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFBlock.m; path = src/OFBlock.m; sourceTree = SOURCE_ROOT; };
4BD98C011338140B0048DD5B /* objfw-defs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "objfw-defs.h"; path = "src/objfw-defs.h"; sourceTree = SOURCE_ROOT; };
4BDF37B41338055600F9A81A /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = SOURCE_ROOT; };
4BE17AD812FD744C002CEB0B /* foundation-compat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "foundation-compat.m"; path = "src/foundation-compat.m"; sourceTree = SOURCE_ROOT; };
|
︙ | | |
790
791
792
793
794
795
796
797
798
799
800
801
802
803
|
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
|
+
+
|
4B17FFA4133A340D003E6DCD /* OFInitializationFailedException.m */,
4B17FF91133A317A003E6DCD /* OFInvalidArgumentException.h */,
4B17FF92133A317B003E6DCD /* OFInvalidArgumentException.m */,
4B17FF97133A3242003E6DCD /* OFInvalidEncodingException.h */,
4B17FF98133A3243003E6DCD /* OFInvalidEncodingException.m */,
4B17FF9B133A32B7003E6DCD /* OFInvalidFormatException.h */,
4B17FF9C133A32B8003E6DCD /* OFInvalidFormatException.m */,
4BC090421584F6760040640F /* OFInvalidJSONException.h */,
4BC090431584F6760040640F /* OFInvalidJSONException.m */,
4B17FFB7133A380F003E6DCD /* OFInvalidServerReplyException.h */,
4B17FFB8133A3813003E6DCD /* OFInvalidServerReplyException.m */,
4B29BC5D133AC9C40004B236 /* OFLinkFailedException.h */,
4B29BC5E133AC9C40004B236 /* OFLinkFailedException.m */,
4B90B79C133AD87D00BD33CB /* OFListenFailedException.h */,
4B90B79D133AD87D00BD33CB /* OFListenFailedException.m */,
4B17FF9F133A3331003E6DCD /* OFMalformedXMLException.h */,
|
︙ | | |
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
|
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
|
+
|
4B17FF87133A2E7B003E6DCD /* OFEnumerationMutationException.h in Headers */,
4B8B16FE133A3B84007CD8B3 /* OFHashAlreadyCalculatedException.h in Headers */,
4B17FFAD133A3591003E6DCD /* OFHTTPRequestFailedException.h in Headers */,
4B17FFA5133A3411003E6DCD /* OFInitializationFailedException.h in Headers */,
4B17FF93133A317C003E6DCD /* OFInvalidArgumentException.h in Headers */,
4B17FF99133A3245003E6DCD /* OFInvalidEncodingException.h in Headers */,
4B17FF9D133A32BA003E6DCD /* OFInvalidFormatException.h in Headers */,
4BC090441584F6760040640F /* OFInvalidJSONException.h in Headers */,
4B17FFB9133A381D003E6DCD /* OFInvalidServerReplyException.h in Headers */,
4B29BC61133AC9CB0004B236 /* OFLinkFailedException.h in Headers */,
4B90B7A6133AD87D00BD33CB /* OFListenFailedException.h in Headers */,
4B17FFA1133A3335003E6DCD /* OFMalformedXMLException.h in Headers */,
4B17FF8F133A3036003E6DCD /* OFMemoryNotPartOfObjectException.h in Headers */,
4B8B1719133A3D04007CD8B3 /* OFMutexLockFailedException.h in Headers */,
4B7FF3B0133CE6DE00000324 /* OFMutexStillLockedException.h in Headers */,
|
︙ | | |
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
|
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
|
+
|
4B17FF73133A2A76003E6DCD /* OFException.m in Sources */,
4B8B16FF133A3B84007CD8B3 /* OFHashAlreadyCalculatedException.m in Sources */,
4B17FFAE133A3591003E6DCD /* OFHTTPRequestFailedException.m in Sources */,
4B17FFA6133A3411003E6DCD /* OFInitializationFailedException.m in Sources */,
4B17FF94133A317C003E6DCD /* OFInvalidArgumentException.m in Sources */,
4B17FF9A133A3245003E6DCD /* OFInvalidEncodingException.m in Sources */,
4B17FF9E133A32BA003E6DCD /* OFInvalidFormatException.m in Sources */,
4BC090451584F6760040640F /* OFInvalidJSONException.m in Sources */,
4B17FFBA133A381D003E6DCD /* OFInvalidServerReplyException.m in Sources */,
4B29BC62133AC9CB0004B236 /* OFLinkFailedException.m in Sources */,
4B90B7A7133AD87D00BD33CB /* OFListenFailedException.m in Sources */,
4B17FFA2133A3335003E6DCD /* OFMalformedXMLException.m in Sources */,
4B17FF90133A3036003E6DCD /* OFMemoryNotPartOfObjectException.m in Sources */,
4B8B171A133A3D04007CD8B3 /* OFMutexLockFailedException.m in Sources */,
4B7FF3B1133CE6DE00000324 /* OFMutexStillLockedException.m in Sources */,
|
︙ | | |
Modified src/OFArray.h
from [bde628b396]
to [01516d5008].
︙ | | |
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
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
297
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
/**
* \brief Returns a copy of the array with the order reversed.
*
* \return A copy of the array with the order reversed
*/
- (OFArray*)reversedArray;
/**
* \brief Creates a new array with the specified object added.
*
* \param object The object to add
* \return A new array with the specified object added
*/
- (OFArray*)arrayByAddingObject: (id)object;
/**
* \brief Creates a new array with the objects from the specified array added.
*
* \param array The array with objects to add
* \return A new array with the objects from the specified array added
*/
- (OFArray*)arrayByAddingObjectsFromArray: (OFArray*)array;
#ifdef OF_HAVE_BLOCKS
/**
* \brief Executes a block for each object.
*
* \param block The block to execute for each object
*/
- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block;
|
︙ | | |
Modified src/OFArray.m
from [5ae87127d9]
to [7b45e24981].
︙ | | |
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
-
-
+
+
|
{
OFObject *container;
size_t count;
id *buffer;
container = [[[OFObject alloc] init] autorelease];
count = [self count];
buffer = [container allocMemoryWithItemSize: sizeof(*buffer)
count: [self count]];
buffer = [container allocMemoryWithSize: sizeof(*buffer)
count: [self count]];
[self getObjects: buffer
inRange: of_range(0, count)];
return buffer;
}
|
︙ | | |
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
-
-
+
+
|
OFArray *ret;
id *buffer;
if (![self isKindOfClass: [OFMutableArray class]])
return [OFArray_subarray arrayWithArray: self
range: range];
buffer = [self allocMemoryWithItemSize: sizeof(*buffer)
count: range.length];
buffer = [self allocMemoryWithSize: sizeof(*buffer)
count: range.length];
@try {
[self getObjects: buffer
inRange: range];
ret = [OFArray arrayWithObjects: buffer
count: range.length];
|
︙ | | |
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
|
block(object, i++, &stop);
if (stop)
break;
}
}
#endif
- (OFArray*)arrayByAddingObject: (id)object
{
OFMutableArray *ret = [[self mutableCopy] autorelease];
[ret addObject: object];
[ret makeImmutable];
return ret;
}
- (OFArray*)arrayByAddingObjectsFromArray: (OFArray*)array
{
OFMutableArray *ret = [[self mutableCopy] autorelease];
[ret addObjectsFromArray: array];
[ret makeImmutable];
return ret;
}
#ifdef OF_HAVE_BLOCKS
- (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block
{
OFArray *ret;
size_t count = [self count];
id *tmp = [self allocMemoryWithItemSize: sizeof(id)
count: count];
id *tmp = [self allocMemoryWithSize: sizeof(id)
count: count];
@try {
[self enumerateObjectsUsingBlock: ^ (id object, size_t index,
BOOL *stop) {
tmp[index] = block(object, index);
}];
ret = [OFArray arrayWithObjects: tmp
count: count];
} @finally {
[self freeMemory: tmp];
}
return ret;
}
- (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block
{
OFArray *ret;
size_t count = [self count];
id *tmp = [self allocMemoryWithItemSize: sizeof(id)
count: count];
id *tmp = [self allocMemoryWithSize: sizeof(id)
count: count];
@try {
__block size_t i = 0;
[self enumerateObjectsUsingBlock: ^ (id object, size_t index,
BOOL *stop) {
if (block(object, index))
|
︙ | | |
Modified src/OFAutoreleasePool.m
from [bc3a0d2a2f]
to [42c4c969f4].
︙ | | |
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
|
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
|
-
-
+
+
-
+
|
#endif
}
if (previousPool != nil)
previousPool->nextPool = self;
size = GROW_SIZE;
objects = [self allocMemoryWithItemSize: sizeof(id)
count: GROW_SIZE];
objects = [self allocMemoryWithSize: sizeof(id)
count: GROW_SIZE];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)_addObject: (id)object
{
if (count + 1 > size) {
objects = [self resizeMemory: objects
itemSize: sizeof(id)
size: sizeof(id)
count: size + GROW_SIZE];
size += GROW_SIZE;
}
objects[count] = object;
count++;
}
|
︙ | | |
Modified src/OFBlock.m
from [36beda4104]
to [d9ed74f314].
︙ | | |
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
-
-
+
+
-
+
-
-
+
+
|
- (void*)allocMemoryWithSize: (size_t)size
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (void*)allocMemoryForNItems: (size_t)nitems
withSize: (size_t)size
- (void*)allocMemoryWithSize: (size_t)size
count: (size_t)count
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (void*)resizeMemory: (void*)ptr
toSize: (size_t)size
size: (size_t)size
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (void*)resizeMemory: (void*)ptr
toNItems: (size_t)nitems
withSize: (size_t)size
size: (size_t)size
count: (size_t)count
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (void)freeMemory: (void*)ptr
{
|
︙ | | |
Modified src/OFConstantString.m
from [e6c815e41d]
to [63e98f3fd3].
︙ | | |
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
-
-
+
+
-
+
|
- (void*)allocMemoryWithSize: (size_t)size
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (void*)allocMemoryForNItems: (size_t)nitems
withSize: (size_t)size
- (void*)allocMemoryWithSize: (size_t)itemSize
count: (size_t)count
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (void*)resizeMemory: (void*)ptr
toSize: (size_t)size
size: (size_t)size
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (void*)resizeMemory: (void*)ptr
toNItems: (size_t)nitems
|
︙ | | |
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
-
-
+
+
-
+
-
-
+
+
|
- (void*)allocMemoryWithSize: (size_t)size
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (void*)allocMemoryForNItems: (size_t)nitems
withSize: (size_t)size
- (void*)allocMemoryWithSize: (size_t)size
count: (size_t)count
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (void*)resizeMemory: (void*)ptr
toSize: (size_t)size
size: (size_t)size
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (void*)resizeMemory: (void*)ptr
toNItems: (size_t)nitems
withSize: (size_t)size
size: (size_t)size
count: (size_t)count
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (void)freeMemory: (void*)ptr
{
|
︙ | | |
Modified src/OFDataArray.m
from [1c8a76eb56]
to [a3f3ece2b2].
︙ | | |
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
-
-
+
+
|
@try {
char *buffer = [self allocMemoryWithSize: of_pagesize];
while (![file isAtEndOfStream]) {
size_t length;
length = [file readNBytes: of_pagesize
intoBuffer: buffer];
length = [file readIntoBuffer: buffer
length: of_pagesize];
[self addItemsFromCArray: buffer
count: length];
}
[self freeMemory: buffer];
} @finally {
[file release];
|
︙ | | |
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
-
+
|
- (void)addItem: (const void*)item
{
if (SIZE_MAX - count < 1)
@throw [OFOutOfRangeException exceptionWithClass: isa];
data = [self resizeMemory: data
itemSize: itemSize
size: itemSize
count: count + 1];
memcpy(data + count * itemSize, item, itemSize);
count++;
}
|
︙ | | |
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
-
+
-
+
|
- (void)addItemsFromCArray: (const void*)cArray
count: (size_t)nItems
{
if (nItems > SIZE_MAX - count)
@throw [OFOutOfRangeException exceptionWithClass: isa];
data = [self resizeMemory: data
itemSize: itemSize
size: itemSize
count: count + nItems];
memcpy(data + count * itemSize, cArray, nItems * itemSize);
count += nItems;
}
- (void)insertItemsFromCArray: (const void*)cArray
atIndex: (size_t)index
count: (size_t)nItems
{
if (nItems > SIZE_MAX - count || index > count)
@throw [OFOutOfRangeException exceptionWithClass: isa];
data = [self resizeMemory: data
itemSize: itemSize
size: itemSize
count: count + nItems];
memmove(data + (index + nItems) * itemSize, data + index * itemSize,
(count - index) * itemSize);
memcpy(data + index * itemSize, cArray, nItems * itemSize);
count += nItems;
|
︙ | | |
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
|
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
|
-
+
-
+
|
memmove(data + range.start * itemSize,
data + (range.start + range.length) * itemSize,
(count - range.start - range.length) * itemSize);
count -= range.length;
@try {
data = [self resizeMemory: data
itemSize: itemSize
size: itemSize
count: count];
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
}
}
- (void)removeLastItem
{
if (count < 1)
@throw [OFOutOfRangeException exceptionWithClass: isa];
count--;
@try {
data = [self resizeMemory: data
itemSize: itemSize
size: itemSize
count: count];
} @catch (OFOutOfMemoryException *e) {
/* We don't care, as we only made it smaller */
}
}
- (void)removeAllItems
|
︙ | | |
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
-
-
+
+
|
- (void)writeToFile: (OFString*)path
{
OFFile *file = [[OFFile alloc] initWithPath: path
mode: @"wb"];
@try {
[file writeNBytes: count * itemSize
fromBuffer: data];
[file writeBuffer: data
length: count * itemSize];
} @finally {
[file release];
}
}
- (OFXMLElement*)XMLElementBySerializing
{
|
︙ | | |
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
|
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
|
-
+
-
+
|
@throw [OFOutOfRangeException exceptionWithClass: isa];
lastPageByte = of_pagesize - 1;
newSize = ((count + 1) * itemSize + lastPageByte) & ~lastPageByte;
if (size != newSize)
data = [self resizeMemory: data
toSize: newSize];
size: newSize];
memcpy(data + count * itemSize, item, itemSize);
count++;
size = newSize;
}
- (void)addItemsFromCArray: (const void*)cArray
count: (size_t)nItems
{
size_t newSize, lastPageByte;
if (nItems > SIZE_MAX - count || count + nItems > SIZE_MAX / itemSize)
@throw [OFOutOfRangeException exceptionWithClass: isa];
lastPageByte = of_pagesize - 1;
newSize = ((count + nItems) * itemSize + lastPageByte) & ~lastPageByte;
if (size != newSize)
data = [self resizeMemory: data
toSize: newSize];
size: newSize];
memcpy(data + count * itemSize, cArray, nItems * itemSize);
count += nItems;
size = newSize;
}
|
︙ | | |
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
|
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
|
-
+
|
@throw [OFOutOfRangeException exceptionWithClass: isa];
lastPageByte = of_pagesize - 1;
newSize = ((count + nItems) * itemSize + lastPageByte) & ~lastPageByte;
if (size != newSize)
data = [self resizeMemory: data
toSize: newSize];
size: newSize];
memmove(data + (index + nItems) * itemSize, data + index * itemSize,
(count - index) * itemSize);
memcpy(data + index * itemSize, cArray, nItems * itemSize);
count += nItems;
size = newSize;
|
︙ | | |
547
548
549
550
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
|
547
548
549
550
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
|
-
+
-
+
|
count -= range.length;
lastPageByte = of_pagesize - 1;
newSize = (count * itemSize + lastPageByte) & ~lastPageByte;
if (size != newSize)
data = [self resizeMemory: data
toSize: newSize];
size: newSize];
size = newSize;
}
- (void)removeLastItem
{
size_t newSize, lastPageByte;
if (count < 1)
@throw [OFOutOfRangeException exceptionWithClass: isa];
count--;
lastPageByte = of_pagesize - 1;
newSize = (count * itemSize + lastPageByte) & ~lastPageByte;
if (size != newSize) {
@try {
data = [self resizeMemory: data
toSize: newSize];
size: newSize];
} @catch (OFOutOfMemoryException *e) {
/* We don't care, as we only made it smaller */
}
size = newSize;
}
}
|
︙ | | |
Modified src/OFDictionary.m
from [170550a25e]
to [d6efe13c19].
︙ | | |
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
-
-
+
+
|
return NO;
}
- (OFArray*)allKeys
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
id *keys = [self allocMemoryWithItemSize: sizeof(id)
count: [self count]];
id *keys = [self allocMemoryWithSize: sizeof(id)
count: [self count]];
OFArray *ret;
OFEnumerator *enumerator;
id key;
size_t i = 0;
pool = [[OFAutoreleasePool alloc] init];
enumerator = [self keyEnumerator];
|
︙ | | |
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
-
-
+
+
|
return ret;
}
- (OFArray*)allObjects
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
id *objects = [self allocMemoryWithItemSize: sizeof(id)
count: [self count]];
id *objects = [self allocMemoryWithSize: sizeof(id)
count: [self count]];
OFArray *ret;
OFEnumerator *enumerator;
id object;
size_t i = 0;
pool = [[OFAutoreleasePool alloc] init];
enumerator = [self objectEnumerator];
|
︙ | | |
Modified src/OFDictionary_hashtable.m
from [c77b46c66d]
to [81e5d7fd45].
︙ | | |
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
-
-
+
+
|
[OFMutableDictionary_hashtable class]])
@throw [OFInvalidArgumentException
exceptionWithClass: isa
selector: _cmd];
hashtable = (OFDictionary_hashtable*)dictionary;
data = [self allocMemoryWithItemSize: sizeof(*data)
count: hashtable->size];
data = [self allocMemoryWithSize: sizeof(*data)
count: hashtable->size];
for (i = 0; i < hashtable->size; i++)
data[i] = NULL;
size = hashtable->size;
count = hashtable->count;
|
︙ | | |
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
-
-
+
+
|
for (newSize = 1; newSize < count; newSize <<= 1);
if (count * 4 / newSize >= 3)
newSize <<= 1;
if (newSize == 0)
@throw [OFOutOfRangeException exceptionWithClass: isa];
data = [self allocMemoryWithItemSize: sizeof(*data)
count: newSize];
data = [self allocMemoryWithSize: sizeof(*data)
count: newSize];
for (i = 0; i < newSize; i++)
data[i] = NULL;
size = newSize;
pool = [[OFAutoreleasePool alloc] init];
|
︙ | | |
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
-
-
+
+
|
struct of_dictionary_hashtable_bucket *bucket;
if (key == nil || object == nil)
@throw [OFInvalidArgumentException
exceptionWithClass: isa
selector: _cmd];
data = [self allocMemoryWithItemSize: sizeof(*data)
count: 2];
data = [self allocMemoryWithSize: sizeof(*data)
count: 2];
size = 2;
for (i = 0; i < size; i++)
data[i] = NULL;
i = [key hash] & 1;
|
︙ | | |
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
-
-
+
+
|
for (newSize = 1; newSize < count; newSize <<= 1);
if (count * 4 / newSize >= 3)
newSize <<= 1;
if (newSize == 0)
@throw [OFOutOfRangeException exceptionWithClass: isa];
data = [self allocMemoryWithItemSize: sizeof(*data)
count: newSize];
data = [self allocMemoryWithSize: sizeof(*data)
count: newSize];
for (j = 0; j < newSize; j++)
data[j] = NULL;
size = newSize;
for (i = 0; i < count; i++) {
|
︙ | | |
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
-
-
+
+
|
for (newSize = 1; newSize < count; newSize <<= 1);
if (count * 4 / newSize >= 3)
newSize <<= 1;
if (newSize == 0)
@throw [OFOutOfRangeException exceptionWithClass: isa];
data = [self allocMemoryWithItemSize: sizeof(*data)
count: newSize];
data = [self allocMemoryWithSize: sizeof(*data)
count: newSize];
for (j = 0; j < newSize; j++)
data[j] = NULL;
size = newSize;
/* Add first key / object pair */
|
︙ | | |
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
|
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
|
-
-
+
+
|
return NO;
}
- (OFArray*)allKeys
{
OFArray *ret;
id *keys = [self allocMemoryWithItemSize: sizeof(*keys)
count: count];
id *keys = [self allocMemoryWithSize: sizeof(*keys)
count: count];
size_t i, j;
for (i = j = 0; i < size; i++)
if (data[i] != NULL && data[i] != DELETED)
keys[j++] = data[i]->key;
assert(j == count);
|
︙ | | |
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
|
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
|
-
-
+
+
|
return ret;
}
- (OFArray*)allObjects
{
OFArray *ret;
id *objects = [self allocMemoryWithItemSize: sizeof(*objects)
count: count];
id *objects = [self allocMemoryWithSize: sizeof(*objects)
count: count];
size_t i, j;
for (i = j = 0; i < size; i++)
if (data[i] != NULL && data[i] != DELETED)
objects[j++] = data[i]->object;
assert(j == count);
|
︙ | | |
Modified src/OFFile.m
from [69833cd0ab]
to [be7cb0fa5d].
︙ | | |
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
|
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
|
-
-
-
-
+
+
+
+
+
+
|
@try {
sourceFile = [OFFile fileWithPath: source
mode: @"rb"];
destinationFile = [OFFile fileWithPath: destination
mode: @"wb"];
while (![sourceFile isAtEndOfStream]) {
size_t len = [sourceFile readNBytes: of_pagesize
intoBuffer: buffer];
[destinationFile writeNBytes: len
fromBuffer: buffer];
size_t length;
length = [sourceFile readIntoBuffer: buffer
length: of_pagesize];
[destinationFile writeBuffer: buffer
length: length];
}
#if !defined(_WIN32) && !defined(_PSP)
if (!override) {
struct stat s;
if (fstat(sourceFile->fileDescriptor, &s) == 0)
|
︙ | | |
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
|
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
|
-
-
+
+
-
-
+
+
|
{
if (fileDescriptor == -1)
return YES;
return atEndOfStream;
}
- (size_t)_readNBytes: (size_t)length
intoBuffer: (void*)buffer
- (size_t)_readIntoBuffer: (void*)buffer
length: (size_t)length
{
ssize_t ret;
if (fileDescriptor == -1 || atEndOfStream ||
(ret = read(fileDescriptor, buffer, length)) < 0)
@throw [OFReadFailedException exceptionWithClass: isa
stream: self
requestedLength: length];
if (ret == 0)
atEndOfStream = YES;
return ret;
}
- (void)_writeNBytes: (size_t)length
fromBuffer: (const void*)buffer
- (void)_writeBuffer: (const void*)buffer
length: (size_t)length
{
if (fileDescriptor == -1 || atEndOfStream ||
write(fileDescriptor, buffer, length) < length)
@throw [OFWriteFailedException exceptionWithClass: isa
stream: self
requestedLength: length];
}
|
︙ | | |
Modified src/OFHTTPRequest.m
from [456aec5d03]
to [bba59f52c5].
︙ | | |
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
-
+
|
[sock connectToHost: [URL host]
port: [URL port]];
/*
* Work around a bug with packet bisection in lighttpd when using
* HTTPS.
*/
[sock setBuffersWrites: YES];
[sock setWriteBufferEnabled: YES];
if (requestType == OF_HTTP_REQUEST_TYPE_GET)
type = "GET";
if (requestType == OF_HTTP_REQUEST_TYPE_HEAD)
type = "HEAD";
if (requestType == OF_HTTP_REQUEST_TYPE_POST)
type = "POST";
|
︙ | | |
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
-
+
|
[queryString UTF8StringLength]];
}
[sock writeString: @"\r\n"];
/* Work around a bug in lighttpd, see above */
[sock flushWriteBuffer];
[sock setBuffersWrites: NO];
[sock setWriteBufferEnabled: NO];
if (requestType == OF_HTTP_REQUEST_TYPE_POST)
[sock writeString: queryString];
@try {
line = [sock readLine];
} @catch (OFInvalidEncodingException *e) {
|
︙ | | |
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
-
-
+
+
|
contentLength >= bytesReceived))
break;
while (toRead > 0) {
size_t length = (toRead < of_pagesize
? toRead : of_pagesize);
length = [sock readNBytes: length
intoBuffer: buffer];
length = [sock readIntoBuffer: buffer
length: length];
[delegate request: self
didReceiveData: buffer
withLength: length];
[pool2 releaseObjects];
bytesReceived += length;
|
︙ | | |
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
|
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
|
-
-
+
+
+
|
exceptionWithClass: isa];
[pool2 releaseObjects];
}
} else {
size_t length;
while ((length = [sock readNBytes: of_pagesize
intoBuffer: buffer]) > 0) {
while ((length = [sock
readIntoBuffer: buffer
length: of_pagesize]) > 0) {
[delegate request: self
didReceiveData: buffer
withLength: length];
[pool2 releaseObjects];
bytesReceived += length;
[data addItemsFromCArray: buffer
|
︙ | | |
Modified src/OFMutableArray.h
from [cef5851cfb]
to [9c7f745e9f].
︙ | | |
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
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
60
61
62
63
64
65
66
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
/**
* \brief Adds an object to the end of the array.
*
* \param object An object to add
*/
- (void)addObject: (id)object;
/**
* \brief Adds the objects from the specified OFArray to the end of the array.
*
* \brief array An array of objects to add
*/
- (void)addObjectsFromArray: (OFArray*)array;
/**
* \brief Inserts an object to the OFArray at the specified index.
*
* \param object An object to add
* \param index The index where the object should be inserted
*/
- (void)insertObject: (id)object
atIndex: (size_t)index;
/**
* \brief Inserts the objects from the specified OFArray at the specified index.
*
* \param array An array of objects
* \param index The index where the objects should be inserted
*/
- (void)insertObjectsFromArray: (OFArray*)array
atIndex: (size_t)index;
/**
* \brief Replaces the first object equivalent to the specified object with the
* other specified object.
*
* \param oldObject The object to replace
* \param newObject The replacement object
*/
|
︙ | | |
Modified src/OFMutableArray.m
from [2fdb683912]
to [0bfaa52216].
︙ | | |
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
}
- (void)addObject: (id)object
{
[self insertObject: object
atIndex: [self count]];
}
- (void)addObjectsFromArray: (OFArray*)array
{
[self insertObjectsFromArray: array
atIndex: [self count]];
}
- (void)insertObject: (id)object
atIndex: (size_t)index
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (void)insertObjectsFromArray: (OFArray*)array
atIndex: (size_t)index
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
OFEnumerator *enumerator = [array objectEnumerator];
size_t i, count = [array count];
for (i = 0; i < count; i++) {
id object = [enumerator nextObject];
assert(object != nil);
[self insertObject: object
atIndex: index + i];
}
[pool release];
}
- (void)replaceObjectAtIndex: (size_t)index
withObject: (id)object
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
|
︙ | | |
Modified src/OFMutableArray_adjacent.m
from [489af893ca]
to [e388818b36].
︙ | | |
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
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
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
{
[array insertItem: &object
atIndex: index];
[object retain];
mutations++;
}
- (void)insertObjectsFromArray: (OFArray*)array_
atIndex: (size_t)index
{
id *objects = [array_ objects];
size_t i, count = [array_ count];
[array insertItemsFromCArray: objects
atIndex: index
count: count];
for (i = 0; i < count; i++)
[objects[i] retain];
mutations++;
}
- (void)replaceObject: (id)oldObject
withObject: (id)newObject
{
id *objects = [array cArray];
size_t i, count = [array count];
|
︙ | | |
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
|
-
-
+
+
|
{
id *objects = [array cArray], *copy;
size_t i, count = [array count];
if (range.length > count - range.start)
@throw [OFOutOfRangeException exceptionWithClass: isa];
copy = [self allocMemoryWithItemSize: sizeof(*copy)
count: range.length];
copy = [self allocMemoryWithSize: sizeof(*copy)
count: range.length];
memcpy(copy, objects + range.start, range.length * sizeof(id));
@try {
[array removeItemsInRange: range];
mutations++;
for (i = 0; i < range.length; i++)
|
︙ | | |
Modified src/OFMutableDictionary_hashtable.m
from [959d2e2496]
to [aeb921a44b].
︙ | | |
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
-
-
+
+
|
newSize = size >> 1;
else
return;
if (newSize == 0)
@throw [OFOutOfRangeException exceptionWithClass: isa];
newData = [self allocMemoryWithItemSize: sizeof(*newData)
count: newSize];
newData = [self allocMemoryWithSize: sizeof(*newData)
count: newSize];
for (i = 0; i < newSize; i++)
newData[i] = NULL;
for (i = 0; i < size; i++) {
if (data[i] != NULL && data[i] != DELETED) {
uint32_t j, last;
|
︙ | | |
Modified src/OFMutableSet.m
from [f111a1faac]
to [ae4b0f4644].
︙ | | |
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
-
-
+
+
|
- (void)intersectSet: (OFSet*)set
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
size_t count = [self count];
id *cArray;
cArray = [self allocMemoryWithItemSize: sizeof(id)
count: count];
cArray = [self allocMemoryWithSize: sizeof(id)
count: count];
@try {
OFEnumerator *enumerator = [self objectEnumerator];
id object;
size_t i = 0;
while ((object = [enumerator nextObject]) != nil) {
|
︙ | | |
Modified src/OFMutableString_UTF8.m
from [3f21e1777e]
to [ccd236b694].
︙ | | |
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
-
-
+
+
|
if ((t = table[0][*p]) != 0)
*p = t;
return;
}
unicodeLen = [self length];
unicodeString = [self allocMemoryWithItemSize: sizeof(of_unichar_t)
count: unicodeLen];
unicodeString = [self allocMemoryWithSize: sizeof(of_unichar_t)
count: unicodeLen];
i = j = 0;
newCStringLength = 0;
while (i < s->cStringLength) {
cLen = of_string_utf8_to_unicode(s->cString + i,
s->cStringLength - i, &c);
|
︙ | | |
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
-
-
+
+
|
if (length == oldLength) {
memcpy(s->cString + index, buffer, length);
return;
}
if (length > oldLength) {
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength -
oldLength + length + 1];
size: s->cStringLength - oldLength +
length + 1];
memmove(s->cString + index + length,
s->cString + index + oldLength,
s->cStringLength - index - oldLength);
memcpy(s->cString + index, buffer, length);
s->cStringLength -= oldLength;
|
︙ | | |
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
-
+
|
s->cStringLength -= oldLength;
s->cStringLength += length;
s->cString[s->cStringLength] = '\0';
@try {
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength + 1];
size: s->cStringLength + 1];
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
}
return;
}
|
︙ | | |
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
-
+
|
break;
case -1:
@throw [OFInvalidEncodingException exceptionWithClass: isa];
}
s->hashed = NO;
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength +
size: s->cStringLength +
UTF8StringLength + 1];
memcpy(s->cString + s->cStringLength, UTF8String, UTF8StringLength + 1);
s->cStringLength += UTF8StringLength;
s->length += length;
}
|
︙ | | |
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
-
+
|
break;
case -1:
@throw [OFInvalidEncodingException exceptionWithClass: isa];
}
s->hashed = NO;
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength +
size: s->cStringLength +
UTF8StringLength + 1];
memcpy(s->cString + s->cStringLength, UTF8String, UTF8StringLength);
s->cStringLength += UTF8StringLength;
s->length += length;
s->cString[s->cStringLength] = 0;
|
︙ | | |
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
-
+
|
@throw [OFInvalidArgumentException exceptionWithClass: isa
selector: _cmd];
UTF8StringLength = [string UTF8StringLength];
s->hashed = NO;
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength +
size: s->cStringLength +
UTF8StringLength + 1];
memcpy(s->cString + s->cStringLength, [string UTF8String],
UTF8StringLength);
s->cStringLength += UTF8StringLength;
s->length += [string length];
|
︙ | | |
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
|
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
|
-
+
|
if (s->UTF8)
index = of_string_index_to_position(s->cString, index,
s->cStringLength);
newCStringLength = s->cStringLength + [string UTF8StringLength];
s->hashed = NO;
s->cString = [self resizeMemory: s->cString
toSize: newCStringLength + 1];
size: newCStringLength + 1];
memmove(s->cString + index + [string UTF8StringLength],
s->cString + index, s->cStringLength - index);
memcpy(s->cString + index, [string UTF8String],
[string UTF8StringLength]);
s->cString[newCStringLength] = '\0';
|
︙ | | |
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
|
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
|
-
+
|
memmove(s->cString + start, s->cString + end, s->cStringLength - end);
s->cStringLength -= end - start;
s->cString[s->cStringLength] = 0;
@try {
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength + 1];
size: s->cStringLength + 1];
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
}
}
- (void)replaceCharactersInRange: (of_range_t)range
withString: (OFString*)replacement
|
︙ | | |
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
|
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
|
-
+
|
s->cStringLength);
}
newCStringLength = s->cStringLength - (end - start) +
[replacement UTF8StringLength];
s->hashed = NO;
s->cString = [self resizeMemory: s->cString
toSize: newCStringLength + 1];
size: newCStringLength + 1];
memmove(s->cString + start + [replacement UTF8StringLength],
s->cString + end, s->cStringLength - end);
memcpy(s->cString + start, [replacement UTF8String],
[replacement UTF8StringLength]);
s->cString[newCStringLength] = '\0';
|
︙ | | |
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
|
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
|
-
+
-
+
-
-
-
+
+
|
for (i = range.start, last = 0; i <= range.length - searchLength; i++) {
if (memcmp(s->cString + i, searchString, searchLength))
continue;
@try {
newCString = [self
resizeMemory: newCString
toSize: newCStringLength + i - last +
size: newCStringLength + i - last +
replacementLength + 1];
} @catch (id e) {
[self freeMemory: newCString];
@throw e;
}
memcpy(newCString + newCStringLength, s->cString + last,
i - last);
memcpy(newCString + newCStringLength + i - last,
replacementString, replacementLength);
newCStringLength += i - last + replacementLength;
newLength = newLength - [string length] + [replacement length];
i += searchLength - 1;
last = i + 1;
}
@try {
newCString = [self
newCString = [self resizeMemory: newCString
resizeMemory: newCString
toSize: newCStringLength +
s->cStringLength - last + 1];
size: newCStringLength +
s->cStringLength - last + 1];
} @catch (id e) {
[self freeMemory: newCString];
@throw e;
}
memcpy(newCString + newCStringLength, s->cString + last,
s->cStringLength - last);
newCStringLength += s->cStringLength - last;
|
︙ | | |
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
|
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
|
-
+
|
s->length -= i;
memmove(s->cString, s->cString + i, s->cStringLength);
s->cString[s->cStringLength] = '\0';
@try {
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength + 1];
size: s->cStringLength + 1];
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
}
}
- (void)deleteTrailingWhitespaces
{
|
︙ | | |
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
|
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
|
-
+
|
}
s->cStringLength -= d;
s->length -= d;
@try {
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength + 1];
size: s->cStringLength + 1];
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
}
}
- (void)deleteEnclosingWhitespaces
{
|
︙ | | |
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
|
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
|
-
+
|
s->length -= i;
memmove(s->cString, s->cString + i, s->cStringLength);
s->cString[s->cStringLength] = '\0';
@try {
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength + 1];
size: s->cStringLength + 1];
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
}
}
- (void)makeImmutable
{
isa = [OFString_UTF8 class];
}
@end
|
Modified src/OFNumber.m
from [f581497f4f]
to [3bd254e0cf].
︙ | | |
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
|
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
|
+
+
|
- copy
{
return [self retain];
}
- (OFString*)description
{
OFMutableString *ret;
switch (type) {
case OF_NUMBER_BOOL:
return (value.bool_ ? @"YES" : @"NO");
case OF_NUMBER_UCHAR:
case OF_NUMBER_USHORT:
case OF_NUMBER_UINT:
case OF_NUMBER_ULONG:
|
︙ | | |
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
|
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
|
-
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
|
case OF_NUMBER_INT64:
case OF_NUMBER_SSIZE:
case OF_NUMBER_INTMAX:
case OF_NUMBER_PTRDIFF:
case OF_NUMBER_INTPTR:
return [OFString stringWithFormat: @"%jd", [self intMaxValue]];
case OF_NUMBER_FLOAT:
return [OFString stringWithFormat: @"%g", value.float_];
ret = [OFMutableString stringWithFormat: @"%g", value.float_];
if (![ret containsString: @"."])
[ret appendString: @".0"];
[ret makeImmutable];
return ret;
case OF_NUMBER_DOUBLE:
return [OFString stringWithFormat: @"%lg", value.double_];
ret = [OFMutableString stringWithFormat: @"%lg", value.double_];
if (![ret containsString: @"."])
[ret appendString: @".0"];
[ret makeImmutable];
return ret;
default:
@throw [OFInvalidFormatException exceptionWithClass: isa];
}
}
- (OFXMLElement*)XMLElementBySerializing
{
|
︙ | | |
Modified src/OFObject.h
from [2f8f69a869]
to [f1d13468c6].
︙ | | |
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
|
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
|
-
+
-
-
+
+
-
+
-
+
-
+
|
/**
* \brief Allocates memory for the specified number of items and stores it in
* the object's memory pool.
*
* It will be free'd automatically when the object is deallocated.
*
* \param itemSize The size of each item to allocate
* \param size The size of each item to allocate
* \param count The number of items to allocate
* \return A pointer to the allocated memory
*/
- (void*)allocMemoryWithItemSize: (size_t)itemSize
count: (size_t)count;
- (void*)allocMemoryWithSize: (size_t)size
count: (size_t)count;
/**
* \brief Resizes memory in the object's memory pool to the specified size.
*
* If the pointer is NULL, this is equivalent to allocating memory.
* If the size is 0, this is equivalent to freeing memory.
*
* \param pointer A pointer to the already allocated memory
* \param size The new size for the memory chunk
* \return A pointer to the resized memory chunk
*/
- (void*)resizeMemory: (void*)pointer
toSize: (size_t)size;
size: (size_t)size;
/**
* \brief Resizes memory in the object's memory pool to the specific number of
* items of the specified size.
*
* If the pointer is NULL, this is equivalent to allocating memory.
* If the size or number of items is 0, this is equivalent to freeing memory.
*
* \param pointer A pointer to the already allocated memory
* \param itemSize The size of each item to resize to
* \param size The size of each item to resize to
* \param count The number of items to resize to
* \return A pointer to the resized memory chunk
*/
- (void*)resizeMemory: (void*)pointer
itemSize: (size_t)itemSize
size: (size_t)size
count: (size_t)count;
/**
* \brief Frees allocated memory and removes it from the object's memory pool.
*
* Does nothing if the pointer is NULL.
*
|
︙ | | |
Modified src/OFObject.m
from [71be745647]
to [f73166965d].
︙ | | |
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
|
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
|
-
-
+
+
-
+
-
+
-
+
-
+
|
PRE_IVAR->lastMem->next = preMem;
PRE_IVAR->lastMem = preMem;
return (char*)pointer + PRE_MEM_ALIGN;
}
- (void*)allocMemoryWithItemSize: (size_t)itemSize
count: (size_t)count
- (void*)allocMemoryWithSize: (size_t)size
count: (size_t)count
{
if (itemSize == 0 || count == 0)
if (size == 0 || count == 0)
return NULL;
if (count > SIZE_MAX / itemSize)
if (count > SIZE_MAX / size)
@throw [OFOutOfRangeException exceptionWithClass: isa];
return [self allocMemoryWithSize: itemSize * count];
return [self allocMemoryWithSize: size * count];
}
- (void*)resizeMemory: (void*)pointer
toSize: (size_t)size
size: (size_t)size
{
void *new;
struct pre_mem *preMem;
if (pointer == NULL)
return [self allocMemoryWithSize: size];
|
︙ | | |
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
|
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
|
-
+
-
-
+
+
-
+
-
+
-
+
|
PRE_IVAR->lastMem = preMem;
}
return (char*)new + PRE_MEM_ALIGN;
}
- (void*)resizeMemory: (void*)pointer
itemSize: (size_t)itemSize
size: (size_t)size
count: (size_t)count
{
if (pointer == NULL)
return [self allocMemoryWithItemSize: itemSize
count: count];
return [self allocMemoryWithSize: size
count: count];
if (itemSize == 0 || count == 0) {
if (size == 0 || count == 0) {
[self freeMemory: pointer];
return NULL;
}
if (count > SIZE_MAX / itemSize)
if (count > SIZE_MAX / size)
@throw [OFOutOfRangeException exceptionWithClass: isa];
return [self resizeMemory: pointer
toSize: itemSize * count];
size: size * count];
}
- (void)freeMemory: (void*)pointer
{
if (pointer == NULL)
return;
|
︙ | | |
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
|
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
|
-
-
+
+
-
+
-
+
|
*/
+ (void*)allocMemoryWithSize: (size_t)size
{
@throw [OFNotImplementedException exceptionWithClass: self
selector: _cmd];
}
+ (void*)allocMemoryWithItemSize: (size_t)itemSize
count: (size_t)count
+ (void*)allocMemoryWithSize: (size_t)size
count: (size_t)count
{
@throw [OFNotImplementedException exceptionWithClass: self
selector: _cmd];
}
+ (void*)resizeMemory: (void*)pointer
toSize: (size_t)size
size: (size_t)size
{
@throw [OFNotImplementedException exceptionWithClass: self
selector: _cmd];
}
+ (void*)resizeMemory: (void*)pointer
itemSize: (size_t)itemSize
size: (size_t)size
count: (size_t)count
{
@throw [OFNotImplementedException exceptionWithClass: self
selector: _cmd];
}
+ (void)freeMemory: (void*)pointer
|
︙ | | |
Modified src/OFProcess.m
from [6f88407ce3]
to [8d0f0fd4b4].
︙ | | |
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
-
-
+
+
|
switch ((pid = fork())) {
case 0:;
OFString **objects = [arguments objects];
size_t i, count = [arguments count];
char **argv;
argv = [self allocMemoryWithItemSize: sizeof(char*)
count: count + 2];
argv = [self allocMemoryWithSize: sizeof(char*)
count: count + 2];
argv[0] = (char*)[programName cStringWithEncoding:
OF_STRING_ENCODING_NATIVE];
for (i = 0; i < count; i++)
argv[i + 1] = (char*)[objects[i]
cStringWithEncoding:
|
︙ | | |
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
-
-
+
+
|
if (readPipe[0] == NULL)
#endif
return YES;
return atEndOfStream;
}
- (size_t)_readNBytes: (size_t)length
intoBuffer: (void*)buffer
- (size_t)_readIntoBuffer: (void*)buffer
length: (size_t)length
{
#ifndef _WIN32
ssize_t ret;
#else
DWORD ret;
#endif
|
︙ | | |
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
-
-
+
+
|
if (ret == 0)
atEndOfStream = YES;
return ret;
}
- (void)_writeNBytes: (size_t)length
fromBuffer: (const void*)buffer
- (void)_writeBuffer: (const void*)buffer
length: (size_t)length
{
#ifndef _WIN32
if (writePipe[1] == -1 || atEndOfStream ||
write(writePipe[1], buffer, length) < length)
#else
DWORD ret;
|
︙ | | |
Modified src/OFStream.h
from [5cd3180445]
to [aea1f2dd6e].
︙ | | |
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
60
|
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
60
|
-
+
-
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
-
+
|
@class OFDataArray;
/**
* \brief A base class for different types of streams.
*
* \warning Even though the OFCopying protocol is implemented, it does
* <i>not</i> return an independant copy of the stream but instead
* <i>not</i> return an independent copy of the stream but instead
* retains it. This is so that the stream can be used as a key for a
* dictionary so context can be associated with a stream. Using a
* dictionary, so context can be associated with a stream. Using a
* stream in more than one thread at the same time is not thread-safe,
* even if copy was called!
* even if copy was called to create one "instance" for every thread!
*
* \warning If you want to subclass this, override _readNBytes:intoBuffer:,
* _writeNBytes:fromBuffer: and _isAtEndOfStream, but nothing else.
* Those are not defined in the headers, but do the actual work.
* OFStream uses those and does all the caching and other stuff. If
* you override these methods without the _ prefix, you *WILL* break
* caching and get broken results!
* \warning If you want to subclass this, override _readIntoBuffer:length:,
* _writeBuffer:length: and _isAtEndOfStream, but nothing else, as
* those are are the methods that do the actual work. OFStream uses
* those for all other methods and does all the caching and other
* stuff for you. If you override these methods without the _ prefix,
* you <i>will</i> break caching and get broken results!
*/
@interface OFStream: OFObject <OFCopying>
{
char *cache;
char *writeBuffer;
size_t cacheLength, writeBufferLength;
BOOL buffersWrites;
BOOL writeBufferEnabled;
BOOL blocking;
BOOL waitingForDelimiter;
}
#ifdef OF_HAVE_PROPERTIES
@property (getter=isBlocking) BOOL blocking;
@property (readonly, getter=isAtEndOfStream) BOOL atEndOfStream;
|
︙ | | |
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
|
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
|
-
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
|
- (BOOL)isAtEndOfStream;
/**
* \brief Reads <i>at most</i> size bytes from the stream into a buffer.
*
* On network streams, this might read less than the specified number of bytes.
* If you want to read exactly the specified number of bytes, use
* -[readExactlyNBytes:intoBuffer:].
* -[readIntoBuffer:exactLength:].
*
* \param buffer The buffer into which the data is read
* \param length The length of the data that should be read at most.
* The buffer MUST be at least this big!
* The buffer <i>must</i> be at least this big!
* \return The number of bytes read
*/
- (size_t)readNBytes: (size_t)size
intoBuffer: (void*)buffer;
- (size_t)readIntoBuffer: (void*)buffer
length: (size_t)size;
/**
* \brief Reads exactly the specified length bytes from the stream into a
* buffer.
*
* Unlike readNBytes:intoBuffer:, this method does not return when less than the
* Unlike readIntoBuffer:length:, this method does not return when less than the
* specified length has been read - instead, it waits until it got exactly the
* specified length.
*
* \warning Only call this when you know that specified amount of data is
* available! Otherwise you will get an exception!
*
* \param buffer The buffer into which the data is read
* \param length The length of the data that should be read.
* The buffer MUST be EXACTLY this big!
* The buffer <i>must</i> be <i>exactly</i> this big!
*/
- (void)readExactlyNBytes: (size_t)length
intoBuffer: (void*)buffer;
- (void)readIntoBuffer: (void*)buffer
exactLength: (size_t)length;
/**
* \brief Reads a uint8_t from the stream.
*
* \warning Only call this when you know that enough data is available!
* Otherwise you will get an exception!
*
|
︙ | | |
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
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
|
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
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
|
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
|
* Otherwise you will get an exception!
*
* \param nInt16s The number of uint16_ts to read
* \param buffer A buffer of sufficient size to store the specified number of
* uint16_ts
* \return The number of bytes read
*/
- (size_t)readNBigEndianInt16s: (size_t)nInt16s
intoBuffer: (uint16_t*)buffer;
- (size_t)readBigEndianInt16sIntoBuffer: (uint16_t*)buffer
count: (size_t)nInt16s;
/**
* \brief Reads the specified number of uint32_ts from the stream which are
* encoded in big endian.
*
* \warning Only call this when you know that enough data is available!
* Otherwise you will get an exception!
*
* \param nInt32s The number of uint32_ts to read
* \param buffer A buffer of sufficient size to store the specified number of
* uint32_ts
* \return The number of bytes read
*/
- (size_t)readNBigEndianInt32s: (size_t)nInt32s
intoBuffer: (uint32_t*)buffer;
- (size_t)readBigEndianInt32sIntoBuffer: (uint32_t*)buffer
count: (size_t)nInt32s;
/**
* \brief Reads the specified number of uint64_ts from the stream which are
* encoded in big endian.
*
* \warning Only call this when you know that enough data is available!
* Otherwise you will get an exception!
*
* \param nInt64s The number of uint64_ts to read
* \param buffer A buffer of sufficient size to store the specified number of
* uint64_ts
* \return The number of bytes read
*/
- (size_t)readNBigEndianInt64s: (size_t)nInt64s
intoBuffer: (uint64_t*)buffer;
- (size_t)readBigEndianInt64sIntoBuffer: (uint64_t*)buffer
count: (size_t)nInt64s;
/**
* \brief Reads the specified number of floats from the stream which are encoded
* in big endian.
*
* \warning Only call this when you know that enough data is available!
* Otherwise you will get an exception!
*
* \param nFloatss The number of floats to read
* \param buffer A buffer of sufficient size to store the specified number of
* floats
* \return The number of bytes read
*/
- (size_t)readNBigEndianFloats: (size_t)nFloats
intoBuffer: (float*)buffer;
- (size_t)readBigEndianFloatsIntoBuffer: (float*)buffer
count: (size_t)nFloats;
/**
* \brief Reads the specified number of doubles from the stream which are
* encoded in big endian.
*
* \warning Only call this when you know that enough data is available!
* Otherwise you will get an exception!
*
* \param nDoubles The number of doubles to read
* \param buffer A buffer of sufficient size to store the specified number of
* doubles
* \return The number of bytes read
*/
- (size_t)readNBigEndianDoubles: (size_t)nDoubles
intoBuffer: (double*)buffer;
- (size_t)readBigEndianDoublesIntoBuffer: (double*)buffer
count: (size_t)nDoubles;
/**
* \brief Reads a uint16_t from the stream which is encoded in little endian.
*
* \warning Only call this when you know that enough data is available!
* Otherwise you will get an exception!
*
|
︙ | | |
293
294
295
296
297
298
299
300
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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
384
385
386
387
388
389
390
391
392
393
394
|
293
294
295
296
297
298
299
300
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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
384
385
386
387
388
389
390
391
392
393
394
|
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
+
|
* Otherwise you will get an exception!
*
* \param nInt16s The number of uint16_ts to read
* \param buffer A buffer of sufficient size to store the specified number of
* uint16_ts
* \return The number of bytes read
*/
- (size_t)readNLittleEndianInt16s: (size_t)nInt16s
intoBuffer: (uint16_t*)buffer;
- (size_t)readLittleEndianInt16sIntoBuffer: (uint16_t*)buffer
count: (size_t)nInt16s;
/**
* \brief Reads the specified number of uint32_ts from the stream which are
* encoded in little endian.
*
* \warning Only call this when you know that enough data is available!
* Otherwise you will get an exception!
*
* \param nInt32s The number of uint32_ts to read
* \param buffer A buffer of sufficient size to store the specified number of
* uint32_ts
* \return The number of bytes read
*/
- (size_t)readNLittleEndianInt32s: (size_t)nInt32s
intoBuffer: (uint32_t*)buffer;
- (size_t)readLittleEndianInt32sIntoBuffer: (uint32_t*)buffer
count: (size_t)nInt32s;
/**
* \brief Reads the specified number of uint64_ts from the stream which are
* encoded in little endian.
*
* \warning Only call this when you know that enough data is available!
* Otherwise you will get an exception!
*
* \param nInt64s The number of uint64_ts to read
* \param buffer A buffer of sufficient size to store the specified number of
* uint64_ts
* \return The number of bytes read
*/
- (size_t)readNLittleEndianInt64s: (size_t)nInt64s
intoBuffer: (uint64_t*)buffer;
- (size_t)readLittleEndianInt64sIntoBuffer: (uint64_t*)buffer
count: (size_t)nInt64s;
/**
* \brief Reads the specified number of floats from the stream which are
* encoded in little endian.
*
* \warning Only call this when you know that enough data is available!
* Otherwise you will get an exception!
*
* \param nFloats The number of floats to read
* \param buffer A buffer of sufficient size to store the specified number of
* floats
* \return The number of bytes read
*/
- (size_t)readNLittleEndianFloats: (size_t)nFloats
intoBuffer: (float*)buffer;
- (size_t)readLittleEndianFloatsIntoBuffer: (float*)buffer
count: (size_t)nFloats;
/**
* \brief Reads the specified number of doubles from the stream which are
* encoded in little endian.
*
* \warning Only call this when you know that enough data is available!
* Otherwise you will get an exception!
*
* \param nDoubles The number of doubles to read
* \param buffer A buffer of sufficient size to store the specified number of
* doubles
* \return The number of bytes read
*/
- (size_t)readNLittleEndianDoubles: (size_t)nDoubles
intoBuffer: (double*)buffer;
- (size_t)readLittleEndianDoublesIntoBuffer: (double*)buffer
count: (size_t)nDoubles;
/**
* \brief Reads the specified number of items with an item size of 1 from the
* stream and returns them in an OFDataArray.
*
* \warning Only call this when you know that enough data is available!
* Otherwise you will get an exception!
*
* \param nItems The number of items to read
* \return An OFDataArray with at nItems items.
*/
- (OFDataArray*)readDataArrayWithNItems: (size_t)nItems;
- (OFDataArray*)readDataArrayWithSize: (size_t)size;
/**
* \brief Reads the specified number of items with the specified item size from
* the stream and returns them in an OFDataArray.
*
* \warning Only call this when you know that enough data is available!
* Otherwise you will get an exception!
*
* \param itemSize The size of each item
* \param nItems The number of items to read
* \return An OFDataArray with at nItems items.
*/
- (OFDataArray*)readDataArrayWithItemSize: (size_t)itemSize
andNItems: (size_t)nItems;
count: (size_t)nItems;
/**
* \brief Returns an OFDataArray with all the remaining data of the stream.
*
* \return An OFDataArray with an item size of 1 with all the data of the
* stream until the end of the stream is reached.
*/
|
︙ | | |
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
-
-
+
+
|
* \warning Only call this when you know that enough data is available!
* Otherwise you will get an exception!
*
* \param encoding The encoding of the string to read from the stream
* \param length The length (in bytes) of the string to read from the stream
* \return A string with the specified length
*/
- (OFString*)readStringWithEncoding: (of_string_encoding_t)encoding
length: (size_t)length;
- (OFString*)readStringWithLength: (size_t)length
encoding: (of_string_encoding_t)encoding;
/**
* \brief Reads until a newline, \\0 or end of stream occurs.
*
* \return The line that was read, autoreleased, or nil if the end of the
* stream has been reached.
*/
|
︙ | | |
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
|
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
|
-
+
|
*
* \param delimiter The delimiter
* \param encoding The encoding used by the stream
* \return The line that was read, autoreleased, or nil if the end of the
* stream has been reached.
*/
- (OFString*)readTillDelimiter: (OFString*)delimiter
withEncoding: (of_string_encoding_t)encoding;
encoding: (of_string_encoding_t)encoding;
/**
* \brief Tries to reads until the specified string or \\0 is found or the end
* of stream (see readTillDelimiter:) and returns nil if not enough data
* has been received yet.
*
* \param delimiter The delimiter
|
︙ | | |
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
|
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
|
-
+
-
+
-
+
-
-
+
+
|
*
* \param delimiter The delimiter
* \param encoding The encoding used by the stream
* \return The line that was read, autoreleased, or nil if the end of the
* stream has been reached.
*/
- (OFString*)tryReadTillDelimiter: (OFString*)delimiter
withEncoding: (of_string_encoding_t)encoding;
encoding: (of_string_encoding_t)encoding;
/**
* \brief Returns a boolen whether writes are buffered.
*
* \return A boolean whether writes are buffered
*/
- (BOOL)buffersWrites;
- (BOOL)writeBufferEnabled;
/**
* \brief Enables or disables the write buffer.
*
* \param enable Whether the write buffer should be enabled or disabled
*/
- (void)setBuffersWrites: (BOOL)enable;
- (void)setWriteBufferEnabled: (BOOL)enable;
/**
* \brief Writes everythig in the write buffer to the stream.
*/
- (void)flushWriteBuffer;
/**
* \brief Writes from a buffer into the stream.
*
* \param buffer The buffer from which the data is written to the stream
* \param length The length of the data that should be written
*/
- (void)writeNBytes: (size_t)length
fromBuffer: (const void*)buffer;
- (void)writeBuffer: (const void*)buffer
length: (size_t)length;
/**
* \brief Writes a uint8_t into the stream.
*
* \param int8 A uint8_t
*/
- (void)writeInt8: (uint8_t)int8;
|
︙ | | |
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
|
* big endian.
*
* \param nInt16 The number of uint16_ts to write
* \param buffer The buffer from which the data is written to the stream after
* it has been byte swapped if necessary
* \return The number of bytes written to the stream
*/
- (size_t)writeNBigEndianInt16s: (size_t)nInt16s
fromBuffer: (const uint16_t*)buffer;
- (size_t)writeBigEndianInt16s: (const uint16_t*)buffer
count: (size_t)nInt16s;
/**
* \brief Writes the specified number of uint32_ts into the stream, encoded in
* big endian.
*
* \param nInt32 The number of uint32_ts to write
* \param buffer The buffer from which the data is written to the stream after
* it has been byte swapped if necessary
* \return The number of bytes written to the stream
*/
- (size_t)writeNBigEndianInt32s: (size_t)nInt32s
fromBuffer: (const uint32_t*)buffer;
- (size_t)writeBigEndianInt32s: (const uint32_t*)buffer
count: (size_t)nInt32s;
/**
* \brief Writes the specified number of uint64_ts into the stream, encoded in
* big endian.
*
* \param nInt64 The number of uint64_ts to write
* \param buffer The buffer from which the data is written to the stream after
* it has been byte swapped if necessary
* \return The number of bytes written to the stream
*/
- (size_t)writeNBigEndianInt64s: (size_t)nInt64s
fromBuffer: (const uint64_t*)buffer;
- (size_t)writeBigEndianInt64s: (const uint64_t*)buffer
count: (size_t)nInt64s;
/**
* \brief Writes the specified number of floats into the stream, encoded in big
* endian.
*
* \param nFloats The number of floats to write
* \param buffer The buffer from which the data is written to the stream after
* it has been byte swapped if necessary
* \return The number of bytes written to the stream
*/
- (size_t)writeNBigEndianFloats: (size_t)nFloats
fromBuffer: (const float*)buffer;
- (size_t)writeBigEndianFloats: (const float*)buffer
count: (size_t)nFloats;
/**
* \brief Writes the specified number of doubles into the stream, encoded in
* big endian.
*
* \param nDoubles The number of doubles to write
* \param buffer The buffer from which the data is written to the stream after
* it has been byte swapped if necessary
* \return The number of bytes written to the stream
*/
- (size_t)writeNBigEndianDoubles: (size_t)nDoubles
fromBuffer: (const double*)buffer;
- (size_t)writeBigEndianDoubles: (const double*)buffer
count: (size_t)nDoubles;
/**
* \brief Writes a uint16_t into the stream, encoded in little endian.
*
* \param int16 A uint16_t
*/
- (void)writeLittleEndianInt16: (uint16_t)int16;
|
︙ | | |
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
|
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
|
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
|
* little endian.
*
* \param nInt16 The number of uint16_ts to write
* \param buffer The buffer from which the data is written to the stream after
* it has been byte swapped if necessary
* \return The number of bytes written to the stream
*/
- (size_t)writeNLittleEndianInt16s: (size_t)nInt16s
fromBuffer: (const uint16_t*)buffer;
- (size_t)writeLittleEndianInt16s: (const uint16_t*)buffer
count: (size_t)nInt16s;
/**
* \brief Writes the specified number of uint32_ts into the stream, encoded in
* little endian.
*
* \param nInt32 The number of uint32_ts to write
* \param buffer The buffer from which the data is written to the stream after
* it has been byte swapped if necessary
* \return The number of bytes written to the stream
*/
- (size_t)writeNLittleEndianInt32s: (size_t)nInt32s
fromBuffer: (const uint32_t*)buffer;
- (size_t)writeLittleEndianInt32s: (const uint32_t*)buffer
count: (size_t)nInt32s;
/**
* \brief Writes the specified number of uint64_ts into the stream, encoded in
* little endian.
*
* \param nInt64 The number of uint64_ts to write
* \param buffer The buffer from which the data is written to the stream after
* it has been byte swapped if necessary
* \return The number of bytes written to the stream
*/
- (size_t)writeNLittleEndianInt64s: (size_t)nInt64s
fromBuffer: (const uint64_t*)buffer;
- (size_t)writeLittleEndianInt64s: (const uint64_t*)buffer
count: (size_t)nInt64s;
/**
* \brief Writes the specified number of floats into the stream, encoded in
* little endian.
*
* \param nFloats The number of floats to write
* \param buffer The buffer from which the data is written to the stream after
* it has been byte swapped if necessary
* \return The number of bytes written to the stream
*/
- (size_t)writeNLittleEndianFloats: (size_t)nFloats
fromBuffer: (const float*)buffer;
- (size_t)writeLittleEndianFloats: (const float*)buffer
count: (size_t)nFloats;
/**
* \brief Writes the specified number of doubles into the stream, encoded in
* little endian.
*
* \param nDoubles The number of doubles to write
* \param buffer The buffer from which the data is written to the stream after
* it has been byte swapped if necessary
* \return The number of bytes written to the stream
*/
- (size_t)writeNLittleEndianDoubles: (size_t)nDoubles
fromBuffer: (const double*)buffer;
- (size_t)writeLittleEndianDoubles: (const double*)buffer
count: (size_t)nDoubles;
/**
* \brief Writes from an OFDataArray into the stream.
*
* \param dataArray The OFDataArray to write into the stream
* \return The number of bytes written
*/
|
︙ | | |
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
|
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
|
-
+
-
+
-
+
|
* specifier for objects.
*
* \param format A string used as format
* \param arguments The arguments used in the format string
* \return The number of bytes written
*/
- (size_t)writeFormat: (OFConstantString*)format
withArguments: (va_list)arguments;
arguments: (va_list)arguments;
/**
* \brief Returns the number of bytes still present in the internal cache.
* \brief Returns the number of bytes still present in the internal read cache.
*
* \return The number of bytes still present in the internal cache.
* \return The number of bytes still present in the internal read cache.
*/
- (size_t)pendingBytes;
/**
* \brief Returns whether the stream is in blocking mode.
*
* \return Whether the stream is in blocking mode
|
︙ | | |
817
818
819
820
821
822
823
824
825
826
827
828
829
|
817
818
819
820
821
822
823
824
825
826
827
828
829
|
-
-
-
-
+
+
+
+
|
- (int)fileDescriptor;
/**
* \brief Closes the stream.
*/
- (void)close;
- (size_t)_readNBytes: (size_t)length
intoBuffer: (void*)buffer;
- (void)_writeNBytes: (size_t)length
fromBuffer: (const void*)buffer;
- (size_t)_readIntoBuffer: (void*)buffer
length: (size_t)length;
- (void)_writeBuffer: (const void*)buffer
length: (size_t)length;
- (BOOL)_isWaitingForDelimiter;
@end
|
Modified src/OFStream.m
from [a84cb06e69]
to [6e083ee3de].
︙ | | |
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
|
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
|
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
|
- (BOOL)_isAtEndOfStream
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (size_t)_readNBytes: (size_t)length
intoBuffer: (void*)buffer
- (size_t)_readIntoBuffer: (void*)buffer
length: (size_t)length
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- (void)_writeNBytes: (size_t)length
fromBuffer: (const void*)buffer
- (void)_writeBuffer: (const void*)buffer
length: (size_t)length
{
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
- copy
{
return [self retain];
}
- (BOOL)isAtEndOfStream
{
if (cache != NULL)
return NO;
return [self _isAtEndOfStream];
}
- (size_t)readNBytes: (size_t)length
intoBuffer: (void*)buffer
- (size_t)readIntoBuffer: (void*)buffer
length: (size_t)length
{
if (cache == NULL)
return [self _readNBytes: length
intoBuffer: buffer];
return [self _readIntoBuffer: buffer
length: length];
if (length >= cacheLength) {
size_t ret = cacheLength;
memcpy(buffer, cache, cacheLength);
[self freeMemory: cache];
cache = NULL;
|
︙ | | |
129
130
131
132
133
134
135
136
137
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
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
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
129
130
131
132
133
134
135
136
137
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
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
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
|
cache = tmp;
cacheLength -= length;
return length;
}
}
- (void)readExactlyNBytes: (size_t)length
intoBuffer: (void*)buffer
- (void)readIntoBuffer: (void*)buffer
exactLength: (size_t)length
{
size_t readLength = 0;
while (readLength < length)
readLength += [self readNBytes: length - readLength
intoBuffer: (char*)buffer + readLength];
readLength += [self readIntoBuffer: (char*)buffer + readLength
length: length - readLength];
}
- (uint8_t)readInt8
{
uint8_t ret;
[self readExactlyNBytes: 1
intoBuffer: (char*)&ret];
[self readIntoBuffer: (char*)&ret
exactLength: 1];
return ret;
}
- (uint16_t)readBigEndianInt16
{
uint16_t ret;
[self readExactlyNBytes: 2
intoBuffer: (char*)&ret];
[self readIntoBuffer: (char*)&ret
exactLength: 2];
return of_bswap16_if_le(ret);
}
- (uint32_t)readBigEndianInt32
{
uint32_t ret;
[self readExactlyNBytes: 4
intoBuffer: (char*)&ret];
[self readIntoBuffer: (char*)&ret
exactLength: 4];
return of_bswap32_if_le(ret);
}
- (uint64_t)readBigEndianInt64
{
uint64_t ret;
[self readExactlyNBytes: 8
intoBuffer: (char*)&ret];
[self readIntoBuffer: (char*)&ret
exactLength: 8];
return of_bswap64_if_le(ret);
}
- (float)readBigEndianFloat
{
float ret;
[self readExactlyNBytes: 4
intoBuffer: (char*)&ret];
[self readIntoBuffer: (char*)&ret
exactLength: 4];
return of_bswap_float_if_le(ret);
}
- (double)readBigEndianDouble
{
double ret;
[self readExactlyNBytes: 8
intoBuffer: (char*)&ret];
[self readIntoBuffer: (char*)&ret
exactLength: 8];
return of_bswap_double_if_le(ret);
}
- (size_t)readNBigEndianInt16s: (size_t)nInt16s
intoBuffer: (uint16_t*)buffer
- (size_t)readBigEndianInt16sIntoBuffer: (uint16_t*)buffer
count: (size_t)nInt16s
{
size_t size = nInt16s * sizeof(uint16_t);
[self readExactlyNBytes: size
intoBuffer: buffer];
[self readIntoBuffer: buffer
exactLength: size];
#ifndef OF_BIG_ENDIAN
size_t i;
for (i = 0; i < nInt16s; i++)
buffer[i] = of_bswap16(buffer[i]);
#endif
return size;
}
- (size_t)readNBigEndianInt32s: (size_t)nInt32s
intoBuffer: (uint32_t*)buffer
- (size_t)readBigEndianInt32sIntoBuffer: (uint32_t*)buffer
count: (size_t)nInt32s
{
size_t size = nInt32s * sizeof(uint32_t);
[self readExactlyNBytes: size
intoBuffer: buffer];
[self readIntoBuffer: buffer
exactLength: size];
#ifndef OF_BIG_ENDIAN
size_t i;
for (i = 0; i < nInt32s; i++)
buffer[i] = of_bswap32(buffer[i]);
#endif
return size;
}
- (size_t)readNBigEndianInt64s: (size_t)nInt64s
intoBuffer: (uint64_t*)buffer
- (size_t)readBigEndianInt64sIntoBuffer: (uint64_t*)buffer
count: (size_t)nInt64s
{
size_t size = nInt64s * sizeof(uint64_t);
[self readExactlyNBytes: size
intoBuffer: buffer];
[self readIntoBuffer: buffer
exactLength: size];
#ifndef OF_BIG_ENDIAN
size_t i;
for (i = 0; i < nInt64s; i++)
buffer[i] = of_bswap64(buffer[i]);
#endif
return size;
}
- (size_t)readNBigEndianFloats: (size_t)nFloats
intoBuffer: (float*)buffer
- (size_t)readBigEndianFloatsIntoBuffer: (float*)buffer
count: (size_t)nFloats
{
size_t size = nFloats * sizeof(float);
[self readExactlyNBytes: size
intoBuffer: buffer];
[self readIntoBuffer: buffer
exactLength: size];
#ifndef OF_FLOAT_BIG_ENDIAN
size_t i;
for (i = 0; i < nFloats; i++)
buffer[i] = of_bswap_float(buffer[i]);
#endif
return size;
}
- (size_t)readNBigEndianDoubles: (size_t)nDoubles
intoBuffer: (double*)buffer
- (size_t)readBigEndianDoublesIntoBuffer: (double*)buffer
count: (size_t)nDoubles
{
size_t size = nDoubles * sizeof(double);
[self readExactlyNBytes: size
intoBuffer: buffer];
[self readIntoBuffer: buffer
exactLength: size];
#ifndef OF_FLOAT_BIG_ENDIAN
size_t i;
for (i = 0; i < nDoubles; i++)
buffer[i] = of_bswap_double(buffer[i]);
#endif
return size;
}
- (uint16_t)readLittleEndianInt16
{
uint16_t ret;
[self readExactlyNBytes: 2
intoBuffer: (char*)&ret];
[self readIntoBuffer: (char*)&ret
exactLength: 2];
return of_bswap16_if_be(ret);
}
- (uint32_t)readLittleEndianInt32
{
uint32_t ret;
[self readExactlyNBytes: 4
intoBuffer: (char*)&ret];
[self readIntoBuffer: (char*)&ret
exactLength: 4];
return of_bswap32_if_be(ret);
}
- (uint64_t)readLittleEndianInt64
{
uint64_t ret;
[self readExactlyNBytes: 8
intoBuffer: (char*)&ret];
[self readIntoBuffer: (char*)&ret
exactLength: 8];
return of_bswap64_if_be(ret);
}
- (float)readLittleEndianFloat
{
float ret;
[self readExactlyNBytes: 4
intoBuffer: (char*)&ret];
[self readIntoBuffer: (char*)&ret
exactLength: 4];
return of_bswap_float_if_be(ret);
}
- (double)readLittleEndianDouble
{
double ret;
[self readExactlyNBytes: 8
intoBuffer: (char*)&ret];
[self readIntoBuffer: (char*)&ret
exactLength: 8];
return of_bswap_double_if_be(ret);
}
- (size_t)readNLittleEndianInt16s: (size_t)nInt16s
intoBuffer: (uint16_t*)buffer
- (size_t)readLittleEndianInt16sIntoBuffer: (uint16_t*)buffer
count: (size_t)nInt16s
{
size_t size = nInt16s * sizeof(uint16_t);
[self readExactlyNBytes: size
intoBuffer: buffer];
[self readIntoBuffer: buffer
exactLength: size];
#ifdef OF_BIG_ENDIAN
size_t i;
for (i = 0; i < nInt16s; i++)
buffer[i] = of_bswap16(buffer[i]);
#endif
return size;
}
- (size_t)readNLittleEndianInt32s: (size_t)nInt32s
intoBuffer: (uint32_t*)buffer
- (size_t)readLittleEndianInt32sIntoBuffer: (uint32_t*)buffer
count: (size_t)nInt32s
{
size_t size = nInt32s * sizeof(uint32_t);
[self readExactlyNBytes: size
intoBuffer: buffer];
[self readIntoBuffer: buffer
exactLength: size];
#ifdef OF_BIG_ENDIAN
size_t i;
for (i = 0; i < nInt32s; i++)
buffer[i] = of_bswap32(buffer[i]);
#endif
return size;
}
- (size_t)readNLittleEndianInt64s: (size_t)nInt64s
intoBuffer: (uint64_t*)buffer
- (size_t)readLittleEndianInt64sIntoBuffer: (uint64_t*)buffer
count: (size_t)nInt64s
{
size_t size = nInt64s * sizeof(uint64_t);
[self readExactlyNBytes: size
intoBuffer: buffer];
[self readIntoBuffer: buffer
exactLength: size];
#ifdef OF_BIG_ENDIAN
size_t i;
for (i = 0; i < nInt64s; i++)
buffer[i] = of_bswap64(buffer[i]);
#endif
return size;
}
- (size_t)readNLittleEndianFloats: (size_t)nFloats
intoBuffer: (float*)buffer
- (size_t)readLittleEndianFloatsIntoBuffer: (float*)buffer
count: (size_t)nFloats
{
size_t size = nFloats * sizeof(float);
[self readExactlyNBytes: size
intoBuffer: buffer];
[self readIntoBuffer: buffer
exactLength: size];
#ifdef OF_FLOAT_BIG_ENDIAN
size_t i;
for (i = 0; i < nFloats; i++)
buffer[i] = of_bswap_float(buffer[i]);
#endif
return size;
}
- (size_t)readNLittleEndianDoubles: (size_t)nDoubles
intoBuffer: (double*)buffer
- (size_t)readLittleEndianDoublesIntoBuffer: (double*)buffer
count: (size_t)nDoubles
{
size_t size = nDoubles * sizeof(double);
[self readExactlyNBytes: size
intoBuffer: buffer];
[self readIntoBuffer: buffer
exactLength: size];
#ifdef OF_FLOAT_BIG_ENDIAN
size_t i;
for (i = 0; i < nDoubles; i++)
buffer[i] = of_bswap_double(buffer[i]);
#endif
return size;
}
- (OFDataArray*)readDataArrayWithNItems: (size_t)nItems
- (OFDataArray*)readDataArrayWithSize: (size_t)nItems
{
return [self readDataArrayWithItemSize: 1
andNItems: nItems];
count: nItems];
}
- (OFDataArray*)readDataArrayWithItemSize: (size_t)itemSize
andNItems: (size_t)nItems
count: (size_t)nItems
{
OFDataArray *dataArray;
char *tmp;
dataArray = [OFDataArray dataArrayWithItemSize: itemSize];
tmp = [self allocMemoryWithItemSize: itemSize
count: nItems];
tmp = [self allocMemoryWithSize: itemSize
count: nItems];
@try {
[self readExactlyNBytes: nItems * itemSize
intoBuffer: tmp];
[self readIntoBuffer: tmp
exactLength: nItems * itemSize];
[dataArray addItemsFromCArray: tmp
count: nItems];
} @finally {
[self freeMemory: tmp];
}
|
︙ | | |
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
|
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
|
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
|
dataArray = [OFDataArray dataArray];
buffer = [self allocMemoryWithSize: of_pagesize];
@try {
while (![self isAtEndOfStream]) {
size_t length;
length = [self readNBytes: of_pagesize
intoBuffer: buffer];
length = [self readIntoBuffer: buffer
length: of_pagesize];
[dataArray addItemsFromCArray: buffer
count: length];
}
} @finally {
[self freeMemory: buffer];
}
return dataArray;
}
- (OFString*)readStringWithLength: (size_t)length
{
return [self readStringWithEncoding: OF_STRING_ENCODING_UTF_8
length: length];
return [self readStringWithLength: length
encoding: OF_STRING_ENCODING_UTF_8];
}
- (OFString*)readStringWithEncoding: (of_string_encoding_t)encoding
length: (size_t)length
- (OFString*)readStringWithLength: (size_t)length
encoding: (of_string_encoding_t)encoding
{
OFString *ret;
char *buffer = [self allocMemoryWithSize: length + 1];
buffer[length] = 0;
@try {
[self readExactlyNBytes: length
intoBuffer: buffer];
[self readIntoBuffer: buffer
exactLength: length];
ret = [OFString stringWithCString: buffer
encoding: encoding];
} @finally {
[self freeMemory: buffer];
}
|
︙ | | |
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
|
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
|
-
-
+
+
|
cache = NULL;
cacheLength = 0;
waitingForDelimiter = NO;
return ret;
}
bufferLength = [self _readNBytes: of_pagesize
intoBuffer: buffer];
bufferLength = [self _readIntoBuffer: buffer
length: of_pagesize];
/* Look if there's a newline or \0 */
for (i = 0; i < bufferLength; i++) {
if (OF_UNLIKELY(buffer[i] == '\n' ||
buffer[i] == '\0')) {
retLength = cacheLength + i;
retCString = [self
|
︙ | | |
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
|
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
|
-
+
|
} @catch (id e) {
/*
* Append data to cache to prevent loss
* of data due to wrong encoding.
*/
cache = [self
resizeMemory: cache
toSize: cacheLength +
size: cacheLength +
bufferLength];
if (cache != NULL)
memcpy(cache + cacheLength,
buffer, bufferLength);
cacheLength += bufferLength;
|
︙ | | |
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
|
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
|
-
+
-
+
|
waitingForDelimiter = NO;
return ret;
}
}
/* There was no newline or \0 */
cache = [self resizeMemory: cache
toSize: cacheLength + bufferLength];
size: cacheLength + bufferLength];
/*
* It's possible that cacheLen + len is 0 and thus cache was
* set to NULL by resizeMemory:toSize:.
* set to NULL by resizeMemory:size:.
*/
if (cache != NULL)
memcpy(cache + cacheLength, buffer, bufferLength);
cacheLength += bufferLength;
} @finally {
[self freeMemory: buffer];
|
︙ | | |
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
|
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
|
-
+
|
- (OFString*)tryReadLine
{
return [self tryReadLineWithEncoding: OF_STRING_ENCODING_UTF_8];
}
- (OFString*)tryReadTillDelimiter: (OFString*)delimiter
withEncoding: (of_string_encoding_t)encoding
encoding: (of_string_encoding_t)encoding
{
const char *delimiterUTF8String;
size_t i, j, delimiterLength, bufferLength, retLength;
char *retCString, *buffer, *newCache;
OFString *ret;
/* FIXME: Convert delimiter to specified charset */
|
︙ | | |
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
|
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
|
-
-
+
+
|
cache = NULL;
cacheLength = 0;
waitingForDelimiter = NO;
return ret;
}
bufferLength = [self _readNBytes: of_pagesize
intoBuffer: buffer];
bufferLength = [self _readIntoBuffer: buffer
length: of_pagesize];
/* Look if there's a delimiter or \0 */
for (i = 0; i < bufferLength; i++) {
if (buffer[i] != delimiterUTF8String[j++])
j = 0;
if (j == delimiterLength || buffer[i] == '\0') {
|
︙ | | |
799
800
801
802
803
804
805
806
807
808
809
810
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
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
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
929
930
931
932
933
934
935
936
937
938
939
940
941
942
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
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
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
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
|
799
800
801
802
803
804
805
806
807
808
809
810
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
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
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
929
930
931
932
933
934
935
936
937
938
939
940
941
942
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
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
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
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
+
-
-
+
+
|
waitingForDelimiter = NO;
return ret;
}
}
/* Neither the delimiter nor \0 was found */
cache = [self resizeMemory: cache
toSize: cacheLength + bufferLength];
size: cacheLength + bufferLength];
/*
* It's possible that cacheLen + len is 0 and thus cache was
* set to NULL by resizeMemory:toSize:.
* set to NULL by resizeMemory:size:.
*/
if (cache != NULL)
memcpy(cache + cacheLength, buffer,
bufferLength);
cacheLength += bufferLength;
} @finally {
[self freeMemory: buffer];
}
waitingForDelimiter = YES;
return nil;
}
- (OFString*)readTillDelimiter: (OFString*)delimiter
{
return [self readTillDelimiter: delimiter
withEncoding: OF_STRING_ENCODING_UTF_8];
encoding: OF_STRING_ENCODING_UTF_8];
}
- (OFString*)readTillDelimiter: (OFString*)delimiter
withEncoding: (of_string_encoding_t)encoding
encoding: (of_string_encoding_t)encoding
{
OFString *ret = nil;
while ((ret = [self tryReadTillDelimiter: delimiter
withEncoding: encoding]) == nil)
encoding: encoding]) == nil)
if ([self isAtEndOfStream])
return nil;
return ret;
}
- (OFString*)tryReadTillDelimiter: (OFString*)delimiter
{
return [self tryReadTillDelimiter: delimiter
withEncoding: OF_STRING_ENCODING_UTF_8];
encoding: OF_STRING_ENCODING_UTF_8];
}
- (BOOL)buffersWrites
- (BOOL)writeBufferEnabled
{
return buffersWrites;
return writeBufferEnabled;
}
- (void)setBuffersWrites: (BOOL)enable
- (void)setWriteBufferEnabled: (BOOL)enable
{
buffersWrites = enable;
writeBufferEnabled = enable;
}
- (void)flushWriteBuffer
{
if (writeBuffer == NULL)
return;
[self _writeNBytes: writeBufferLength
fromBuffer: writeBuffer];
[self _writeBuffer: writeBuffer
length: writeBufferLength];
[self freeMemory: writeBuffer];
writeBuffer = NULL;
writeBufferLength = 0;
}
- (void)writeNBytes: (size_t)length
fromBuffer: (const void*)buffer
- (void)writeBuffer: (const void*)buffer
length: (size_t)length
{
if (!buffersWrites)
if (!writeBufferEnabled)
[self _writeNBytes: length
fromBuffer: buffer];
[self _writeBuffer: buffer
length: length];
else {
writeBuffer = [self resizeMemory: writeBuffer
toSize: writeBufferLength + length];
size: writeBufferLength + length];
memcpy(writeBuffer + writeBufferLength, buffer, length);
writeBufferLength += length;
}
}
- (void)writeInt8: (uint8_t)int8
{
[self writeNBytes: 1
fromBuffer: (char*)&int8];
[self writeBuffer: (char*)&int8
length: 1];
}
- (void)writeBigEndianInt16: (uint16_t)int16
{
int16 = of_bswap16_if_le(int16);
[self writeNBytes: 2
fromBuffer: (char*)&int16];
[self writeBuffer: (char*)&int16
length: 2];
}
- (void)writeBigEndianInt32: (uint32_t)int32
{
int32 = of_bswap32_if_le(int32);
[self writeNBytes: 4
fromBuffer: (char*)&int32];
[self writeBuffer: (char*)&int32
length: 4];
}
- (void)writeBigEndianInt64: (uint64_t)int64
{
int64 = of_bswap64_if_le(int64);
[self writeNBytes: 8
fromBuffer: (char*)&int64];
[self writeBuffer: (char*)&int64
length: 8];
}
- (void)writeBigEndianFloat: (float)float_
{
float_ = of_bswap_float_if_le(float_);
[self writeNBytes: 4
fromBuffer: (char*)&float_];
[self writeBuffer: (char*)&float_
length: 4];
}
- (void)writeBigEndianDouble: (double)double_
{
double_ = of_bswap_double_if_le(double_);
[self writeNBytes: 8
fromBuffer: (char*)&double_];
[self writeBuffer: (char*)&double_
length: 8];
}
- (size_t)writeNBigEndianInt16s: (size_t)nInt16s
fromBuffer: (const uint16_t*)buffer
- (size_t)writeBigEndianInt16s: (const uint16_t*)buffer
count: (size_t)nInt16s
{
size_t size = nInt16s * sizeof(uint16_t);
#ifdef OF_BIG_ENDIAN
[self writeNBytes: size
fromBuffer: buffer];
[self writeBuffer: buffer
length: size];
#else
uint16_t *tmp;
tmp = [self allocMemoryWithItemSize: sizeof(uint16_t)
count: nInt16s];
tmp = [self allocMemoryWithSize: sizeof(uint16_t)
count: nInt16s];
@try {
size_t i;
for (i = 0; i < nInt16s; i++)
tmp[i] = of_bswap16(buffer[i]);
[self writeNBytes: size
fromBuffer: tmp];
[self writeBuffer: tmp
length: size];
} @finally {
[self freeMemory: tmp];
}
#endif
return size;
}
- (size_t)writeNBigEndianInt32s: (size_t)nInt32s
fromBuffer: (const uint32_t*)buffer
- (size_t)writeBigEndianInt32s: (const uint32_t*)buffer
count: (size_t)nInt32s
{
size_t size = nInt32s * sizeof(uint32_t);
#ifdef OF_BIG_ENDIAN
[self writeNBytes: size
fromBuffer: buffer];
[self writeBuffer: buffer
length: size];
#else
uint32_t *tmp;
tmp = [self allocMemoryWithItemSize: sizeof(uint32_t)
count: nInt32s];
tmp = [self allocMemoryWithSize: sizeof(uint32_t)
count: nInt32s];
@try {
size_t i;
for (i = 0; i < nInt32s; i++)
tmp[i] = of_bswap32(buffer[i]);
[self writeNBytes: size
fromBuffer: tmp];
[self writeBuffer: tmp
length: size];
} @finally {
[self freeMemory: tmp];
}
#endif
return size;
}
- (size_t)writeNBigEndianInt64s: (size_t)nInt64s
fromBuffer: (const uint64_t*)buffer
- (size_t)writeBigEndianInt64s: (const uint64_t*)buffer
count: (size_t)nInt64s
{
size_t size = nInt64s * sizeof(uint64_t);
#ifdef OF_BIG_ENDIAN
[self writeNBytes: size
fromBuffer: buffer];
[self writeBuffer: buffer
length: size];
#else
uint64_t *tmp;
tmp = [self allocMemoryWithItemSize: sizeof(uint64_t)
count: nInt64s];
tmp = [self allocMemoryWithSize: sizeof(uint64_t)
count: nInt64s];
@try {
size_t i;
for (i = 0; i < nInt64s; i++)
tmp[i] = of_bswap64(buffer[i]);
[self writeNBytes: size
fromBuffer: tmp];
[self writeBuffer: tmp
length: size];
} @finally {
[self freeMemory: tmp];
}
#endif
return size;
}
- (size_t)writeNBigEndianFloats: (size_t)nFloats
fromBuffer: (const float*)buffer
- (size_t)writeBigEndianFloats: (const float*)buffer
count: (size_t)nFloats
{
size_t size = nFloats * sizeof(float);
#ifdef OF_FLOAT_BIG_ENDIAN
[self writeNBytes: size
fromBuffer: buffer];
[self writeBuffer: buffer
length: size];
#else
float *tmp;
tmp = [self allocMemoryWithItemSize: sizeof(float)
count: nFloats];
tmp = [self allocMemoryWithSize: sizeof(float)
count: nFloats];
@try {
size_t i;
for (i = 0; i < nFloats; i++)
tmp[i] = of_bswap_float(buffer[i]);
[self writeNBytes: size
fromBuffer: tmp];
[self writeBuffer: tmp
length: size];
} @finally {
[self freeMemory: tmp];
}
#endif
return size;
}
- (size_t)writeNBigEndianDoubles: (size_t)nDoubles
fromBuffer: (const double*)buffer
- (size_t)writeBigEndianDoubles: (const double*)buffer
count: (size_t)nDoubles
{
size_t size = nDoubles * sizeof(double);
#ifdef OF_FLOAT_BIG_ENDIAN
[self writeNBytes: size
fromBuffer: buffer];
[self writeBuffer: buffer
length: size];
#else
double *tmp;
tmp = [self allocMemoryWithItemSize: sizeof(double)
count: nDoubles];
tmp = [self allocMemoryWithSize: sizeof(double)
count: nDoubles];
@try {
size_t i;
for (i = 0; i < nDoubles; i++)
tmp[i] = of_bswap_double(buffer[i]);
[self writeNBytes: size
fromBuffer: tmp];
[self writeBuffer: tmp
length: size];
} @finally {
[self freeMemory: tmp];
}
#endif
return size;
}
- (void)writeLittleEndianInt16: (uint16_t)int16
{
int16 = of_bswap16_if_be(int16);
[self writeNBytes: 2
fromBuffer: (char*)&int16];
[self writeBuffer: (char*)&int16
length: 2];
}
- (void)writeLittleEndianInt32: (uint32_t)int32
{
int32 = of_bswap32_if_be(int32);
[self writeNBytes: 4
fromBuffer: (char*)&int32];
[self writeBuffer: (char*)&int32
length: 4];
}
- (void)writeLittleEndianInt64: (uint64_t)int64
{
int64 = of_bswap64_if_be(int64);
[self writeNBytes: 8
fromBuffer: (char*)&int64];
[self writeBuffer: (char*)&int64
length: 8];
}
- (void)writeLittleEndianFloat: (float)float_
{
float_ = of_bswap_float_if_be(float_);
[self writeNBytes: 4
fromBuffer: (char*)&float_];
[self writeBuffer: (char*)&float_
length: 4];
}
- (void)writeLittleEndianDouble: (double)double_
{
double_ = of_bswap_double_if_be(double_);
[self writeNBytes: 8
fromBuffer: (char*)&double_];
[self writeBuffer: (char*)&double_
length: 8];
}
- (size_t)writeNLittleEndianInt16s: (size_t)nInt16s
fromBuffer: (const uint16_t*)buffer
- (size_t)writeLittleEndianInt16s: (const uint16_t*)buffer
count: (size_t)nInt16s
{
size_t size = nInt16s * sizeof(uint16_t);
#ifndef OF_BIG_ENDIAN
[self writeNBytes: size
fromBuffer: buffer];
[self writeBuffer: buffer
length: size];
#else
uint16_t *tmp;
tmp = [self allocMemoryWithItemSize: sizeof(uint16_t)
count: nInt16s];
tmp = [self allocMemoryWithSize: sizeof(uint16_t)
count: nInt16s];
@try {
size_t i;
for (i = 0; i < nInt16s; i++)
tmp[i] = of_bswap16(buffer[i]);
[self writeNBytes: size
fromBuffer: tmp];
[self writeBuffer: tmp
length: size];
} @finally {
[self freeMemory: tmp];
}
#endif
return size;
}
- (size_t)writeLittleEndianInt32s: (const uint32_t*)buffer
count: (size_t)nInt32s
{
size_t size = nInt32s * sizeof(uint32_t);
#ifndef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint32_t *tmp;
tmp = [self allocMemoryWithSize: sizeof(uint32_t)
count: nInt32s];
@try {
size_t i;
for (i = 0; i < nInt32s; i++)
tmp[i] = of_bswap32(buffer[i]);
[self writeBuffer: tmp
length: size];
} @finally {
[self freeMemory: tmp];
}
#endif
return size;
}
- (size_t)writeLittleEndianInt64s: (const uint64_t*)buffer
count: (size_t)nInt64s
{
size_t size = nInt64s * sizeof(uint64_t);
#ifndef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint64_t *tmp;
tmp = [self allocMemoryWithSize: sizeof(uint64_t)
count: nInt64s];
@try {
size_t i;
for (i = 0; i < nInt64s; i++)
tmp[i] = of_bswap64(buffer[i]);
[self writeBuffer: tmp
length: size];
} @finally {
[self freeMemory: tmp];
}
#endif
return size;
}
- (size_t)writeNLittleEndianInt32s: (size_t)nInt32s
fromBuffer: (const uint32_t*)buffer
- (size_t)writeLittleEndianFloats: (const float*)buffer
count: (size_t)nFloats
{
size_t size = nInt32s * sizeof(uint32_t);
size_t size = nFloats * sizeof(float);
#ifndef OF_BIG_ENDIAN
#ifndef OF_FLOAT_BIG_ENDIAN
[self writeNBytes: size
fromBuffer: buffer];
[self writeBuffer: buffer
length: size];
#else
uint32_t *tmp;
float *tmp;
tmp = [self allocMemoryWithItemSize: sizeof(uint32_t)
count: nInt32s];
tmp = [self allocMemoryWithSize: sizeof(float)
count: nFloats];
@try {
size_t i;
for (i = 0; i < nInt32s; i++)
tmp[i] = of_bswap32(buffer[i]);
for (i = 0; i < nFloats; i++)
tmp[i] = of_bswap_float(buffer[i]);
[self writeNBytes: size
fromBuffer: tmp];
[self writeBuffer: tmp
} @finally {
[self freeMemory: tmp];
}
#endif
return size;
length: size];
}
- (size_t)writeNLittleEndianInt64s: (size_t)nInt64s
fromBuffer: (const uint64_t*)buffer
{
size_t size = nInt64s * sizeof(uint64_t);
#ifndef OF_BIG_ENDIAN
[self writeNBytes: size
fromBuffer: buffer];
#else
uint64_t *tmp;
tmp = [self allocMemoryWithItemSize: sizeof(uint64_t)
count: nInt64s];
@try {
size_t i;
for (i = 0; i < nInt64s; i++)
tmp[i] = of_bswap64(buffer[i]);
[self writeNBytes: size
fromBuffer: tmp];
} @finally {
[self freeMemory: tmp];
}
#endif
return size;
}
- (size_t)writeNLittleEndianFloats: (size_t)nFloats
fromBuffer: (const float*)buffer
{
size_t size = nFloats * sizeof(float);
- (size_t)writeLittleEndianDoubles: (const double*)buffer
#ifndef OF_FLOAT_BIG_ENDIAN
[self writeNBytes: size
fromBuffer: buffer];
#else
float *tmp;
tmp = [self allocMemoryWithItemSize: sizeof(float)
count: nFloats];
@try {
size_t i;
for (i = 0; i < nFloats; i++)
tmp[i] = of_bswap_float(buffer[i]);
[self writeNBytes: size
fromBuffer: tmp];
} @finally {
[self freeMemory: tmp];
}
#endif
return size;
}
- (size_t)writeNLittleEndianDoubles: (size_t)nDoubles
count: (size_t)nDoubles
fromBuffer: (const double*)buffer
{
size_t size = nDoubles * sizeof(double);
#ifndef OF_FLOAT_BIG_ENDIAN
[self writeNBytes: size
fromBuffer: buffer];
[self writeBuffer: buffer
length: size];
#else
double *tmp;
tmp = [self allocMemoryWithItemSize: sizeof(double)
count: nDoubles];
tmp = [self allocMemoryWithSize: sizeof(double)
count: nDoubles];
@try {
size_t i;
for (i = 0; i < nDoubles; i++)
tmp[i] = of_bswap_double(buffer[i]);
[self writeNBytes: size
fromBuffer: tmp];
[self writeBuffer: tmp
length: size];
} @finally {
[self freeMemory: tmp];
}
#endif
return size;
}
- (size_t)writeDataArray: (OFDataArray*)dataArray
{
size_t length = [dataArray count] * [dataArray itemSize];
[self writeNBytes: length
fromBuffer: [dataArray cArray]];
[self writeBuffer: [dataArray cArray]
length: length];
return [dataArray count] * [dataArray itemSize];
}
- (size_t)writeString: (OFString*)string
{
size_t length = [string UTF8StringLength];
[self writeNBytes: length
fromBuffer: [string UTF8String]];
[self writeBuffer: [string UTF8String]
length: length];
return length;
}
- (size_t)writeLine: (OFString*)string
{
size_t stringLength = [string UTF8StringLength];
char *buffer;
buffer = [self allocMemoryWithSize: stringLength + 1];
@try {
memcpy(buffer, [string UTF8String], stringLength);
buffer[stringLength] = '\n';
[self writeNBytes: stringLength + 1
fromBuffer: buffer];
[self writeBuffer: buffer
length: stringLength + 1];
} @finally {
[self freeMemory: buffer];
}
return stringLength + 1;
}
- (size_t)writeFormat: (OFConstantString*)format, ...
{
va_list arguments;
size_t ret;
va_start(arguments, format);
ret = [self writeFormat: format
withArguments: arguments];
arguments: arguments];
va_end(arguments);
return ret;
}
- (size_t)writeFormat: (OFConstantString*)format
withArguments: (va_list)arguments
arguments: (va_list)arguments
{
char *UTF8String;
int length;
if (format == nil)
@throw [OFInvalidArgumentException exceptionWithClass: isa
selector: _cmd];
if ((length = of_vasprintf(&UTF8String, [format UTF8String],
arguments)) == -1)
@throw [OFInvalidFormatException exceptionWithClass: isa];
@try {
[self writeNBytes: length
fromBuffer: UTF8String];
[self writeBuffer: UTF8String
length: length];
} @finally {
free(UTF8String);
}
return length;
}
|
︙ | | |
Modified src/OFStreamObserver.m
from [75b0a6497b]
to [aaaee883eb].
︙ | | |
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
-
-
+
+
|
if (getsockname(cancelFD[0], (struct sockaddr*)&cancelAddr,
&cancelAddrLen))
@throw [OFInitializationFailedException
exceptionWithClass: isa];
#endif
maxFD = cancelFD[0];
FDToStream = [self allocMemoryWithItemSize: sizeof(OFStream*)
count: maxFD + 1];
FDToStream = [self allocMemoryWithSize: sizeof(OFStream*)
count: maxFD + 1];
FDToStream[cancelFD[0]] = nil;
#ifdef OF_THREADS
mutex = [[OFMutex alloc] init];
#endif
} @catch (id e) {
[self release];
|
︙ | | |
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
-
+
|
int fd = queueFDsCArray[i];
if ((action & QUEUE_ACTION) == QUEUE_ADD) {
if (fd > maxFD) {
maxFD = fd;
FDToStream = [self
resizeMemory: FDToStream
itemSize: sizeof(OFStream*)
size: sizeof(OFStream*)
count: maxFD + 1];
}
FDToStream[fd] = stream;
}
if ((action & QUEUE_ACTION) == QUEUE_REMOVE) {
|
︙ | | |
Modified src/OFStreamSocket.m
from [acbc1571b5]
to [57d59bfcb8].
︙ | | |
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
-
-
+
+
|
}
- (BOOL)_isAtEndOfStream
{
return atEndOfStream;
}
- (size_t)_readNBytes: (size_t)length
intoBuffer: (void*)buffer
- (size_t)_readIntoBuffer: (void*)buffer
length: (size_t)length
{
ssize_t ret;
if (sock == INVALID_SOCKET)
@throw [OFNotConnectedException exceptionWithClass: isa
socket: self];
|
︙ | | |
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
-
-
+
+
|
if (ret == 0)
atEndOfStream = YES;
return ret;
}
- (void)_writeNBytes: (size_t)length
fromBuffer: (const void*)buffer
- (void)_writeBuffer: (const void*)buffer
length: (size_t)length
{
if (sock == INVALID_SOCKET)
@throw [OFNotConnectedException exceptionWithClass: isa
socket: self];
if (atEndOfStream) {
OFWriteFailedException *e;
|
︙ | | |
Modified src/OFString+JSONValue.m
from [06182df9e0]
to [291a080964].
︙ | | |
23
24
25
26
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
|
23
24
25
26
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
60
61
|
-
+
-
+
+
-
+
+
-
+
+
+
+
+
-
+
+
|
#import "OFString+JSONValue.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OFNull.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidJSONException.h"
#import "macros.h"
int _OFString_JSONValue_reference;
static id nextObject(const char *restrict *, const char*);
static id nextObject(const char *restrict *, const char*,
size_t *restrict line);
static void
skipWhitespaces(const char *restrict *pointer, const char *stop)
skipWhitespaces(const char *restrict *pointer, const char *stop,
size_t *restrict line)
{
while (*pointer < stop && (**pointer == ' ' || **pointer == '\t' ||
**pointer == '\r' || **pointer == '\n'))
**pointer == '\r' || **pointer == '\n')) {
if (**pointer == '\n')
(*line)++;
(*pointer)++;
}
}
static void
skipComment(const char *restrict *pointer, const char *stop)
skipComment(const char *restrict *pointer, const char *stop,
size_t *restrict line)
{
if (**pointer != '/')
return;
if (*pointer + 1 >= stop)
return;
|
︙ | | |
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
|
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
|
+
+
+
-
+
+
-
+
+
-
+
+
-
-
+
+
|
while (*pointer < stop) {
if (lastIsAsterisk && **pointer == '/') {
(*pointer)++;
return;
}
lastIsAsterisk = (**pointer == '*');
if (**pointer == '\n')
(*line)++;
(*pointer)++;
}
} else {
} else if (**pointer == '/') {
(*pointer)++;
while (*pointer < stop) {
if (**pointer == '\r' || **pointer == '\n') {
(*pointer)++;
(*line)++;
return;
}
(*pointer)++;
}
}
} else
(*pointer)--;
}
static void
skipWhitespacesAndComments(const char *restrict *pointer, const char *stop)
skipWhitespacesAndComments(const char *restrict *pointer, const char *stop,
size_t *restrict line)
{
const char *old = NULL;
while (old != *pointer) {
old = *pointer;
skipWhitespaces(pointer, stop);
skipComment(pointer, stop);
skipWhitespaces(pointer, stop, line);
skipComment(pointer, stop, line);
}
}
static inline uint16_t
parseUnicodeEscape(const char *pointer, const char *stop)
{
uint16_t ret = 0;
|
︙ | | |
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
-
+
+
|
return 0xFFFF;
}
return ret;
}
static inline OFString*
parseString(const char *restrict *pointer, const char *stop)
parseString(const char *restrict *pointer, const char *stop,
size_t *restrict line)
{
char *buffer;
size_t i = 0;
char delimiter = **pointer;
if (++(*pointer) + 1 >= stop)
return nil;
|
︙ | | |
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
-
+
+
+
+
|
i += l;
*pointer += 11;
break;
case '\r':
(*pointer)++;
if (*pointer < stop && **pointer == '\n')
if (*pointer < stop && **pointer == '\n') {
(*pointer)++;
(*line)++;
}
break;
case '\n':
(*pointer)++;
(*line)++;
break;
default:
free(buffer);
return nil;
}
/* End of string found */
} else if (**pointer == delimiter) {
|
︙ | | |
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
+
|
}
(*pointer)++;
return ret;
/* Newlines in strings are disallowed */
} else if (**pointer == '\n' || **pointer == '\r') {
(*line)++;
free(buffer);
return nil;
} else {
buffer[i++] = **pointer;
(*pointer)++;
}
}
|
︙ | | |
369
370
371
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
397
398
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
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
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
515
516
517
518
519
520
521
522
523
524
|
387
388
389
390
391
392
393
394
395
396
397
398
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
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
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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
|
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
-
+
+
+
+
+
|
* It is never possible to end with an identifier, thus we should never
* reach stop.
*/
return nil;
}
static inline OFMutableArray*
parseArray(const char *restrict *pointer, const char *stop)
parseArray(const char *restrict *pointer, const char *stop,
size_t *restrict line)
{
OFMutableArray *array = [OFMutableArray array];
if (++(*pointer) >= stop)
return nil;
while (**pointer != ']') {
id object;
skipWhitespacesAndComments(pointer, stop);
skipWhitespacesAndComments(pointer, stop, line);
if (*pointer >= stop)
return nil;
if (**pointer == ']')
break;
if (**pointer == ',') {
(*pointer)++;
skipWhitespacesAndComments(pointer, stop);
skipWhitespacesAndComments(pointer, stop, line);
if (*pointer >= stop || **pointer != ']')
return nil;
break;
}
if ((object = nextObject(pointer, stop)) == nil)
if ((object = nextObject(pointer, stop, line)) == nil)
return nil;
[array addObject: object];
skipWhitespacesAndComments(pointer, stop);
skipWhitespacesAndComments(pointer, stop, line);
if (*pointer >= stop)
return nil;
if (**pointer == ',') {
(*pointer)++;
skipWhitespacesAndComments(pointer, stop);
skipWhitespacesAndComments(pointer, stop, line);
if (*pointer >= stop)
return nil;
} else if (**pointer != ']')
return nil;
}
(*pointer)++;
return array;
}
static inline OFMutableDictionary*
parseDictionary(const char *restrict *pointer, const char *stop)
parseDictionary(const char *restrict *pointer, const char *stop,
size_t *restrict line)
{
OFMutableDictionary *dictionary = [OFMutableDictionary dictionary];
if (++(*pointer) >= stop)
return nil;
while (**pointer != '}') {
id key, object;
skipWhitespacesAndComments(pointer, stop);
skipWhitespacesAndComments(pointer, stop, line);
if (*pointer >= stop)
return nil;
if (**pointer == '}')
break;
if (**pointer == ',') {
(*pointer)++;
skipWhitespacesAndComments(pointer, stop);
skipWhitespacesAndComments(pointer, stop, line);
if (*pointer >= stop || **pointer != '}')
return nil;
break;
}
skipWhitespacesAndComments(pointer, stop);
skipWhitespacesAndComments(pointer, stop, line);
if (*pointer + 1 >= stop)
return nil;
if ((**pointer >= 'a' && **pointer <= 'z') ||
(**pointer >= 'A' && **pointer <= 'Z') ||
**pointer == '_' || **pointer == '$' || **pointer == '\\')
key = parseIdentifier(pointer, stop);
else
key = nextObject(pointer, stop);
key = nextObject(pointer, stop, line);
if (key == nil)
return nil;
skipWhitespacesAndComments(pointer, stop);
skipWhitespacesAndComments(pointer, stop, line);
if (*pointer + 1 >= stop || **pointer != ':')
return nil;
(*pointer)++;
if ((object = nextObject(pointer, stop)) == nil)
if ((object = nextObject(pointer, stop, line)) == nil)
return nil;
[dictionary setObject: object
forKey: key];
skipWhitespacesAndComments(pointer, stop);
skipWhitespacesAndComments(pointer, stop, line);
if (*pointer >= stop)
return nil;
if (**pointer == ',') {
(*pointer)++;
skipWhitespacesAndComments(pointer, stop);
skipWhitespacesAndComments(pointer, stop, line);
if (*pointer >= stop)
return nil;
} else if (**pointer != '}')
return nil;
}
(*pointer)++;
return dictionary;
}
static inline OFNumber*
parseNumber(const char *restrict *pointer, const char *stop)
parseNumber(const char *restrict *pointer, const char *stop,
size_t *restrict line)
{
BOOL isHex = (*pointer + 1 < stop && (*pointer)[1] == 'x');
BOOL hasDecimal = NO;
size_t i;
OFString *string;
OFNumber *number;
for (i = 0; *pointer + i < stop; i++) {
if ((*pointer)[i] == '.')
hasDecimal = YES;
if ((*pointer)[i] == ' ' || (*pointer)[i] == '\t' ||
(*pointer)[i] == '\r' || (*pointer)[i] == '\n' ||
(*pointer)[i] == ',' || (*pointer)[i] == ']' ||
(*pointer)[i] == '}')
(*pointer)[i] == '}') {
if ((*pointer)[i] == '\n')
(*line)++;
break;
}
}
string = [[OFString alloc] initWithUTF8String: *pointer
length: i];
*pointer += i;
@try {
|
︙ | | |
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
|
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
|
-
+
+
-
+
-
+
-
+
-
+
|
[string release];
}
return number;
}
static id
nextObject(const char *restrict *pointer, const char *stop)
nextObject(const char *restrict *pointer, const char *stop,
size_t *restrict line)
{
skipWhitespacesAndComments(pointer, stop);
skipWhitespacesAndComments(pointer, stop, line);
if (*pointer >= stop)
return nil;
switch (**pointer) {
case '"':
case '\'':
return parseString(pointer, stop);
return parseString(pointer, stop, line);
case '[':
return parseArray(pointer, stop);
return parseArray(pointer, stop, line);
case '{':
return parseDictionary(pointer, stop);
return parseDictionary(pointer, stop, line);
case 't':
if (*pointer + 3 >= stop)
return nil;
if (memcmp(*pointer, "true", 4))
return nil;
|
︙ | | |
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
|
-
+
+
-
-
+
+
-
+
+
|
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
case '.':
return parseNumber(pointer, stop);
return parseNumber(pointer, stop, line);
default:
return nil;
}
}
@implementation OFString (JSONValue)
- (id)JSONValue
{
const char *pointer = [self UTF8String];
const char *stop = pointer + [self UTF8StringLength];
id object;
size_t line = 1;
object = nextObject(&pointer, stop);
skipWhitespacesAndComments(&pointer, stop);
object = nextObject(&pointer, stop, &line);
skipWhitespacesAndComments(&pointer, stop, &line);
if (pointer < stop || object == nil)
@throw [OFInvalidEncodingException exceptionWithClass: isa];
@throw [OFInvalidJSONException exceptionWithClass: isa
line: line];
return object;
}
@end
|
Modified src/OFString.m
from [788fd6f59d]
to [a987125a46].
︙ | | |
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
|
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
|
-
-
+
+
|
file = [[OFFile alloc] initWithPath: path
mode: @"rb"];
@try {
tmp = [self allocMemoryWithSize: (size_t)st.st_size];
[file readExactlyNBytes: (size_t)st.st_size
intoBuffer: tmp];
[file readIntoBuffer: tmp
exactLength: (size_t)st.st_size];
} @finally {
[file release];
}
} @catch (id e) {
[self release];
@throw e;
}
|
︙ | | |
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
|
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
|
-
+
|
}
}
UTF8String[j] = '\0';
@try {
UTF8String = [object resizeMemory: UTF8String
toSize: UTF8StringLength + 1];
size: UTF8StringLength + 1];
} @catch (OFOutOfMemoryException *e) {
/* We don't care, as we only tried to make it smaller */
}
return UTF8String;
}
|
︙ | | |
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
|
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
|
-
-
+
+
|
const of_unichar_t *prefixString;
size_t prefixLength;
int compare;
if ((prefixLength = [prefix length]) > [self length])
return NO;
tmp = [self allocMemoryWithItemSize: sizeof(of_unichar_t)
count: prefixLength];
tmp = [self allocMemoryWithSize: sizeof(of_unichar_t)
count: prefixLength];
@try {
OFAutoreleasePool *pool;
[self getCharacters: tmp
inRange: of_range(0, prefixLength)];
pool = [[OFAutoreleasePool alloc] init];
|
︙ | | |
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
|
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
|
-
-
+
+
|
int compare;
if ((suffixLength = [suffix length]) > [self length])
return NO;
length = [self length];
tmp = [self allocMemoryWithItemSize: sizeof(of_unichar_t)
count: suffixLength];
tmp = [self allocMemoryWithSize: sizeof(of_unichar_t)
count: suffixLength];
@try {
OFAutoreleasePool *pool;
[self getCharacters: tmp
inRange: of_range(length - suffixLength,
suffixLength)];
|
︙ | | |
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
|
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
|
-
-
+
+
-
-
+
+
|
- (const of_unichar_t*)unicodeString
{
OFObject *object = [[[OFObject alloc] init] autorelease];
size_t length = [self length];
of_unichar_t *ret;
ret = [object allocMemoryWithItemSize: sizeof(of_unichar_t)
count: length + 1];
ret = [object allocMemoryWithSize: sizeof(of_unichar_t)
count: length + 1];
[self getCharacters: ret
inRange: of_range(0, length)];
ret[length] = 0;
return ret;
}
- (const uint16_t*)UTF16String
{
OFObject *object = [[[OFObject alloc] init] autorelease];
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
const of_unichar_t *unicodeString = [self unicodeString];
size_t length = [self length];
uint16_t *ret;
size_t i, j;
/* Allocate memory for the worst case */
ret = [object allocMemoryWithItemSize: sizeof(uint16_t)
count: length * 2 + 1];
ret = [object allocMemoryWithSize: sizeof(uint16_t)
count: length * 2 + 1];
j = 0;
for (i = 0; i < length; i++) {
of_unichar_t c = unicodeString[i];
if (c > 0x10FFFF)
|
︙ | | |
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
|
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
|
-
+
|
ret[j++] = of_bswap16_if_le(c);
}
ret[j] = 0;
@try {
ret = [object resizeMemory: ret
itemSize: sizeof(uint16_t)
size: sizeof(uint16_t)
count: j + 1];
} @catch (OFOutOfMemoryException *e) {
/* We don't care, as we only tried to make it smaller */
}
[pool release];
|
︙ | | |
Modified src/OFString_UTF8.m
from [5faa6d539b]
to [65dd22d751].
︙ | | |
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
-
+
|
if (bytes == 0)
@throw [OFInvalidEncodingException
exceptionWithClass: isa];
s->cStringLength += bytes - 1;
s->cString = [self
resizeMemory: s->cString
toSize: s->cStringLength + 1];
size: s->cStringLength + 1];
memcpy(s->cString + j, buffer, bytes);
j += bytes;
}
s->cString[s->cStringLength] = 0;
|
︙ | | |
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
-
+
|
if (characterBytes == 0)
@throw [OFInvalidEncodingException
exceptionWithClass: isa];
s->cStringLength += characterBytes - 1;
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength + 1];
size: s->cStringLength + 1];
memcpy(s->cString + j, buffer, characterBytes);
j += characterBytes;
}
s->cString[s->cStringLength] = 0;
} @catch (id e) {
|
︙ | | |
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
-
+
|
}
}
s->cString[j] = '\0';
@try {
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength + 1];
size: s->cStringLength + 1];
} @catch (OFOutOfMemoryException *e) {
/* We don't care, as we only tried to make it smaller */
}
} @catch (id e) {
[self release];
@throw e;
}
|
︙ | | |
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
|
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
|
-
+
|
}
}
s->cString[j] = '\0';
@try {
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength + 1];
size: s->cStringLength + 1];
} @catch (OFOutOfMemoryException *e) {
/* We don't care, as we only tried to make it smaller */
}
} @catch (id e) {
[self release];
@throw e;
}
|
︙ | | |
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
|
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
|
-
-
+
+
|
- (const of_unichar_t*)unicodeString
{
OFObject *object = [[[OFObject alloc] init] autorelease];
of_unichar_t *ret;
size_t i, j;
ret = [object allocMemoryWithItemSize: sizeof(of_unichar_t)
count: s->length + 1];
ret = [object allocMemoryWithSize: sizeof(of_unichar_t)
count: s->length + 1];
i = 0;
j = 0;
while (i < s->cStringLength) {
of_unichar_t c;
size_t cLen;
|
︙ | | |
Modified src/OFTCPSocket+SOCKS5.m
from [fa4c8cce5e]
to [a16701d00f].
︙ | | |
25
26
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
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
|
25
26
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
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
|
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
|
@implementation OFTCPSocket (SOCKS5)
- (void)_SOCKS5ConnectToHost: (OFString*)host
port: (uint16_t)port
{
const char request[] = { 5, 1, 0, 3 };
char reply[256];
BOOL oldBuffersWrites;
BOOL oldWriteBufferEnabled;
/* 5 1 0 -> no authentication */
[self writeNBytes: 3
fromBuffer: request];
[self writeBuffer: request
length: 3];
[self readExactlyNBytes: 2
intoBuffer: reply];
[self readIntoBuffer: reply
exactLength: 2];
if (reply[0] != 5 || reply[1] != 0) {
[self close];
@throw [OFConnectionFailedException
exceptionWithClass: isa
socket: self
host: host
port: port];
}
oldBuffersWrites = [self buffersWrites];
[self setBuffersWrites: YES];
oldWriteBufferEnabled = [self writeBufferEnabled];
[self setWriteBufferEnabled: YES];
/* CONNECT request */
[self writeNBytes: 4
fromBuffer: request];
[self writeBuffer: request
length: 4];
[self writeInt8:
[host cStringLengthWithEncoding: OF_STRING_ENCODING_NATIVE]];
[self writeNBytes: [host cStringLengthWithEncoding:
[self writeBuffer: [host cStringWithEncoding:
OF_STRING_ENCODING_NATIVE]
fromBuffer: [host cStringWithEncoding:
length: [host cStringLengthWithEncoding:
OF_STRING_ENCODING_NATIVE]];
[self writeBigEndianInt16: port];
[self flushWriteBuffer];
[self setBuffersWrites: oldBuffersWrites];
[self setWriteBufferEnabled: oldWriteBufferEnabled];
[self readExactlyNBytes: 4
intoBuffer: reply];
[self readIntoBuffer: reply
exactLength: 4];
if (reply[0] != 5 || reply[1] != 0 || reply[2] != 0) {
[self close];
@throw [OFConnectionFailedException exceptionWithClass: isa
socket: self
host: host
port: port];
}
/* Skip the rest of the reply */
switch (reply[3]) {
case 1: /* IPv4 */
[self readExactlyNBytes: 4
intoBuffer: reply];
[self readIntoBuffer: reply
exactLength: 4];
break;
case 3: /* Domainname */
[self readExactlyNBytes: [self readInt8]
intoBuffer: reply];
[self readIntoBuffer: reply
exactLength: [self readInt8]];
break;
case 4: /* IPv6 */
[self readExactlyNBytes: 16
intoBuffer: reply];
[self readIntoBuffer: reply
exactLength: 16];
break;
default:
[self close];
@throw [OFConnectionFailedException exceptionWithClass: isa
socket: self
host: host
port: port];
|
︙ | | |
Modified src/OFXMLElement.m
from [23e15b2038]
to [dff10de86f].
︙ | | |
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
|
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
|
-
+
-
+
|
/* Start of tag */
cString[i++] = '<';
if (prefix != nil && ![ns isEqual: defaultNS]) {
length += [prefix UTF8StringLength] + 1;
@try {
cString = [self resizeMemory: cString
toSize: length];
size: length];
} @catch (id e) {
[self freeMemory: cString];
@throw e;
}
memcpy(cString + i, [prefix UTF8String],
[prefix UTF8StringLength]);
i += [prefix UTF8StringLength];
cString[i++] = ':';
}
memcpy(cString + i, [name UTF8String], [name UTF8StringLength]);
i += [name UTF8StringLength];
/* xmlns if necessary */
if (prefix == nil && ((ns != nil && ![ns isEqual: defaultNS]) ||
(ns == nil && defaultNS != nil))) {
length += [ns UTF8StringLength] + 9;
@try {
cString = [self resizeMemory: cString
toSize: length];
size: length];
} @catch (id e) {
[self freeMemory: cString];
@throw e;
}
memcpy(cString + i, " xmlns='", 8);
i += 8;
|
︙ | | |
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
|
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
|
-
+
|
length += [attributeName UTF8StringLength] +
(attributePrefix != nil ?
[attributePrefix UTF8StringLength] + 1 : 0) +
[tmp UTF8StringLength] + 4;
@try {
cString = [self resizeMemory: cString
toSize: length];
size: length];
} @catch (id e) {
[self freeMemory: cString];
@throw e;
}
cString[i++] = ' ';
if (attributePrefix != nil) {
|
︙ | | |
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
|
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
|
-
+
|
if (indent)
[tmp addItem: "\n"];
length += [tmp count] + [name UTF8StringLength] + 2 +
(indent ? level * indentation : 0);
@try {
cString = [self resizeMemory: cString
toSize: length];
size: length];
} @catch (id e) {
[self freeMemory: cString];
@throw e;
}
cString[i++] = '>';
|
︙ | | |
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
|
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
|
-
+
|
cString[i++] = '<';
cString[i++] = '/';
if (prefix != nil) {
length += [prefix UTF8StringLength] + 1;
@try {
cString = [self resizeMemory: cString
toSize: length];
size: length];
} @catch (id e) {
[self freeMemory: cString];
@throw e;
}
memcpy(cString + i, [prefix UTF8String],
[prefix UTF8StringLength]);
|
︙ | | |
Modified src/OFXMLParser.h
from [6be0e684f3]
to [81cc682f41].
︙ | | |
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
-
+
|
/**
* \brief Parses the specified buffer with the specified size.
*
* \param buffer The buffer to parse
* \param length The length of the buffer
*/
- (void)parseBuffer: (const char*)buffer
withLength: (size_t)length;
length: (size_t)length;
/**
* \brief Parses the specified string.
*
* \param string The string to parse
*/
- (void)parseString: (OFString*)string;
|
︙ | | |
Modified src/OFXMLParser.m
from [2619682154]
to [a3d968177a].
︙ | | |
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
-
+
|
- (void)setDelegate: (id <OFXMLParserDelegate>)delegate_
{
delegate = delegate_;
}
- (void)parseBuffer: (const char*)buffer
withLength: (size_t)length
length: (size_t)length
{
size_t i, last = 0;
for (i = 0; i < length; i++) {
size_t j = i;
lookupTable[state](self, selectors[state], buffer, &i, &last);
|
︙ | | |
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
|
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
|
-
+
-
-
+
+
-
+
|
if (length - last > 0 && state != OF_XMLPARSER_IN_TAG)
cache_append(cache, buffer + last, encoding, length - last);
}
- (void)parseString: (OFString*)string
{
[self parseBuffer: [string UTF8String]
withLength: [string UTF8StringLength]];
length: [string UTF8StringLength]];
}
- (void)parseStream: (OFStream*)stream
{
char *buffer = [self allocMemoryWithSize: of_pagesize];
@try {
while (![stream isAtEndOfStream]) {
size_t length = [stream readNBytes: of_pagesize
intoBuffer: buffer];
size_t length = [stream readIntoBuffer: buffer
length: of_pagesize];
[self parseBuffer: buffer
withLength: length];
length: length];
}
} @finally {
[self freeMemory: buffer];
}
}
- (void)parseFile: (OFString*)path
|
︙ | | |
Modified src/ObjFW.h
from [951501aebd]
to [d4c97a2a17].
︙ | | |
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
+
|
#import "OFEnumerationMutationException.h"
#import "OFHashAlreadyCalculatedException.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidJSONException.h"
#import "OFInvalidServerReplyException.h"
#import "OFLinkFailedException.h"
#import "OFListenFailedException.h"
#import "OFMalformedXMLException.h"
#import "OFMemoryNotPartOfObjectException.h"
#import "OFMutexLockFailedException.h"
#import "OFMutexStillLockedException.h"
|
︙ | | |
Modified src/exceptions/Makefile
from [7c2fda7df6]
to [9c19595da9].
︙ | | |
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
+
|
OFException.m \
OFHTTPRequestFailedException.m \
OFHashAlreadyCalculatedException.m \
OFInitializationFailedException.m \
OFInvalidArgumentException.m \
OFInvalidEncodingException.m \
OFInvalidFormatException.m \
OFInvalidJSONException.m \
OFInvalidServerReplyException.m \
OFLinkFailedException.m \
OFListenFailedException.m \
OFMalformedXMLException.m \
OFMemoryNotPartOfObjectException.m \
OFMutexLockFailedException.m \
OFMutexStillLockedException.m \
|
︙ | | |
Added src/exceptions/OFInvalidJSONException.h version [28abef2a60].
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012
* Jonathan Schleifer <js@webkeks.org>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#import "OFException.h"
/**
* \brief An exception indicating a JSON representation is invalid.
*/
@interface OFInvalidJSONException: OFException
{
size_t line;
}
#ifdef OF_HAVE_PROPERTIES
@property (readonly) size_t line;
#endif
/**
* \param class_ The class of the object which caused the exception
* \param line The line in which the parsing error encountered
* \return A new invalid JSON exception
*/
+ exceptionWithClass: (Class)class_
line: (size_t)line;
/**
* Initializes an already allocated invalid JSON exception.
*
* \param class_ The class of the object which caused the exception
* \param line The line in which the parsing error encountered
* \return An initialized invalid JSON exception
*/
- initWithClass: (Class)class_
line: (size_t)line;
/**
* \return The line in which parsing the JSON representation failed
*/
- (size_t)line;
@end
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Added src/exceptions/OFInvalidJSONException.m version [ca1d0c629a].
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
60
61
62
63
64
65
66
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012
* Jonathan Schleifer <js@webkeks.org>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "OFInvalidJSONException.h"
#import "OFString.h"
#import "OFNotImplementedException.h"
@implementation OFInvalidJSONException
+ exceptionWithClass: (Class)class_
line: (size_t)line
{
return [[[self alloc] initWithClass: class_
line: line] autorelease];
}
- init
{
Class c = isa;
[self release];
@throw [OFNotImplementedException exceptionWithClass: c
selector: _cmd];
}
- initWithClass: (Class)class_
line: (size_t)line_
{
self = [super initWithClass: class_];
line = line_;
return self;
}
- (OFString*)description
{
if (description != nil)
return description;
description = [[OFString alloc] initWithFormat:
@"The JSON representation class %@ tried to parse is invalid in "
@"line %zd!", inClass, line];
return description;
}
- (size_t)line
{
return line;
}
@end
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Modified tests/OFJSONTests.m
from [ae9d04304d]
to [c4b49139b1].
︙ | | |
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
-
+
|
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OFNull.h"
#import "OFAutoreleasePool.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidJSONException.h"
#import "TestsAppDelegate.h"
static OFString *module = @"OFJSON";
@implementation TestsAppDelegate (JSONTests)
- (void)JSONTests
|
︙ | | |
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
-
+
-
+
-
+
-
+
|
nil];
TEST(@"-[JSONValue #1]", [[s JSONValue] isEqual: d])
TEST(@"-[JSONRepresentation]", [[d JSONRepresentation] isEqual:
@"{\"foo\":\"ba\\r\",\"x\":[0.5,15,null,\"foo\",false]}"])
EXPECT_EXCEPTION(@"-[JSONValue #2]", OFInvalidEncodingException,
EXPECT_EXCEPTION(@"-[JSONValue #2]", OFInvalidJSONException,
[@"{" JSONValue])
EXPECT_EXCEPTION(@"-[JSONValue #3]", OFInvalidEncodingException,
EXPECT_EXCEPTION(@"-[JSONValue #3]", OFInvalidJSONException,
[@"]" JSONValue])
EXPECT_EXCEPTION(@"-[JSONValue #4]", OFInvalidEncodingException,
EXPECT_EXCEPTION(@"-[JSONValue #4]", OFInvalidJSONException,
[@"bar" JSONValue])
EXPECT_EXCEPTION(@"-[JSONValue #5]", OFInvalidEncodingException,
EXPECT_EXCEPTION(@"-[JSONValue #5]", OFInvalidJSONException,
[@"[\"a\" \"b\"]" JSONValue])
[pool drain];
}
@end
|
Modified tests/OFMD5HashTests.m
from [dbff846819]
to [3d9bebb920].
︙ | | |
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
-
-
+
+
|
OFFile *f = [OFFile fileWithPath: @"testfile.bin"
mode: @"rb"];
TEST(@"+[MD5Hash]", (md5 = [OFMD5Hash MD5Hash]))
while (![f isAtEndOfStream]) {
char buf[64];
size_t len = [f readNBytes: 64
intoBuffer: buf];
size_t len = [f readIntoBuffer: buf
length: 64];
[md5 updateWithBuffer: buf
length: len];
}
[f close];
TEST(@"-[digest]",
!memcmp([md5 digest], testfile_md5, OF_MD5_DIGEST_SIZE))
|
︙ | | |
Modified tests/OFObjectTests.m
from [4509cfc31c]
to [dd072d17db].
︙ | | |
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
|
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
|
-
+
-
+
-
+
|
OFOutOfMemoryException, [obj allocMemoryWithSize: SIZE_MAX - 128])
EXPECT_EXCEPTION(@"Detect out of memory on resize",
OFOutOfMemoryException,
{
p = [obj allocMemoryWithSize: 1];
[obj resizeMemory: p
toSize: SIZE_MAX - 128];
size: SIZE_MAX - 128];
})
[obj freeMemory: p];
TEST(@"Allocate when trying to resize NULL",
(p = [obj resizeMemory: NULL
toSize: 1024]) != NULL)
size: 1024]) != NULL)
[obj freeMemory: p];
EXPECT_EXCEPTION(@"Detect resizing of memory not allocated by object",
OFMemoryNotPartOfObjectException, [obj resizeMemory: tmp
toSize: 2048])
size: 2048])
[self freeMemory: tmp];
TEST(@"+[description]",
[[OFObject description] isEqual: @"OFObject"] &&
[[MyObj description] isEqual: @"MyObj"])
o = [[[OFObject alloc] init] autorelease];
|
︙ | | |
Modified tests/OFSHA1HashTests.m
from [73080758bd]
to [1cad042110].
︙ | | |
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
-
-
+
+
|
OFFile *f = [OFFile fileWithPath: @"testfile.bin"
mode: @"rb"];
TEST(@"+[SHA1Hash]", (sha1 = [OFSHA1Hash SHA1Hash]))
while (![f isAtEndOfStream]) {
char buf[64];
size_t len = [f readNBytes: 64
intoBuffer: buf];
size_t len = [f readIntoBuffer: buf
length: 64];
[sha1 updateWithBuffer: buf
length: len];
}
[f close];
TEST(@"-[digest]",
!memcmp([sha1 digest], testfile_sha1, OF_SHA1_DIGEST_SIZE))
|
︙ | | |
Modified tests/OFStreamTests.m
from [25c328e52e]
to [cf598bf19b].
︙ | | |
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
-
-
+
+
|
@implementation StreamTester
- (BOOL)_isAtEndOfStream
{
return (state > 1 ? YES : NO);
}
- (size_t)_readNBytes: (size_t)size
intoBuffer: (void*)buffer
- (size_t)_readIntoBuffer: (void*)buffer
length: (size_t)size
{
switch (state) {
case 0:
if (size < 1)
return 0;
memcpy(buffer, "f", 1);
|
︙ | | |
Modified tests/OFTCPSocketTests.m
from [3905bc918e]
to [090030e624].
︙ | | |
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
-
-
+
+
|
TEST(@"-[accept]", (accepted = [server accept]))
TEST(@"-[remoteAddress]",
[[accepted remoteAddress] isEqual: @"127.0.0.1"])
TEST(@"-[writeString:]", [client writeString: @"Hello!"])
TEST(@"-[readNBytes:intoBuffer:]", [accepted readNBytes: 6
intoBuffer: buf] &&
TEST(@"-[readIntoBuffer:length:]", [accepted readIntoBuffer: buf
length: 6] &&
!memcmp(buf, "Hello!", 6))
[pool drain];
}
@end
|
Modified tests/OFXMLParserTests.m
from [56d6347fce]
to [c34c13b545].
︙ | | |
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
-
+
-
+
|
for (j = 0; j < len; j+= 2) {
if ([parser finishedParsing])
abort();
if (j + 2 > len)
[parser parseBuffer: str + j
withLength: 1];
length: 1];
else
[parser parseBuffer: str + j
withLength: 2];
length: 2];
}
TEST(@"Checking if everything was parsed",
i == 32 && [parser lineNumber] == 18)
TEST(@"-[finishedParsing]", [parser finishedParsing])
|
︙ | | |