Comment: | Make use of C99-style for loops |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
e0b91676939fb364b5add73d465daf88 |
User & Date: | js on 2016-02-21 15:37:42 |
Other Links: | manifest | tags |
2016-02-21
| ||
16:25 | OFInflateStream: Fix memory leak on early dealloc check-in: 1eb94a26f6 user: js tags: trunk | |
15:37 | Make use of C99-style for loops check-in: e0b9167693 user: js tags: trunk | |
12:04 | Add +[OFURL fileURLWithPath:] check-in: 3eb411511e user: js tags: trunk | |
Modified generators/TableGenerator.m from [a1cc0c76e7] to [6b76762325].
︙ | ︙ | |||
171 172 173 174 175 176 177 | } - (void)writeTablesToFile: (OFString*)path { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"wb"]; | < | | | | | | | | | | | | | 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 | } - (void)writeTablesToFile: (OFString*)path { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"wb"]; [file writeString: COPYRIGHT @"#include \"config.h\"\n" @"\n" @"#import \"OFString.h\"\n\n" @"static const of_unichar_t emptyPage[0x100] = { 0 };\n\n"]; /* Write uppercasePage%u */ for (of_unichar_t i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (of_unichar_t j = i; j < i + 0x100; j++) { if (_uppercaseTable[j] != 0) { isEmpty = false; _uppercaseTableSize = i >> 8; _uppercaseTableUsed[_uppercaseTableSize] = 1; break; } } if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeString: [OFString stringWithFormat: @"static const of_unichar_t " @"uppercasePage%u[0x100] = {\n", i >> 8]]; for (of_unichar_t j = i; j < i + 0x100; j += 8) [file writeString: [OFString stringWithFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", _uppercaseTable[j], _uppercaseTable[j + 1], _uppercaseTable[j + 2], _uppercaseTable[j + 3], _uppercaseTable[j + 4], _uppercaseTable[j + 5], _uppercaseTable[j + 6], _uppercaseTable[j + 7]]]; [file writeString: @"};\n\n"]; objc_autoreleasePoolPop(pool2); } } /* Write lowercasePage%u */ for (of_unichar_t i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (of_unichar_t j = i; j < i + 0x100; j++) { if (_lowercaseTable[j] != 0) { isEmpty = false; _lowercaseTableSize = i >> 8; _lowercaseTableUsed[_lowercaseTableSize] = 1; break; } } if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeString: [OFString stringWithFormat: @"static const of_unichar_t " @"lowercasePage%u[0x100] = {\n", i >> 8]]; for (of_unichar_t j = i; j < i + 0x100; j += 8) [file writeString: [OFString stringWithFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", _lowercaseTable[j], _lowercaseTable[j + 1], _lowercaseTable[j + 2], _lowercaseTable[j + 3], _lowercaseTable[j + 4], _lowercaseTable[j + 5], _lowercaseTable[j + 6], _lowercaseTable[j + 7]]]; [file writeString: @"};\n\n"]; objc_autoreleasePoolPop(pool2); } } /* Write titlecasePage%u if it does NOT match uppercasePage%u */ for (of_unichar_t i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (of_unichar_t j = i; j < i + 0x100; j++) { if (_titlecaseTable[j] != 0) { isEmpty = !memcmp(_uppercaseTable + i, _titlecaseTable + i, 256 * sizeof(of_unichar_t)); _titlecaseTableSize = i >> 8; _titlecaseTableUsed[_titlecaseTableSize] = (isEmpty ? 2 : 1); break; } } if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeString: [OFString stringWithFormat: @"static const of_unichar_t " @"titlecasePage%u[0x100] = {\n", i >> 8]]; for (of_unichar_t j = i; j < i + 0x100; j += 8) [file writeString: [OFString stringWithFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", _titlecaseTable[j], _titlecaseTable[j + 1], _titlecaseTable[j + 2], _titlecaseTable[j + 3], _titlecaseTable[j + 4], _titlecaseTable[j + 5], _titlecaseTable[j + 6], _titlecaseTable[j + 7]]]; [file writeString: @"};\n\n"]; objc_autoreleasePoolPop(pool2); } } /* Write casefoldingPage%u if it does NOT match lowercasePage%u */ for (of_unichar_t i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (of_unichar_t j = i; j < i + 0x100; j++) { if (_casefoldingTable[j] != 0) { isEmpty = !memcmp(_lowercaseTable + i, _casefoldingTable + i, 256 * sizeof(of_unichar_t)); _casefoldingTableSize = i >> 8; _casefoldingTableUsed[_casefoldingTableSize] = (isEmpty ? 2 : 1); break; } } if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeString: [OFString stringWithFormat: @"static const of_unichar_t " @"casefoldingPage%u[0x100] = {\n", i >> 8]]; for (of_unichar_t j = i; j < i + 0x100; j += 8) [file writeString: [OFString stringWithFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", _casefoldingTable[j], _casefoldingTable[j + 1], _casefoldingTable[j + 2], _casefoldingTable[j + 3], _casefoldingTable[j + 4], |
︙ | ︙ | |||
351 352 353 354 355 356 357 | _casefoldingTableSize++; /* Write of_unicode_uppercase_table */ [file writeString: [OFString stringWithFormat: @"const of_unichar_t* const of_unicode_uppercase_table[0x%X] = " @"{\n\t", _uppercaseTableSize]]; | | | 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | _casefoldingTableSize++; /* Write of_unicode_uppercase_table */ [file writeString: [OFString stringWithFormat: @"const of_unichar_t* const of_unicode_uppercase_table[0x%X] = " @"{\n\t", _uppercaseTableSize]]; for (of_unichar_t i = 0; i < _uppercaseTableSize; i++) { if (_uppercaseTableUsed[i]) { [file writeString: [OFString stringWithFormat: @"uppercasePage%u", i]]; } else [file writeString: @"emptyPage"]; if (i + 1 < _uppercaseTableSize) { |
︙ | ︙ | |||
373 374 375 376 377 378 379 | [file writeString: @"\n};\n\n"]; /* Write of_unicode_lowercase_table */ [file writeString: [OFString stringWithFormat: @"const of_unichar_t* const of_unicode_lowercase_table[0x%X] = " @"{\n\t", _lowercaseTableSize]]; | | | 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | [file writeString: @"\n};\n\n"]; /* Write of_unicode_lowercase_table */ [file writeString: [OFString stringWithFormat: @"const of_unichar_t* const of_unicode_lowercase_table[0x%X] = " @"{\n\t", _lowercaseTableSize]]; for (of_unichar_t i = 0; i < _lowercaseTableSize; i++) { if (_lowercaseTableUsed[i]) { [file writeString: [OFString stringWithFormat: @"lowercasePage%u", i]]; } else [file writeString: @"emptyPage"]; if (i + 1 < _lowercaseTableSize) { |
︙ | ︙ | |||
395 396 397 398 399 400 401 | [file writeString: @"\n};\n\n"]; /* Write of_unicode_titlecase_table */ [file writeString: [OFString stringWithFormat: @"const of_unichar_t* const of_unicode_titlecase_table[0x%X] = {" @"\n\t", _titlecaseTableSize]]; | | | 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | [file writeString: @"\n};\n\n"]; /* Write of_unicode_titlecase_table */ [file writeString: [OFString stringWithFormat: @"const of_unichar_t* const of_unicode_titlecase_table[0x%X] = {" @"\n\t", _titlecaseTableSize]]; for (of_unichar_t i = 0; i < _titlecaseTableSize; i++) { if (_titlecaseTableUsed[i] == 1) { [file writeString: [OFString stringWithFormat: @"titlecasePage%u", i]]; } else if (_titlecaseTableUsed[i] == 2) { [file writeString: [OFString stringWithFormat: @"uppercasePage%u", i]]; } else |
︙ | ︙ | |||
420 421 422 423 424 425 426 | [file writeString: @"\n};\n\n"]; /* Write of_unicode_casefolding_table */ [file writeString: [OFString stringWithFormat: @"const of_unichar_t* const of_unicode_casefolding_table[0x%X] = " @"{\n\t", _casefoldingTableSize]]; | | | 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | [file writeString: @"\n};\n\n"]; /* Write of_unicode_casefolding_table */ [file writeString: [OFString stringWithFormat: @"const of_unichar_t* const of_unicode_casefolding_table[0x%X] = " @"{\n\t", _casefoldingTableSize]]; for (of_unichar_t i = 0; i < _casefoldingTableSize; i++) { if (_casefoldingTableUsed[i] == 1) { [file writeString: [OFString stringWithFormat: @"casefoldingPage%u", i]]; } else if (_casefoldingTableUsed[i] == 2) { [file writeString: [OFString stringWithFormat: @"lowercasePage%u", i]]; } else |
︙ | ︙ |
Modified src/OFApplication.m from [932d52d201] to [8b89a99f6e].
︙ | ︙ | |||
331 332 333 334 335 336 337 | - (void)OF_setArgumentCount: (int*)argc andArgumentValues: (char***)argv { #ifndef OF_WINDOWS void *pool = objc_autoreleasePoolPush(); OFMutableArray *arguments; | < | < | | 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 | - (void)OF_setArgumentCount: (int*)argc andArgumentValues: (char***)argv { #ifndef OF_WINDOWS void *pool = objc_autoreleasePoolPush(); OFMutableArray *arguments; of_string_encoding_t encoding; _argc = argc; _argv = argv; encoding = [OFSystemInfo native8BitEncoding]; # ifndef OF_NINTENDO_DS if (*argc > 0) { # else if (__system_argv->argvMagic == ARGV_MAGIC && __system_argv->argc > 0) { # endif _programName = [[OFString alloc] initWithCString: (*argv)[0] encoding: encoding]; arguments = [[OFMutableArray alloc] init]; _arguments = arguments; for (int i = 1; i < *argc; i++) [arguments addObject: [OFString stringWithCString: (*argv)[i] encoding: encoding]]; [arguments makeImmutable]; } objc_autoreleasePoolPop(pool); #else _argc = argc; _argv = argv; #endif } #ifdef OF_WINDOWS - (void)OF_setArgumentCount: (int)argc andWideArgumentValues: (wchar_t**)argv { void *pool = objc_autoreleasePoolPush(); OFMutableArray *arguments; if (argc > 0) { _programName = [[OFString alloc] initWithUTF16String: argv[0]]; arguments = [[OFMutableArray alloc] init]; for (int i = 1; i < argc; i++) [arguments addObject: [OFString stringWithUTF16String: argv[i]]]; [arguments makeImmutable]; _arguments = arguments; } |
︙ | ︙ |
Modified src/OFArray.m from [a01924feba] to [a881a5d8d9].
︙ | ︙ | |||
230 231 232 233 234 235 236 | { OF_UNRECOGNIZED_SELECTOR } - (void)getObjects: (id*)buffer inRange: (of_range_t)range { | < < | | 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | { OF_UNRECOGNIZED_SELECTOR } - (void)getObjects: (id*)buffer inRange: (of_range_t)range { for (size_t i = 0; i < range.length; i++) buffer[i] = [self objectAtIndex: range.location + i]; } - (id const*)objects { OFObject *container; size_t count; |
︙ | ︙ | |||
443 444 445 446 447 448 449 | return ret; } - (bool)isEqual: (id)object { /* FIXME: Optimize (for example, buffer of 16 for each) */ OFArray *otherArray; | | | | 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 | return ret; } - (bool)isEqual: (id)object { /* FIXME: Optimize (for example, buffer of 16 for each) */ OFArray *otherArray; size_t count; if (![object isKindOfClass: [OFArray class]]) return false; otherArray = object; count = [self count]; if (count != [otherArray count]) return false; for (size_t i = 0; i < count; i++) if (![[self objectAtIndex: i] isEqual: [otherArray objectAtIndex: i]]) return false; return true; } |
︙ | ︙ |
Modified src/OFArray_adjacent.m from [66616ef22a] to [b1e29fe508].
︙ | ︙ | |||
84 85 86 87 88 89 90 | return self; } - initWithArray: (OFArray*)array { id const *objects; | | | | < | < < | | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | return self; } - initWithArray: (OFArray*)array { id const *objects; size_t count; self = [super init]; if (array == nil) return self; @try { objects = [array objects]; count = [array count]; _array = [[OFDataArray alloc] initWithItemSize: sizeof(id) capacity: count]; } @catch (id e) { [self release]; @throw e; } @try { for (size_t i = 0; i < count; i++) [objects[i] retain]; [_array addItems: objects count: count]; } @catch (id e) { for (size_t i = 0; i < count; i++) [objects[i] release]; /* Prevent double-release of objects */ [_array release]; _array = nil; [self release]; @throw e; } return self; } - initWithObjects: (id const*)objects count: (size_t)count { self = [self init]; @try { bool ok = true; for (size_t i = 0; i < count; i++) { if (objects[i] == nil) ok = false; [objects[i] retain]; } if (!ok) @throw [OFInvalidArgumentException exception]; [_array addItems: objects count: count]; } @catch (id e) { for (size_t i = 0; i < count; i++) [objects[i] release]; [self release]; @throw e; } return self; |
︙ | ︙ | |||
214 215 216 217 218 219 220 | return *((id*)[_array itemAtIndex: index]); } - (void)getObjects: (id*)buffer inRange: (of_range_t)range { id *objects = [_array items]; | | | | | | | | 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 | return *((id*)[_array itemAtIndex: index]); } - (void)getObjects: (id*)buffer inRange: (of_range_t)range { id *objects = [_array items]; size_t count = [_array count]; if (range.length > SIZE_MAX - range.location || range.location + range.length > count) @throw [OFOutOfRangeException exception]; for (size_t i = 0; i < range.length; i++) buffer[i] = objects[range.location + i]; } - (size_t)indexOfObject: (id)object { id *objects; size_t count; if (object == nil) return OF_NOT_FOUND; objects = [_array items]; count = [_array count]; for (size_t i = 0; i < count; i++) if ([objects[i] isEqual: object]) return i; return OF_NOT_FOUND; } - (size_t)indexOfObjectIdenticalTo: (id)object { id *objects; size_t count; if (object == nil) return OF_NOT_FOUND; objects = [_array items]; count = [_array count]; for (size_t i = 0; i < count; i++) if (objects[i] == object) return i; return OF_NOT_FOUND; } |
︙ | ︙ | |||
280 281 282 283 284 285 286 | range: range]; } - (bool)isEqual: (id)object { OFArray *otherArray; id const *objects, *otherObjects; | | | | | | 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 | range: range]; } - (bool)isEqual: (id)object { OFArray *otherArray; id const *objects, *otherObjects; size_t count; if (![object isKindOfClass: [OFArray_adjacent class]] && ![object isKindOfClass: [OFMutableArray_adjacent class]]) return [super isEqual: object]; otherArray = object; count = [_array count]; if (count != [otherArray count]) return false; objects = [_array items]; otherObjects = [otherArray objects]; for (size_t i = 0; i < count; i++) if (![objects[i] isEqual: otherObjects[i]]) return false; return true; } - (uint32_t)hash { id *objects = [_array items]; size_t count = [_array count]; uint32_t hash; OF_HASH_INIT(hash); for (size_t i = 0; i < count; i++) OF_HASH_ADD_HASH(hash, [objects[i] hash]); OF_HASH_FINALIZE(hash); return hash; } |
︙ | ︙ | |||
348 349 350 351 352 353 354 | return (int)count; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { id *objects = [_array items]; | | | | | | 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 | return (int)count; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { id *objects = [_array items]; size_t count = [_array count]; bool stop = false; for (size_t i = 0; i < count && !stop; i++) block(objects[i], i, &stop); } #endif - (void)dealloc { id *objects = [_array items]; size_t count = [_array count]; for (size_t i = 0; i < count; i++) [objects[i] release]; [_array release]; [super dealloc]; } @end |
Modified src/OFArray_adjacentSubarray.m from [1abd78bce4] to [a1caaaae82].
︙ | ︙ | |||
26 27 28 29 30 31 32 | return [_array objects] + _range.location; } - (bool)isEqual: (id)object { OFArray *otherArray; id const *objects, *otherObjects; | < | < | | 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 | return [_array objects] + _range.location; } - (bool)isEqual: (id)object { OFArray *otherArray; id const *objects, *otherObjects; if (![object isKindOfClass: [OFArray_adjacent class]] && ![object isKindOfClass: [OFMutableArray_adjacent class]]) return [super isEqual: object]; otherArray = object; if (_range.length != [otherArray count]) return false; objects = [self objects]; otherObjects = [otherArray objects]; for (size_t i = 0; i < _range.length; i++) if (![objects[i] isEqual: otherObjects[i]]) return false; return true; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { id const *objects = [self objects]; bool stop = false; for (size_t i = 0; i < _range.length && !stop; i++) block(objects[i], i, &stop); } #endif @end |
Modified src/OFAutoreleasePool.m from [f48e2b8969] to [98e7771e8f].
︙ | ︙ | |||
51 52 53 54 55 56 57 | + alloc { #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OFAutoreleasePool **cache = of_tlskey_get(cacheKey); #endif if (cache != NULL) { | < < | | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | + alloc { #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OFAutoreleasePool **cache = of_tlskey_get(cacheKey); #endif if (cache != NULL) { for (size_t i = 0; i < MAX_CACHE_SIZE; i++) { if (cache[i] != NULL) { OFAutoreleasePool *pool = cache[i]; cache[i] = NULL; return pool; } } } |
︙ | ︙ | |||
75 76 77 78 79 80 81 | } + (void)OF_handleThreadTermination { #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OFAutoreleasePool **cache = of_tlskey_get(cacheKey); #endif | < | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | } + (void)OF_handleThreadTermination { #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OFAutoreleasePool **cache = of_tlskey_get(cacheKey); #endif if (cache != NULL) { for (size_t i = 0; i < MAX_CACHE_SIZE; i++) [cache[i] OF_super_dealloc]; free(cache); cache = NULL; } } |
︙ | ︙ | |||
154 155 156 157 158 159 160 | free(cache); cache = NULL; } #endif } if (cache != NULL) { | < < | | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | free(cache); cache = NULL; } #endif } if (cache != NULL) { for (size_t i = 0; i < MAX_CACHE_SIZE; i++) { if (cache[i] == NULL) { _pool = NULL; _ignoreRelease = false; cache[i] = self; return; |
︙ | ︙ |
Modified src/OFBlock.m from [39f7323be4] to [49bc2fd375].
︙ | ︙ | |||
306 307 308 309 310 311 312 | } } @implementation OFBlock + (void)load { #ifndef OF_HAVE_ATOMIC_OPS | < < | | 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | } } @implementation OFBlock + (void)load { #ifndef OF_HAVE_ATOMIC_OPS for (size_t i = 0; i < NUM_SPINLOCKS; i++) if (!of_spinlock_new(&spinlocks[i])) @throw [OFInitializationFailedException exceptionWithClass: self]; #endif #ifdef OF_APPLE_RUNTIME Class tmp; |
︙ | ︙ |
Modified src/OFCountedSet.m from [62c23de042] to [0fe79da407].
︙ | ︙ | |||
235 236 237 238 239 240 241 | { void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet*)set; for (id object in countedSet) { | | | | | | 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 | { void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet*)set; for (id object in countedSet) { size_t count = [countedSet countForObject: object]; for (size_t i = 0; i < count; i++) [self removeObject: object]; } } else for (id object in set) [self removeObject: object]; objc_autoreleasePoolPop(pool); } - (void)unionSet: (OFSet*)set { void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet*)set; for (id object in countedSet) { size_t count = [countedSet countForObject: object]; for (size_t i = 0; i < count; i++) [self addObject: object]; } } else for (id object in set) [self addObject: object]; objc_autoreleasePoolPop(pool); } @end |
Modified src/OFCountedSet_hashtable.m from [8b86adbc94] to [14556b7ee8].
︙ | ︙ | |||
43 44 45 46 47 48 49 | @try { void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet*)countedSet; for (id object in countedSet) { | | < | | | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | @try { void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet*)countedSet; for (id object in countedSet) { size_t count = [countedSet countForObject: object]; for (size_t i = 0; i < count; i++) [self addObject: object]; } } else for (id object in set) [self addObject: object]; objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
69 70 71 72 73 74 75 | - initWithArray: (OFArray*)array { self = [self init]; @try { id const *objects = [array objects]; | | | < < | | 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 | - initWithArray: (OFArray*)array { self = [self init]; @try { id const *objects = [array objects]; size_t count = [array count]; for (size_t i = 0; i < count; i++) [self addObject: objects[i]]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithObjects: (id const*)objects count: (size_t)count { self = [self init]; @try { for (size_t i = 0; i < count; i++) [self addObject: objects[i]]; } @catch (id e) { [self release]; @throw e; } return self; |
︙ | ︙ |
Modified src/OFDataArray+Hashing.m from [8e1b2d71a4] to [155e7ea0e4].
︙ | ︙ | |||
33 34 35 36 37 38 39 | - (OFString*)OF_hashAsStringWithHash: (Class <OFHash>)hashClass { void *pool = objc_autoreleasePoolPush(); id <OFHash> hash = [hashClass hash]; size_t digestSize = [hashClass digestSize]; const uint8_t *digest; char cString[digestSize * 2]; | < | | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | - (OFString*)OF_hashAsStringWithHash: (Class <OFHash>)hashClass { void *pool = objc_autoreleasePoolPush(); id <OFHash> hash = [hashClass hash]; size_t digestSize = [hashClass digestSize]; const uint8_t *digest; char cString[digestSize * 2]; [hash updateWithBuffer: _items length: _count * _itemSize]; digest = [hash digest]; for (size_t i = 0; i < digestSize; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; cString[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); cString[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); |
︙ | ︙ |
Modified src/OFDataArray+MessagePackValue.m from [d8bc2c6ad4] to [36fe618ac5].
︙ | ︙ | |||
53 54 55 56 57 58 59 | ((uint64_t)buffer[6] << 8) | buffer[7]; } static size_t parseArray(const uint8_t *buffer, size_t length, id *object, size_t count) { void *pool; | | < | | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | ((uint64_t)buffer[6] << 8) | buffer[7]; } static size_t parseArray(const uint8_t *buffer, size_t length, id *object, size_t count) { void *pool; size_t pos = 0; /* * Don't use capacity! For data and strings, this is safe, as we can * check if we still have enough bytes left. For an array however, we * can't know this, as every child can be more than one byte. */ *object = [OFMutableArray array]; for (size_t i = 0; i < count; i++) { id child; size_t childLength; pool = objc_autoreleasePoolPush(); childLength = parseObject(buffer + pos, length - pos, &child); if (childLength == 0 || child == nil) { |
︙ | ︙ | |||
90 91 92 93 94 95 96 | return pos; } static size_t parseTable(const uint8_t *buffer, size_t length, id *object, size_t count) { void *pool; | | < | | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | return pos; } static size_t parseTable(const uint8_t *buffer, size_t length, id *object, size_t count) { void *pool; size_t pos = 0; /* * Don't use capacity! For data and strings, this is safe, as we can * check if we still have enough bytes left. For a dictionary however, * we can't know this, as every key / value can be more than one byte. */ *object = [OFMutableDictionary dictionary]; for (size_t i = 0; i < count; i++) { id key, value; size_t keyLength, valueLength; pool = objc_autoreleasePoolPush(); keyLength = parseObject(buffer + pos, length - pos, &key); if (keyLength == 0 || key == nil) { |
︙ | ︙ | |||
136 137 138 139 140 141 142 | return pos; } static size_t parseObject(const uint8_t *buffer, size_t length, id *object) { | | | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | return pos; } static size_t parseObject(const uint8_t *buffer, size_t length, id *object) { size_t count; int8_t type; OFDataArray *data; if (length < 1) goto error; /* positive fixint */ |
︙ | ︙ | |||
240 241 242 243 244 245 246 | uint8_t u8[4]; float f; } f; if (length < 5) goto error; | | | | 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 | uint8_t u8[4]; float f; } f; if (length < 5) goto error; for (size_t i = 0; i < 4; i++) f.u8[i] = buffer[i + 1]; *object = [OFNumber numberWithFloat: OF_BSWAP_FLOAT_IF_LE(f.f)]; return 5; case 0xCB:; /* float 64 */ union { uint8_t u8[8]; double d; } d; if (length < 9) goto error; for (size_t i = 0; i < 8; i++) d.u8[i] = buffer[i + 1]; *object = [OFNumber numberWithDouble: OF_BSWAP_DOUBLE_IF_LE(d.d)]; return 9; /* nil */ case 0xC0: |
︙ | ︙ |
Modified src/OFDataArray.m from [27e43ba467] to [c249bb8623].
︙ | ︙ | |||
265 266 267 268 269 270 271 | } #endif - initWithStringRepresentation: (OFString*)string { @try { const char *cString; | | | | 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 | } #endif - initWithStringRepresentation: (OFString*)string { @try { const char *cString; size_t count; count = [string cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII]; if (count % 2 != 0) @throw [OFInvalidFormatException exception]; count /= 2; self = [self initWithCapacity: count]; cString = [string cStringWithEncoding: OF_STRING_ENCODING_ASCII]; for (size_t i = 0; i < count; i++) { uint8_t c1 = cString[2 * i]; uint8_t c2 = cString[2 * i + 1]; uint8_t byte; if (c1 >= '0' && c1 <= '9') byte = (c1 - '0') << 4; else if (c1 >= 'a' && c1 <= 'f') |
︙ | ︙ | |||
567 568 569 570 571 572 573 | else return OF_ORDERED_ASCENDING; } - (uint32_t)hash { uint32_t hash; | < | < | < < | < | | | 567 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 605 606 607 608 609 610 611 612 613 614 615 | else return OF_ORDERED_ASCENDING; } - (uint32_t)hash { uint32_t hash; OF_HASH_INIT(hash); for (size_t i = 0; i < _count * _itemSize; i++) OF_HASH_ADD(hash, ((uint8_t*)_items)[i]); OF_HASH_FINALIZE(hash); return hash; } - (OFString*)description { OFMutableString *ret = [OFMutableString stringWithString: @"<"]; for (size_t i = 0; i < _count; i++) { if (i > 0) [ret appendString: @" "]; for (size_t j = 0; j < _itemSize; j++) [ret appendFormat: @"%02x", _items[i * _itemSize + j]]; } [ret appendString: @">"]; [ret makeImmutable]; return ret; } - (OFString*)stringRepresentation { OFMutableString *ret = [OFMutableString string]; for (size_t i = 0; i < _count; i++) for (size_t j = 0; j < _itemSize; j++) [ret appendFormat: @"%02x", _items[i * _itemSize + j]]; [ret makeImmutable]; return ret; } - (OFString*)stringByBase64Encoding |
︙ | ︙ |
Modified src/OFDate.m from [69ce62e752] to [fa697c55af].
︙ | ︙ | |||
353 354 355 356 357 358 359 | - (uint32_t)hash { uint32_t hash; union { double d; uint8_t b[sizeof(double)]; } d; | < | | 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | - (uint32_t)hash { uint32_t hash; union { double d; uint8_t b[sizeof(double)]; } d; d.d = OF_BSWAP_DOUBLE_IF_BE(_seconds); OF_HASH_INIT(hash); for (size_t i = 0; i < sizeof(double); i++) OF_HASH_ADD(hash, d.b[i]); OF_HASH_FINALIZE(hash); return hash; } |
︙ | ︙ |
Modified src/OFINICategory.m from [607056e622] to [b22706da67].
︙ | ︙ | |||
394 395 396 397 398 399 400 | - (void)setArray: (OFArray*)array forKey: (OFString*)key { void *pool; OFMutableArray *pairs; id const *lines; | | | 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | - (void)setArray: (OFArray*)array forKey: (OFString*)key { void *pool; OFMutableArray *pairs; id const *lines; size_t count; bool replaced; if ([array count] == 0) { [self removeValueForKey: key]; return; } |
︙ | ︙ | |||
423 424 425 426 427 428 429 | [pairs addObject: pair]; } lines = [_lines objects]; count = [_lines count]; replaced = false; | | | 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | [pairs addObject: pair]; } lines = [_lines objects]; count = [_lines count]; replaced = false; for (size_t i = 0; i < count; i++) { OFINICategory_Pair *pair; if (![lines[i] isKindOfClass: [OFINICategory_Pair class]]) continue; pair = lines[i]; |
︙ | ︙ | |||
461 462 463 464 465 466 467 | objc_autoreleasePoolPop(pool); } - (void)removeValueForKey: (OFString*)key { void *pool = objc_autoreleasePoolPush(); id const *lines = [_lines objects]; | | | | 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | objc_autoreleasePoolPop(pool); } - (void)removeValueForKey: (OFString*)key { void *pool = objc_autoreleasePoolPush(); id const *lines = [_lines objects]; size_t count = [_lines count]; for (size_t i = 0; i < count; i++) { OFINICategory_Pair *pair; if (![lines[i] isKindOfClass: [OFINICategory_Pair class]]) continue; pair = lines[i]; |
︙ | ︙ |
Modified src/OFINIFile.m from [0bf5277eff] to [53dbf23d52].
︙ | ︙ | |||
33 34 35 36 37 38 39 | encoding: (of_string_encoding_t)encoding; @end static bool isWhitespaceLine(OFString *line) { const char *cString = [line UTF8String]; | | | | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | encoding: (of_string_encoding_t)encoding; @end static bool isWhitespaceLine(OFString *line) { const char *cString = [line UTF8String]; size_t length = [line UTF8StringLength]; for (size_t i = 0; i < length; i++) { switch (cString[i]) { case ' ': case '\t': case '\n': case '\r': continue; default: |
︙ | ︙ |
Modified src/OFInflateStream.m from [47e2756e95] to [c913b5050c].
︙ | ︙ | |||
104 105 106 107 108 109 110 | }; static struct huffman_tree *fixedLitLenTree, *fixedDistTree; static bool tryReadBits(OFInflateStream *stream, uint16_t *bits, uint8_t count) { uint16_t ret = stream->_savedBits; | < | | 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | }; static struct huffman_tree *fixedLitLenTree, *fixedDistTree; static bool tryReadBits(OFInflateStream *stream, uint16_t *bits, uint8_t count) { uint16_t ret = stream->_savedBits; assert(stream->_savedBitsLength < count); for (uint8_t i = stream->_savedBitsLength; i < count; i++) { if OF_UNLIKELY (stream->_bitIndex == 8) { if (stream->_bufferIndex < stream->_bufferLength) stream->_byte = stream->_buffer[stream->_bufferIndex++]; else { size_t length = [stream->_stream readIntoBuffer: stream->_buffer |
︙ | ︙ | |||
182 183 184 185 186 187 188 | static struct huffman_tree* constructTree(uint8_t lengths[], uint16_t count) { struct huffman_tree *tree; uint16_t lengthCount[MAX_BITS + 1] = { 0 }; uint16_t code, maxCode = 0, nextCode[MAX_BITS + 1]; | < | | | | 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 | static struct huffman_tree* constructTree(uint8_t lengths[], uint16_t count) { struct huffman_tree *tree; uint16_t lengthCount[MAX_BITS + 1] = { 0 }; uint16_t code, maxCode = 0, nextCode[MAX_BITS + 1]; for (uint16_t i = 0; i < count; i++) { uint8_t length = lengths[i]; if OF_UNLIKELY (length > MAX_BITS) @throw [OFInvalidFormatException exception]; if (length > 0) { lengthCount[length]++; maxCode = i; } } code = 0; for (size_t i = 1; i <= MAX_BITS; i++) { code = (code + lengthCount[i - 1]) << 1; nextCode[i] = code; } tree = newTree(); for (uint16_t i = 0; i <= maxCode; i++) { uint8_t length = lengths[i]; if (length > 0) treeInsert(tree, nextCode[length]++, length, i); } return tree; |
︙ | ︙ | |||
239 240 241 242 243 244 245 | *value = iter->value; return true; } static void releaseTree(struct huffman_tree *tree) { | < < | < | | | | | | 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 | *value = iter->value; return true; } static void releaseTree(struct huffman_tree *tree) { for (uint8_t i = 0; i < 2; i++) if OF_LIKELY (tree->leafs[i] != NULL) releaseTree(tree->leafs[i]); free(tree); } @implementation OFInflateStream + (void)initialize { uint8_t lengths[288]; if (self != [OFInflateStream class]) return; for (uint16_t i = 0; i <= 143; i++) lengths[i] = 8; for (uint16_t i = 144; i <= 255; i++) lengths[i] = 9; for (uint16_t i = 256; i <= 279; i++) lengths[i] = 7; for (uint16_t i = 280; i <= 287; i++) lengths[i] = 8; fixedLitLenTree = constructTree(lengths, 288); for (uint16_t i = 0; i <= 31; i++) lengths[i] = 5; fixedDistTree = constructTree(lengths, 32); } #ifndef DEFLATE64 + (instancetype)streamWithStream: (OFStream*)stream |
︙ | ︙ | |||
308 309 310 311 312 313 314 | } #endif - (size_t)lowlevelReadIntoBuffer: (void*)buffer_ length: (size_t)length { uint8_t *buffer = buffer_; | | | 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | } #endif - (size_t)lowlevelReadIntoBuffer: (void*)buffer_ length: (size_t)length { uint8_t *buffer = buffer_; uint16_t bits, tmp; uint16_t value; size_t bytesWritten = 0; uint8_t *slidingWindow; uint16_t slidingWindowIndex; if (_atEndOfStream) @throw [OFReadFailedException exceptionWithObject: self |
︙ | ︙ | |||
413 414 415 416 417 418 419 | [self allocMemoryWithSize: _slidingWindowMask + 1]; /* Avoid leaking data */ memset(_slidingWindow, 0, _slidingWindowMask + 1); } slidingWindow = _slidingWindow; slidingWindowIndex = _slidingWindowIndex; | | | 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | [self allocMemoryWithSize: _slidingWindowMask + 1]; /* Avoid leaking data */ memset(_slidingWindow, 0, _slidingWindowMask + 1); } slidingWindow = _slidingWindow; slidingWindowIndex = _slidingWindowIndex; for (uint16_t i = 0; i < tmp; i++) { slidingWindow[slidingWindowIndex] = buffer[bytesWritten + i]; slidingWindowIndex = (slidingWindowIndex + 1) & _slidingWindowMask; } _slidingWindowIndex = slidingWindowIndex; |
︙ | ︙ | |||
463 464 465 466 467 468 469 | } if OF_LIKELY (CTX.lengths == NULL) { CTX.lengths = [self allocMemoryWithSize: 19]; memset(CTX.lengths, 0, 19); } | | | 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | } if OF_LIKELY (CTX.lengths == NULL) { CTX.lengths = [self allocMemoryWithSize: 19]; memset(CTX.lengths, 0, 19); } for (uint16_t i = CTX.receivedCount; i < CTX.codeLenCodesCount + 4; i++) { if OF_UNLIKELY (!tryReadBits(self, &bits, 3)) { CTX.receivedCount = i; return bytesWritten; } CTX.lengths[codeLengthsOrder[i]] = bits; |
︙ | ︙ | |||
486 487 488 489 490 491 492 | CTX.value = 0xFF; } if OF_LIKELY (CTX.lengths == NULL) CTX.lengths = [self allocMemoryWithSize: CTX.litLenCodesCount + CTX.distCodesCount + 258]; | | | 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | CTX.value = 0xFF; } if OF_LIKELY (CTX.lengths == NULL) CTX.lengths = [self allocMemoryWithSize: CTX.litLenCodesCount + CTX.distCodesCount + 258]; for (uint16_t i = CTX.receivedCount; i < CTX.litLenCodesCount + CTX.distCodesCount + 258;) { uint8_t j, count; if OF_LIKELY (CTX.value == 0xFF) { if OF_UNLIKELY (!walkTree(self, &CTX.treeIter, &value)) { CTX.receivedCount = i; |
︙ | ︙ |
Modified src/OFIntrospection.m from [0997c2730b] to [ce69904b51].
︙ | ︙ | |||
115 116 117 118 119 120 121 | uint32_t hash; OF_HASH_INIT(hash); OF_HASH_ADD_HASH(hash, [_name hash]); if (_typeEncoding != NULL) { | | < | | 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | uint32_t hash; OF_HASH_INIT(hash); OF_HASH_ADD_HASH(hash, [_name hash]); if (_typeEncoding != NULL) { size_t length = strlen(_typeEncoding); for (size_t i = 0; i < length; i++) OF_HASH_ADD(hash, _typeEncoding[i]); } OF_HASH_FINALIZE(hash); return hash; } |
︙ | ︙ | |||
436 437 438 439 440 441 442 | struct objc_property_list *propertyList; #elif defined(OF_APPLE_RUNTIME) Method *methodList; objc_property_t *propertyList; Ivar *ivarList; unsigned count; #endif | < | | | | | | | | | 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 550 551 552 | struct objc_property_list *propertyList; #elif defined(OF_APPLE_RUNTIME) Method *methodList; objc_property_t *propertyList; Ivar *ivarList; unsigned count; #endif void *pool; _classMethods = [[OFMutableArray alloc] init]; _instanceMethods = [[OFMutableArray alloc] init]; _properties = [[OFMutableArray alloc] init]; _instanceVariables = [[OFMutableArray alloc] init]; #if defined(OF_OBJFW_RUNTIME) for (methodList = object_getClass(class)->methodlist; methodList != NULL; methodList = methodList->next) { pool = objc_autoreleasePoolPush(); for (unsigned int i = 0; i < methodList->count; i++) [_classMethods addObject: [[[OFMethod alloc] OF_initWithMethod: &methodList->methods[i]] autorelease]]; objc_autoreleasePoolPop(pool); } for (methodList = class->methodlist; methodList != NULL; methodList = methodList->next) { pool = objc_autoreleasePoolPush(); for (unsigned int i = 0; i < methodList->count; i++) [_instanceMethods addObject: [[[OFMethod alloc] OF_initWithMethod: &methodList->methods[i]] autorelease]]; objc_autoreleasePoolPop(pool); } for (propertyList = class->properties; propertyList != NULL; propertyList = propertyList->next) { pool = objc_autoreleasePoolPush(); for (unsigned int i = 0; i < propertyList->count; i++) [_properties addObject: [[[OFProperty alloc] OF_initWithProperty: &propertyList->properties[i]] autorelease]]; objc_autoreleasePoolPop(pool); } if (class->ivars != NULL) { pool = objc_autoreleasePoolPush(); for (unsigned int i = 0; i < class->ivars->count; i++) [_instanceVariables addObject: [[[OFInstanceVariable alloc] OF_initWithIvar: &class->ivars->ivars[i]] autorelease]]; objc_autoreleasePoolPop(pool); } #elif defined(OF_APPLE_RUNTIME) methodList = class_copyMethodList(object_getClass(class), &count); @try { pool = objc_autoreleasePoolPush(); for (unsigned int i = 0; i < count; i++) [_classMethods addObject: [[[OFMethod alloc] OF_initWithMethod: methodList[i]] autorelease]]; objc_autoreleasePoolPop(pool); } @finally { free(methodList); } methodList = class_copyMethodList(class, &count); @try { pool = objc_autoreleasePoolPush(); for (unsigned int i = 0; i < count; i++) [_instanceMethods addObject: [[[OFMethod alloc] OF_initWithMethod: methodList[i]] autorelease]]; objc_autoreleasePoolPop(pool); } @finally { free(methodList); } propertyList = class_copyPropertyList(class, &count); @try { pool = objc_autoreleasePoolPush(); for (unsigned int i = 0; i < count; i++) [_properties addObject: [[[OFProperty alloc] OF_initWithProperty: propertyList[i]] autorelease]]; objc_autoreleasePoolPop(pool); } @finally { free(propertyList); } ivarList = class_copyIvarList(class, &count); @try { pool = objc_autoreleasePoolPush(); for (unsigned int i = 0; i < count; i++) [_instanceVariables addObject: [[[OFInstanceVariable alloc] OF_initWithIvar: ivarList[i]] autorelease]]; objc_autoreleasePoolPop(pool); } @finally { free(ivarList); |
︙ | ︙ |
Modified src/OFKernelEventObserver_LockedQueue.m from [abbca7e630] to [06cbc8baae].
︙ | ︙ | |||
173 174 175 176 177 178 179 | #ifdef OF_HAVE_THREADS [_mutex lock]; @try { #endif int *queueActions = [_queueActions items]; int *queueFDs = [_queueFDs items]; id const *queueObjects = [_queueObjects objects]; | | | | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | #ifdef OF_HAVE_THREADS [_mutex lock]; @try { #endif int *queueActions = [_queueActions items]; int *queueFDs = [_queueFDs items]; id const *queueObjects = [_queueObjects objects]; size_t count = [_queueActions count]; OF_ENSURE([_queueFDs count] == count); OF_ENSURE([_queueObjects count] == count); for (size_t i = 0; i < count; i++) { int action = queueActions[i]; int fd = queueFDs[i]; id object = queueObjects[i]; switch (action) { case QUEUE_ADD | QUEUE_READ: [_readObjects addObject: object]; |
︙ | ︙ |
Modified src/OFKernelEventObserver_epoll.m from [1081329583] to [dd16d51752].
︙ | ︙ | |||
207 208 209 210 211 212 213 | } - (void)observeForTimeInterval: (of_time_interval_t)timeInterval { OFNull *nullObject = [OFNull null]; void *pool = objc_autoreleasePoolPush(); struct epoll_event eventList[EVENTLIST_SIZE]; | | | | 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 | } - (void)observeForTimeInterval: (of_time_interval_t)timeInterval { OFNull *nullObject = [OFNull null]; void *pool = objc_autoreleasePoolPush(); struct epoll_event eventList[EVENTLIST_SIZE]; int events; [self OF_processReadBuffers]; objc_autoreleasePoolPop(pool); events = epoll_wait(_epfd, eventList, EVENTLIST_SIZE, (timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: errno]; for (int i = 0; i < events; i++) { if (eventList[i].data.ptr == nullObject) { char buffer; assert(eventList[i].events == EPOLLIN); OF_ENSURE(read(_cancelFD[0], &buffer, 1) == 1); continue; |
︙ | ︙ |
Modified src/OFKernelEventObserver_kqueue.m from [c7ba665a18] to [6945083a36].
︙ | ︙ | |||
204 205 206 207 208 209 210 | } - (void)observeForTimeInterval: (of_time_interval_t)timeInterval { void *pool = objc_autoreleasePoolPush(); struct timespec timeout; struct kevent eventList[EVENTLIST_SIZE]; | | | | 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 | } - (void)observeForTimeInterval: (of_time_interval_t)timeInterval { void *pool = objc_autoreleasePoolPush(); struct timespec timeout; struct kevent eventList[EVENTLIST_SIZE]; int events; timeout.tv_sec = (time_t)timeInterval; timeout.tv_nsec = lrint((timeInterval - timeout.tv_sec) * 1000000000); [self OF_processReadBuffers]; objc_autoreleasePoolPop(pool); events = kevent(_kernelQueue, NULL, 0, eventList, EVENTLIST_SIZE, (timeInterval != -1 ? &timeout : NULL)); if (events < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: errno]; for (int i = 0; i < events; i++) { if (eventList[i].flags & EV_ERROR) @throw [OFObserveFailedException exceptionWithObserver: self errNo: (int)eventList[i].data]; if (eventList[i].ident == _cancelFD[0]) { char buffer; |
︙ | ︙ |
Modified src/OFKernelEventObserver_poll.m from [4a4c51ed64] to [bb3d801549].
︙ | ︙ | |||
71 72 73 74 75 76 77 | } - (void)OF_addObject: (id)object fileDescriptor: (int)fd events: (short)events { struct pollfd *FDs = [_FDs items]; | | | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | } - (void)OF_addObject: (id)object fileDescriptor: (int)fd events: (short)events { struct pollfd *FDs = [_FDs items]; size_t count = [_FDs count]; bool found = false; for (size_t i = 0; i < count; i++) { if (FDs[i].fd == fd) { FDs[i].events |= events; found = true; break; } } |
︙ | ︙ | |||
102 103 104 105 106 107 108 | } - (void)OF_removeObject: (id)object fileDescriptor: (int)fd events: (short)events { struct pollfd *FDs = [_FDs items]; | | | | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | } - (void)OF_removeObject: (id)object fileDescriptor: (int)fd events: (short)events { struct pollfd *FDs = [_FDs items]; size_t nFDs = [_FDs count]; for (size_t i = 0; i < nFDs; i++) { if (FDs[i].fd == fd) { FDs[i].events &= ~events; if (FDs[i].events == 0) { /* * TODO: Remove from and resize _FDToObject, * adjust _maxFD. |
︙ | ︙ | |||
158 159 160 161 162 163 164 | } - (void)observeForTimeInterval: (of_time_interval_t)timeInterval { void *pool = objc_autoreleasePoolPush(); struct pollfd *FDs; int events; | | | 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | } - (void)observeForTimeInterval: (of_time_interval_t)timeInterval { void *pool = objc_autoreleasePoolPush(); struct pollfd *FDs; int events; size_t nFDs; [self OF_processQueue]; [self OF_processReadBuffers]; objc_autoreleasePoolPop(pool); FDs = [_FDs items]; |
︙ | ︙ | |||
180 181 182 183 184 185 186 | events = poll(FDs, (nfds_t)nFDs, (int)(timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: errno]; | | | 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | events = poll(FDs, (nfds_t)nFDs, (int)(timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: errno]; for (size_t i = 0; i < nFDs; i++) { assert(FDs[i].fd <= _maxFD); if (FDs[i].revents & POLLIN) { if (FDs[i].fd == _cancelFD[0]) { char buffer; #ifdef OF_HAVE_PIPE |
︙ | ︙ |
Modified src/OFKernelEventObserver_select.m from [c497599b97] to [1968f741af].
︙ | ︙ | |||
134 135 136 137 138 139 140 | { void *pool = objc_autoreleasePoolPush(); id const *objects; fd_set readFDs; fd_set writeFDs; struct timeval timeout; int events; | | | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | { void *pool = objc_autoreleasePoolPush(); id const *objects; fd_set readFDs; fd_set writeFDs; struct timeval timeout; int events; size_t count; [self OF_processQueue]; [self OF_processReadBuffers]; objc_autoreleasePoolPop(pool); #ifdef FD_COPY |
︙ | ︙ | |||
183 184 185 186 187 188 189 | NULL) == 1); #endif } objects = [_readObjects objects]; count = [_readObjects count]; | | | | 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 | NULL) == 1); #endif } objects = [_readObjects objects]; count = [_readObjects count]; for (size_t i = 0; i < count; i++) { int fd; pool = objc_autoreleasePoolPush(); fd = [objects[i] fileDescriptorForReading]; if (FD_ISSET(fd, &readFDs) && [_delegate respondsToSelector: @selector(objectIsReadyForReading:)]) [_delegate objectIsReadyForReading: objects[i]]; objc_autoreleasePoolPop(pool); } objects = [_writeObjects objects]; count = [_writeObjects count]; for (size_t i = 0; i < count; i++) { int fd; pool = objc_autoreleasePoolPush(); fd = [objects[i] fileDescriptorForWriting]; if (FD_ISSET(fd, &writeFDs) && [_delegate respondsToSelector: @selector(objectIsReadyForWriting:)]) [_delegate objectIsReadyForWriting: objects[i]]; objc_autoreleasePoolPop(pool); } } @end |
Modified src/OFList.m from [99a256af1a] to [809ddd51dc].
︙ | ︙ | |||
63 64 65 66 67 68 69 | } return self; } - (void)dealloc { | | < | | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | } return self; } - (void)dealloc { for (of_list_object_t *iter = _firstListObject; iter != NULL; iter = iter->next) [iter->object release]; [super dealloc]; } - (of_list_object_t*)appendObject: (id)object { |
︙ | ︙ | |||
225 226 227 228 229 230 231 | assert(iter == NULL && iter2 == NULL); return true; } - (bool)containsObject: (id)object { | < < > | < < > | | 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 | assert(iter == NULL && iter2 == NULL); return true; } - (bool)containsObject: (id)object { if (_count == 0) return false; for (of_list_object_t *iter = _firstListObject; iter != NULL; iter = iter->next) if ([iter->object isEqual: object]) return true; return false; } - (bool)containsObjectIdenticalTo: (id)object { if (_count == 0) return false; for (of_list_object_t *iter = _firstListObject; iter != NULL; iter = iter->next) if (iter->object == object) return true; return false; } - (void)removeAllObjects |
︙ | ︙ | |||
270 271 272 273 274 275 276 | _firstListObject = _lastListObject = NULL; } - copy { OFList *copy = [[[self class] alloc] init]; | | > | | 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | _firstListObject = _lastListObject = NULL; } - copy { OFList *copy = [[[self class] alloc] init]; of_list_object_t *listObject, *previous; listObject = NULL; previous = NULL; @try { for (of_list_object_t *iter = _firstListObject; iter != NULL; iter = iter->next) { listObject = [copy allocMemoryWithSize: sizeof(of_list_object_t)]; listObject->object = [iter->object retain]; listObject->next = NULL; listObject->previous = previous; if (copy->_firstListObject == NULL) |
︙ | ︙ | |||
304 305 306 307 308 309 310 | copy->_lastListObject = listObject; return copy; } - (uint32_t)hash { | < > | < > | | < < | | > | < | | 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 | copy->_lastListObject = listObject; return copy; } - (uint32_t)hash { uint32_t hash; OF_HASH_INIT(hash); for (of_list_object_t *iter = _firstListObject; iter != NULL; iter = iter->next) OF_HASH_ADD_HASH(hash, [iter->object hash]); OF_HASH_FINALIZE(hash); return hash; } - (OFString*)description { OFMutableString *ret; if (_count == 0) return @"[]"; ret = [OFMutableString stringWithString: @"[\n"]; for (of_list_object_t *iter = _firstListObject; iter != NULL; iter = iter->next) { void *pool = objc_autoreleasePoolPush(); [ret appendString: [iter->object description]]; if (iter->next != NULL) [ret appendString: @",\n"]; objc_autoreleasePoolPop(pool); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n]"]; [ret makeImmutable]; return ret; } - (OFXMLElement*)XMLElementBySerializing { OFXMLElement *element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; for (of_list_object_t *iter = _firstListObject; iter != NULL; iter = iter->next) { void *pool = objc_autoreleasePoolPush(); [element addChild: [iter->object XMLElementBySerializing]]; objc_autoreleasePoolPop(pool); } return element; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count { of_list_object_t *listObject; memcpy(&listObject, state->extra, sizeof(listObject)); state->itemsPtr = objects; state->mutationsPtr = &_mutations; if (state->state == 0) { listObject = _firstListObject; state->state = 1; } for (int i = 0; i < count; i++) { if (listObject == NULL) return i; objects[i] = listObject->object; listObject = listObject->next; } |
︙ | ︙ |
Modified src/OFMD5Hash.m from [76a6936277] to [5a22333932].
︙ | ︙ | |||
61 62 63 64 65 66 67 | 6, 10, 15, 21 }; static OF_INLINE void byteSwapVectorIfBE(uint32_t *vector, uint8_t length) { #ifdef OF_BIG_ENDIAN | < < | | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | 6, 10, 15, 21 }; static OF_INLINE void byteSwapVectorIfBE(uint32_t *vector, uint8_t length) { #ifdef OF_BIG_ENDIAN for (uint8_t i = 0; i < length; i++) vector[i] = OF_BSWAP32(vector[i]); #endif } static void processBlock(uint32_t *state, uint32_t *buffer) { |
︙ | ︙ |
Modified src/OFMapTable.m from [0f58c455bb] to [d08b0754f8].
︙ | ︙ | |||
178 179 180 181 182 183 184 | } return self; } - (void)dealloc { | < < | < | | | < < | | 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 | } return self; } - (void)dealloc { for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deleted) { _keyFunctions.release(_buckets[i]->key); _valueFunctions.release(_buckets[i]->value); } } [super dealloc]; } - (bool)isEqual: (id)object { OFMapTable *mapTable; if (![object isKindOfClass: [OFMapTable class]]) return false; mapTable = object; if (mapTable->_count != _count || mapTable->_keyFunctions.equal != _keyFunctions.equal || mapTable->_valueFunctions.equal != _valueFunctions.equal) return false; for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deleted) { void *value = [mapTable valueForKey: _buckets[i]->key]; if (!_valueFunctions.equal(value, _buckets[i]->value)) return false; } } return true; } - (uint32_t)hash { uint32_t hash = 0; for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deleted) { hash += OF_ROR(_buckets[i]->hash, _rotate); hash += _valueFunctions.hash(_buckets[i]->value); } } return hash; } - copy { OFMapTable *copy = [[OFMapTable alloc] initWithKeyFunctions: _keyFunctions valueFunctions: _valueFunctions capacity: _capacity]; @try { for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deleted) [copy OF_setValue: _buckets[i]->value forKey: _buckets[i]->key hash: OF_ROR(_buckets[i]->hash, _rotate)]; } @catch (id e) { [copy release]; |
︙ | ︙ | |||
297 298 299 300 301 302 303 | } return NULL; } - (void)OF_resizeForCount: (uint32_t)count { | | | 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | } return NULL; } - (void)OF_resizeForCount: (uint32_t)count { uint32_t fullness, capacity; struct of_map_table_bucket **buckets; if (count > UINT32_MAX / sizeof(*_buckets) || count > UINT32_MAX / 8) @throw [OFOutOfRangeException exception]; fullness = count * 8 / _capacity; |
︙ | ︙ | |||
327 328 329 330 331 332 333 | return; buckets = [self allocMemoryWithSize: sizeof(*buckets) count: capacity]; memset(buckets, 0, capacity * sizeof(*buckets)); | | | 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | return; buckets = [self allocMemoryWithSize: sizeof(*buckets) count: capacity]; memset(buckets, 0, capacity * sizeof(*buckets)); for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deleted) { uint32_t j, last; last = capacity; for (j = _buckets[i]->hash & (capacity - 1); j < last && buckets[j] != NULL; j++); |
︙ | ︙ | |||
510 511 512 513 514 515 516 | return; } } } - (void)removeAllValues { | < < | | 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | return; } } } - (void)removeAllValues { for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL) { if (_buckets[i] == &deleted) { _buckets[i] = NULL; continue; } _keyFunctions.release(_buckets[i]->key); |
︙ | ︙ | |||
549 550 551 552 553 554 555 | #else _rotate = rand() & 31; #endif } - (bool)containsValue: (void*)value { | < < | < < | | 542 543 544 545 546 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 | #else _rotate = rand() & 31; #endif } - (bool)containsValue: (void*)value { if (value == NULL || _count == 0) return false; for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deleted) if (_valueFunctions.equal(_buckets[i]->value, value)) return true; return false; } - (bool)containsValueIdenticalTo: (void*)value { if (value == NULL || _count == 0) return false; for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deleted) if (_buckets[i]->value == value) return true; return false; } |
︙ | ︙ | |||
624 625 626 627 628 629 630 | return i; } #ifdef OF_HAVE_BLOCKS - (void)enumerateKeysAndValuesUsingBlock: (of_map_table_enumeration_block_t)block { | < | < | | 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 | return i; } #ifdef OF_HAVE_BLOCKS - (void)enumerateKeysAndValuesUsingBlock: (of_map_table_enumeration_block_t)block { bool stop = false; unsigned long mutations = _mutations; for (size_t i = 0; i < _capacity && !stop; i++) { if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; if (_buckets[i] != NULL && _buckets[i] != &deleted) block(_buckets[i]->key, _buckets[i]->value, &stop); } } - (void)replaceValuesUsingBlock: (of_map_table_replace_block_t)block { unsigned long mutations = _mutations; for (size_t i = 0; i < _capacity; i++) { if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; if (_buckets[i] != NULL && _buckets[i] != &deleted) { void *new; |
︙ | ︙ |
Modified src/OFMutableArray.m from [14cd41b76c] to [e4d2b4619e].
︙ | ︙ | |||
240 241 242 243 244 245 246 | [self replaceObjectAtIndex: index withObject: object]; } - (void)replaceObject: (id)oldObject withObject: (id)newObject { | | | | | | | | | < < | | 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 | [self replaceObjectAtIndex: index withObject: object]; } - (void)replaceObject: (id)oldObject withObject: (id)newObject { size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; count = [self count]; for (size_t i = 0; i < count; i++) { if ([[self objectAtIndex: i] isEqual: oldObject]) { [self replaceObjectAtIndex: i withObject: newObject]; return; } } } - (void)replaceObjectIdenticalTo: (id)oldObject withObject: (id)newObject { size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; count = [self count]; for (size_t i = 0; i < count; i++) { if ([self objectAtIndex: i] == oldObject) { [self replaceObjectAtIndex: i withObject: newObject]; return; } } } - (void)removeObjectAtIndex: (size_t)index { OF_UNRECOGNIZED_SELECTOR } - (void)removeObject: (id)object { size_t count; if (object == nil) @throw [OFInvalidArgumentException exception]; count = [self count]; for (size_t i = 0; i < count; i++) { if ([[self objectAtIndex: i] isEqual: object]) { [self removeObjectAtIndex: i]; return; } } } - (void)removeObjectIdenticalTo: (id)object { size_t count; if (object == nil) @throw [OFInvalidArgumentException exception]; count = [self count]; for (size_t i = 0; i < count; i++) { if ([self objectAtIndex: i] == object) { [self removeObjectAtIndex: i]; return; } } } - (void)removeObjectsInRange: (of_range_t)range { for (size_t i = 0; i < range.length; i++) [self removeObjectAtIndex: range.location]; } - (void)removeLastObject { size_t count = [self count]; |
︙ | ︙ |
Modified src/OFMutableArray_adjacent.m from [9319ae3a70] to [d11d5110e4].
︙ | ︙ | |||
76 77 78 79 80 81 82 | _mutations++; } - (void)insertObjectsFromArray: (OFArray*)array atIndex: (size_t)index { id const *objects = [array objects]; | | | | | | 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 | _mutations++; } - (void)insertObjectsFromArray: (OFArray*)array atIndex: (size_t)index { id const *objects = [array objects]; size_t count = [array count]; @try { [_array insertItems: objects atIndex: index count: count]; } @catch (OFOutOfRangeException *e) { @throw [OFOutOfRangeException exception]; } for (size_t i = 0; i < count; i++) [objects[i] retain]; _mutations++; } - (void)replaceObject: (id)oldObject withObject: (id)newObject { id *objects; size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; objects = [_array items]; count = [_array count]; for (size_t i = 0; i < count; i++) { if ([objects[i] isEqual: oldObject]) { [newObject retain]; [objects[i] release]; objects[i] = newObject; return; } |
︙ | ︙ | |||
138 139 140 141 142 143 144 | [oldObject release]; } - (void)replaceObjectIdenticalTo: (id)oldObject withObject: (id)newObject { id *objects; | | | | | | | | 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 | [oldObject release]; } - (void)replaceObjectIdenticalTo: (id)oldObject withObject: (id)newObject { id *objects; size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; objects = [_array items]; count = [_array count]; for (size_t i = 0; i < count; i++) { if (objects[i] == oldObject) { [newObject retain]; [objects[i] release]; objects[i] = newObject; return; } } } - (void)removeObject: (id)object { id *objects; size_t count; if (object == nil) @throw [OFInvalidArgumentException exception]; objects = [_array items]; count = [_array count]; for (size_t i = 0; i < count; i++) { if ([objects[i] isEqual: object]) { object = objects[i]; [_array removeItemAtIndex: i]; _mutations++; [object release]; return; } } } - (void)removeObjectIdenticalTo: (id)object { id *objects; size_t count; if (object == nil) @throw [OFInvalidArgumentException exception]; objects = [_array items]; count = [_array count]; for (size_t i = 0; i < count; i++) { if (objects[i] == object) { [_array removeItemAtIndex: i]; _mutations++; [object release]; return; |
︙ | ︙ | |||
217 218 219 220 221 222 223 | _mutations++; } - (void)removeAllObjects { id *objects = [_array items]; | | | | | | 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 | _mutations++; } - (void)removeAllObjects { id *objects = [_array items]; size_t count = [_array count]; for (size_t i = 0; i < count; i++) [objects[i] release]; [_array removeAllItems]; } - (void)removeObjectsInRange: (of_range_t)range { id *objects = [_array items], *copy; size_t count = [_array count]; if (range.length > SIZE_MAX - range.location || range.length > count - range.location) @throw [OFOutOfRangeException exception]; copy = [self allocMemoryWithSize: sizeof(*copy) count: range.length]; memcpy(copy, objects + range.location, range.length * sizeof(id)); @try { [_array removeItemsInRange: range]; _mutations++; for (size_t i = 0; i < range.length; i++) [copy[i] release]; } @finally { [self freeMemory: copy]; } } - (void)removeLastObject |
︙ | ︙ | |||
334 335 336 337 338 339 340 | mutationsPtr: &_mutations] autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { id *objects = [_array items]; | | | | | | 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 | mutationsPtr: &_mutations] autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { id *objects = [_array items]; size_t count = [_array count]; bool stop = false; unsigned long mutations = _mutations; for (size_t i = 0; i < count && !stop; i++) { if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; block(objects[i], i, &stop); } } - (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block { id *objects = [_array items]; size_t count = [_array count]; unsigned long mutations = _mutations; for (size_t i = 0; i < count; i++) { id new; if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; new = block(objects[i], i); |
︙ | ︙ |
Modified src/OFMutableString.m from [4c381c3b4d] to [b0b4b6766d].
︙ | ︙ | |||
243 244 245 246 247 248 249 | - (void)OF_convertWithWordStartTable: (const of_unichar_t *const[])startTable wordMiddleTable: (const of_unichar_t *const[])middleTable wordStartTableSize: (size_t)startTableSize wordMiddleTableSize: (size_t)middleTableSize { void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters = [self characters]; | | | | 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | - (void)OF_convertWithWordStartTable: (const of_unichar_t *const[])startTable wordMiddleTable: (const of_unichar_t *const[])middleTable wordStartTableSize: (size_t)startTableSize wordMiddleTableSize: (size_t)middleTableSize { void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters = [self characters]; size_t length = [self length]; bool isStart = true; for (size_t i = 0; i < length; i++) { const of_unichar_t *const *table; size_t tableSize; of_unichar_t c = characters[i]; if (isStart) { table = startTable; tableSize = middleTableSize; |
︙ | ︙ | |||
467 468 469 470 471 472 473 | range: (of_range_t)range { void *pool = objc_autoreleasePoolPush(), *pool2; const of_unichar_t *characters; const of_unichar_t *searchCharacters = [string characters]; size_t searchLength = [string length]; size_t replacementLength = [replacement length]; | < | | 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 | range: (of_range_t)range { void *pool = objc_autoreleasePoolPush(), *pool2; const of_unichar_t *characters; const of_unichar_t *searchCharacters = [string characters]; size_t searchLength = [string length]; size_t replacementLength = [replacement length]; if (range.length > SIZE_MAX - range.location || range.location + range.length > [self length]) @throw [OFOutOfRangeException exception]; if (searchLength > range.length) { objc_autoreleasePoolPop(pool); return; } pool2 = objc_autoreleasePoolPush(); characters = [self characters]; for (size_t i = range.location; i <= range.length - searchLength; i++) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(of_unichar_t)) != 0) continue; [self replaceCharactersInRange: of_range(i, searchLength) withString: replacement]; |
︙ | ︙ |
Modified src/OFMutableString_UTF8.m from [7b388678b4] to [3b7cce9749].
︙ | ︙ | |||
385 386 387 388 389 390 391 | - (void)appendCharacters: (of_unichar_t*)characters length: (size_t)length { char *tmp; tmp = [self allocMemoryWithSize: (length * 4) + 1]; @try { | | | | 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | - (void)appendCharacters: (of_unichar_t*)characters length: (size_t)length { char *tmp; tmp = [self allocMemoryWithSize: (length * 4) + 1]; @try { size_t j = 0; bool isUTF8 = false; for (size_t i = 0; i < length; i++) { size_t len = of_string_utf8_encode(characters[i], tmp + j); if (len == 0) @throw [OFInvalidEncodingException exception]; if (len > 1) |
︙ | ︙ | |||
645 646 647 648 649 650 651 | options: (int)options range: (of_range_t)range { const char *searchString = [string UTF8String]; const char *replacementString = [replacement UTF8String]; size_t searchLength = [string UTF8StringLength]; size_t replacementLength = [replacement UTF8StringLength]; | | < > | | 645 646 647 648 649 650 651 652 653 654 655 656 657 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 | options: (int)options range: (of_range_t)range { const char *searchString = [string UTF8String]; const char *replacementString = [replacement UTF8String]; size_t searchLength = [string UTF8StringLength]; size_t replacementLength = [replacement UTF8StringLength]; size_t last, newCStringLength, newLength; char *newCString; if (range.length > SIZE_MAX - range.location || range.location + range.length > [self length]) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { range.location = of_string_utf8_get_position(_s->cString, range.location, _s->cStringLength); range.length = of_string_utf8_get_position( _s->cString + range.location, range.length, _s->cStringLength - range.location); } if ([string UTF8StringLength] > range.length) return; newCString = NULL; newCStringLength = 0; newLength = _s->length; last = 0; for (size_t i = range.location; i <= range.length - searchLength; i++) { if (memcmp(_s->cString + i, searchString, searchLength) != 0) continue; @try { newCString = [self resizeMemory: newCString size: newCStringLength + i - last + |
︙ | ︙ |
Modified src/OFNumber.m from [8f726b2505] to [3586cf276f].
︙ | ︙ | |||
828 829 830 831 832 833 834 | OF_HASH_INIT(hash); if (type & OF_NUMBER_TYPE_FLOAT) { union { double d; uint8_t b[sizeof(double)]; } d; | < | | 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 | OF_HASH_INIT(hash); if (type & OF_NUMBER_TYPE_FLOAT) { union { double d; uint8_t b[sizeof(double)]; } d; if (isnan([self doubleValue])) return 0; d.d = OF_BSWAP_DOUBLE_IF_BE([self doubleValue]); for (uint8_t i = 0; i < sizeof(double); i++) OF_HASH_ADD(hash, d.b[i]); } else if (type & OF_NUMBER_TYPE_SIGNED) { intmax_t v = [self intMaxValue] * -1; while (v != 0) { OF_HASH_ADD(hash, v & 0xFF); v >>= 8; |
︙ | ︙ |
Modified src/OFObject.m from [4b9ff362fe] to [6e92aa6c33].
︙ | ︙ | |||
276 277 278 279 280 281 282 | { return [OFString stringWithCString: class_getName(self) encoding: OF_STRING_ENCODING_ASCII]; } + (bool)isSubclassOfClass: (Class)class { | < < | | 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | { return [OFString stringWithCString: class_getName(self) encoding: OF_STRING_ENCODING_ASCII]; } + (bool)isSubclassOfClass: (Class)class { for (Class iter = self; iter != Nil; iter = class_getSuperclass(iter)) if (iter == class) return true; return false; } + (Class)superclass |
︙ | ︙ | |||
382 383 384 385 386 387 388 | { Class superclass = [self superclass]; if ([self isSubclassOfClass: class]) return; #if defined(OF_OBJFW_RUNTIME) | | < | < < | | | < < | | | | | 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 | { Class superclass = [self superclass]; if ([self isSubclassOfClass: class]) return; #if defined(OF_OBJFW_RUNTIME) for (struct objc_method_list *methodlist = object_getClass(class)->methodlist; methodlist != NULL; methodlist = methodlist->next) { for (int i = 0; i < methodlist->count; i++) { SEL selector = (SEL)&methodlist->methods[i].sel; /* * Don't replace methods implemented in the receiving * class. */ if ([self methodForSelector: selector] != [superclass methodForSelector: selector]) continue; [self replaceClassMethod: selector withMethodFromClass: class]; } } for (struct objc_method_list *methodlist = class->methodlist; methodlist != NULL; methodlist = methodlist->next) { for (int i = 0; i < methodlist->count; i++) { SEL selector = (SEL)&methodlist->methods[i].sel; /* * Don't replace methods implemented in the receiving * class. */ if ([self instanceMethodForSelector: selector] != [superclass instanceMethodForSelector: selector]) continue; [self replaceInstanceMethod: selector withMethodFromClass: class]; } } #elif defined(OF_APPLE_RUNTIME) Method *methodList; unsigned int count; methodList = class_copyMethodList(object_getClass(class), &count); @try { for (unsigned int i = 0; i < count; i++) { SEL selector = method_getName(methodList[i]); /* * Don't replace methods implemented in the receiving * class. */ if ([self methodForSelector: selector] != [superclass methodForSelector: selector]) continue; [self replaceClassMethod: selector withMethodFromClass: class]; } } @finally { free(methodList); } methodList = class_copyMethodList(class, &count); @try { for (unsigned int i = 0; i < count; i++) { SEL selector = method_getName(methodList[i]); /* * Don't replace methods implemented in the receiving * class. */ if ([self instanceMethodForSelector: selector] != |
︙ | ︙ | |||
504 505 506 507 508 509 510 | { return [OFString stringWithCString: object_getClassName(self) encoding: OF_STRING_ENCODING_ASCII]; } - (bool)isKindOfClass: (Class)class { | < < | | 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | { return [OFString stringWithCString: object_getClassName(self) encoding: OF_STRING_ENCODING_ASCII]; } - (bool)isKindOfClass: (Class)class { for (Class iter = object_getClass(self); iter != Nil; iter = class_getSuperclass(iter)) if (iter == class) return true; return false; } |
︙ | ︙ |
Modified src/OFRIPEMD160Hash.m from [d790f259b5] to [fbdb761c67].
︙ | ︙ | |||
57 58 59 60 61 62 63 | 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 }; static OF_INLINE void byteSwapVectorIfBE(uint32_t *vector, uint8_t length) { #ifdef OF_BIG_ENDIAN | < < | | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 }; static OF_INLINE void byteSwapVectorIfBE(uint32_t *vector, uint8_t length) { #ifdef OF_BIG_ENDIAN for (uint8_t i = 0; i < length; i++) vector[i] = OF_BSWAP32(vector[i]); #endif } static void processBlock(uint32_t *state, uint32_t *buffer) { |
︙ | ︙ |
Modified src/OFSHA1Hash.m from [7ce937b30f] to [bdf798905f].
︙ | ︙ | |||
27 28 29 30 31 32 33 | #define H(a, b, c, d) (((b) & (c)) | ((d) & ((b) | (c)))) #define I(a, b, c, d) ((b) ^ (c) ^ (d)) static OF_INLINE void byteSwapVectorIfLE(uint32_t *vector, uint8_t length) { #ifndef OF_BIG_ENDIAN | < < | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #define H(a, b, c, d) (((b) & (c)) | ((d) & ((b) | (c)))) #define I(a, b, c, d) ((b) ^ (c) ^ (d)) static OF_INLINE void byteSwapVectorIfLE(uint32_t *vector, uint8_t length) { #ifndef OF_BIG_ENDIAN for (uint8_t i = 0; i < length; i++) vector[i] = OF_BSWAP32(vector[i]); #endif } static void processBlock(uint32_t *state, uint32_t *buffer) { |
︙ | ︙ |
Modified src/OFSHA224Or256Hash.m from [80ddf15097] to [6ab18f2a4c].
︙ | ︙ | |||
41 42 43 44 45 46 47 | 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 }; static OF_INLINE void byteSwapVectorIfLE(uint32_t *vector, uint8_t length) { #ifndef OF_BIG_ENDIAN | < < | | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 }; static OF_INLINE void byteSwapVectorIfLE(uint32_t *vector, uint8_t length) { #ifndef OF_BIG_ENDIAN for (uint8_t i = 0; i < length; i++) vector[i] = OF_BSWAP32(vector[i]); #endif } static void processBlock(uint32_t *state, uint32_t *buffer) { |
︙ | ︙ |
Modified src/OFSHA384Or512Hash.m from [0930b3cee0] to [e332bfebbc].
︙ | ︙ | |||
52 53 54 55 56 57 58 | 0x5FCB6FAB3AD6FAEC, 0x6C44198C4A475817 }; static OF_INLINE void byteSwapVectorIfLE(uint64_t *vector, uint8_t length) { #ifndef OF_BIG_ENDIAN | < < | | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | 0x5FCB6FAB3AD6FAEC, 0x6C44198C4A475817 }; static OF_INLINE void byteSwapVectorIfLE(uint64_t *vector, uint8_t length) { #ifndef OF_BIG_ENDIAN for (uint8_t i = 0; i < length; i++) vector[i] = OF_BSWAP64(vector[i]); #endif } static void processBlock(uint64_t *state, uint64_t *buffer) { |
︙ | ︙ |
Modified src/OFSet_hashtable.m from [a4b014ae97] to [97b4c86e48].
︙ | ︙ | |||
141 142 143 144 145 146 147 | - initWithObjects: (id const*)objects count: (size_t)count { self = [self initWithCapacity: count]; @try { | < < | | 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | - initWithObjects: (id const*)objects count: (size_t)count { self = [self initWithCapacity: count]; @try { for (size_t i = 0; i < count; i++) [_mapTable setValue: (void*)1 forKey: objects[i]]; } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ |
Modified src/OFStream.m from [9229ae9098] to [fefe498c92].
︙ | ︙ | |||
264 265 266 267 268 269 270 | { size_t size = count * sizeof(uint16_t); [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_BIG_ENDIAN | < < | < < | < < | < < | < < | | 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 | { size_t size = count * sizeof(uint16_t); [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OF_BSWAP16(buffer[i]); #endif return size; } - (size_t)readBigEndianInt32sIntoBuffer: (uint32_t*)buffer count: (size_t)count { size_t size = count * sizeof(uint32_t); [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OF_BSWAP32(buffer[i]); #endif return size; } - (size_t)readBigEndianInt64sIntoBuffer: (uint64_t*)buffer count: (size_t)count { size_t size = count * sizeof(uint64_t); [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OF_BSWAP64(buffer[i]); #endif return size; } - (size_t)readBigEndianFloatsIntoBuffer: (float*)buffer count: (size_t)count { size_t size = count * sizeof(float); [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_FLOAT_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OF_BSWAP_FLOAT(buffer[i]); #endif return size; } - (size_t)readBigEndianDoublesIntoBuffer: (double*)buffer count: (size_t)count { size_t size = count * sizeof(double); [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_FLOAT_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OF_BSWAP_DOUBLE(buffer[i]); #endif return size; } - (uint16_t)readLittleEndianInt16 |
︙ | ︙ | |||
404 405 406 407 408 409 410 | { size_t size = count * sizeof(uint16_t); [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_BIG_ENDIAN | < < | < < | < < | < < | < < | | 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 | { size_t size = count * sizeof(uint16_t); [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OF_BSWAP16(buffer[i]); #endif return size; } - (size_t)readLittleEndianInt32sIntoBuffer: (uint32_t*)buffer count: (size_t)count { size_t size = count * sizeof(uint32_t); [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OF_BSWAP32(buffer[i]); #endif return size; } - (size_t)readLittleEndianInt64sIntoBuffer: (uint64_t*)buffer count: (size_t)count { size_t size = count * sizeof(uint64_t); [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OF_BSWAP64(buffer[i]); #endif return size; } - (size_t)readLittleEndianFloatsIntoBuffer: (float*)buffer count: (size_t)count { size_t size = count * sizeof(float); [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_FLOAT_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OF_BSWAP_FLOAT(buffer[i]); #endif return size; } - (size_t)readLittleEndianDoublesIntoBuffer: (double*)buffer count: (size_t)count { size_t size = count * sizeof(double); [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_FLOAT_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OF_BSWAP_DOUBLE(buffer[i]); #endif return size; } - (OFDataArray*)readDataArrayWithCount: (size_t)count |
︙ | ︙ | |||
568 569 570 571 572 573 574 | } return ret; } - (OFString*)tryReadLineWithEncoding: (of_string_encoding_t)encoding { | | | | 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | } return ret; } - (OFString*)tryReadLineWithEncoding: (of_string_encoding_t)encoding { size_t pageSize, bufferLength, retLength; char *retCString, *buffer, *readBuffer; OFString *ret; /* Look if there's a line or \0 in our buffer */ if (!_waitingForDelimiter && _readBuffer != NULL) { for (size_t i = 0; i < _readBufferLength; i++) { if OF_UNLIKELY (_readBuffer[i] == '\n' || _readBuffer[i] == '\0') { retLength = i; if (i > 0 && _readBuffer[i - 1] == '\r') retLength--; |
︙ | ︙ | |||
634 635 636 637 638 639 640 | return ret; } bufferLength = [self lowlevelReadIntoBuffer: buffer length: pageSize]; /* Look if there's a newline or \0 */ | | | 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 | return ret; } bufferLength = [self lowlevelReadIntoBuffer: buffer length: pageSize]; /* Look if there's a newline or \0 */ for (size_t i = 0; i < bufferLength; i++) { if OF_UNLIKELY (buffer[i] == '\n' || buffer[i] == '\0') { retLength = _readBufferLength + i; retCString = [self allocMemoryWithSize: retLength]; if (_readBuffer != NULL) |
︙ | ︙ | |||
779 780 781 782 783 784 785 | return [self tryReadLineWithEncoding: OF_STRING_ENCODING_UTF_8]; } - (OFString*)tryReadTillDelimiter: (OFString*)delimiter encoding: (of_string_encoding_t)encoding { const char *delimiterCString; | | | | 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | return [self tryReadLineWithEncoding: OF_STRING_ENCODING_UTF_8]; } - (OFString*)tryReadTillDelimiter: (OFString*)delimiter encoding: (of_string_encoding_t)encoding { const char *delimiterCString; size_t j, delimiterLength, pageSize, bufferLength, retLength; char *retCString, *buffer, *readBuffer; OFString *ret; delimiterCString = [delimiter cStringWithEncoding: encoding]; delimiterLength = [delimiter cStringLengthWithEncoding: encoding]; j = 0; if (delimiterLength == 0) @throw [OFInvalidArgumentException exception]; /* Look if there's something in our buffer */ if (!_waitingForDelimiter && _readBuffer != NULL) { for (size_t i = 0; i < _readBufferLength; i++) { if (_readBuffer[i] != delimiterCString[j++]) j = 0; if (j == delimiterLength || _readBuffer[i] == '\0') { if (_readBuffer[i] == '\0') delimiterLength = 1; |
︙ | ︙ | |||
848 849 850 851 852 853 854 | return ret; } bufferLength = [self lowlevelReadIntoBuffer: buffer length: pageSize]; /* Look if there's a delimiter or \0 */ | | | 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 | return ret; } bufferLength = [self lowlevelReadIntoBuffer: buffer length: pageSize]; /* Look if there's a delimiter or \0 */ for (size_t i = 0; i < bufferLength; i++) { if (buffer[i] != delimiterCString[j++]) j = 0; if (j == delimiterLength || buffer[i] == '\0') { if (buffer[i] == '\0') delimiterLength = 1; |
︙ | ︙ | |||
1040 1041 1042 1043 1044 1045 1046 | { size_t size = count * sizeof(uint16_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else | < < | | < < | | 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 | { size_t size = count * sizeof(uint16_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint16_t *tmp = [self allocMemoryWithSize: sizeof(uint16_t) count: count]; @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP16(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { [self freeMemory: tmp]; } |
︙ | ︙ | |||
1070 1071 1072 1073 1074 1075 1076 | { size_t size = count * sizeof(uint32_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else | < < | | < < | | 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 | { size_t size = count * sizeof(uint32_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint32_t *tmp = [self allocMemoryWithSize: sizeof(uint32_t) count: count]; @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP32(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { [self freeMemory: tmp]; } |
︙ | ︙ | |||
1100 1101 1102 1103 1104 1105 1106 | { size_t size = count * sizeof(uint64_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else | < < | | < < | | 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 | { size_t size = count * sizeof(uint64_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint64_t *tmp = [self allocMemoryWithSize: sizeof(uint64_t) count: count]; @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP64(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { [self freeMemory: tmp]; } |
︙ | ︙ | |||
1130 1131 1132 1133 1134 1135 1136 | { size_t size = count * sizeof(float); #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else | < < | | < < | | 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 | { size_t size = count * sizeof(float); #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else float *tmp = [self allocMemoryWithSize: sizeof(float) count: count]; @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_FLOAT(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { [self freeMemory: tmp]; } |
︙ | ︙ | |||
1160 1161 1162 1163 1164 1165 1166 | { size_t size = count * sizeof(double); #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else | < < | | < < | | 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 | { size_t size = count * sizeof(double); #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else double *tmp = [self allocMemoryWithSize: sizeof(double) count: count]; @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_DOUBLE(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { [self freeMemory: tmp]; } |
︙ | ︙ | |||
1230 1231 1232 1233 1234 1235 1236 | { size_t size = count * sizeof(uint16_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else | < < | | < < | | 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 | { size_t size = count * sizeof(uint16_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint16_t *tmp = [self allocMemoryWithSize: sizeof(uint16_t) count: count]; @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP16(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { [self freeMemory: tmp]; } |
︙ | ︙ | |||
1260 1261 1262 1263 1264 1265 1266 | { size_t size = count * sizeof(uint32_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else | < < | | < < | | 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 | { size_t size = count * sizeof(uint32_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint32_t *tmp = [self allocMemoryWithSize: sizeof(uint32_t) count: count]; @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP32(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { [self freeMemory: tmp]; } |
︙ | ︙ | |||
1290 1291 1292 1293 1294 1295 1296 | { size_t size = count * sizeof(uint64_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else | < < | | < < | | 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 | { size_t size = count * sizeof(uint64_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint64_t *tmp = [self allocMemoryWithSize: sizeof(uint64_t) count: count]; @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP64(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { [self freeMemory: tmp]; } |
︙ | ︙ | |||
1320 1321 1322 1323 1324 1325 1326 | { size_t size = count * sizeof(float); #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else | < < | | < < | | 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 | { size_t size = count * sizeof(float); #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else float *tmp = [self allocMemoryWithSize: sizeof(float) count: count]; @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_FLOAT(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { [self freeMemory: tmp]; } |
︙ | ︙ | |||
1350 1351 1352 1353 1354 1355 1356 | { size_t size = count * sizeof(double); #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else | < < | | < < | | 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 | { size_t size = count * sizeof(double); #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else double *tmp = [self allocMemoryWithSize: sizeof(double) count: count]; @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_DOUBLE(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { [self freeMemory: tmp]; } |
︙ | ︙ |
Modified src/OFString+Hashing.m from [8511d233d9] to [0bdccbd7c3].
︙ | ︙ | |||
32 33 34 35 36 37 38 | - (OFString*)OF_hashAsStringWithHash: (Class <OFHash>)hashClass { void *pool = objc_autoreleasePoolPush(); id <OFHash> hash = [hashClass hash]; size_t digestSize = [hashClass digestSize]; const uint8_t *digest; char cString[digestSize * 2]; | < | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | - (OFString*)OF_hashAsStringWithHash: (Class <OFHash>)hashClass { void *pool = objc_autoreleasePoolPush(); id <OFHash> hash = [hashClass hash]; size_t digestSize = [hashClass digestSize]; const uint8_t *digest; char cString[digestSize * 2]; [hash updateWithBuffer: [self UTF8String] length: [self UTF8StringLength]]; digest = [hash digest]; for (size_t i = 0; i < digestSize; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; cString[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); cString[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); |
︙ | ︙ |
Modified src/OFString+JSONValue.m from [77e12ed016] to [0e3855dae5].
︙ | ︙ | |||
109 110 111 112 113 114 115 | } } static inline of_char16_t parseUnicodeEscape(const char *pointer, const char *stop) { of_char16_t ret = 0; | < | | 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | } } static inline of_char16_t parseUnicodeEscape(const char *pointer, const char *stop) { of_char16_t ret = 0; if (pointer + 5 >= stop) return 0xFFFF; if (pointer[0] != '\\' || pointer[1] != 'u') return 0xFFFF; for (uint8_t i = 0; i < 4; i++) { char c = pointer[i + 2]; ret <<= 4; if (c >= '0' && c <= '9') ret |= c - '0'; else if (c >= 'a' && c <= 'f') ret |= c + 10 - 'a'; |
︙ | ︙ |
Modified src/OFString+XMLEscaping.m from [0594cc40a6] to [90c811c9d5].
︙ | ︙ | |||
29 30 31 32 33 34 35 | @implementation OFString (XMLEscaping) - (OFString*)stringByXMLEscaping { void *pool = objc_autoreleasePoolPush(); char *retCString; const char *string, *append; size_t length, retLength, appendLen; | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 | @implementation OFString (XMLEscaping) - (OFString*)stringByXMLEscaping { void *pool = objc_autoreleasePoolPush(); char *retCString; const char *string, *append; size_t length, retLength, appendLen; size_t j; OFString *ret; string = [self UTF8String]; length = [self UTF8StringLength]; j = 0; retLength = length; /* * We can't use allocMemoryWithSize: here as it might be a @"" literal */ if ((retCString = malloc(retLength)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: retLength]; for (size_t i = 0; i < length; i++) { switch (string[i]) { case '<': append = "<"; appendLen = 4; break; case '>': append = ">"; appendLen = 4; break; case '"': append = """; appendLen = 6; break; case '\'': append = "'"; appendLen = 6; break; case '&': append = "&"; appendLen = 5; break; case '\r': append = "
"; appendLen = 5; break; default: append = NULL; appendLen = 0; } if (append != NULL) { char *newRetCString; if ((newRetCString = realloc(retCString, retLength + appendLen)) == NULL) { |
︙ | ︙ |
Modified src/OFString.m from [63a41717d2] to [e3e6e72034].
︙ | ︙ | |||
201 202 203 204 205 206 207 | array = [[components mutableCopy] autorelease]; if ((startsWithEmpty = [[array firstObject] isEqual: @""])) [array removeObjectAtIndex: 0]; endsWithEmpty = [[array lastObject] isEqual: @""]; while (!done) { | | | | 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | array = [[components mutableCopy] autorelease]; if ((startsWithEmpty = [[array firstObject] isEqual: @""])) [array removeObjectAtIndex: 0]; endsWithEmpty = [[array lastObject] isEqual: @""]; while (!done) { size_t length = [array count]; done = true; for (size_t i = 0; i < length; i++) { id object = [array objectAtIndex: i]; id parent; if (i > 0) parent = [array objectAtIndex: i - 1]; else parent = nil; |
︙ | ︙ | |||
1188 1189 1190 1191 1192 1193 1194 | } - (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding { switch (encoding) { case OF_STRING_ENCODING_UTF_8:; const of_unichar_t *characters; | | | | 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 | } - (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding { switch (encoding) { case OF_STRING_ENCODING_UTF_8:; const of_unichar_t *characters; size_t length, UTF8StringLength = 0; characters = [self characters]; length = [self length]; for (size_t i = 0; i < length; i++) { char buffer[4]; size_t len = of_string_utf8_encode(characters[i], buffer); if (len == 0) @throw [OFInvalidEncodingException exception]; |
︙ | ︙ | |||
1229 1230 1231 1232 1233 1234 1235 | { OF_UNRECOGNIZED_SELECTOR } - (void)getCharacters: (of_unichar_t*)buffer inRange: (of_range_t)range { | < < | | 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 | { OF_UNRECOGNIZED_SELECTOR } - (void)getCharacters: (of_unichar_t*)buffer inRange: (of_range_t)range { for (size_t i = 0; i < range.length; i++) buffer[i] = [self characterAtIndex: range.location + i]; } - (bool)isEqual: (id)object { void *pool; OFString *otherString; |
︙ | ︙ | |||
1285 1286 1287 1288 1289 1290 1291 | } - (of_comparison_result_t)compare: (id <OFComparing>)object { void *pool; OFString *otherString; const of_unichar_t *characters, *otherCharacters; | | | | 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 | } - (of_comparison_result_t)compare: (id <OFComparing>)object { void *pool; OFString *otherString; const of_unichar_t *characters, *otherCharacters; size_t minimumLength; if (object == self) return OF_ORDERED_SAME; if (![object isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; otherString = (OFString*)object; minimumLength = ([self length] > [otherString length] ? [otherString length] : [self length]); pool = objc_autoreleasePoolPush(); characters = [self characters]; otherCharacters = [otherString characters]; for (size_t i = 0; i < minimumLength; i++) { if (characters[i] > otherCharacters[i]) { objc_autoreleasePoolPop(pool); return OF_ORDERED_DESCENDING; } if (characters[i] < otherCharacters[i]) { objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
1328 1329 1330 1331 1332 1333 1334 | return OF_ORDERED_SAME; } - (of_comparison_result_t)caseInsensitiveCompare: (OFString*)otherString { void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters, *otherCharacters; | | | | 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 1352 | return OF_ORDERED_SAME; } - (of_comparison_result_t)caseInsensitiveCompare: (OFString*)otherString { void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters, *otherCharacters; size_t length, otherLength, minimumLength; if (otherString == self) return OF_ORDERED_SAME; characters = [self characters]; otherCharacters = [otherString characters]; length = [self length]; otherLength = [otherString length]; minimumLength = (length > otherLength ? otherLength : length); for (size_t i = 0; i < minimumLength; i++) { of_unichar_t c = characters[i]; of_unichar_t oc = otherCharacters[i]; if (c >> 8 < OF_UNICODE_CASEFOLDING_TABLE_SIZE) { of_unichar_t tc = of_unicode_casefolding_table[c >> 8][c & 0xFF]; |
︙ | ︙ | |||
1383 1384 1385 1386 1387 1388 1389 | return OF_ORDERED_SAME; } - (uint32_t)hash { const of_unichar_t *characters = [self characters]; | | | | 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 | return OF_ORDERED_SAME; } - (uint32_t)hash { const of_unichar_t *characters = [self characters]; size_t length = [self length]; uint32_t hash; OF_HASH_INIT(hash); for (size_t i = 0; i < length; i++) { const of_unichar_t c = characters[i]; OF_HASH_ADD(hash, (c & 0xFF0000) >> 16); OF_HASH_ADD(hash, (c & 0x00FF00) >> 8); OF_HASH_ADD(hash, c & 0x0000FF); } |
︙ | ︙ | |||
1563 1564 1565 1566 1567 1568 1569 | - (of_range_t)rangeOfString: (OFString*)string options: (int)options range: (of_range_t)range { void *pool; const of_unichar_t *searchCharacters; of_unichar_t *characters; | | | 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 | - (of_range_t)rangeOfString: (OFString*)string options: (int)options range: (of_range_t)range { void *pool; const of_unichar_t *searchCharacters; of_unichar_t *characters; size_t searchLength; if ((searchLength = [string length]) == 0) return of_range(0, 0); if (searchLength > range.length) return of_range(OF_NOT_FOUND, 0); |
︙ | ︙ | |||
1588 1589 1590 1591 1592 1593 1594 | range.length * sizeof(of_unichar_t)]; @try { [self getCharacters: characters inRange: range]; if (options & OF_STRING_SEARCH_BACKWARDS) { | | > | | 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 | range.length * sizeof(of_unichar_t)]; @try { [self getCharacters: characters inRange: range]; if (options & OF_STRING_SEARCH_BACKWARDS) { for (size_t i = range.length - searchLength;; i--) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(of_unichar_t)) == 0) { objc_autoreleasePoolPop(pool); return of_range(range.location + i, searchLength); } /* No match and we're at the last character */ if (i == 0) break; } } else { for (size_t i = 0; i <= range.length - searchLength; i++) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(of_unichar_t)) == 0) { objc_autoreleasePoolPop(pool); return of_range(range.location + i, searchLength); } } |
︙ | ︙ | |||
1623 1624 1625 1626 1627 1628 1629 | return of_range(OF_NOT_FOUND, 0); } - (bool)containsString: (OFString*)string { void *pool; const of_unichar_t *characters, *searchCharacters; | | | | 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 | return of_range(OF_NOT_FOUND, 0); } - (bool)containsString: (OFString*)string { void *pool; const of_unichar_t *characters, *searchCharacters; size_t length, searchLength; if ((searchLength = [string length]) == 0) return true; if (searchLength > (length = [self length])) return false; pool = objc_autoreleasePoolPush(); characters = [self characters]; searchCharacters = [string characters]; for (size_t i = 0; i <= length - searchLength; i++) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(of_unichar_t)) == 0) { objc_autoreleasePoolPop(pool); return true; } } |
︙ | ︙ | |||
1904 1905 1906 1907 1908 1909 1910 | { void *pool; OFMutableArray *array = [OFMutableArray array]; const of_unichar_t *characters, *delimiterCharacters; bool skipEmpty = (options & OF_STRING_SKIP_EMPTY); size_t length = [self length]; size_t delimiterLength = [delimiter length]; | | > | | 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 | { void *pool; OFMutableArray *array = [OFMutableArray array]; const of_unichar_t *characters, *delimiterCharacters; bool skipEmpty = (options & OF_STRING_SKIP_EMPTY); size_t length = [self length]; size_t delimiterLength = [delimiter length]; size_t last; OFString *component; pool = objc_autoreleasePoolPush(); characters = [self characters]; delimiterCharacters = [delimiter characters]; if (delimiterLength > length) { [array addObject: [[self copy] autorelease]]; [array makeImmutable]; objc_autoreleasePoolPop(pool); return array; } last = 0; for (size_t i = 0; i <= length - delimiterLength; i++) { if (memcmp(characters + i, delimiterCharacters, delimiterLength * sizeof(of_unichar_t)) != 0) continue; component = [self substringWithRange: of_range(last, i - last)]; if (!skipEmpty || [component length] > 0) [array addObject: component]; |
︙ | ︙ | |||
2050 2051 2052 2053 2054 2055 2056 | return [ret autorelease]; } - (OFString*)stringByDeletingLastPathComponent { void *pool; const of_unichar_t *characters; | | | | 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 | return [ret autorelease]; } - (OFString*)stringByDeletingLastPathComponent { void *pool; const of_unichar_t *characters; size_t length = [self length]; if (length == 0) return @""; pool = objc_autoreleasePoolPush(); characters = [self characters]; if (OF_IS_PATH_DELIMITER(characters[length - 1])) length--; if (length == 0) { objc_autoreleasePoolPop(pool); return [self substringWithRange: of_range(0, 1)]; } for (size_t i = length - 1; i >= 1; i--) { if (OF_IS_PATH_DELIMITER(characters[i])) { objc_autoreleasePoolPop(pool); return [self substringWithRange: of_range(0, i)]; } } if (OF_IS_PATH_DELIMITER(characters[0])) { |
︙ | ︙ | |||
2328 2329 2330 2331 2332 2333 2334 | - (const of_char16_t*)UTF16StringWithByteOrder: (of_byte_order_t)byteOrder { OFObject *object = [[[OFObject alloc] init] autorelease]; void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters = [self characters]; size_t length = [self length]; of_char16_t *ret; | | < | | 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 | - (const of_char16_t*)UTF16StringWithByteOrder: (of_byte_order_t)byteOrder { OFObject *object = [[[OFObject alloc] init] autorelease]; void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters = [self characters]; size_t length = [self length]; of_char16_t *ret; size_t j; bool swap = (byteOrder != OF_BYTE_ORDER_NATIVE); /* Allocate memory for the worst case */ ret = [object allocMemoryWithSize: sizeof(of_char16_t) count: (length + 1) * 2]; j = 0; for (size_t i = 0; i < length; i++) { of_unichar_t c = characters[i]; if (c > 0x10FFFF) @throw [OFInvalidEncodingException exception]; if (swap) { if (c > 0xFFFF) { |
︙ | ︙ | |||
2377 2378 2379 2380 2381 2382 2383 | return ret; } - (size_t)UTF16StringLength { const of_unichar_t *characters = [self characters]; | | | | 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 | return ret; } - (size_t)UTF16StringLength { const of_unichar_t *characters = [self characters]; size_t length, UTF16StringLength; length = UTF16StringLength = [self length]; for (size_t i = 0; i < length; i++) if (characters[i] > 0xFFFF) UTF16StringLength++; return UTF16StringLength; } - (const of_char32_t*)UTF32String |
︙ | ︙ | |||
2405 2406 2407 2408 2409 2410 2411 | ret = [object allocMemoryWithSize: sizeof(of_char32_t) count: length + 1]; [self getCharacters: ret inRange: of_range(0, length)]; ret[length] = 0; | | < < | < | 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 | ret = [object allocMemoryWithSize: sizeof(of_char32_t) count: length + 1]; [self getCharacters: ret inRange: of_range(0, length)]; ret[length] = 0; if (byteOrder != OF_BYTE_ORDER_NATIVE) for (size_t i = 0; i < length; i++) ret[i] = OF_BSWAP32(ret[i]); return ret; } #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString*)path { |
︙ | ︙ |
Modified src/OFString_UTF8.m from [035a617a1b] to [f9779f2392].
︙ | ︙ | |||
41 42 43 44 45 46 47 | extern const of_char16_t of_iso_8859_15[128]; extern const of_char16_t of_windows_1252[128]; extern const of_char16_t of_codepage_437[128]; static inline int memcasecmp(const char *first, const char *second, size_t length) { | < < | | | | 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 | extern const of_char16_t of_iso_8859_15[128]; extern const of_char16_t of_windows_1252[128]; extern const of_char16_t of_codepage_437[128]; static inline int memcasecmp(const char *first, const char *second, size_t length) { for (size_t i = 0; i < length; i++) { if (tolower((int)first[i]) > tolower((int)second[i])) return OF_ORDERED_DESCENDING; if (tolower((int)first[i]) < tolower((int)second[i])) return OF_ORDERED_ASCENDING; } return OF_ORDERED_SAME; } int of_string_utf8_check(const char *UTF8String, size_t UTF8Length, size_t *length) { size_t tmpLength = UTF8Length; int isUTF8 = 0; for (size_t i = 0; i < UTF8Length; i++) { /* No sign of UTF-8 here */ if OF_LIKELY (!(UTF8String[i] & 0x80)) continue; isUTF8 = 1; /* We're missing a start byte here */ |
︙ | ︙ | |||
123 124 125 126 127 128 129 | return isUTF8; } size_t of_string_utf8_get_index(const char *string, size_t position) { | | | < < | | 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | return isUTF8; } size_t of_string_utf8_get_index(const char *string, size_t position) { size_t index = position; for (size_t i = 0; i < position; i++) if OF_UNLIKELY ((string[i] & 0xC0) == 0x80) index--; return index; } size_t of_string_utf8_get_position(const char *string, size_t index, size_t length) { for (size_t i = 0; i <= index; i++) if OF_UNLIKELY ((string[i] & 0xC0) == 0x80) if (++index > length) return OF_NOT_FOUND; return index; } |
︙ | ︙ | |||
207 208 209 210 211 212 213 | - initWithCString: (const char*)cString encoding: (of_string_encoding_t)encoding length: (size_t)cStringLength { self = [super init]; @try { | < > | 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | - initWithCString: (const char*)cString encoding: (of_string_encoding_t)encoding length: (size_t)cStringLength { self = [super init]; @try { const of_char16_t *table; size_t j; if (encoding == OF_STRING_ENCODING_UTF_8 && cStringLength >= 3 && memcmp(cString, "\xEF\xBB\xBF", 3) == 0) { cString += 3; cStringLength -= 3; } |
︙ | ︙ | |||
247 248 249 250 251 252 253 | return self; } /* All other encodings we support are single byte encodings */ _s->length = cStringLength; if (encoding == OF_STRING_ENCODING_ISO_8859_1) { | > | | 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | return self; } /* All other encodings we support are single byte encodings */ _s->length = cStringLength; if (encoding == OF_STRING_ENCODING_ISO_8859_1) { j = 0; for (size_t i = 0; i < cStringLength; i++) { char buffer[4]; size_t bytes; if (!(cString[i] & 0x80)) { _s->cString[j++] = cString[i]; continue; } |
︙ | ︙ | |||
292 293 294 295 296 297 298 | case OF_STRING_ENCODING_CODEPAGE_437: table = of_codepage_437; break; default: @throw [OFInvalidEncodingException exception]; } | > | | 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | case OF_STRING_ENCODING_CODEPAGE_437: table = of_codepage_437; break; default: @throw [OFInvalidEncodingException exception]; } j = 0; for (size_t i = 0; i < cStringLength; i++) { char buffer[4]; of_unichar_t character; size_t characterBytes; if (!(cString[i] & 0x80)) { _s->cString[j++] = cString[i]; continue; |
︙ | ︙ | |||
403 404 405 406 407 408 409 | - initWithCharacters: (const of_unichar_t*)characters length: (size_t)length { self = [super init]; @try { | | > | | 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | - initWithCharacters: (const of_unichar_t*)characters length: (size_t)length { self = [super init]; @try { size_t j; _s = &_storage; _s->cString = [self allocMemoryWithSize: (length * 4) + 1]; _s->length = length; j = 0; for (size_t i = 0; i < length; i++) { size_t len = of_string_utf8_encode(characters[i], _s->cString + j); if (len == 0) @throw [OFInvalidEncodingException exception]; if (len > 1) |
︙ | ︙ | |||
447 448 449 450 451 452 453 | - initWithUTF16String: (const of_char16_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { self = [super init]; @try { | | > | | 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 | - initWithUTF16String: (const of_char16_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { self = [super init]; @try { size_t j; bool swap = false; if (length > 0 && *string == 0xFEFF) { string++; length--; } else if (length > 0 && *string == 0xFFFE) { swap = true; string++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = true; _s = &_storage; _s->cString = [self allocMemoryWithSize: (length * 4) + 1]; _s->length = length; j = 0; for (size_t i = 0; i < length; i++) { of_unichar_t character = (swap ? OF_BSWAP16(string[i]) : string[i]); size_t len; /* Missing high surrogate */ if ((character & 0xFC00) == 0xDC00) @throw [OFInvalidEncodingException exception]; |
︙ | ︙ | |||
531 532 533 534 535 536 537 | - initWithUTF32String: (const of_char32_t*)characters length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { self = [super init]; @try { | | > | | 531 532 533 534 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 564 | - initWithUTF32String: (const of_char32_t*)characters length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { self = [super init]; @try { size_t j; bool swap = false; if (length > 0 && *characters == 0xFEFF) { characters++; length--; } else if (length > 0 && *characters == 0xFFFE0000) { swap = true; characters++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = true; _s = &_storage; _s->cString = [self allocMemoryWithSize: (length * 4) + 1]; _s->length = length; j = 0; for (size_t i = 0; i < length; i++) { char buffer[4]; size_t len = of_string_utf8_encode( (swap ? OF_BSWAP32(characters[i]) : characters[i]), buffer); switch (len) { case 1: |
︙ | ︙ | |||
848 849 850 851 852 853 854 | return OF_ORDERED_ASCENDING; return OF_ORDERED_SAME; } - (uint32_t)hash { | < | | 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | return OF_ORDERED_ASCENDING; return OF_ORDERED_SAME; } - (uint32_t)hash { uint32_t hash; if (_s->hashed) return _s->hash; OF_HASH_INIT(hash); for (size_t i = 0; i < _s->cStringLength; i++) { of_unichar_t c; size_t length; if ((length = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c)) == 0) @throw [OFInvalidEncodingException exception]; |
︙ | ︙ | |||
921 922 923 924 925 926 927 | } - (of_range_t)rangeOfString: (OFString*)string options: (int)options range: (of_range_t)range { const char *cString = [string UTF8String]; | | | 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 | } - (of_range_t)rangeOfString: (OFString*)string options: (int)options range: (of_range_t)range { const char *cString = [string UTF8String]; size_t cStringLength = [string UTF8StringLength]; size_t rangeLocation, rangeLength; if (range.length > SIZE_MAX - range.location || range.location + range.length > _s->length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { |
︙ | ︙ | |||
946 947 948 949 950 951 952 | if (cStringLength == 0) return of_range(0, 0); if (cStringLength > rangeLength) return of_range(OF_NOT_FOUND, 0); if (options & OF_STRING_SEARCH_BACKWARDS) { | | | | | | 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 | if (cStringLength == 0) return of_range(0, 0); if (cStringLength > rangeLength) return of_range(OF_NOT_FOUND, 0); if (options & OF_STRING_SEARCH_BACKWARDS) { for (size_t i = rangeLength - cStringLength;; i--) { if (memcmp(_s->cString + rangeLocation + i, cString, cStringLength) == 0) { range.location += of_string_utf8_get_index( _s->cString + rangeLocation, i); range.length = [string length]; return range; } /* Did not match and we're at the last char */ if (i == 0) return of_range(OF_NOT_FOUND, 0); } } else { for (size_t i = 0; i <= rangeLength - cStringLength; i++) { if (memcmp(_s->cString + rangeLocation + i, cString, cStringLength) == 0) { range.location += of_string_utf8_get_index( _s->cString + rangeLocation, i); range.length = [string length]; return range; } } } return of_range(OF_NOT_FOUND, 0); } - (bool)containsString: (OFString*)string { const char *cString = [string UTF8String]; size_t cStringLength = [string UTF8StringLength]; if (cStringLength == 0) return true; if (cStringLength > _s->cStringLength) return false; for (size_t i = 0; i <= _s->cStringLength - cStringLength; i++) if (memcmp(_s->cString + i, cString, cStringLength) == 0) return true; return false; } - (OFString*)substringWithRange: (of_range_t)range |
︙ | ︙ | |||
1042 1043 1044 1045 1046 1047 1048 | options: (int)options { void *pool; OFMutableArray *array; const char *cString = [delimiter UTF8String]; size_t cStringLength = [delimiter UTF8StringLength]; bool skipEmpty = (options & OF_STRING_SKIP_EMPTY); | | > | | 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 | options: (int)options { void *pool; OFMutableArray *array; const char *cString = [delimiter UTF8String]; size_t cStringLength = [delimiter UTF8StringLength]; bool skipEmpty = (options & OF_STRING_SKIP_EMPTY); size_t last; OFString *component; array = [OFMutableArray array]; pool = objc_autoreleasePoolPush(); if (cStringLength > _s->cStringLength) { [array addObject: [[self copy] autorelease]]; objc_autoreleasePoolPop(pool); return array; } last = 0; for (size_t i = 0; i <= _s->cStringLength - cStringLength; i++) { if (memcmp(_s->cString + i, cString, cStringLength) != 0) continue; component = [OFString stringWithUTF8String: _s->cString + last length: i - last]; if (!skipEmpty || [component length] > 0) [array addObject: component]; |
︙ | ︙ | |||
1150 1151 1152 1153 1154 1155 1156 | return [OFString stringWithUTF8String: _s->cString + i length: pathCStringLength - i]; } - (OFString*)stringByDeletingLastPathComponent { | | | | 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 | return [OFString stringWithUTF8String: _s->cString + i length: pathCStringLength - i]; } - (OFString*)stringByDeletingLastPathComponent { size_t pathCStringLength = _s->cStringLength; if (pathCStringLength == 0) return @""; if (OF_IS_PATH_DELIMITER(_s->cString[pathCStringLength - 1])) pathCStringLength--; if (pathCStringLength == 0) return [OFString stringWithUTF8String: _s->cString length: 1]; for (size_t i = pathCStringLength - 1; i >= 1; i--) if (OF_IS_PATH_DELIMITER(_s->cString[i])) return [OFString stringWithUTF8String: _s->cString length: i]; if (OF_IS_PATH_DELIMITER(_s->cString[0])) return [OFString stringWithUTF8String: _s->cString length: 1]; |
︙ | ︙ |
Modified src/OFThreadPool.m from [3a80ac4df5] to [629df82865].
︙ | ︙ | |||
256 257 258 259 260 261 262 | } - initWithSize: (size_t)size { self = [super init]; @try { | < < | | | | 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 | } - initWithSize: (size_t)size { self = [super init]; @try { _size = size; _threads = [[OFMutableArray alloc] init]; _queue = [[OFList alloc] init]; _queueCondition = [[OFCondition alloc] init]; _countCondition = [[OFCondition alloc] init]; for (size_t i = 0; i < size; i++) { void *pool = objc_autoreleasePoolPush(); OFThreadPoolThread *thread = [OFThreadPoolThread threadWithThreadPool: self]; [_threads addObject: thread]; objc_autoreleasePoolPop(pool); } /* * We need to start the threads in a separate loop to make sure * _threads is not modified anymore to prevent a race condition. */ for (size_t i = 0; i < size; i++) [[_threads objectAtIndex: i] start]; } @catch (id e) { [self release]; @throw e; } return self; |
︙ | ︙ |
Modified src/OFUDPSocket.m from [0280b236b8] to [40c5efdd20].
︙ | ︙ | |||
232 233 234 235 236 237 238 | of_udp_socket_address_hash(of_udp_socket_address_t *address) { uint32_t hash = of_hash_seed; struct sockaddr_in *sin; #ifdef AF_INET6 struct sockaddr_in6 *sin6; uint32_t subhash; | < | 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | of_udp_socket_address_hash(of_udp_socket_address_t *address) { uint32_t hash = of_hash_seed; struct sockaddr_in *sin; #ifdef AF_INET6 struct sockaddr_in6 *sin6; uint32_t subhash; #endif hash += address->address.ss_family; switch (address->address.ss_family) { case AF_INET: #ifndef OF_WII |
︙ | ︙ | |||
264 265 266 267 268 269 270 | sin6 = (struct sockaddr_in6*)&address->address; hash += (sin6->sin6_port << 1); OF_HASH_INIT(subhash); | | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | sin6 = (struct sockaddr_in6*)&address->address; hash += (sin6->sin6_port << 1); OF_HASH_INIT(subhash); for (size_t i = 0; i < sizeof(sin6->sin6_addr.s6_addr); i++) OF_HASH_ADD(subhash, sin6->sin6_addr.s6_addr[i]); OF_HASH_FINALIZE(subhash); hash ^= subhash; break; |
︙ | ︙ |
Modified src/OFXMLElement.m from [1b3b42ec8f] to [09fc7f39d0].
︙ | ︙ | |||
423 424 425 426 427 428 429 | - (OFString*)OF_XMLStringWithParent: (OFXMLElement*)parent namespaces: (OFDictionary*)allNamespaces indentation: (unsigned int)indentation level: (unsigned int)level { void *pool; char *cString; | | | 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | - (OFString*)OF_XMLStringWithParent: (OFXMLElement*)parent namespaces: (OFDictionary*)allNamespaces indentation: (unsigned int)indentation level: (unsigned int)level { void *pool; char *cString; size_t length, i, attributesCount; OFString *prefix, *parentPrefix; OFXMLAttribute *const *attributesObjects; OFString *ret; OFString *defaultNS; pool = objc_autoreleasePoolPush(); |
︙ | ︙ | |||
517 518 519 520 521 522 523 | cString[i++] = '\''; } /* Attributes */ attributesObjects = [_attributes objects]; attributesCount = [_attributes count]; | | | 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | cString[i++] = '\''; } /* Attributes */ attributesObjects = [_attributes objects]; attributesCount = [_attributes count]; for (size_t j = 0; j < attributesCount; j++) { void *pool2 = objc_autoreleasePoolPush(); OFString *attributeName = [attributesObjects[j] name]; OFString *attributePrefix = nil; OFString *tmp = [[attributesObjects[j] stringValue] stringByXMLEscaping]; if ([attributesObjects[j] namespace] != nil && |
︙ | ︙ | |||
574 575 576 577 578 579 580 | size_t childrenCount = [_children count]; OFDataArray *tmp = [OFDataArray dataArray]; bool indent; if (indentation > 0) { indent = true; | | | | 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 | size_t childrenCount = [_children count]; OFDataArray *tmp = [OFDataArray dataArray]; bool indent; if (indentation > 0) { indent = true; for (size_t j = 0; j < childrenCount; j++) { if ([childrenObjects[j] isKindOfClass: charactersClass] || [childrenObjects[j] isKindOfClass: CDATAClass]) { indent = false; break; } } } else indent = false; for (size_t j = 0; j < childrenCount; j++) { OFString *child; unsigned int ind = (indent ? indentation : 0); if (ind) [tmp addItem: "\n"]; if ([childrenObjects[j] isKindOfClass: |
︙ | ︙ | |||
819 820 821 822 823 824 825 | return nil; } - (void)removeAttributeForName: (OFString*)attributeName { OFXMLAttribute *const *objects = [_attributes objects]; | | | | | | 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 | return nil; } - (void)removeAttributeForName: (OFString*)attributeName { OFXMLAttribute *const *objects = [_attributes objects]; size_t count = [_attributes count]; for (size_t i = 0; i < count; i++) { if (objects[i]->_namespace == nil && [objects[i]->_name isEqual: attributeName]) { [_attributes removeObjectAtIndex: i]; return; } } } - (void)removeAttributeForName: (OFString*)attributeName namespace: (OFString*)attributeNS { OFXMLAttribute *const *objects; size_t count; if (attributeNS == nil) { [self removeAttributeForName: attributeName]; return; } objects = [_attributes objects]; count = [_attributes count]; for (size_t i = 0; i < count; i++) { if ([objects[i]->_namespace isEqual: attributeNS] && [objects[i]->_name isEqual: attributeName]) { [_attributes removeObjectAtIndex: i]; return; } } } |
︙ | ︙ |
Modified src/OFXMLParser.m from [497caa1df6] to [0b91cb99ed].
︙ | ︙ | |||
60 61 62 63 64 65 66 | } } static OFString* transformString(OFXMLParser *parser, OFDataArray *buffer, size_t cut, bool unescape) { | | | < < < | | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | } } static OFString* transformString(OFXMLParser *parser, OFDataArray *buffer, size_t cut, bool unescape) { char *items = [buffer items]; size_t length = [buffer count] - cut; bool hasEntities = false; OFString *ret; for (size_t i = 0; i < length; i++) { if (items[i] == '\r') { if (i + 1 < length && items[i + 1] == '\n') { [buffer removeItemAtIndex: i]; items = [buffer items]; i--; length--; |
︙ | ︙ | |||
102 103 104 105 106 107 108 | } static OFString* namespaceForPrefix(OFString *prefix, OFArray *namespaces) { OFDictionary *const *objects = [namespaces objects]; size_t count = [namespaces count]; | < | | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | } static OFString* namespaceForPrefix(OFString *prefix, OFArray *namespaces) { OFDictionary *const *objects = [namespaces objects]; size_t count = [namespaces count]; if (prefix == nil) prefix = @""; if (count - 1 > SSIZE_MAX) @throw [OFOutOfRangeException exception]; for (ssize_t i = count - 1; i >= 0; i--) { OFString *tmp; if ((tmp = [objects[i] objectForKey: prefix]) != nil) return tmp; } return nil; |
︙ | ︙ | |||
146 147 148 149 150 151 152 | } @implementation OFXMLParser @synthesize delegate = _delegate, depthLimit = _depthLimit; + (void)initialize { | < < | 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | } @implementation OFXMLParser @synthesize delegate = _delegate, depthLimit = _depthLimit; + (void)initialize { const SEL selectors_[OF_XMLPARSER_NUM_STATES] = { @selector(OF_inByteOrderMarkState), @selector(OF_outsideTagState), @selector(OF_tagOpenedState), @selector(OF_inProcessingInstructionsState), @selector(OF_inTagNameState), @selector(OF_inCloseTagNameState), |
︙ | ︙ | |||
172 173 174 175 176 177 178 | @selector(OF_inCommentOpeningState), @selector(OF_inCommentState1), @selector(OF_inCommentState2), @selector(OF_inDOCTYPEState) }; memcpy(selectors, selectors_, sizeof(selectors_)); | | | 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | @selector(OF_inCommentOpeningState), @selector(OF_inCommentState1), @selector(OF_inCommentState2), @selector(OF_inDOCTYPEState) }; memcpy(selectors, selectors_, sizeof(selectors_)); for (size_t i = 0; i < OF_XMLPARSER_NUM_STATES; i++) { if (![self instancesRespondToSelector: selectors[i]]) @throw [OFInitializationFailedException exceptionWithClass: self]; lookupTable[i] = (state_function_t) [self instanceMethodForSelector: selectors[i]]; } |
︙ | ︙ | |||
395 396 397 398 399 400 401 | } } /* <?xml […]?> */ - (bool)OF_parseXMLProcessingInstructions: (OFString*)pi { const char *cString; | | > | | 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 | } } /* <?xml […]?> */ - (bool)OF_parseXMLProcessingInstructions: (OFString*)pi { const char *cString; size_t length, last; int PIState = 0; OFString *attribute = nil; OFMutableString *value = nil; char piDelimiter = 0; bool hasVersion = false; if (!_acceptProlog) return false; _acceptProlog = false; pi = [pi substringWithRange: of_range(3, [pi length] - 3)]; pi = [pi stringByDeletingEnclosingWhitespaces]; cString = [pi UTF8String]; length = [pi UTF8StringLength]; last = 0; for (size_t i = 0; i < length; i++) { switch (PIState) { case 0: if (cString[i] == ' ' || cString[i] == '\t' || cString[i] == '\r' || cString[i] == '\n') continue; last = i; |
︙ | ︙ | |||
688 689 690 691 692 693 694 | /* Inside a tag, name found */ - (void)OF_inTagState { void *pool; OFString *namespace; OFXMLAttribute *const *attributesObjects; | | | 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | /* Inside a tag, name found */ - (void)OF_inTagState { void *pool; OFString *namespace; OFXMLAttribute *const *attributesObjects; size_t attributesCount; if (_data[_i] != '>' && _data[_i] != '/') { if (_data[_i] != ' ' && _data[_i] != '\t' && _data[_i] != '\n' && _data[_i] != '\r') { _last = _i; _state = OF_XMLPARSER_IN_ATTRIBUTE_NAME; _i--; |
︙ | ︙ | |||
710 711 712 713 714 715 716 | namespace = namespaceForPrefix(_prefix, _namespaces); if (_prefix != nil && namespace == nil) @throw [OFUnboundPrefixException exceptionWithPrefix: _prefix parser: self]; | | | 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | namespace = namespaceForPrefix(_prefix, _namespaces); if (_prefix != nil && namespace == nil) @throw [OFUnboundPrefixException exceptionWithPrefix: _prefix parser: self]; for (size_t j = 0; j < attributesCount; j++) resolveAttributeNamespace(attributesObjects[j], _namespaces, self); pool = objc_autoreleasePoolPush(); if ([_delegate respondsToSelector: @selector(parser:didStartElement:prefix:namespace:attributes:)]) |
︙ | ︙ |
Modified src/OFZIPArchive.m from [b5e5e4f9e4] to [8e1e5b444d].
︙ | ︙ | |||
82 83 84 85 86 87 88 | localFileHeader: (OFZIPArchive_LocalFileHeader*)localFileHeader; @end uint32_t of_zip_archive_read_field32(uint8_t **data, uint16_t *size) { uint32_t field = 0; | < | < | < < | < < | | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | localFileHeader: (OFZIPArchive_LocalFileHeader*)localFileHeader; @end uint32_t of_zip_archive_read_field32(uint8_t **data, uint16_t *size) { uint32_t field = 0; if (*size < 4) @throw [OFInvalidFormatException exception]; for (uint8_t i = 0; i < 4; i++) field |= (uint32_t)(*data)[i] << (i * 8); *data += 4; *size -= 4; return field; } uint64_t of_zip_archive_read_field64(uint8_t **data, uint16_t *size) { uint64_t field = 0; if (*size < 8) @throw [OFInvalidFormatException exception]; for (uint8_t i = 0; i < 8; i++) field |= (uint64_t)(*data)[i] << (i * 8); *data += 8; *size -= 8; return field; } static uint32_t calculateCRC32(uint32_t crc, uint8_t *bytes, size_t length) { for (size_t i = 0; i < length; i++) { crc ^= bytes[i]; for (uint8_t j = 0; j < 8; j++) crc = (crc >> 1) ^ (CRC32_MAGIC & (~(crc & 1) + 1)); } return crc; } static void |
︙ | ︙ | |||
300 301 302 303 304 305 306 | objc_autoreleasePoolPop(pool); } - (void)OF_readEntries { void *pool = objc_autoreleasePoolPush(); | < | | 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 | objc_autoreleasePoolPop(pool); } - (void)OF_readEntries { void *pool = objc_autoreleasePoolPush(); if ((of_offset_t)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat(_stream, (of_offset_t)_centralDirectoryOffset, SEEK_SET); _entries = [[OFMutableArray alloc] init]; _pathToEntryMap = [[OFMutableDictionary alloc] init]; for (size_t i = 0; i < _centralDirectoryEntries; i++) { OFZIPArchiveEntry *entry = [[[OFZIPArchiveEntry alloc] OF_initWithStream: _stream] autorelease]; if ([_pathToEntryMap objectForKey: [entry fileName]] != nil) @throw [OFInvalidFormatException exception]; [_entries addObject: entry]; |
︙ | ︙ |
Modified src/OFZIPArchiveEntry.m from [66169b3a5c] to [1b46fcc45c].
︙ | ︙ | |||
107 108 109 110 111 112 113 | (version % 0xFF) / 10, (version & 0xFF) % 10, version >> 8]; } void of_zip_archive_entry_extra_field_find(OFDataArray *extraField, uint16_t tag, uint8_t **data, uint16_t *size) { | < < < | | | | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | (version % 0xFF) / 10, (version & 0xFF) % 10, version >> 8]; } void of_zip_archive_entry_extra_field_find(OFDataArray *extraField, uint16_t tag, uint8_t **data, uint16_t *size) { uint8_t *bytes = [extraField items]; size_t count = [extraField count]; for (size_t i = 0; i < count;) { uint16_t currentTag, currentSize; if (i + 3 >= count) @throw [OFInvalidFormatException exception]; currentTag = (bytes[i + 1] << 8) | bytes[i]; currentSize = (bytes[i + 3] << 8) | bytes[i + 2]; |
︙ | ︙ |
Modified src/codepage_437.m from [31a2de52cc] to [02f57a645e].
︙ | ︙ | |||
37 38 39 40 41 42 43 | 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 }; bool of_unicode_to_codepage_437(const of_unichar_t *input, uint8_t *output, size_t length, bool lossy) { | < < | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 }; bool of_unicode_to_codepage_437(const of_unichar_t *input, uint8_t *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { of_unichar_t c = input[i]; if OF_UNLIKELY (c > 0x7F) { if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; |
︙ | ︙ |
Modified src/exceptions/OFException.m from [79bfb21fe1] to [cf73e10b2d].
︙ | ︙ | |||
258 259 260 261 262 263 264 | } - (OFArray*)backtrace { #ifdef HAVE_DWARF_EXCEPTIONS OFMutableArray *backtrace = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); | < > | | 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | } - (OFArray*)backtrace { #ifdef HAVE_DWARF_EXCEPTIONS OFMutableArray *backtrace = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (uint8_t i = 0; i < OF_BACKTRACE_SIZE && _backtrace[i] != NULL; i++) { # ifdef HAVE_DLADDR Dl_info info; if (dladdr(_backtrace[i], &info)) { OFString *frame; if (info.dli_sname != NULL) { |
︙ | ︙ |
Modified src/iso_8859_15.m from [d399d3a43d] to [f44e6f6312].
︙ | ︙ | |||
37 38 39 40 41 42 43 | 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF }; bool of_unicode_to_iso_8859_15(const of_unichar_t *input, uint8_t *output, size_t length, bool lossy) { | < < | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF }; bool of_unicode_to_iso_8859_15(const of_unichar_t *input, uint8_t *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { of_unichar_t c = input[i]; if OF_UNLIKELY (c > 0xFF) { if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; |
︙ | ︙ |
Modified src/of_asprintf.m from [45f853ae7d] to [bff5bd9808].
︙ | ︙ | |||
377 378 379 380 381 382 383 | return false; ctx->subformat[ctx->subformatLen - 1] = 's'; { const of_unichar_t *arg = va_arg(ctx->arguments, const of_unichar_t*); | | > | | 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 | return false; ctx->subformat[ctx->subformatLen - 1] = 's'; { const of_unichar_t *arg = va_arg(ctx->arguments, const of_unichar_t*); size_t j, len = of_string_utf32_length(arg); char *buffer; if (SIZE_MAX / 4 < len || (SIZE_MAX / 4) - len < 1) return false; if ((buffer = malloc((len * 4) + 1)) == NULL) return false; j = 0; for (size_t i = 0; i < len; i++) { size_t clen = of_string_utf8_encode(arg[i], buffer + j); if (clen == 0) { free(buffer); return false; } |
︙ | ︙ |
Modified src/of_strptime.m from [d08e29e35b] to [e62baac3c8].
︙ | ︙ | |||
25 26 27 28 29 30 31 | const char* of_strptime(const char *buffer, const char *format, struct tm *tm) { enum { SEARCH_CONVERSION_SPECIFIER, IN_CONVERSION_SPECIFIER } state = SEARCH_CONVERSION_SPECIFIER; | | > | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | const char* of_strptime(const char *buffer, const char *format, struct tm *tm) { enum { SEARCH_CONVERSION_SPECIFIER, IN_CONVERSION_SPECIFIER } state = SEARCH_CONVERSION_SPECIFIER; size_t j, buffer_len, format_len; buffer_len = strlen(buffer); format_len = strlen(format); j = 0; for (size_t i = 0; i < format_len; i++) { if (j >= buffer_len) return NULL; switch (state) { case SEARCH_CONVERSION_SPECIFIER: if (format[i] == '%') state = IN_CONVERSION_SPECIFIER; |
︙ | ︙ |
Modified src/runtime/category.m from [11d1996c9a] to [95abd1e8f7].
︙ | ︙ | |||
24 25 26 27 28 29 30 | #import "runtime-private.h" static struct objc_hashtable *categories = NULL; static void register_selectors(struct objc_abi_category *cat) { | | < < | | > | | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #import "runtime-private.h" static struct objc_hashtable *categories = NULL; static void register_selectors(struct objc_abi_category *cat) { for (struct objc_abi_method_list *ml = cat->instance_methods; ml != NULL; ml = ml->next) for (unsigned int i = 0; i < ml->count; i++) objc_register_selector( (struct objc_abi_selector*)&ml->methods[i]); for (struct objc_abi_method_list *ml = cat->class_methods; ml != NULL; ml = ml->next) for (unsigned int i = 0; i < ml->count; i++) objc_register_selector( (struct objc_abi_selector*)&ml->methods[i]); } static void register_category(struct objc_abi_category *cat) { |
︙ | ︙ | |||
91 92 93 94 95 96 97 | objc_update_dtable(cls->isa); } } void objc_register_all_categories(struct objc_abi_symtab *symtab) { | | < < | | < < | | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | objc_update_dtable(cls->isa); } } void objc_register_all_categories(struct objc_abi_symtab *symtab) { struct objc_abi_category **cats = (struct objc_abi_category**)symtab->defs + symtab->cls_def_cnt; for (size_t i = 0; i < symtab->cat_def_cnt; i++) { register_selectors(cats[i]); register_category(cats[i]); } } struct objc_category** objc_categories_for_class(Class cls) { if (categories == NULL) return NULL; return (struct objc_category**)objc_hashtable_get(categories, cls->name); } void objc_unregister_all_categories(void) { if (categories == NULL) return; for (uint32_t i = 0; i < categories->size; i++) if (categories->data[i] != NULL) free((void*)categories->data[i]->obj); objc_hashtable_free(categories); categories = NULL; } |
Modified src/runtime/class.m from [ecd4869918] to [5e1eae7608].
︙ | ︙ | |||
64 65 66 67 68 69 70 | return YES; } static void register_selectors(struct objc_abi_class *cls) { struct objc_abi_method_list *ml; | < | | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | return YES; } static void register_selectors(struct objc_abi_class *cls) { struct objc_abi_method_list *ml; for (ml = cls->methodlist; ml != NULL; ml = ml->next) for (unsigned int i = 0; i < ml->count; i++) objc_register_selector( (struct objc_abi_selector*)&ml->methods[i]); } Class objc_classname_to_class(const char *name, bool cache) { |
︙ | ︙ | |||
126 127 128 129 130 131 132 | return cls; } static void call_method(Class cls, const char *method) { | < | < < | | | < | < < | | | | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | return cls; } static void call_method(Class cls, const char *method) { SEL selector = sel_registerName(method); for (struct objc_method_list *ml = cls->isa->methodlist; ml != NULL; ml = ml->next) for (unsigned int i = 0; i < ml->count; i++) if (sel_isEqual((SEL)&ml->methods[i].sel, selector)) ((void(*)(id, SEL))ml->methods[i].imp)(cls, selector); } static bool has_load(Class cls) { SEL selector = sel_registerName("load"); for (struct objc_method_list *ml = cls->isa->methodlist; ml != NULL; ml = ml->next) for (size_t i = 0; i < ml->count; i++) if (sel_isEqual((SEL)&ml->methods[i].sel, selector)) return true; return false; } static void |
︙ | ︙ | |||
175 176 177 178 179 180 181 | } void objc_update_dtable(Class cls) { struct objc_method_list *ml; struct objc_category **cats; | < | | < < | | < < | < | 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 | } void objc_update_dtable(Class cls) { struct objc_method_list *ml; struct objc_category **cats; if (!(cls->info & OBJC_CLASS_INFO_DTABLE)) return; if (cls->dtable == empty_dtable) cls->dtable = objc_dtable_new(); if (cls->superclass != Nil) objc_dtable_copy(cls->dtable, cls->superclass->dtable); for (ml = cls->methodlist; ml != NULL; ml = ml->next) for (unsigned int i = 0; i < ml->count; i++) objc_dtable_set(cls->dtable, (uint32_t)ml->methods[i].sel.uid, ml->methods[i].imp); if ((cats = objc_categories_for_class(cls)) != NULL) { for (unsigned int i = 0; cats[i] != NULL; i++) { ml = (cls->info & OBJC_CLASS_INFO_CLASS ? cats[i]->instance_methods : cats[i]->class_methods); for (; ml != NULL; ml = ml->next) for (unsigned int j = 0; j < ml->count; j++) objc_dtable_set(cls->dtable, (uint32_t)ml->methods[j].sel.uid, ml->methods[j].imp); } } if (cls->subclass_list != NULL) for (Class *iter = cls->subclass_list; *iter != NULL; iter++) objc_update_dtable(*iter); } static void add_subclass(Class cls) { size_t i; |
︙ | ︙ | |||
249 250 251 252 253 254 255 | cls->superclass->subclass_list[i + 1] = Nil; } static void update_ivar_offsets(Class cls) { | < < | | | 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 | cls->superclass->subclass_list[i + 1] = Nil; } static void update_ivar_offsets(Class cls) { if (!(cls->info & OBJC_CLASS_INFO_NEW_ABI)) return; if (cls->instance_size > 0) return; cls->instance_size = -cls->instance_size; if (cls->superclass != Nil) { cls->instance_size += cls->superclass->instance_size; if (cls->ivars != NULL) { for (unsigned int i = 0; i < cls->ivars->count; i++) { cls->ivars->ivars[i].offset += cls->superclass->instance_size; *cls->ivar_offsets[i] = cls->ivars->ivars[i].offset; } } } else for (unsigned int i = 0; i < cls->ivars->count; i++) *cls->ivar_offsets[i] = cls->ivars->ivars[i].offset; } static void setup_class(Class cls) { const char *superclass; |
︙ | ︙ | |||
366 367 368 369 370 371 372 | objc_global_mutex_unlock(); } void objc_register_all_classes(struct objc_abi_symtab *symtab) { | < < | | | 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | objc_global_mutex_unlock(); } void objc_register_all_classes(struct objc_abi_symtab *symtab) { for (uint16_t i = 0; i < symtab->cls_def_cnt; i++) { struct objc_abi_class *cls = (struct objc_abi_class*)symtab->defs[i]; register_class(cls); register_selectors(cls); register_selectors(cls->metaclass); } for (uint16_t i = 0; i < symtab->cls_def_cnt; i++) { Class cls = (Class)symtab->defs[i]; if (has_load(cls)) { setup_class(cls); if (cls->info & OBJC_CLASS_INFO_SETUP) call_load(cls); |
︙ | ︙ | |||
400 401 402 403 404 405 406 | load_queue[load_queue_cnt++] = cls; } } else cls->info |= OBJC_CLASS_INFO_LOADED; } /* Process load queue */ | | | 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | load_queue[load_queue_cnt++] = cls; } } else cls->info |= OBJC_CLASS_INFO_LOADED; } /* Process load queue */ for (size_t i = 0; i < load_queue_cnt; i++) { setup_class(load_queue[i]); if (load_queue[i]->info & OBJC_CLASS_INFO_SETUP) { call_load(load_queue[i]); load_queue_cnt--; |
︙ | ︙ | |||
480 481 482 483 484 485 486 | { return objc_getRequiredClass(name); } unsigned int objc_getClassList(Class *buf, unsigned int count) { | < > | | 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 | { return objc_getRequiredClass(name); } unsigned int objc_getClassList(Class *buf, unsigned int count) { unsigned int j; objc_global_mutex_lock(); if (buf == NULL) return classes_cnt; if (classes_cnt < count) count = classes_cnt; j = 0; for (uint32_t i = 0; i < classes->size; i++) { void *cls; if (j >= count) { objc_global_mutex_unlock(); return j; } |
︙ | ︙ | |||
624 625 626 627 628 629 630 | } const char* class_getMethodTypeEncoding(Class cls, SEL sel) { struct objc_method_list *ml; struct objc_category **cats; | < | | | 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 | } const char* class_getMethodTypeEncoding(Class cls, SEL sel) { struct objc_method_list *ml; struct objc_category **cats; if (cls == Nil) return NULL; objc_global_mutex_lock(); for (ml = cls->methodlist; ml != NULL; ml = ml->next) { for (unsigned int i = 0; i < ml->count; i++) { if (sel_isEqual((SEL)&ml->methods[i].sel, sel)) { const char *ret = ml->methods[i].sel.types; objc_global_mutex_unlock(); return ret; } } } if ((cats = objc_categories_for_class(cls)) != NULL) { for (; *cats != NULL; cats++) { for (ml = (*cats)->instance_methods; ml != NULL; ml = ml->next) { for (unsigned int i = 0; i < ml->count; i++) { if (ml->methods[i].sel.uid == sel->uid) { const char *ret = ml->methods[i].sel.types; objc_global_mutex_unlock(); return ret; } |
︙ | ︙ | |||
671 672 673 674 675 676 677 | } IMP class_replaceMethod(Class cls, SEL sel, IMP newimp, const char *types) { struct objc_method_list *ml; struct objc_category **cats; | < | | 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | } IMP class_replaceMethod(Class cls, SEL sel, IMP newimp, const char *types) { struct objc_method_list *ml; struct objc_category **cats; IMP oldimp; objc_global_mutex_lock(); for (ml = cls->methodlist; ml != NULL; ml = ml->next) { for (unsigned int i = 0; i < ml->count; i++) { if (ml->methods[i].sel.uid == sel->uid) { oldimp = ml->methods[i].imp; ml->methods[i].imp = newimp; objc_update_dtable(cls); objc_global_mutex_unlock(); |
︙ | ︙ | |||
699 700 701 702 703 704 705 | for (; *cats != NULL; cats++) { if (cls->info & OBJC_CLASS_INFO_METACLASS) ml = (*cats)->class_methods; else ml = (*cats)->instance_methods; for (; ml != NULL; ml = ml->next) { | | | 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | for (; *cats != NULL; cats++) { if (cls->info & OBJC_CLASS_INFO_METACLASS) ml = (*cats)->class_methods; else ml = (*cats)->instance_methods; for (; ml != NULL; ml = ml->next) { for (unsigned int i = 0; i < ml->count; i++) { if (ml->methods[i].sel.uid == sel->uid) { oldimp = ml->methods[i].imp; ml->methods[i].imp = newimp; objc_update_dtable(cls); |
︙ | ︙ | |||
838 839 840 841 842 843 844 | unregister_class(cls); unregister_class(cls->isa); } void objc_unregister_all_classes(void) { | < < | | 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 | unregister_class(cls); unregister_class(cls->isa); } void objc_unregister_all_classes(void) { if (classes == NULL) return; for (uint32_t i = 0; i < classes->size; i++) { if (classes->data[i] != NULL && classes->data[i] != &objc_deleted_bucket) { void *cls = (Class)classes->data[i]->obj; if (cls == Nil || (uintptr_t)cls & 1) continue; |
︙ | ︙ |
Modified src/runtime/dtable.m from [bbd4fbe6f2] to [f7fe271509].
︙ | ︙ | |||
26 27 28 29 30 31 32 | #ifdef OF_SELUID24 static struct objc_dtable_level3 *empty_level3 = NULL; #endif static void init(void) { | < < | | < | < < < < < < | | | > | < < | > | 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | #ifdef OF_SELUID24 static struct objc_dtable_level3 *empty_level3 = NULL; #endif static void init(void) { empty_level2 = malloc(sizeof(struct objc_dtable_level2)); if (empty_level2 == NULL) OBJC_ERROR("Not enough memory to allocate dtable!"); #ifdef OF_SELUID24 empty_level3 = malloc(sizeof(struct objc_dtable_level3)); if (empty_level3 == NULL) OBJC_ERROR("Not enough memory to allocate dtable!"); #endif #ifdef OF_SELUID24 for (uint_fast16_t i = 0; i < 256; i++) { empty_level2->buckets[i] = empty_level3; empty_level3->buckets[i] = (IMP)0; } #else for (uint_fast16_t i = 0; i < 256; i++) empty_level2->buckets[i] = (IMP)0; #endif } struct objc_dtable* objc_dtable_new(void) { struct objc_dtable *dtable; #ifdef OF_SELUID24 if (empty_level2 == NULL || empty_level3 == NULL) init(); #else if (empty_level2 == NULL) init(); #endif if ((dtable = malloc(sizeof(struct objc_dtable))) == NULL) OBJC_ERROR("Not enough memory to allocate dtable!"); for (uint_fast16_t i = 0; i < 256; i++) dtable->buckets[i] = empty_level2; return dtable; } void objc_dtable_copy(struct objc_dtable *dst, struct objc_dtable *src) { for (uint_fast16_t i = 0; i < 256; i++) { if (src->buckets[i] == empty_level2) continue; #ifdef OF_SELUID24 for (uint_fast16_t j = 0; j < 256; j++) { if (src->buckets[i]->buckets[j] == empty_level3) continue; for (uint_fast16_t k = 0; k < 256; k++) { IMP obj; uint32_t idx; obj = src->buckets[i]->buckets[j]->buckets[k]; if (obj == (IMP)0) continue; idx = (uint32_t) (((uint32_t)i << 16) | (j << 8) | k); objc_dtable_set(dst, idx, obj); } } #else for (uint_fast16_t j = 0; j < 256; j++) { IMP obj = src->buckets[i]->buckets[j]; uint32_t idx; if (obj == (IMP)0) continue; idx = (uint32_t)((i << 8) | j); objc_dtable_set(dst, idx, obj); } |
︙ | ︙ | |||
132 133 134 135 136 137 138 | uint8_t k = idx; #else uint8_t i = idx >> 8; uint8_t j = idx; #endif if (dtable->buckets[i] == empty_level2) { | | < < | | | < < | | < < < < < | | | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 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 | uint8_t k = idx; #else uint8_t i = idx >> 8; uint8_t j = idx; #endif if (dtable->buckets[i] == empty_level2) { struct objc_dtable_level2 *level2 = malloc(sizeof(struct objc_dtable_level2)); if (level2 == NULL) OBJC_ERROR("Not enough memory to insert into dtable!"); for (uint_fast16_t l = 0; l < 256; l++) #ifdef OF_SELUID24 level2->buckets[l] = empty_level3; #else level2->buckets[l] = (IMP)0; #endif dtable->buckets[i] = level2; } #ifdef OF_SELUID24 if (dtable->buckets[i]->buckets[j] == empty_level3) { struct objc_dtable_level3 *level3 = malloc(sizeof(struct objc_dtable_level3)); if (level3 == NULL) OBJC_ERROR("Not enough memory to insert into dtable!"); for (uint_fast16_t l = 0; l < 256; l++) level3->buckets[l] = (IMP)0; dtable->buckets[i]->buckets[j] = level3; } dtable->buckets[i]->buckets[j]->buckets[k] = obj; #else dtable->buckets[i]->buckets[j] = obj; #endif } void objc_dtable_free(struct objc_dtable *dtable) { for (uint_fast16_t i = 0; i < 256; i++) { if (dtable->buckets[i] == empty_level2) continue; #ifdef OF_SELUID24 for (uint_fast16_t j = 0; j < 256; j++) if (dtable->buckets[i]->buckets[j] != empty_level3) free(dtable->buckets[i]->buckets[j]); #endif free(dtable->buckets[i]); } |
︙ | ︙ |
Modified src/runtime/hashtable.m from [9b5e456642] to [57f764fde9].
︙ | ︙ | |||
73 74 75 76 77 78 79 | return table; } static void resize(struct objc_hashtable *table, uint32_t count) { | | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | return table; } static void resize(struct objc_hashtable *table, uint32_t count) { uint32_t fullness, nsize; struct objc_hashtable_bucket **ndata; if (count > UINT32_MAX / sizeof(*table->data) || count > UINT32_MAX / 8) OBJC_ERROR("Integer overflow!"); fullness = count * 8 / table->size; |
︙ | ︙ | |||
97 98 99 100 101 102 103 | if (count < table->count && nsize < 16) return; if ((ndata = calloc(nsize, sizeof(sizeof(*ndata)))) == NULL) OBJC_ERROR("Not enough memory to resize hash table!"); | | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | if (count < table->count && nsize < 16) return; if ((ndata = calloc(nsize, sizeof(sizeof(*ndata)))) == NULL) OBJC_ERROR("Not enough memory to resize hash table!"); for (uint32_t i = 0; i < table->size; i++) { if (table->data[i] != NULL && table->data[i] != &objc_deleted_bucket) { uint32_t j, last; last = nsize; for (j = table->data[i]->hash & (nsize - 1); |
︙ | ︙ | |||
228 229 230 231 232 233 234 | table->count--; resize(table, table->count); } void objc_hashtable_free(struct objc_hashtable *table) { | < < | | 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | table->count--; resize(table, table->count); } void objc_hashtable_free(struct objc_hashtable *table) { for (uint32_t i = 0; i < table->size; i++) if (table->data[i] != NULL && table->data[i] != &objc_deleted_bucket) free(table->data[i]); free(table->data); free(table); } |
Modified src/runtime/property.m from [fc195ff020] to [80983f9ddc].
︙ | ︙ | |||
30 31 32 33 34 35 36 | static of_spinlock_t spinlocks[NUM_SPINLOCKS]; #endif #ifdef OF_HAVE_THREADS static void __attribute__((__constructor__)) init(void) { | < < | | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | static of_spinlock_t spinlocks[NUM_SPINLOCKS]; #endif #ifdef OF_HAVE_THREADS static void __attribute__((__constructor__)) init(void) { for (size_t i = 0; i < NUM_SPINLOCKS; i++) if (!of_spinlock_new(&spinlocks[i])) OBJC_ERROR("Failed to initialize spinlocks!") } #endif id objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, BOOL atomic) |
︙ | ︙ |
Modified src/runtime/protocol.m from [67fc62df32] to [7da3a7d11f].
︙ | ︙ | |||
35 36 37 38 39 40 41 | { return (strcmp(protocol_getName(a), protocol_getName(b)) == 0); } bool protocol_conformsToProtocol(Protocol *a, Protocol *b) { | < < < > | | < < > | | | > | | | 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 | { return (strcmp(protocol_getName(a), protocol_getName(b)) == 0); } bool protocol_conformsToProtocol(Protocol *a, Protocol *b) { if (protocol_isEqual(a, b)) return true; for (struct objc_protocol_list *pl = a->protocol_list; pl != NULL; pl = pl->next) for (size_t i = 0; i < pl->count; i++) if (protocol_conformsToProtocol(pl->list[i], b)) return true; return false; } bool class_conformsToProtocol(Class cls, Protocol *p) { struct objc_category **cats; for (struct objc_protocol_list *pl = cls->protocols; pl != NULL; pl = pl->next) for (long i = 0; i < pl->count; i++) if (protocol_conformsToProtocol(pl->list[i], p)) return true; objc_global_mutex_lock(); if ((cats = objc_categories_for_class(cls)) == NULL) { objc_global_mutex_unlock(); return false; } for (long i = 0; cats[i] != NULL; i++) { for (struct objc_protocol_list *pl = cats[i]->protocols; pl != NULL; pl = pl->next) { for (long j = 0; j < pl->count; j++) { if (protocol_conformsToProtocol( pl->list[j], p)) { objc_global_mutex_unlock(); return true; } } } } objc_global_mutex_unlock(); return false; } |
Modified src/runtime/selector.m from [1df1d6cb9f] to [106040fda3].
︙ | ︙ | |||
135 136 137 138 139 140 141 | void objc_unregister_all_selectors(void) { objc_hashtable_free(selectors); objc_sparsearray_free(selector_names); if (free_list != NULL) { | < < | | 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | void objc_unregister_all_selectors(void) { objc_hashtable_free(selectors); objc_sparsearray_free(selector_names); if (free_list != NULL) { for (size_t i = 0; i < free_list_cnt; i++) free(free_list[i]); free(free_list); } selectors = NULL; selectors_cnt = 0; selector_names = NULL; free_list = NULL; free_list_cnt = 0; } |
Modified src/runtime/sparsearray.m from [f7f4dd215e] to [ec11c93501].
︙ | ︙ | |||
38 39 40 41 42 43 44 | return sparsearray; } void* objc_sparsearray_get(struct objc_sparsearray *sparsearray, uintptr_t idx) { struct objc_sparsearray_data *iter = sparsearray->data; | < | < | < < | | 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 | return sparsearray; } void* objc_sparsearray_get(struct objc_sparsearray *sparsearray, uintptr_t idx) { struct objc_sparsearray_data *iter = sparsearray->data; for (uint8_t i = 0; i < sparsearray->index_size - 1; i++) { uintptr_t j = (idx >> ((sparsearray->index_size - i - 1) * 8)) & 0xFF; if ((iter = iter->next[j]) == NULL) return NULL; } return iter->next[idx & 0xFF]; } void objc_sparsearray_set(struct objc_sparsearray *sparsearray, uintptr_t idx, void *value) { struct objc_sparsearray_data *iter = sparsearray->data; for (uint8_t i = 0; i < sparsearray->index_size - 1; i++) { uintptr_t j = (idx >> ((sparsearray->index_size - i - 1) * 8)) & 0xFF; if (iter->next[j] == NULL) if ((iter->next[j] = calloc(1, sizeof(struct objc_sparsearray_data))) == NULL) OBJC_ERROR("Failed to allocate memory for " "sparse array!"); iter = iter->next[j]; } iter->next[idx & 0xFF] = value; } static void free_sparsearray_data(struct objc_sparsearray_data *data, uint8_t depth) { if (data == NULL || depth == 0) return; for (uint_fast16_t i = 0; i < 256; i++) free_sparsearray_data(data->next[i], depth - 1); free(data); } void objc_sparsearray_free(struct objc_sparsearray *sparsearray) { free_sparsearray_data(sparsearray->data, sparsearray->index_size); free(sparsearray); } |
Modified src/runtime/static-instances.m from [5540d87e86] to [dbfe4cc308].
︙ | ︙ | |||
25 26 27 28 29 30 31 | static struct objc_abi_static_instances **static_instances = NULL; static size_t static_instances_cnt = 0; void objc_init_static_instances(struct objc_abi_symtab *symtab) { struct objc_abi_static_instances **si; | < | < < | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | static struct objc_abi_static_instances **static_instances = NULL; static size_t static_instances_cnt = 0; void objc_init_static_instances(struct objc_abi_symtab *symtab) { struct objc_abi_static_instances **si; /* Check if the class for a static instance became available */ for (size_t i = 0; i < static_instances_cnt; i++) { Class cls = objc_lookUpClass(static_instances[i]->class_name); if (cls != Nil) { for (id *instances = static_instances[i]->instances; *instances != nil; instances++) object_setClass(*instances, cls); static_instances_cnt--; if (static_instances_cnt == 0) { free(static_instances); |
︙ | ︙ | |||
69 70 71 72 73 74 75 | if (si == NULL) return; for (; *si != NULL; si++) { Class cls = objc_lookUpClass((*si)->class_name); if (cls != Nil) { | < < | | | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | if (si == NULL) return; for (; *si != NULL; si++) { Class cls = objc_lookUpClass((*si)->class_name); if (cls != Nil) { for (id *instances = (*si)->instances; *instances != nil; instances++) object_setClass(*instances, cls); } else { static_instances = realloc(static_instances, sizeof(struct objc_abi_static_instances*) * (static_instances_cnt + 1)); if (static_instances == NULL) |
︙ | ︙ |
Modified src/threading.h from [3ce1164040] to [2fb0666be8].
︙ | ︙ | |||
200 201 202 203 204 205 206 | } static OF_INLINE bool of_spinlock_lock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) # if defined(OF_HAVE_SCHED_YIELD) || defined(OF_WINDOWS) | < < | | 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | } static OF_INLINE bool of_spinlock_lock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) # if defined(OF_HAVE_SCHED_YIELD) || defined(OF_WINDOWS) for (size_t i = 0; i < OF_SPINCOUNT; i++) if (of_spinlock_trylock(spinlock)) return true; while (!of_spinlock_trylock(spinlock)) # ifndef OF_WINDOWS sched_yield(); # else |
︙ | ︙ |
Modified src/threading_winapi.m from [86ffe1de89] to [eefc937c4b].
︙ | ︙ | |||
157 158 159 160 161 162 163 | { return SetEvent(condition->event); } bool of_condition_broadcast(of_condition_t *condition) { | < < | | 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | { return SetEvent(condition->event); } bool of_condition_broadcast(of_condition_t *condition) { for (int i = 0; i < condition->count; i++) if (!SetEvent(condition->event)) return false; return true; } bool |
︙ | ︙ |
Modified src/windows_1252.m from [341946825e] to [351d5bfad0].
︙ | ︙ | |||
37 38 39 40 41 42 43 | 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF }; bool of_unicode_to_windows_1252(const of_unichar_t *input, uint8_t *output, size_t length, bool lossy) { | < < | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF }; bool of_unicode_to_windows_1252(const of_unichar_t *input, uint8_t *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { of_unichar_t c = input[i]; if OF_UNLIKELY (c > 0xFF) { if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; continue; |
︙ | ︙ |
Modified tests/TestsAppDelegate.m from [1a3475c054] to [fb3c8c5bbc].
︙ | ︙ | |||
178 179 180 181 182 183 184 | } @implementation TestsAppDelegate - (void)outputString: (OFString*)str inColor: (int)color { #if defined(OF_PSP) | | | | 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | } @implementation TestsAppDelegate - (void)outputString: (OFString*)str inColor: (int)color { #if defined(OF_PSP) char space = ' '; int y = pspDebugScreenGetY(); pspDebugScreenSetXY(0, y); for (uint8_t i = 0; i < 68; i++) pspDebugScreenPrintData(&space, 1); switch (color) { case NO_COLOR: pspDebugScreenSetTextColor(0xFFFFFF); break; case RED: |
︙ | ︙ |
Modified utils/ofhash/OFHash.m from [47c8f02867] to [db4af5bb82].
︙ | ︙ | |||
82 83 84 85 86 87 88 | if ((hash = hashForName([arguments firstObject])) == nil) help(); for (OFString *path in arguments) { void *pool; OFStream *file; const uint8_t *digest; | | | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | if ((hash = hashForName([arguments firstObject])) == nil) help(); for (OFString *path in arguments) { void *pool; OFStream *file; const uint8_t *digest; size_t digestSize; if (first) { first = false; continue; } pool = objc_autoreleasePoolPush(); |
︙ | ︙ | |||
134 135 136 137 138 139 140 | } [file close]; digest = [hash digest]; digestSize = [[hash class] digestSize]; | | | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | } [file close]; digest = [hash digest]; digestSize = [[hash class] digestSize]; for (size_t i = 0; i < digestSize; i++) [of_stdout writeFormat: @"%02x", digest[i]]; [of_stdout writeFormat: @" %@\n", path]; outer_loop_end: objc_autoreleasePoolPop(pool); } [OFApplication terminateWithStatus: exitStatus]; } @end |
Modified utils/ofhttp/OFHTTP.m from [ed4e5bef24] to [4bc226ed65].
︙ | ︙ | |||
414 415 416 417 418 419 420 | DISPOSITION_TYPE_SEMICOLON, DISPOSITION_PARAM_NAME_SKIP_SPACE, DISPOSITION_PARAM_NAME, DISPOSITION_PARAM_VALUE, DISPOSITION_PARAM_QUOTED, DISPOSITION_EXPECT_SEMICOLON } state; | | | | 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 | DISPOSITION_TYPE_SEMICOLON, DISPOSITION_PARAM_NAME_SKIP_SPACE, DISPOSITION_PARAM_NAME, DISPOSITION_PARAM_VALUE, DISPOSITION_PARAM_QUOTED, DISPOSITION_EXPECT_SEMICOLON } state; size_t last; OFString *type = nil, *paramName = nil, *paramValue; OFMutableDictionary *params; OFString *fileName; if (contentDisposition == nil) return nil; pool = objc_autoreleasePoolPush(); UTF8String = [contentDisposition UTF8String]; UTF8StringLength = [contentDisposition UTF8StringLength]; state = DISPOSITION_TYPE; params = [OFMutableDictionary dictionary]; last = 0; for (size_t i = 0; i < UTF8StringLength; i++) { switch (state) { case DISPOSITION_TYPE: if (UTF8String[i] == ';' || UTF8String[i] == ' ') { type = [OFString stringWithUTF8String: UTF8String length: i]; |
︙ | ︙ |
Modified utils/ofhttp/ProgressBar.m from [84262304c6] to [e437710ddc].
︙ | ︙ | |||
88 89 90 91 92 93 94 | - (void)setReceived: (intmax_t)received { _received = received; } - (void)_drawProgress { | < | | 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | - (void)setReceived: (intmax_t)received { _received = received; } - (void)_drawProgress { float bars, percent; unsigned short barWidth; #ifdef HAVE_SYS_IOCTL_H struct winsize ws; if (ioctl(0, TIOCGWINSZ, &ws) == 0 && ws.ws_col > 37) barWidth = ws.ws_col - 37; else barWidth = 0; #else barWidth = 43; #endif bars = (float)(_resumedFrom + _received) / (float)(_resumedFrom + _length) * barWidth; percent = (float)(_resumedFrom + _received) / (float)(_resumedFrom + _length) * 100; [of_stdout writeString: @"\r ▕"]; for (size_t i = 0; i < (size_t)bars; i++) [of_stdout writeString: @"█"]; if (bars < barWidth) { float remainder = bars - floorf(bars); if (remainder >= 0.875) [of_stdout writeString: @"▉"]; else if (remainder >= 0.75) |
︙ | ︙ | |||
131 132 133 134 135 136 137 | else if (remainder >= 0.25) [of_stdout writeString: @"▎"]; else if (remainder >= 0.125) [of_stdout writeString: @"▏"]; else [of_stdout writeString: @" "]; | | | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | else if (remainder >= 0.25) [of_stdout writeString: @"▎"]; else if (remainder >= 0.125) [of_stdout writeString: @"▏"]; else [of_stdout writeString: @" "]; for (size_t i = 0; i < barWidth - (size_t)bars - 1; i++) [of_stdout writeString: @" "]; } [of_stdout writeFormat: @"▏ %6.2f%% ", percent]; if (percent == 100) { double timeInterval = -[_startDate timeIntervalSinceNow]; |
︙ | ︙ |