Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Rename all functions in macros.h |
|---|---|
| Timelines: | family | ancestors | descendants | both | new-naming-convention |
| Files: | files | file ages | folders |
| SHA3-256: |
7392685ffce2004010643b94982a8b4d |
| User & Date: | js 2021-04-18 15:55:32.283 |
Context
|
2021-04-18
| ||
| 20:51 | Rename everything in several smaller files check-in: 35de667566 user: js tags: new-naming-convention | |
| 15:55 | Rename all functions in macros.h check-in: 7392685ffc user: js tags: new-naming-convention | |
| 13:24 | Rename remaining functions in OFObject.h check-in: d9f8960fc5 user: js tags: new-naming-convention | |
Changes
Changes to src/OFAdjacentArray.m.
| ︙ | ︙ | |||
300 301 302 303 304 305 306 |
return true;
}
- (unsigned long)hash
{
id const *objects = _array.items;
size_t count = _array.count;
| | | | | | 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
return true;
}
- (unsigned long)hash
{
id const *objects = _array.items;
size_t count = _array.count;
unsigned long hash;
OFHashInit(&hash);
for (size_t i = 0; i < count; i++)
OFHashAddHash(&hash, [objects[i] hash]);
OFHashFinalize(&hash);
return hash;
}
- (int)countByEnumeratingWithState: (OFFastEnumerationState *)state
objects: (id *)objects
count: (int)count_
|
| ︙ | ︙ |
Changes to src/OFArray.m.
| ︙ | ︙ | |||
504 505 506 507 508 509 510 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
for (id object in self)
OFHashAddHash(&hash, [object hash]);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
void *pool;
|
| ︙ | ︙ | |||
654 655 656 657 658 659 660 |
count = self.count;
if (count <= 15) {
uint8_t tmp = 0x90 | ((uint8_t)count & 0xF);
[data addItem: &tmp];
} else if (count <= UINT16_MAX) {
uint8_t type = 0xDC;
| | | | 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
count = self.count;
if (count <= 15) {
uint8_t tmp = 0x90 | ((uint8_t)count & 0xF);
[data addItem: &tmp];
} else if (count <= UINT16_MAX) {
uint8_t type = 0xDC;
uint16_t tmp = OFToBigEndian16((uint16_t)count);
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else if (count <= UINT32_MAX) {
uint8_t type = 0xDD;
uint32_t tmp = OFToBigEndian32((uint32_t)count);
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else
@throw [OFOutOfRangeException exception];
pool = objc_autoreleasePoolPush();
|
| ︙ | ︙ |
Changes to src/OFBitSetCharacterSet.m.
| ︙ | ︙ | |||
41 42 43 44 45 46 47 |
if (c / CHAR_BIT >= _size) {
size_t newSize;
if (UINT32_MAX - c < 1)
@throw [OFOutOfRangeException
exception];
| | | | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
if (c / CHAR_BIT >= _size) {
size_t newSize;
if (UINT32_MAX - c < 1)
@throw [OFOutOfRangeException
exception];
newSize = OFRoundUpToPowerOf2(CHAR_BIT, c + 1) /
CHAR_BIT;
_bitset = OFResizeMemory(_bitset, newSize, 1);
memset(_bitset + _size, '\0', newSize - _size);
_size = newSize;
}
OFBitsetSet(_bitset, c);
}
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
|
| ︙ | ︙ | |||
74 75 76 77 78 79 80 |
}
- (bool)characterIsMember: (OFUnichar)character
{
if (character / CHAR_BIT >= _size)
return false;
| | | 74 75 76 77 78 79 80 81 82 83 |
}
- (bool)characterIsMember: (OFUnichar)character
{
if (character / CHAR_BIT >= _size)
return false;
return OFBitsetIsSet(_bitset, character);
}
@end
|
Changes to src/OFBlock.m.
| ︙ | ︙ | |||
200 201 202 203 204 205 206 |
if ([(id)block isMemberOfClass: (Class)&_NSConcreteMallocBlock]) {
#ifdef OF_HAVE_ATOMIC_OPS
OFAtomicIntIncrease(&block->flags);
#else
unsigned hash = SPINLOCK_HASH(block);
| | | | 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
if ([(id)block isMemberOfClass: (Class)&_NSConcreteMallocBlock]) {
#ifdef OF_HAVE_ATOMIC_OPS
OFAtomicIntIncrease(&block->flags);
#else
unsigned hash = SPINLOCK_HASH(block);
OFEnsure(OFSpinlockLock(&blockSpinlocks[hash]) == 0);
block->flags++;
OFEnsure(OFSpinlockUnlock(&blockSpinlocks[hash]) == 0);
#endif
}
return block;
}
void
|
| ︙ | ︙ | |||
228 229 230 231 232 233 234 | block->descriptor->dispose_helper(block); free(block); } #else unsigned hash = SPINLOCK_HASH(block); | | | | | 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 |
block->descriptor->dispose_helper(block);
free(block);
}
#else
unsigned hash = SPINLOCK_HASH(block);
OFEnsure(OFSpinlockLock(&blockSpinlocks[hash]) == 0);
if ((--block->flags & OF_BLOCK_REFCOUNT_MASK) == 0) {
OFEnsure(OFSpinlockUnlock(&blockSpinlocks[hash]) == 0);
if (block->flags & OF_BLOCK_HAS_COPY_DISPOSE)
block->descriptor->dispose_helper(block);
free(block);
return;
}
OFEnsure(OFSpinlockUnlock(&blockSpinlocks[hash]) == 0);
#endif
}
void
_Block_object_assign(void *dst_, const void *src_, const int flags_)
{
int flags = flags_ & (OF_BLOCK_FIELD_IS_BLOCK |
|
| ︙ | ︙ | |||
293 294 295 296 297 298 299 | free(*dst); *dst = src->forwarding; } #else unsigned hash = SPINLOCK_HASH(src); | | < | | | | 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 |
free(*dst);
*dst = src->forwarding;
}
#else
unsigned hash = SPINLOCK_HASH(src);
OFEnsure(OFSpinlockLock(&byrefSpinlocks[hash]) == 0);
if (src->forwarding == src)
src->forwarding = *dst;
else {
src->byref_dispose(*dst);
free(*dst);
*dst = src->forwarding;
}
OFEnsure(OFSpinlockUnlock(&byrefSpinlocks[hash]) == 0);
#endif
} else
*dst = src;
#ifdef OF_HAVE_ATOMIC_OPS
OFAtomicIntIncrease(&(*dst)->flags);
#else
unsigned hash = SPINLOCK_HASH(*dst);
OFEnsure(OFSpinlockLock(&byrefSpinlocks[hash]) == 0);
(*dst)->flags++;
OFEnsure(OFSpinlockUnlock(&byrefSpinlocks[hash]) == 0);
#endif
break;
}
}
void
_Block_object_dispose(const void *object_, const int flags_)
|
| ︙ | ︙ | |||
354 355 356 357 358 359 360 | object->byref_dispose(object); free(object); } #else unsigned hash = SPINLOCK_HASH(object); | | < | | | 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
object->byref_dispose(object);
free(object);
}
#else
unsigned hash = SPINLOCK_HASH(object);
OFEnsure(OFSpinlockLock(&byrefSpinlocks[hash]) == 0);
if ((--object->flags & OF_BLOCK_REFCOUNT_MASK) == 0) {
OFEnsure(OFSpinlockUnlock(&byrefSpinlocks[hash]) == 0);
if (object->flags & OF_BLOCK_HAS_COPY_DISPOSE)
object->byref_dispose(object);
free(object);
}
OFEnsure(OFSpinlockUnlock(&byrefSpinlocks[hash]) == 0);
#endif
break;
}
}
@implementation OFBlock
+ (void)load
|
| ︙ | ︙ |
Changes to src/OFColor.m.
| ︙ | ︙ | |||
118 119 120 121 122 123 124 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | | | 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 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
float tmp;
OFHashInit(&hash);
tmp = OFToLittleEndianFloat(_red);
for (uint_fast8_t i = 0; i < sizeof(float); i++)
OFHashAdd(&hash, ((char *)&tmp)[i]);
tmp = OFToLittleEndianFloat(_green);
for (uint_fast8_t i = 0; i < sizeof(float); i++)
OFHashAdd(&hash, ((char *)&tmp)[i]);
tmp = OFToLittleEndianFloat(_blue);
for (uint_fast8_t i = 0; i < sizeof(float); i++)
OFHashAdd(&hash, ((char *)&tmp)[i]);
tmp = OFToLittleEndianFloat(_alpha);
for (uint_fast8_t i = 0; i < sizeof(float); i++)
OFHashAdd(&hash, ((char *)&tmp)[i]);
OFHashFinalize(&hash);
return hash;
}
- (void)getRed: (float *)red
green: (float *)green
blue: (float *)blue
|
| ︙ | ︙ |
Changes to src/OFCondition.m.
| ︙ | ︙ | |||
49 50 51 52 53 54 55 |
- (void)dealloc
{
if (_conditionInitialized) {
int error = OFPlainConditionFree(&_condition);
if (error != 0) {
| | | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
- (void)dealloc
{
if (_conditionInitialized) {
int error = OFPlainConditionFree(&_condition);
if (error != 0) {
OFEnsure(error == EBUSY);
@throw [OFConditionStillWaitingException
exceptionWithCondition: self];
}
}
[super dealloc];
|
| ︙ | ︙ |
Changes to src/OFDNSQuery.m.
| ︙ | ︙ | |||
89 90 91 92 93 94 95 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _domainName.hash);
OFHashAdd(&hash, _DNSClass);
OFHashAdd(&hash, _recordType);
OFHashFinalize(&hash);
return hash;
}
- (id)copy
{
return [self retain];
|
| ︙ | ︙ |
Changes to src/OFDNSResolver.m.
| ︙ | ︙ | |||
486 487 488 489 490 491 492 | _settings = [settings copy]; _delegate = [delegate retain]; queryData = [OFMutableData dataWithCapacity: 512]; /* Header */ | | | | | 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | _settings = [settings copy]; _delegate = [delegate retain]; queryData = [OFMutableData dataWithCapacity: 512]; /* Header */ tmp = OFToBigEndian16(_ID.unsignedShortValue); [queryData addItems: &tmp count: 2]; /* RD */ tmp = OFToBigEndian16(1u << 8); [queryData addItems: &tmp count: 2]; /* QDCOUNT */ tmp = OFToBigEndian16(1); [queryData addItems: &tmp count: 2]; /* ANCOUNT, NSCOUNT and ARCOUNT */ [queryData increaseCountBy: 6]; /* Question */ /* QNAME */ |
| ︙ | ︙ | |||
515 516 517 518 519 520 521 | length8 = (uint8_t)length; [queryData addItem: &length8]; [queryData addItems: component.UTF8String count: length]; } /* QTYPE */ | | | | 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
length8 = (uint8_t)length;
[queryData addItem: &length8];
[queryData addItems: component.UTF8String
count: length];
}
/* QTYPE */
tmp = OFToBigEndian16(_query.recordType);
[queryData addItems: &tmp count: 2];
/* QCLASS */
tmp = OFToBigEndian16(_query.DNSClass);
[queryData addItems: &tmp count: 2];
[queryData makeImmutable];
_queryData = [queryData copy];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
|
| ︙ | ︙ | |||
721 722 723 724 725 726 727 |
[[OFRunLoop currentRunLoop] addTimer: context->_cancelTimer
forMode: runLoopMode];
nameServer = [context->_settings->_nameServers
objectAtIndex: context->_nameServersIndex];
if (context->_settings->_usesTCP) {
| | | 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 |
[[OFRunLoop currentRunLoop] addTimer: context->_cancelTimer
forMode: runLoopMode];
nameServer = [context->_settings->_nameServers
objectAtIndex: context->_nameServersIndex];
if (context->_settings->_usesTCP) {
OFEnsure(context->_TCPSocket == nil);
context->_TCPSocket = [[OFTCPSocket alloc] init];
[_TCPQueries setObject: context forKey: context->_TCPSocket];
context->_TCPSocket.delegate = self;
[context->_TCPSocket asyncConnectToHost: nameServer
port: 53
|
| ︙ | ︙ | |||
1057 1058 1059 1060 1061 1062 1063 |
- (void)socket: (OFTCPSocket *)sock
didConnectToHost: (OFString *)host
port: (uint16_t)port
exception: (id)exception
{
OFDNSResolverContext *context = [_TCPQueries objectForKey: sock];
| | | 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 |
- (void)socket: (OFTCPSocket *)sock
didConnectToHost: (OFString *)host
port: (uint16_t)port
exception: (id)exception
{
OFDNSResolverContext *context = [_TCPQueries objectForKey: sock];
OFEnsure(context != nil);
if (exception != nil) {
/*
* TODO: Handle error immediately instead of waiting for the
* timer to try the next nameserver or to retry.
*/
[_TCPQueries removeObjectForKey: context->_TCPSocket];
|
| ︙ | ︙ | |||
1081 1082 1083 1084 1085 1086 1087 | if (queryDataCount > UINT16_MAX) @throw [OFOutOfRangeException exception]; context->_TCPQueryData = [[OFMutableData alloc] initWithCapacity: queryDataCount + 2]; | | | | 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 |
if (queryDataCount > UINT16_MAX)
@throw [OFOutOfRangeException exception];
context->_TCPQueryData = [[OFMutableData alloc]
initWithCapacity: queryDataCount + 2];
tmp = OFToBigEndian16(queryDataCount);
[context->_TCPQueryData addItems: &tmp count: sizeof(tmp)];
[context->_TCPQueryData addItems: context->_queryData.items
count: queryDataCount];
}
[sock asyncWriteData: context->_TCPQueryData];
}
- (OFData *)stream: (OFStream *)stream
didWriteData: (OFData *)data
bytesWritten: (size_t)bytesWritten
exception: (id)exception
{
OFTCPSocket *sock = (OFTCPSocket *)stream;
OFDNSResolverContext *context = [_TCPQueries objectForKey: sock];
OFEnsure(context != nil);
if (exception != nil) {
/*
* TODO: Handle error immediately instead of waiting for the
* timer to try the next nameserver or to retry.
*/
[_TCPQueries removeObjectForKey: context->_TCPSocket];
|
| ︙ | ︙ | |||
1127 1128 1129 1130 1131 1132 1133 |
didReadIntoBuffer: (void *)buffer
length: (size_t)length
exception: (id)exception
{
OFTCPSocket *sock = (OFTCPSocket *)stream;
OFDNSResolverContext *context = [_TCPQueries objectForKey: sock];
| | | | 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 |
didReadIntoBuffer: (void *)buffer
length: (size_t)length
exception: (id)exception
{
OFTCPSocket *sock = (OFTCPSocket *)stream;
OFDNSResolverContext *context = [_TCPQueries objectForKey: sock];
OFEnsure(context != nil);
if (exception != nil) {
/*
* TODO: Handle error immediately instead of waiting for the
* timer to try the next nameserver or to retry.
*/
goto done;
}
if (context->_responseLength == 0) {
unsigned char *ucBuffer = buffer;
OFEnsure(length == 2);
context->_responseLength = (ucBuffer[0] << 8) | ucBuffer[1];
if (context->_responseLength > MAX_DNS_RESPONSE_LENGTH)
@throw [OFOutOfRangeException exception];
if (context->_responseLength == 0)
|
| ︙ | ︙ |
Changes to src/OFDNSResolverSettings.m.
| ︙ | ︙ | |||
570 571 572 573 574 575 576 |
* We're fine if this gets smaller in a future release (unlikely), as
* long as two entries still fit.
*/
if (optLen < sizeof(buffer.entries))
return;
for (uint_fast8_t i = 0; i < 2; i++) {
| | | 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
* We're fine if this gets smaller in a future release (unlikely), as
* long as two entries still fit.
*/
if (optLen < sizeof(buffer.entries))
return;
for (uint_fast8_t i = 0; i < 2; i++) {
uint32_t ip = OFFromBigEndian32(buffer.entries[i].ip.s_addr);
if (ip == 0)
continue;
[nameServers addObject: [OFString stringWithFormat:
@"%u.%u.%u.%u", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF,
(ip >> 8) & 0xFF, ip & 0xFF]];
|
| ︙ | ︙ |
Changes to src/OFDNSResourceRecord.m.
| ︙ | ︙ | |||
241 242 243 244 245 246 247 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | 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 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAdd(&hash, _DNSClass >> 8);
OFHashAdd(&hash, _DNSClass);
OFHashAdd(&hash, _recordType >> 8);
OFHashAdd(&hash, _recordType);
OFHashAddHash(&hash, OFSocketAddressHash(&_address));
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
return [OFString stringWithFormat:
|
| ︙ | ︙ | |||
326 327 328 329 330 331 332 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | 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 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAdd(&hash, _DNSClass >> 8);
OFHashAdd(&hash, _DNSClass);
OFHashAdd(&hash, _recordType >> 8);
OFHashAdd(&hash, _recordType);
OFHashAddHash(&hash, OFSocketAddressHash(&_address));
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
return [OFString stringWithFormat:
|
| ︙ | ︙ | |||
421 422 423 424 425 426 427 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | 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 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAdd(&hash, _DNSClass >> 8);
OFHashAdd(&hash, _DNSClass);
OFHashAdd(&hash, _recordType >> 8);
OFHashAdd(&hash, _recordType);
OFHashAddHash(&hash, _alias.hash);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
return [OFString stringWithFormat:
|
| ︙ | ︙ | |||
523 524 525 526 527 528 529 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | | 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 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAdd(&hash, _DNSClass >> 8);
OFHashAdd(&hash, _DNSClass);
OFHashAdd(&hash, _recordType >> 8);
OFHashAdd(&hash, _recordType);
OFHashAddHash(&hash, _CPU.hash);
OFHashAddHash(&hash, _OS.hash);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
return [OFString stringWithFormat:
|
| ︙ | ︙ | |||
627 628 629 630 631 632 633 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | | | 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAdd(&hash, _DNSClass >> 8);
OFHashAdd(&hash, _DNSClass);
OFHashAdd(&hash, _recordType >> 8);
OFHashAdd(&hash, _recordType);
OFHashAdd(&hash, _preference >> 8);
OFHashAdd(&hash, _preference);
OFHashAddHash(&hash, _mailExchange.hash);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
return [OFString stringWithFormat:
|
| ︙ | ︙ | |||
728 729 730 731 732 733 734 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAdd(&hash, _DNSClass >> 8);
OFHashAdd(&hash, _DNSClass);
OFHashAdd(&hash, _recordType >> 8);
OFHashAdd(&hash, _recordType);
OFHashAddHash(&hash, _authoritativeHost.hash);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
return [OFString stringWithFormat:
|
| ︙ | ︙ | |||
826 827 828 829 830 831 832 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | 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 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAdd(&hash, _DNSClass >> 8);
OFHashAdd(&hash, _DNSClass);
OFHashAdd(&hash, _recordType >> 8);
OFHashAdd(&hash, _recordType);
OFHashAddHash(&hash, _domainName.hash);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
return [OFString stringWithFormat:
|
| ︙ | ︙ | |||
931 932 933 934 935 936 937 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | | 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAdd(&hash, _DNSClass >> 8);
OFHashAdd(&hash, _DNSClass);
OFHashAdd(&hash, _recordType >> 8);
OFHashAdd(&hash, _recordType);
OFHashAddHash(&hash, _mailbox.hash);
OFHashAddHash(&hash, _TXTDomainName.hash);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
return [OFString stringWithFormat:
|
| ︙ | ︙ | |||
1067 1068 1069 1070 1071 1072 1073 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAdd(&hash, _DNSClass >> 8);
OFHashAdd(&hash, _DNSClass);
OFHashAdd(&hash, _recordType >> 8);
OFHashAdd(&hash, _recordType);
OFHashAddHash(&hash, _primaryNameServer.hash);
OFHashAddHash(&hash, _responsiblePerson.hash);
OFHashAdd(&hash, _serialNumber >> 24);
OFHashAdd(&hash, _serialNumber >> 16);
OFHashAdd(&hash, _serialNumber >> 8);
OFHashAdd(&hash, _serialNumber);
OFHashAdd(&hash, _refreshInterval >> 24);
OFHashAdd(&hash, _refreshInterval >> 16);
OFHashAdd(&hash, _refreshInterval >> 8);
OFHashAdd(&hash, _refreshInterval);
OFHashAdd(&hash, _retryInterval >> 24);
OFHashAdd(&hash, _retryInterval >> 16);
OFHashAdd(&hash, _retryInterval >> 8);
OFHashAdd(&hash, _retryInterval);
OFHashAdd(&hash, _expirationInterval >> 24);
OFHashAdd(&hash, _expirationInterval >> 16);
OFHashAdd(&hash, _expirationInterval >> 8);
OFHashAdd(&hash, _expirationInterval);
OFHashAdd(&hash, _minTTL >> 24);
OFHashAdd(&hash, _minTTL >> 16);
OFHashAdd(&hash, _minTTL >> 8);
OFHashAdd(&hash, _minTTL);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
return [OFString stringWithFormat:
|
| ︙ | ︙ | |||
1208 1209 1210 1211 1212 1213 1214 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | | | | | | | 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAdd(&hash, _DNSClass >> 8);
OFHashAdd(&hash, _DNSClass);
OFHashAdd(&hash, _recordType >> 8);
OFHashAdd(&hash, _recordType);
OFHashAdd(&hash, _priority >> 8);
OFHashAdd(&hash, _priority);
OFHashAdd(&hash, _weight >> 8);
OFHashAdd(&hash, _weight);
OFHashAddHash(&hash, _target.hash);
OFHashAdd(&hash, _port >> 8);
OFHashAdd(&hash, _port);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
return [OFString stringWithFormat:
|
| ︙ | ︙ | |||
1313 1314 1315 1316 1317 1318 1319 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAdd(&hash, _DNSClass >> 8);
OFHashAdd(&hash, _DNSClass);
OFHashAdd(&hash, _recordType >> 8);
OFHashAdd(&hash, _recordType);
OFHashAddHash(&hash, _textStrings.hash);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
void *pool = objc_autoreleasePoolPush();
|
| ︙ | ︙ |
Changes to src/OFDNSResponse.m.
| ︙ | ︙ | |||
97 98 99 100 101 102 103 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _domainName.hash);
OFHashAddHash(&hash, [_answerRecords hash]);
OFHashAddHash(&hash, [_authorityRecords hash]);
OFHashAddHash(&hash, [_additionalRecords hash]);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
OFString *answerRecords = [_answerRecords.description
|
| ︙ | ︙ |
Changes to src/OFData+MessagePackParsing.m.
| ︙ | ︙ | |||
130 131 132 133 134 135 136 |
createDate(OFData *data)
{
switch (data.count) {
case 4: {
uint32_t timestamp;
memcpy(×tamp, data.items, 4);
| | | | | | 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 |
createDate(OFData *data)
{
switch (data.count) {
case 4: {
uint32_t timestamp;
memcpy(×tamp, data.items, 4);
timestamp = OFFromBigEndian32(timestamp);
return [OFDate dateWithTimeIntervalSince1970: timestamp];
}
case 8: {
uint64_t combined;
memcpy(&combined, data.items, 8);
combined = OFFromBigEndian64(combined);
return [OFDate dateWithTimeIntervalSince1970:
(double)(combined & 0x3FFFFFFFF) +
(double)(combined >> 34) / 1000000000];
}
case 12: {
uint32_t nanoseconds;
int64_t seconds;
memcpy(&nanoseconds, data.items, 4);
memcpy(&seconds, (char *)data.items + 4, 8);
nanoseconds = OFFromBigEndian32(nanoseconds);
seconds = OFFromBigEndian64(seconds);
return [OFDate dateWithTimeIntervalSince1970:
(double)seconds + (double)nanoseconds / 1000000000];
}
default:
@throw [OFInvalidFormatException exception];
}
|
| ︙ | ︙ | |||
283 284 285 286 287 288 289 | float f; if (length < 5) @throw [OFTruncatedDataException exception]; memcpy(&f, buffer + 1, 4); | | | | 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 | float f; if (length < 5) @throw [OFTruncatedDataException exception]; memcpy(&f, buffer + 1, 4); *object = [OFNumber numberWithFloat: OFFromBigEndianFloat(f)]; return 5; case 0xCB:; /* float 64 */ double d; if (length < 9) @throw [OFTruncatedDataException exception]; memcpy(&d, buffer + 1, 8); *object = [OFNumber numberWithDouble: OFFromBigEndianDouble(d)]; return 9; /* nil */ case 0xC0: *object = [OFNull null]; return 1; /* false */ case 0xC2: |
| ︙ | ︙ |
Changes to src/OFData.m.
| ︙ | ︙ | |||
476 477 478 479 480 481 482 |
return OFOrderedDescending;
else
return OFOrderedAscending;
}
- (unsigned long)hash
{
| | | | | | 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
return OFOrderedDescending;
else
return OFOrderedAscending;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
for (size_t i = 0; i < _count * _itemSize; i++)
OFHashAdd(&hash, ((uint8_t *)_items)[i]);
OFHashFinalize(&hash);
return hash;
}
- (OFData *)subdataWithRange: (OFRange)range
{
OFData *ret;
|
| ︙ | ︙ | |||
645 646 647 648 649 650 651 |
uint8_t tmp = (uint8_t)_count;
data = [OFMutableData dataWithCapacity: _count + 2];
[data addItem: &type];
[data addItem: &tmp];
} else if (_count <= UINT16_MAX) {
uint8_t type = 0xC5;
| | | | 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 |
uint8_t tmp = (uint8_t)_count;
data = [OFMutableData dataWithCapacity: _count + 2];
[data addItem: &type];
[data addItem: &tmp];
} else if (_count <= UINT16_MAX) {
uint8_t type = 0xC5;
uint16_t tmp = OFToBigEndian16((uint16_t)_count);
data = [OFMutableData dataWithCapacity: _count + 3];
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else if (_count <= UINT32_MAX) {
uint8_t type = 0xC6;
uint32_t tmp = OFToBigEndian32((uint32_t)_count);
data = [OFMutableData dataWithCapacity: _count + 5];
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else
@throw [OFOutOfRangeException exception];
[data addItems: _items count: _count];
[data makeImmutable];
return data;
}
@end
|
Changes to src/OFDate.m.
| ︙ | ︙ | |||
93 94 95 96 97 98 99 |
static OFTimeInterval
now(void)
{
struct timeval tv;
OFTimeInterval seconds;
| | | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
static OFTimeInterval
now(void)
{
struct timeval tv;
OFTimeInterval seconds;
OFEnsure(gettimeofday(&tv, NULL) == 0);
seconds = tv.tv_sec;
seconds += (OFTimeInterval)tv.tv_usec / 1000000;
return seconds;
}
|
| ︙ | ︙ | |||
297 298 299 300 301 302 303 |
if (seconds == 0) {
static OFOnceControl once = OFOnceControlInitValue;
OFOnce(&once, initZeroDate);
return (id)zeroDate;
}
#if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX
| | | 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
if (seconds == 0) {
static OFOnceControl once = OFOnceControlInitValue;
OFOnce(&once, initZeroDate);
return (id)zeroDate;
}
#if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX
value = OFFromBigEndian64(OFDoubleToRawUInt64(OFToBigEndianDouble(
seconds)));
/* Almost all dates fall into this range. */
if (value & (UINT64_C(4) << 60)) {
id ret = objc_createTaggedPointer(dateTag,
value & ~(UINT64_C(4) << 60));
|
| ︙ | ︙ | |||
325 326 327 328 329 330 331 |
@implementation OFTaggedPointerDate
- (OFTimeInterval)timeIntervalSince1970
{
uint64_t value = (uint64_t)object_getTaggedPointerValue(self);
value |= UINT64_C(4) << 60;
| | | 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
@implementation OFTaggedPointerDate
- (OFTimeInterval)timeIntervalSince1970
{
uint64_t value = (uint64_t)object_getTaggedPointerValue(self);
value |= UINT64_C(4) << 60;
return OFFromBigEndianDouble(OFRawUInt64ToDouble(OFToBigEndian64(
value)));
}
@end
#endif
@implementation OFDate
+ (void)initialize
|
| ︙ | ︙ | |||
509 510 511 512 513 514 515 | @throw [OFInvalidArgumentException exception]; value = [element unsignedLongLongValueWithBase: 16]; if (value > UINT64_MAX) @throw [OFOutOfRangeException exception]; | | | | 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
@throw [OFInvalidArgumentException exception];
value = [element unsignedLongLongValueWithBase: 16];
if (value > UINT64_MAX)
@throw [OFOutOfRangeException exception];
seconds = OFFromBigEndianDouble(OFRawUInt64ToDouble(
OFToBigEndian64(value)));
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
|
| ︙ | ︙ | |||
541 542 543 544 545 546 547 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
double tmp;
OFHashInit(&hash);
tmp = OFToLittleEndianDouble(self.timeIntervalSince1970);
for (size_t i = 0; i < sizeof(double); i++)
OFHashAdd(&hash, ((char *)&tmp)[i]);
OFHashFinalize(&hash);
return hash;
}
- (id)copy
{
return [self retain];
|
| ︙ | ︙ | |||
588 589 590 591 592 593 594 | void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: @"OFDate" namespace: OF_SERIALIZATION_NS]; element.stringValue = [OFString stringWithFormat: @"%016" PRIx64, | | | 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: @"OFDate" namespace: OF_SERIALIZATION_NS]; element.stringValue = [OFString stringWithFormat: @"%016" PRIx64, OFFromBigEndian64(OFDoubleToRawUInt64(OFToBigEndianDouble( self.timeIntervalSince1970)))]; [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; |
| ︙ | ︙ | |||
612 613 614 615 616 617 618 |
OFData *ret;
if (seconds >= 0 && seconds < 0x400000000) {
if (seconds <= UINT32_MAX && nanoseconds == 0) {
uint32_t seconds32 = (uint32_t)seconds;
OFData *data;
| | | | | | 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
OFData *ret;
if (seconds >= 0 && seconds < 0x400000000) {
if (seconds <= UINT32_MAX && nanoseconds == 0) {
uint32_t seconds32 = (uint32_t)seconds;
OFData *data;
seconds32 = OFToBigEndian32(seconds32);
data = [OFData dataWithItems: &seconds32
count: sizeof(seconds32)];
ret = [[OFMessagePackExtension
extensionWithType: -1
data: data] messagePackRepresentation];
} else {
uint64_t combined = ((uint64_t)nanoseconds << 34) |
(uint64_t)seconds;
OFData *data;
combined = OFToBigEndian64(combined);
data = [OFData dataWithItems: &combined
count: sizeof(combined)];
ret = [[OFMessagePackExtension
extensionWithType: -1
data: data] messagePackRepresentation];
}
} else {
OFMutableData *data = [OFMutableData dataWithCapacity: 12];
nanoseconds = OFToBigEndian32(nanoseconds);
[data addItems: &nanoseconds count: sizeof(nanoseconds)];
seconds = OFToBigEndian64(seconds);
[data addItems: &seconds count: sizeof(seconds)];
ret = [[OFMessagePackExtension
extensionWithType: -1
data: data] messagePackRepresentation];
}
|
| ︙ | ︙ | |||
891 892 893 894 895 896 897 |
}
- (OFTimeInterval)timeIntervalSinceNow
{
struct timeval t;
OFTimeInterval seconds;
| | | 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 |
}
- (OFTimeInterval)timeIntervalSinceNow
{
struct timeval t;
OFTimeInterval seconds;
OFEnsure(gettimeofday(&t, NULL) == 0);
seconds = t.tv_sec;
seconds += (OFTimeInterval)t.tv_usec / 1000000;
return self.timeIntervalSince1970 - seconds;
}
- (OFDate *)dateByAddingTimeInterval: (OFTimeInterval)seconds
{
return [OFDate dateWithTimeIntervalSince1970:
self.timeIntervalSince1970 + seconds];
}
@end
|
Changes to src/OFDictionary.m.
| ︙ | ︙ | |||
173 174 175 176 177 178 179 |
- (unsigned int)retainCount
{
return OF_RETAIN_COUNT_MAX;
}
- (bool)characterIsMember: (OFUnichar)character
{
| | | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
- (unsigned int)retainCount
{
return OF_RETAIN_COUNT_MAX;
}
- (bool)characterIsMember: (OFUnichar)character
{
if (character < CHAR_MAX && OFASCIIIsAlnum(character))
return true;
switch (character) {
case '-':
case '.':
case '_':
case '~':
|
| ︙ | ︙ | |||
820 821 822 823 824 825 826 |
count = self.count;
if (count <= 15) {
uint8_t tmp = 0x80 | ((uint8_t)count & 0xF);
[data addItem: &tmp];
} else if (count <= UINT16_MAX) {
uint8_t type = 0xDE;
| | | | 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 |
count = self.count;
if (count <= 15) {
uint8_t tmp = 0x80 | ((uint8_t)count & 0xF);
[data addItem: &tmp];
} else if (count <= UINT16_MAX) {
uint8_t type = 0xDE;
uint16_t tmp = OFToBigEndian16((uint16_t)count);
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else if (count <= UINT32_MAX) {
uint8_t type = 0xDF;
uint32_t tmp = OFToBigEndian32((uint32_t)count);
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else
@throw [OFOutOfRangeException exception];
pool = objc_autoreleasePoolPush();
|
| ︙ | ︙ |
Changes to src/OFEpollKernelEventObserver.m.
| ︙ | ︙ | |||
205 206 207 208 209 210 211 |
for (int i = 0; i < events; i++) {
if (eventList[i].events & EPOLLIN) {
void *pool = objc_autoreleasePoolPush();
if (eventList[i].data.ptr == nullObject) {
char buffer;
| | | 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
for (int i = 0; i < events; i++) {
if (eventList[i].events & EPOLLIN) {
void *pool = objc_autoreleasePoolPush();
if (eventList[i].data.ptr == nullObject) {
char buffer;
OFEnsure(read(_cancelFD[0], &buffer, 1) == 1);
continue;
}
if ([_delegate respondsToSelector:
@selector(objectIsReadyForReading:)])
[_delegate objectIsReadyForReading:
eventList[i].data.ptr];
|
| ︙ | ︙ |
Changes to src/OFHTTPClient.m.
| ︙ | ︙ | |||
215 216 217 218 219 220 221 |
static OF_INLINE void
normalizeKey(char *str_)
{
unsigned char *str = (unsigned char *)str_;
bool firstLetter = true;
while (*str != '\0') {
| | < | | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
static OF_INLINE void
normalizeKey(char *str_)
{
unsigned char *str = (unsigned char *)str_;
bool firstLetter = true;
while (*str != '\0') {
if (!OFASCIIIsAlpha(*str)) {
firstLetter = true;
str++;
continue;
}
*str = (firstLetter
? OFASCIIToUpper(*str) : OFASCIIToLower(*str));
firstLetter = false;
str++;
}
}
static bool
|
| ︙ | ︙ |
Changes to src/OFHTTPCookie.m.
| ︙ | ︙ | |||
359 360 361 362 363 364 365 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | | | 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 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAddHash(&hash, _value.hash);
OFHashAddHash(&hash, _domain.hash);
OFHashAddHash(&hash, _path.hash);
OFHashAddHash(&hash, _expires.hash);
OFHashAdd(&hash, _secure);
OFHashAdd(&hash, _HTTPOnly);
OFHashAddHash(&hash, _extensions.hash);
OFHashFinalize(&hash);
return hash;
}
- (id)copy
{
OFHTTPCookie *copy = [[OFHTTPCookie alloc] initWithName: _name
|
| ︙ | ︙ |
Changes to src/OFHTTPRequest.m.
| ︙ | ︙ | |||
181 182 183 184 185 186 187 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | 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 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAdd(&hash, _method);
OFHashAdd(&hash, _protocolVersion.major);
OFHashAdd(&hash, _protocolVersion.minor);
OFHashAddHash(&hash, _URL.hash);
OFHashAddHash(&hash, _headers.hash);
if (_hasRemoteAddress)
OFHashAddHash(&hash, OFSocketAddressHash(&_remoteAddress));
OFHashFinalize(&hash);
return hash;
}
- (void)setProtocolVersion: (OFHTTPRequestProtocolVersion)protocolVersion
{
if (protocolVersion.major != 1 || protocolVersion.minor > 1)
|
| ︙ | ︙ |
Changes to src/OFHTTPServer.m.
| ︙ | ︙ | |||
118 119 120 121 122 123 124 |
- (void)stop;
@end
#endif
static OF_INLINE OFString *
normalizedKey(OFString *key)
{
| | | < | | 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 |
- (void)stop;
@end
#endif
static OF_INLINE OFString *
normalizedKey(OFString *key)
{
char *cString = OFStrdup(key.UTF8String);
unsigned char *tmp = (unsigned char *)cString;
bool firstLetter = true;
if (cString == NULL)
@throw [OFOutOfMemoryException
exceptionWithRequestedSize: strlen(key.UTF8String)];
while (*tmp != '\0') {
if (!OFASCIIIsAlpha(*tmp)) {
firstLetter = true;
tmp++;
continue;
}
*tmp = (firstLetter
? OFASCIIToUpper(*tmp) : OFASCIIToLower(*tmp));
firstLetter = false;
tmp++;
}
@try {
return [OFString stringWithUTF8StringNoCopy: cString
|
| ︙ | ︙ | |||
339 340 341 342 343 344 345 |
default:
return false;
}
} @catch (OFWriteFailedException *e) {
return false;
}
| | | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
default:
return false;
}
} @catch (OFWriteFailedException *e) {
return false;
}
OFEnsure(0);
}
- (bool)parseProlog: (OFString *)line
{
OFString *method;
OFMutableString *path;
size_t pos;
|
| ︙ | ︙ |
Changes to src/OFINIFile.m.
| ︙ | ︙ | |||
35 36 37 38 39 40 41 |
static bool
isWhitespaceLine(OFString *line)
{
const char *cString = line.UTF8String;
size_t length = line.UTF8StringLength;
for (size_t i = 0; i < length; i++)
| | | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
static bool
isWhitespaceLine(OFString *line)
{
const char *cString = line.UTF8String;
size_t length = line.UTF8StringLength;
for (size_t i = 0; i < length; i++)
if (!OFASCIIIsSpace(cString[i]))
return false;
return true;
}
@implementation OFINIFile
@synthesize categories = _categories;
|
| ︙ | ︙ |
Changes to src/OFIPSocketAsyncConnector.m.
| ︙ | ︙ | |||
67 68 69 70 71 72 73 |
[_socket setCanBlock: true];
#ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
if ([_socket isKindOfClass: [OFTCPSocket class]])
((OFTCPSocketAsyncConnectBlock)_block)(_exception);
else
| | | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
[_socket setCanBlock: true];
#ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
if ([_socket isKindOfClass: [OFTCPSocket class]])
((OFTCPSocketAsyncConnectBlock)_block)(_exception);
else
OFEnsure(0);
} else {
#endif
if ([_delegate respondsToSelector:
@selector(socket:didConnectToHost:port:exception:)])
[_delegate socket: _socket
didConnectToHost: _host
port: _port
|
| ︙ | ︙ |
Changes to src/OFKernelEventObserver.m.
| ︙ | ︙ | |||
146 147 148 149 150 151 152 |
for (;;) {
uint16_t rnd = 0;
int ret;
while (rnd < 1024)
rnd = (uint16_t)rand();
| | | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
for (;;) {
uint16_t rnd = 0;
int ret;
while (rnd < 1024)
rnd = (uint16_t)rand();
_cancelAddr.sin_port = OFToBigEndian16(rnd);
ret = bind(_cancelFD[0],
(struct sockaddr *)&_cancelAddr,
sizeof(_cancelAddr));
if (ret == 0)
break;
|
| ︙ | ︙ | |||
263 264 265 266 267 268 269 |
if (_waitingTask != NULL) {
Signal(_waitingTask, (1ul << _cancelSignal));
_waitingTask = NULL;
}
Permit();
#elif defined(OF_HAVE_PIPE)
| | | | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
if (_waitingTask != NULL) {
Signal(_waitingTask, (1ul << _cancelSignal));
_waitingTask = NULL;
}
Permit();
#elif defined(OF_HAVE_PIPE)
OFEnsure(write(_cancelFD[1], "", 1) > 0);
#elif defined(OF_WII)
OFEnsure(sendto(_cancelFD[1], "", 1, 0,
(struct sockaddr *)&_cancelAddr, 8) > 0);
#else
OFEnsure(sendto(_cancelFD[1], (void *)"", 1, 0,
(struct sockaddr *)&_cancelAddr, sizeof(_cancelAddr)) > 0);
#endif
}
@end
|
Changes to src/OFKqueueKernelEventObserver.m.
| ︙ | ︙ | |||
180 181 182 183 184 185 186 |
exceptionWithObserver: self
errNo: (int)eventList[i].data];
if (eventList[i].ident == (uintptr_t)_cancelFD[0]) {
char buffer;
assert(eventList[i].filter == EVFILT_READ);
| | | 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
exceptionWithObserver: self
errNo: (int)eventList[i].data];
if (eventList[i].ident == (uintptr_t)_cancelFD[0]) {
char buffer;
assert(eventList[i].filter == EVFILT_READ);
OFEnsure(read(_cancelFD[0], &buffer, 1) == 1);
continue;
}
pool = objc_autoreleasePoolPush();
switch (eventList[i].filter) {
|
| ︙ | ︙ |
Changes to src/OFLHAArchiveEntry.m.
| ︙ | ︙ | |||
116 117 118 119 120 121 122 |
{
uint16_t mode;
if (extension.count != 3)
@throw [OFInvalidFormatException exception];
memcpy(&mode, (char *)extension.items + 1, 2);
| | | | | 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 |
{
uint16_t mode;
if (extension.count != 3)
@throw [OFInvalidFormatException exception];
memcpy(&mode, (char *)extension.items + 1, 2);
mode = OFFromLittleEndian16(mode);
[entry->_mode release];
entry->_mode = nil;
entry->_mode = [[OFNumber alloc] initWithUnsignedShort: mode];
}
static void
parseGIDUIDExtension(OFLHAArchiveEntry *entry, OFData *extension,
OFStringEncoding encoding)
{
uint16_t UID, GID;
if (extension.count != 5)
@throw [OFInvalidFormatException exception];
memcpy(&GID, (char *)extension.items + 1, 2);
GID = OFFromLittleEndian16(GID);
memcpy(&UID, (char *)extension.items + 3, 2);
UID = OFFromLittleEndian16(UID);
[entry->_GID release];
entry->_GID = nil;
[entry->_UID release];
entry->_UID = nil;
|
| ︙ | ︙ | |||
185 186 187 188 189 190 191 |
{
uint32_t modificationDate;
if (extension.count != 5)
@throw [OFInvalidFormatException exception];
memcpy(&modificationDate, (char *)extension.items + 1, 4);
| | | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
{
uint32_t modificationDate;
if (extension.count != 5)
@throw [OFInvalidFormatException exception];
memcpy(&modificationDate, (char *)extension.items + 1, 4);
modificationDate = OFFromLittleEndian32(modificationDate);
[entry->_modificationDate release];
entry->_modificationDate = nil;
entry->_modificationDate = [[OFDate alloc]
initWithTimeIntervalSince1970: modificationDate];
}
|
| ︙ | ︙ | |||
341 342 343 344 345 346 347 | _compressionMethod = [[OFString alloc] initWithCString: header + 2 encoding: OFStringEncodingASCII length: 5]; memcpy(&_compressedSize, header + 7, 4); | | | | | 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
_compressionMethod = [[OFString alloc]
initWithCString: header + 2
encoding: OFStringEncodingASCII
length: 5];
memcpy(&_compressedSize, header + 7, 4);
_compressedSize = OFFromLittleEndian32(_compressedSize);
memcpy(&_uncompressedSize, header + 11, 4);
_uncompressedSize = OFFromLittleEndian32(_uncompressedSize);
memcpy(&date, header + 15, 4);
date = OFFromLittleEndian32(date);
_headerLevel = header[20];
_extensions = [[OFMutableArray alloc] init];
switch (_headerLevel) {
case 0:
case 1:;
|
| ︙ | ︙ | |||
578 579 580 581 582 583 584 | /* Length. Filled in after we're done. */ [data increaseCountBy: 2]; [data addItems: [_compressionMethod cStringWithEncoding: OFStringEncodingASCII] count: 5]; | | | | | | | | | | | | | | | | | | | | | | 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 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 |
/* Length. Filled in after we're done. */
[data increaseCountBy: 2];
[data addItems: [_compressionMethod
cStringWithEncoding: OFStringEncodingASCII]
count: 5];
tmp32 = OFToLittleEndian32(_compressedSize);
[data addItems: &tmp32 count: sizeof(tmp32)];
tmp32 = OFToLittleEndian32(_uncompressedSize);
[data addItems: &tmp32 count: sizeof(tmp32)];
tmp32 = OFToLittleEndian32((uint32_t)_date.timeIntervalSince1970);
[data addItems: &tmp32 count: sizeof(tmp32)];
/* Reserved */
[data increaseCountBy: 1];
/* Header level */
[data addItem: "\x02"];
/* CRC16 */
tmp16 = OFToLittleEndian16(_CRC16);
[data addItems: &tmp16 count: sizeof(tmp16)];
/* Operating system identifier */
[data addItem: "U"];
/* Common header. Contains CRC16, which is written at the end. */
tmp16 = OFToLittleEndian16(5);
[data addItems: &tmp16 count: sizeof(tmp16)];
[data addItem: "\x00"];
[data increaseCountBy: 2];
tmp16 = OFToLittleEndian16((uint16_t)fileNameLength + 3);
[data addItems: &tmp16 count: sizeof(tmp16)];
[data addItem: "\x01"];
[data addItems: fileName count: fileNameLength];
if (directoryNameLength > 0) {
tmp16 = OFToLittleEndian16((uint16_t)directoryNameLength + 3);
[data addItems: &tmp16 count: sizeof(tmp16)];
[data addItem: "\x02"];
[data addItems: directoryName count: directoryNameLength];
}
if (_fileComment != nil) {
size_t fileCommentLength =
[_fileComment cStringLengthWithEncoding: encoding];
if (fileCommentLength > UINT16_MAX - 3)
@throw [OFOutOfRangeException exception];
tmp16 = OFToLittleEndian16((uint16_t)fileCommentLength + 3);
[data addItems: &tmp16 count: sizeof(tmp16)];
[data addItem: "\x3F"];
[data addItems: [_fileComment cStringWithEncoding: encoding]
count: fileCommentLength];
}
if (_mode != nil) {
tmp16 = OFToLittleEndian16(5);
[data addItems: &tmp16 count: sizeof(tmp16)];
[data addItem: "\x50"];
tmp16 = OFToLittleEndian16(_mode.unsignedShortValue);
[data addItems: &tmp16 count: sizeof(tmp16)];
}
if (_UID != nil || _GID != nil) {
if (_UID == nil || _GID == nil)
@throw [OFInvalidArgumentException exception];
tmp16 = OFToLittleEndian16(7);
[data addItems: &tmp16 count: sizeof(tmp16)];
[data addItem: "\x51"];
tmp16 = OFToLittleEndian16(_GID.unsignedShortValue);
[data addItems: &tmp16 count: sizeof(tmp16)];
tmp16 = OFToLittleEndian16(_UID.unsignedShortValue);
[data addItems: &tmp16 count: sizeof(tmp16)];
}
if (_group != nil) {
size_t groupLength =
[_group cStringLengthWithEncoding: encoding];
if (groupLength > UINT16_MAX - 3)
@throw [OFOutOfRangeException exception];
tmp16 = OFToLittleEndian16((uint16_t)groupLength + 3);
[data addItems: &tmp16 count: sizeof(tmp16)];
[data addItem: "\x52"];
[data addItems: [_group cStringWithEncoding: encoding]
count: groupLength];
}
if (_owner != nil) {
size_t ownerLength =
[_owner cStringLengthWithEncoding: encoding];
if (ownerLength > UINT16_MAX - 3)
@throw [OFOutOfRangeException exception];
tmp16 = OFToLittleEndian16((uint16_t)ownerLength + 3);
[data addItems: &tmp16 count: sizeof(tmp16)];
[data addItem: "\x53"];
[data addItems: [_owner cStringWithEncoding: encoding]
count: ownerLength];
}
if (_modificationDate != nil) {
tmp16 = OFToLittleEndian16(7);
[data addItems: &tmp16 count: sizeof(tmp16)];
[data addItem: "\x54"];
tmp32 = OFToLittleEndian32(
(uint32_t)_modificationDate.timeIntervalSince1970);
[data addItems: &tmp32 count: sizeof(tmp32)];
}
for (OFData *extension in _extensions) {
size_t extensionLength = extension.count;
if (extension.itemSize != 1)
@throw [OFInvalidArgumentException exception];
if (extensionLength > UINT16_MAX - 2)
@throw [OFOutOfRangeException exception];
tmp16 = OFToLittleEndian16((uint16_t)extensionLength + 2);
[data addItems: &tmp16 count: sizeof(tmp16)];
[data addItems: extension.items count: extension.count];
}
/* Zero-length extension to terminate */
[data increaseCountBy: 2];
headerSize = data.count;
if (headerSize > UINT16_MAX)
@throw [OFOutOfRangeException exception];
/* Now fill in the size and CRC16 for the entire header */
tmp16 = OFToLittleEndian16(headerSize);
memcpy([data mutableItemAtIndex: 0], &tmp16, sizeof(tmp16));
tmp16 = of_crc16(0, data.items, data.count);
tmp16 = OFToLittleEndian16(tmp16);
memcpy([data mutableItemAtIndex: 27], &tmp16, sizeof(tmp16));
[stream writeData: data];
objc_autoreleasePoolPop(pool);
}
|
| ︙ | ︙ |
Changes to src/OFLHADecompressingStream.m.
| ︙ | ︙ | |||
282 283 284 285 286 287 288 | if OF_UNLIKELY (!tryReadBits(self, &bits, 9)) return bytesWritten; skipCount = bits + 20; break; default: | | | 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | if OF_UNLIKELY (!tryReadBits(self, &bits, 9)) return bytesWritten; skipCount = bits + 20; break; default: OFEnsure(0); } if OF_UNLIKELY (_codesReceived + skipCount > _codesCount) @throw [OFInvalidFormatException exception]; |
| ︙ | ︙ |
Changes to src/OFList.m.
| ︙ | ︙ | |||
313 314 315 316 317 318 319 |
copy->_lastListItem = listItem;
return copy;
}
- (unsigned long)hash
{
| | | | < | | | 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
copy->_lastListItem = listItem;
return copy;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
for (OFListItem *iter = _firstListItem; iter != NULL; iter = iter->next)
OFHashAddHash(&hash, [iter->object hash]);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
OFMutableString *ret;
|
| ︙ | ︙ |
Changes to src/OFLocale.m.
| ︙ | ︙ | |||
38 39 40 41 42 43 44 |
static OFDictionary *operatorPrecedences = nil;
#ifndef OF_AMIGAOS
static void
parseLocale(char *locale, OFStringEncoding *encoding,
OFString **language, OFString **territory)
{
| | | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
static OFDictionary *operatorPrecedences = nil;
#ifndef OF_AMIGAOS
static void
parseLocale(char *locale, OFStringEncoding *encoding,
OFString **language, OFString **territory)
{
if ((locale = OFStrdup(locale)) == NULL)
return;
@try {
OFStringEncoding enc = OFStringEncodingASCII;
char *tmp;
/* We don't care for extras behind the @ */
|
| ︙ | ︙ | |||
217 218 219 220 221 222 223 | else if ([token isEqual: @"&&"]) var = [OFNumber numberWithBool: [first boolValue] && [second boolValue]]; else if ([token isEqual: @"||"]) var = [OFNumber numberWithBool: [first boolValue] || [second boolValue]]; else | | | | 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 |
else if ([token isEqual: @"&&"])
var = [OFNumber numberWithBool:
[first boolValue] && [second boolValue]];
else if ([token isEqual: @"||"])
var = [OFNumber numberWithBool:
[first boolValue] || [second boolValue]];
else
OFEnsure(0);
[stack replaceObjectAtIndex: stackSize - 2
withObject: var];
[stack removeLastObject];
} else if (precedence == 1) {
stackSize = stack.count;
first = stack.lastObject;
if ([token isEqual: @"!"])
var = [OFNumber numberWithBool:
![first boolValue]];
else if ([token isEqual: @"is_real"])
var = [OFNumber numberWithBool:
([first doubleValue] !=
[first longLongValue])];
else
OFEnsure(0);
[stack replaceObjectAtIndex: stackSize - 1
withObject: var];
} else
[stack addObject: token];
}
|
| ︙ | ︙ | |||
453 454 455 456 457 458 459 |
if ((locale = OpenLocale(NULL)) != NULL) {
@try {
uint32_t territory;
size_t length;
territory =
| | | 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
if ((locale = OpenLocale(NULL)) != NULL) {
@try {
uint32_t territory;
size_t length;
territory =
OFToBigEndian32(locale->loc_CountryCode);
for (length = 0; length < 4; length++)
if (((char *)&territory)[length] == 0)
break;
_territory = [[OFString alloc]
initWithCString: (char *)&territory
|
| ︙ | ︙ |
Changes to src/OFMD5Hash.m.
| ︙ | ︙ | |||
71 72 73 74 75 76 77 |
};
static OF_INLINE void
byteSwapVectorIfBE(uint32_t *vector, uint_fast8_t length)
{
#ifdef OF_BIG_ENDIAN
for (uint_fast8_t i = 0; i < length; i++)
| | | | | | | | | | > | | | 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 |
};
static OF_INLINE void
byteSwapVectorIfBE(uint32_t *vector, uint_fast8_t length)
{
#ifdef OF_BIG_ENDIAN
for (uint_fast8_t i = 0; i < length; i++)
vector[i] = OFByteSwap32(vector[i]);
#endif
}
static void
processBlock(uint32_t *state, uint32_t *buffer)
{
uint32_t new[4];
uint_fast8_t i = 0;
new[0] = state[0];
new[1] = state[1];
new[2] = state[2];
new[3] = state[3];
byteSwapVectorIfBE(buffer, 16);
#define LOOP_BODY(f) \
{ \
uint32_t tmp = new[3]; \
tmp = new[3]; \
new[0] += f(new[1], new[2], new[3]) + \
buffer[wordOrder[i]] + table[i]; \
new[3] = new[2]; \
new[2] = new[1]; \
new[1] += OFRotateLeft(new[0], \
rotateBits[(i % 4) + (i / 16) * 4]); \
new[0] = tmp; \
}
for (; i < 16; i++)
LOOP_BODY(F)
for (; i < 32; i++)
LOOP_BODY(G)
for (; i < 48; i++)
|
| ︙ | ︙ | |||
243 244 245 246 247 248 249 |
- (const unsigned char *)digest
{
if (_calculated)
return (const unsigned char *)_iVars->state;
_iVars->buffer.bytes[_iVars->bufferLength] = 0x80;
| | | | | | | | 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 |
- (const unsigned char *)digest
{
if (_calculated)
return (const unsigned char *)_iVars->state;
_iVars->buffer.bytes[_iVars->bufferLength] = 0x80;
OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1,
64 - _iVars->bufferLength - 1);
if (_iVars->bufferLength >= 56) {
processBlock(_iVars->state, _iVars->buffer.words);
OFZeroMemory(_iVars->buffer.bytes, 64);
}
_iVars->buffer.words[14] =
OFToLittleEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF));
_iVars->buffer.words[15] =
OFToLittleEndian32((uint32_t)(_iVars->bits >> 32));
processBlock(_iVars->state, _iVars->buffer.words);
OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer));
byteSwapVectorIfBE(_iVars->state, 4);
_calculated = true;
return (const unsigned char *)_iVars->state;
}
- (void)reset
{
[self of_resetState];
_iVars->bits = 0;
OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer));
_iVars->bufferLength = 0;
_calculated = false;
}
@end
|
Changes to src/OFMapTable.m.
| ︙ | ︙ | |||
248 249 250 251 252 253 254 |
{
unsigned long i, last;
void *old;
if (key == NULL || object == NULL)
@throw [OFInvalidArgumentException exception];
| | | 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
{
unsigned long i, last;
void *old;
if (key == NULL || object == NULL)
@throw [OFInvalidArgumentException exception];
hash = OFRotateLeft(hash, self->_rotate);
last = self->_capacity;
for (i = hash & (self->_capacity - 1);
i < last && self->_buckets[i] != NULL; i++) {
if (self->_buckets[i] == &deleted)
continue;
|
| ︙ | ︙ | |||
367 368 369 370 371 372 373 |
- (unsigned long)hash
{
unsigned long hash = 0;
for (unsigned long i = 0; i < _capacity; i++) {
if (_buckets[i] != NULL && _buckets[i] != &deleted) {
| | | | | 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
- (unsigned long)hash
{
unsigned long hash = 0;
for (unsigned long i = 0; i < _capacity; i++) {
if (_buckets[i] != NULL && _buckets[i] != &deleted) {
hash ^= OFRotateRight(_buckets[i]->hash, _rotate);
hash ^= _objectFunctions.hash(_buckets[i]->object);
}
}
return hash;
}
- (id)copy
{
OFMapTable *copy = [[OFMapTable alloc]
initWithKeyFunctions: _keyFunctions
objectFunctions: _objectFunctions
capacity: _capacity];
@try {
for (unsigned long i = 0; i < _capacity; i++)
if (_buckets[i] != NULL && _buckets[i] != &deleted)
setObject(copy, _buckets[i]->key,
_buckets[i]->object,
OFRotateRight(_buckets[i]->hash, _rotate));
} @catch (id e) {
[copy release];
@throw e;
}
return copy;
}
- (size_t)count
{
return _count;
}
- (void *)objectForKey: (void *)key
{
unsigned long i, hash, last;
if (key == NULL)
@throw [OFInvalidArgumentException exception];
hash = OFRotateLeft(_keyFunctions.hash(key), _rotate);
last = _capacity;
for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) {
if (_buckets[i] == &deleted)
continue;
if (_keyFunctions.equal(_buckets[i]->key, key))
|
| ︙ | ︙ | |||
448 449 450 451 452 453 454 |
- (void)removeObjectForKey: (void *)key
{
unsigned long i, hash, last;
if (key == NULL)
@throw [OFInvalidArgumentException exception];
| | | 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
- (void)removeObjectForKey: (void *)key
{
unsigned long i, hash, last;
if (key == NULL)
@throw [OFInvalidArgumentException exception];
hash = OFRotateLeft(_keyFunctions.hash(key), _rotate);
last = _capacity;
for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) {
if (_buckets[i] == &deleted)
continue;
if (_keyFunctions.equal(_buckets[i]->key, key)) {
|
| ︙ | ︙ |
Changes to src/OFMessagePackExtension.m.
| ︙ | ︙ | |||
116 117 118 119 120 121 122 | uint16_t length; ret = [OFMutableData dataWithCapacity: count + 4]; prefix = 0xC8; [ret addItem: &prefix]; | | | | 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 |
uint16_t length;
ret = [OFMutableData dataWithCapacity: count + 4];
prefix = 0xC8;
[ret addItem: &prefix];
length = OFToBigEndian16((uint16_t)count);
[ret addItems: &length count: 2];
[ret addItem: &_type];
} else {
uint32_t length;
ret = [OFMutableData dataWithCapacity: count + 6];
prefix = 0xC9;
[ret addItem: &prefix];
length = OFToBigEndian32((uint32_t)count);
[ret addItems: &length count: 4];
[ret addItem: &_type];
}
[ret addItems: _data.items count: _data.count];
[ret makeImmutable];
|
| ︙ | ︙ | |||
166 167 168 169 170 171 172 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAdd(&hash, (uint8_t)_type);
OFHashAddHash(&hash, _data.hash);
OFHashFinalize(&hash);
return hash;
}
- (id)copy
{
return [self retain];
}
@end
|
Changes to src/OFMethodSignature.m.
| ︙ | ︙ | |||
36 37 38 39 40 41 42 | size_t align; assert(*length > 0); (*type)++; (*length)--; | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
size_t align;
assert(*length > 0);
(*type)++;
(*length)--;
while (*length > 0 && OFASCIIIsDigit(**type)) {
(*type)++;
(*length)--;
}
align = alignofEncoding(type, length, true);
if (*length == 0 || **type != ']')
|
| ︙ | ︙ | |||
288 289 290 291 292 293 294 | size_t size; assert(*length > 0); (*type)++; (*length)--; | | | 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
size_t size;
assert(*length > 0);
(*type)++;
(*length)--;
while (*length > 0 && OFASCIIIsDigit(**type)) {
count = count * 10 + **type - '0';
(*type)++;
(*length)--;
}
if (count == 0)
|
| ︙ | ︙ | |||
601 602 603 604 605 606 607 |
_typesPointers = [[OFMutableData alloc]
initWithItemSize: sizeof(char *)];
_offsets = [[OFMutableData alloc]
initWithItemSize: sizeof(size_t)];
last = _types;
for (size_t i = 0; i < length; i++) {
| | | | 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 |
_typesPointers = [[OFMutableData alloc]
initWithItemSize: sizeof(char *)];
_offsets = [[OFMutableData alloc]
initWithItemSize: sizeof(size_t)];
last = _types;
for (size_t i = 0; i < length; i++) {
if (OFASCIIIsDigit(_types[i])) {
size_t offset = _types[i] - '0';
if (last == _types + i)
@throw [OFInvalidFormatException
exception];
_types[i] = '\0';
[_typesPointers addItem: &last];
i++;
for (; i < length &&
OFASCIIIsDigit(_types[i]); i++)
offset = offset * 10 + _types[i] - '0';
[_offsets addItem: &offset];
last = _types + i;
i--;
} else if (_types[i] == '{') {
|
| ︙ | ︙ |
Changes to src/OFMutableString.m.
| ︙ | ︙ | |||
250 251 252 253 254 255 256 | table = middleTable; tableSize = middleTableSize; } if (c >> 8 < tableSize && table[c >> 8][c & 0xFF]) [self setCharacter: table[c >> 8][c & 0xFF] atIndex: i]; | | | 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | table = middleTable; tableSize = middleTableSize; } if (c >> 8 < tableSize && table[c >> 8][c & 0xFF]) [self setCharacter: table[c >> 8][c & 0xFF] atIndex: i]; isStart = OFASCIIIsSpace(c); } objc_autoreleasePoolPop(pool); } #else static void convert(OFMutableString *self, char (*startFunction)(char), |
| ︙ | ︙ | |||
273 274 275 276 277 278 279 | char (*function)(char) = (isStart ? startFunction : middleFunction); OFUnichar c = characters[i]; if (c <= 0x7F) [self setCharacter: (int)function(c) atIndex: i]; | | | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | char (*function)(char) = (isStart ? startFunction : middleFunction); OFUnichar c = characters[i]; if (c <= 0x7F) [self setCharacter: (int)function(c) atIndex: i]; isStart = OFASCIIIsSpace(c); } objc_autoreleasePoolPop(pool); } #endif - (void)setCharacter: (OFUnichar)character atIndex: (size_t)idx |
| ︙ | ︙ | |||
411 412 413 414 415 416 417 |
wordMiddleTable: of_unicode_lowercase_table
wordStartTableSize: OF_UNICODE_TITLECASE_TABLE_SIZE
wordMiddleTableSize: OF_UNICODE_LOWERCASE_TABLE_SIZE];
}
#else
- (void)uppercase
{
| | | | | 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 |
wordMiddleTable: of_unicode_lowercase_table
wordStartTableSize: OF_UNICODE_TITLECASE_TABLE_SIZE
wordMiddleTableSize: OF_UNICODE_LOWERCASE_TABLE_SIZE];
}
#else
- (void)uppercase
{
convert(self, OFASCIIToUpper, OFASCIIToUpper);
}
- (void)lowercase
{
convert(self, OFASCIIToLower, OFASCIIToLower);
}
- (void)capitalize
{
convert(self, OFASCIIToUpper, OFASCIIToLower);
}
#endif
- (void)insertString: (OFString *)string atIndex: (size_t)idx
{
[self replaceCharactersInRange: OFRangeMake(idx, 0) withString: string];
}
|
| ︙ | ︙ | |||
507 508 509 510 511 512 513 |
void *pool = objc_autoreleasePoolPush();
const OFUnichar *characters = self.characters;
size_t i, length = self.length;
for (i = 0; i < length; i++) {
OFUnichar c = characters[i];
| | | 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
void *pool = objc_autoreleasePoolPush();
const OFUnichar *characters = self.characters;
size_t i, length = self.length;
for (i = 0; i < length; i++) {
OFUnichar c = characters[i];
if (!OFASCIIIsSpace(c))
break;
}
objc_autoreleasePoolPop(pool);
[self deleteCharactersInRange: OFRangeMake(0, i)];
}
|
| ︙ | ︙ | |||
532 533 534 535 536 537 538 |
return;
pool = objc_autoreleasePoolPush();
characters = self.characters;
d = 0;
for (p = characters + length - 1; p >= characters; p--) {
| | | 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
return;
pool = objc_autoreleasePoolPush();
characters = self.characters;
d = 0;
for (p = characters + length - 1; p >= characters; p--) {
if (!OFASCIIIsSpace(*p))
break;
d++;
}
objc_autoreleasePoolPop(pool);
|
| ︙ | ︙ |
Changes to src/OFMutableUTF8String.m.
| ︙ | ︙ | |||
85 86 87 88 89 90 91 |
for (i = 0; i < _s->cStringLength; i++) {
if (isStart)
table = startTable;
else
table = middleTable;
| | | 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
for (i = 0; i < _s->cStringLength; i++) {
if (isStart)
table = startTable;
else
table = middleTable;
isStart = OFASCIIIsSpace(_s->cString[i]);
if ((t = table[0][(uint8_t)_s->cString[i]]) != 0)
_s->cString[i] = t;
}
return;
}
|
| ︙ | ︙ | |||
122 123 124 125 126 127 128 |
_s->cStringLength - i, &c);
if (cLen <= 0 || c > 0x10FFFF) {
OFFreeMemory(unicodeString);
@throw [OFInvalidEncodingException exception];
}
| | | 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
_s->cStringLength - i, &c);
if (cLen <= 0 || c > 0x10FFFF) {
OFFreeMemory(unicodeString);
@throw [OFInvalidEncodingException exception];
}
isStart = OFASCIIIsSpace(c);
if (c >> 8 < tableSize) {
OFUnichar tc = table[c >> 8][c & 0xFF];
if (tc)
c = tc;
}
|
| ︙ | ︙ | |||
717 718 719 720 721 722 723 |
}
- (void)deleteLeadingWhitespaces
{
size_t i;
for (i = 0; i < _s->cStringLength; i++)
| | | 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 |
}
- (void)deleteLeadingWhitespaces
{
size_t i;
for (i = 0; i < _s->cStringLength; i++)
if (!OFASCIIIsSpace(_s->cString[i]))
break;
_s->hashed = false;
_s->cStringLength -= i;
_s->length -= i;
memmove(_s->cString, _s->cString + i, _s->cStringLength);
|
| ︙ | ︙ | |||
744 745 746 747 748 749 750 |
size_t d;
char *p;
_s->hashed = false;
d = 0;
for (p = _s->cString + _s->cStringLength - 1; p >= _s->cString; p--) {
| | | 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 |
size_t d;
char *p;
_s->hashed = false;
d = 0;
for (p = _s->cString + _s->cStringLength - 1; p >= _s->cString; p--) {
if (!OFASCIIIsSpace(*p))
break;
*p = '\0';
d++;
}
_s->cStringLength -= d;
|
| ︙ | ︙ | |||
771 772 773 774 775 776 777 |
size_t d, i;
char *p;
_s->hashed = false;
d = 0;
for (p = _s->cString + _s->cStringLength - 1; p >= _s->cString; p--) {
| | | | 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 |
size_t d, i;
char *p;
_s->hashed = false;
d = 0;
for (p = _s->cString + _s->cStringLength - 1; p >= _s->cString; p--) {
if (!OFASCIIIsSpace(*p))
break;
*p = '\0';
d++;
}
_s->cStringLength -= d;
_s->length -= d;
for (i = 0; i < _s->cStringLength; i++)
if (!OFASCIIIsSpace(_s->cString[i]))
break;
_s->cStringLength -= i;
_s->length -= i;
memmove(_s->cString, _s->cString + i, _s->cStringLength);
_s->cString[_s->cStringLength] = '\0';
|
| ︙ | ︙ |
Changes to src/OFMutex.m.
| ︙ | ︙ | |||
50 51 52 53 54 55 56 |
- (void)dealloc
{
if (_initialized) {
int error = OFPlainMutexFree(&_mutex);
if (error != 0) {
| | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
- (void)dealloc
{
if (_initialized) {
int error = OFPlainMutexFree(&_mutex);
if (error != 0) {
OFEnsure(error == EBUSY);
@throw [OFStillLockedException exceptionWithLock: self];
}
}
[_name release];
|
| ︙ | ︙ |
Changes to src/OFNumber.m.
| ︙ | ︙ | |||
767 768 769 770 771 772 773 |
} else if ([typeString isEqual: @"float"]) {
unsigned long long value =
[element unsignedLongLongValueWithBase: 16];
if (value > UINT64_MAX)
@throw [OFOutOfRangeException exception];
| | | | 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 |
} else if ([typeString isEqual: @"float"]) {
unsigned long long value =
[element unsignedLongLongValueWithBase: 16];
if (value > UINT64_MAX)
@throw [OFOutOfRangeException exception];
self = [self initWithDouble: OFFromBigEndianDouble(
OFRawUInt64ToDouble(OFToBigEndian64(value)))];
} else if ([typeString isEqual: @"signed"])
self = [self initWithLongLong: element.longLongValue];
else if ([typeString isEqual: @"unsigned"])
self = [self initWithUnsignedLongLong:
element.unsignedLongLongValue];
else
@throw [OFInvalidArgumentException exception];
|
| ︙ | ︙ | |||
979 980 981 982 983 984 985 |
return OFOrderedSame;
}
}
- (unsigned long)hash
{
| | | | | | | | 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 |
return OFOrderedSame;
}
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
if (isFloat(self)) {
double d;
if (isnan(self.doubleValue))
return 0;
d = OFToLittleEndianDouble(self.doubleValue);
for (uint_fast8_t i = 0; i < sizeof(double); i++)
OFHashAdd(&hash, ((char *)&d)[i]);
} else if (isSigned(self) || isUnsigned(self)) {
unsigned long long value = self.unsignedLongLongValue;
while (value != 0) {
OFHashAdd(&hash, value & 0xFF);
value >>= 8;
}
} else
@throw [OFInvalidFormatException exception];
OFHashFinalize(&hash);
return hash;
}
- (id)copy
{
return [self retain];
|
| ︙ | ︙ | |||
1048 1049 1050 1051 1052 1053 1054 |
if (*self.objCType == 'B')
[element addAttributeWithName: @"type" stringValue: @"bool"];
else if (isFloat(self)) {
[element addAttributeWithName: @"type" stringValue: @"float"];
element.stringValue = [OFString
stringWithFormat: @"%016" PRIx64,
| | | 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 |
if (*self.objCType == 'B')
[element addAttributeWithName: @"type" stringValue: @"bool"];
else if (isFloat(self)) {
[element addAttributeWithName: @"type" stringValue: @"float"];
element.stringValue = [OFString
stringWithFormat: @"%016" PRIx64,
OFFromBigEndian64(OFDoubleToRawUInt64(OFToBigEndianDouble(
self.doubleValue)))];
} else if (isSigned(self))
[element addAttributeWithName: @"type" stringValue: @"signed"];
else if (isUnsigned(self))
[element addAttributeWithName: @"type"
stringValue: @"unsigned"];
else
|
| ︙ | ︙ | |||
1109 1110 1111 1112 1113 1114 1115 |
const char *typeEncoding = self.objCType;
if (*typeEncoding == 'B') {
uint8_t type = (self.boolValue ? 0xC3 : 0xC2);
data = [OFMutableData dataWithItems: &type count: 1];
} else if (*typeEncoding == 'f') {
uint8_t type = 0xCA;
| | | | | | | 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 |
const char *typeEncoding = self.objCType;
if (*typeEncoding == 'B') {
uint8_t type = (self.boolValue ? 0xC3 : 0xC2);
data = [OFMutableData dataWithItems: &type count: 1];
} else if (*typeEncoding == 'f') {
uint8_t type = 0xCA;
float tmp = OFToBigEndianFloat(self.floatValue);
data = [OFMutableData dataWithCapacity: 5];
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else if (*typeEncoding == 'd') {
uint8_t type = 0xCB;
double tmp = OFToBigEndianDouble(self.doubleValue);
data = [OFMutableData dataWithCapacity: 9];
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else if (isSigned(self)) {
long long value = self.longLongValue;
if (value >= -32 && value < 0) {
uint8_t tmp = 0xE0 | ((uint8_t)(value - 32) & 0x1F);
data = [OFMutableData dataWithItems: &tmp count: 1];
} else if (value >= INT8_MIN && value <= INT8_MAX) {
uint8_t type = 0xD0;
int8_t tmp = (int8_t)value;
data = [OFMutableData dataWithCapacity: 2];
[data addItem: &type];
[data addItem: &tmp];
} else if (value >= INT16_MIN && value <= INT16_MAX) {
uint8_t type = 0xD1;
int16_t tmp = OFToBigEndian16((int16_t)value);
data = [OFMutableData dataWithCapacity: 3];
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else if (value >= INT32_MIN && value <= INT32_MAX) {
uint8_t type = 0xD2;
int32_t tmp = OFToBigEndian32((int32_t)value);
data = [OFMutableData dataWithCapacity: 5];
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else if (value >= INT64_MIN && value <= INT64_MAX) {
uint8_t type = 0xD3;
int64_t tmp = OFToBigEndian64((int64_t)value);
data = [OFMutableData dataWithCapacity: 9];
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else
@throw [OFOutOfRangeException exception];
} else if (isUnsigned(self)) {
|
| ︙ | ︙ | |||
1173 1174 1175 1176 1177 1178 1179 |
uint8_t tmp = (uint8_t)value;
data = [OFMutableData dataWithCapacity: 2];
[data addItem: &type];
[data addItem: &tmp];
} else if (value <= UINT16_MAX) {
uint8_t type = 0xCD;
| | | | | 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 |
uint8_t tmp = (uint8_t)value;
data = [OFMutableData dataWithCapacity: 2];
[data addItem: &type];
[data addItem: &tmp];
} else if (value <= UINT16_MAX) {
uint8_t type = 0xCD;
uint16_t tmp = OFToBigEndian16((uint16_t)value);
data = [OFMutableData dataWithCapacity: 3];
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else if (value <= UINT32_MAX) {
uint8_t type = 0xCE;
uint32_t tmp = OFToBigEndian32((uint32_t)value);
data = [OFMutableData dataWithCapacity: 5];
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else if (value <= UINT64_MAX) {
uint8_t type = 0xCF;
uint64_t tmp = OFToBigEndian64((uint64_t)value);
data = [OFMutableData dataWithCapacity: 9];
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else
@throw [OFOutOfRangeException exception];
} else
|
| ︙ | ︙ |
Changes to src/OFObject+KeyValueCoding.m.
| ︙ | ︙ | |||
50 51 52 53 54 55 56 |
name = OFAllocMemory(keyLength + 3, 1);
@try {
memcpy(name, "is", 2);
memcpy(name + 2, key.UTF8String, keyLength);
name[keyLength + 2] = '\0';
| | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
name = OFAllocMemory(keyLength + 3, 1);
@try {
memcpy(name, "is", 2);
memcpy(name + 2, key.UTF8String, keyLength);
name[keyLength + 2] = '\0';
name[2] = OFASCIIToUpper(name[2]);
selector = sel_registerName(name);
} @finally {
OFFreeMemory(name);
}
methodSignature = [self methodSignatureForSelector: selector];
|
| ︙ | ︙ | |||
159 160 161 162 163 164 165 |
name = OFAllocMemory(keyLength + 5, 1);
@try {
memcpy(name, "set", 3);
memcpy(name + 3, key.UTF8String, keyLength);
memcpy(name + keyLength + 3, ":", 2);
| | | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
name = OFAllocMemory(keyLength + 5, 1);
@try {
memcpy(name, "set", 3);
memcpy(name + 3, key.UTF8String, keyLength);
memcpy(name + keyLength + 3, ":", 2);
name[3] = OFASCIIToUpper(name[3]);
selector = sel_registerName(name);
} @finally {
OFFreeMemory(name);
}
methodSignature = [self methodSignatureForSelector: selector];
|
| ︙ | ︙ |
Changes to src/OFObject.h.
| ︙ | ︙ | |||
1310 1311 1312 1313 1314 1315 1316 |
void *_Nullable bytes);
extern void *_Nullable objc_destructInstance(id _Nullable object);
# endif
#endif
extern id OFAllocObject(Class class_, size_t extraSize, size_t extraAlignment,
void *_Nullable *_Nullable extra);
extern void OF_NO_RETURN_FUNC OFMethodNotFound(id self, SEL _cmd);
| < | 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 |
void *_Nullable bytes);
extern void *_Nullable objc_destructInstance(id _Nullable object);
# endif
#endif
extern id OFAllocObject(Class class_, size_t extraSize, size_t extraAlignment,
void *_Nullable *_Nullable extra);
extern void OF_NO_RETURN_FUNC OFMethodNotFound(id self, SEL _cmd);
/**
* @brief Returns 16 bit or non-cryptographical randomness.
*
* @return 16 bit or non-cryptographical randomness
*/
extern uint16_t OFRandom16(void);
|
| ︙ | ︙ |
Changes to src/OFObject.m.
| ︙ | ︙ | |||
90 91 92 93 94 95 96 |
(OF_BIGGEST_ALIGNMENT - 1)) & ~(OF_BIGGEST_ALIGNMENT - 1))
#define PRE_IVARS ((struct pre_ivar *)(void *)((char *)self - PRE_IVARS_ALIGN))
static struct {
Class isa;
} allocFailedException;
| | | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
(OF_BIGGEST_ALIGNMENT - 1)) & ~(OF_BIGGEST_ALIGNMENT - 1))
#define PRE_IVARS ((struct pre_ivar *)(void *)((char *)self - PRE_IVARS_ALIGN))
static struct {
Class isa;
} allocFailedException;
unsigned long OFHashSeed;
void *
OFAllocMemory(size_t count, size_t size)
{
void *pointer;
if OF_UNLIKELY (count == 0 || size == 0)
|
| ︙ | ︙ | |||
175 176 177 178 179 180 181 |
OFRandom16(void)
{
#if defined(HAVE_ARC4RANDOM)
return arc4random();
#elif defined(HAVE_GETRANDOM)
uint16_t buffer;
| | | 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
OFRandom16(void)
{
#if defined(HAVE_ARC4RANDOM)
return arc4random();
#elif defined(HAVE_GETRANDOM)
uint16_t buffer;
OFEnsure(getrandom(&buffer, sizeof(buffer), 0) == sizeof(buffer));
return buffer;
#else
static OFOnceControl onceControl = OFOnceControlInitValue;
OFOnce(&onceControl, initRandom);
# ifdef HAVE_RANDOM
return random() & 0xFFFF;
|
| ︙ | ︙ | |||
197 198 199 200 201 202 203 |
OFRandom32(void)
{
#if defined(HAVE_ARC4RANDOM)
return arc4random();
#elif defined(HAVE_GETRANDOM)
uint32_t buffer;
| | | | 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 |
OFRandom32(void)
{
#if defined(HAVE_ARC4RANDOM)
return arc4random();
#elif defined(HAVE_GETRANDOM)
uint32_t buffer;
OFEnsure(getrandom(&buffer, sizeof(buffer), 0) == sizeof(buffer));
return buffer;
#else
return ((uint32_t)OFRandom16() << 16) | OFRandom16();
#endif
}
uint64_t
OFRandom64(void)
{
#if defined(HAVE_ARC4RANDOM_BUF)
uint64_t buffer;
arc4random_buf(&buffer, sizeof(buffer));
return buffer;
#elif defined(HAVE_GETRANDOM)
uint64_t buffer;
OFEnsure(getrandom(&buffer, sizeof(buffer), 0) == sizeof(buffer));
return buffer;
#else
return ((uint64_t)OFRandom32() << 32) | OFRandom32();
#endif
}
|
| ︙ | ︙ | |||
1066 1067 1068 1069 1070 1071 1072 |
{
return (object == self);
}
- (unsigned long)hash
{
uintptr_t ptr = (uintptr_t)self;
| | | | | | 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 |
{
return (object == self);
}
- (unsigned long)hash
{
uintptr_t ptr = (uintptr_t)self;
unsigned long hash;
OFHashInit(&hash);
for (size_t i = 0; i < sizeof(ptr); i++) {
OFHashAdd(&hash, ptr & 0xFF);
ptr >>= 8;
}
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
/* Classes containing data should reimplement this! */
|
| ︙ | ︙ | |||
1116 1117 1118 1119 1120 1121 1122 | Forbid(); # endif PRE_IVARS->retainCount++; # ifndef OF_AMIGAOS_M68K Permit(); # endif #else | | | | 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 |
Forbid();
# endif
PRE_IVARS->retainCount++;
# ifndef OF_AMIGAOS_M68K
Permit();
# endif
#else
OFEnsure(OFSpinlockLock(&PRE_IVARS->retainCountSpinlock) == 0);
PRE_IVARS->retainCount++;
OFEnsure(OFSpinlockUnlock(&PRE_IVARS->retainCountSpinlock) == 0);
#endif
return self;
}
- (unsigned int)retainCount
{
|
| ︙ | ︙ | |||
1152 1153 1154 1155 1156 1157 1158 | Permit(); if (retainCount == 0) [self dealloc]; #else int retainCount; | | | | 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 | Permit(); if (retainCount == 0) [self dealloc]; #else int retainCount; OFEnsure(OFSpinlockLock(&PRE_IVARS->retainCountSpinlock) == 0); retainCount = --PRE_IVARS->retainCount; OFEnsure(OFSpinlockUnlock(&PRE_IVARS->retainCountSpinlock) == 0); if (retainCount == 0) [self dealloc]; #endif } - (instancetype)autorelease |
| ︙ | ︙ |
Changes to src/OFPair.m.
| ︙ | ︙ | |||
81 82 83 84 85 86 87 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, [_firstObject hash]);
OFHashAddHash(&hash, [_secondObject hash]);
OFHashFinalize(&hash);
return hash;
}
- (id)copy
{
return [self retain];
|
| ︙ | ︙ |
Changes to src/OFPollKernelEventObserver.m.
| ︙ | ︙ | |||
195 196 197 198 199 200 201 |
if (FDs[i].revents & POLLIN) {
void *pool2;
if (FDs[i].fd == _cancelFD[0]) {
char buffer;
#ifdef OF_HAVE_PIPE
| | | | | 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
if (FDs[i].revents & POLLIN) {
void *pool2;
if (FDs[i].fd == _cancelFD[0]) {
char buffer;
#ifdef OF_HAVE_PIPE
OFEnsure(read(_cancelFD[0], &buffer, 1) == 1);
#else
OFEnsure(recvfrom(_cancelFD[0], &buffer, 1, 0,
NULL, NULL) == 1);
#endif
FDs[i].revents = 0;
continue;
}
pool2 = objc_autoreleasePoolPush();
|
| ︙ | ︙ |
Changes to src/OFRIPEMD160Hash.m.
| ︙ | ︙ | |||
67 68 69 70 71 72 73 |
};
static OF_INLINE void
byteSwapVectorIfBE(uint32_t *vector, uint_fast8_t length)
{
#ifdef OF_BIG_ENDIAN
for (uint_fast8_t i = 0; i < length; i++)
| | | | | | | | | | | | | | | | | | | | | | | | | | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
};
static OF_INLINE void
byteSwapVectorIfBE(uint32_t *vector, uint_fast8_t length)
{
#ifdef OF_BIG_ENDIAN
for (uint_fast8_t i = 0; i < length; i++)
vector[i] = OFByteSwap32(vector[i]);
#endif
}
static void
processBlock(uint32_t *state, uint32_t *buffer)
{
uint32_t new[5], new2[5];
uint_fast8_t i = 0;
new[0] = new2[0] = state[0];
new[1] = new2[1] = state[1];
new[2] = new2[2] = state[2];
new[3] = new2[3] = state[3];
new[4] = new2[4] = state[4];
byteSwapVectorIfBE(buffer, 16);
#define LOOP_BODY(f, g, k, k2) \
{ \
uint32_t tmp; \
\
tmp = new[0] + f(new[1], new[2], new[3]) + \
buffer[wordOrder[i]] + k; \
tmp = OFRotateLeft(tmp, rotateBits[i]) + new[4]; \
\
new[0] = new[4]; \
new[4] = new[3]; \
new[3] = OFRotateLeft(new[2], 10); \
new[2] = new[1]; \
new[1] = tmp; \
\
tmp = new2[0] + g(new2[1], new2[2], new2[3]) + \
buffer[wordOrder2[i]] + k2; \
tmp = OFRotateLeft(tmp, rotateBits2[i]) + new2[4]; \
\
new2[0] = new2[4]; \
new2[4] = new2[3]; \
new2[3] = OFRotateLeft(new2[2], 10); \
new2[2] = new2[1]; \
new2[1] = tmp; \
}
for (; i < 16; i++)
LOOP_BODY(F, J, 0x00000000, 0x50A28BE6)
for (; i < 32; i++)
LOOP_BODY(G, I, 0x5A827999, 0x5C4DD124)
for (; i < 48; i++)
|
| ︙ | ︙ | |||
258 259 260 261 262 263 264 |
- (const unsigned char *)digest
{
if (_calculated)
return (const unsigned char *)_iVars->state;
_iVars->buffer.bytes[_iVars->bufferLength] = 0x80;
| | | | | | | | 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 |
- (const unsigned char *)digest
{
if (_calculated)
return (const unsigned char *)_iVars->state;
_iVars->buffer.bytes[_iVars->bufferLength] = 0x80;
OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1,
64 - _iVars->bufferLength - 1);
if (_iVars->bufferLength >= 56) {
processBlock(_iVars->state, _iVars->buffer.words);
OFZeroMemory(_iVars->buffer.bytes, 64);
}
_iVars->buffer.words[14] =
OFToLittleEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF));
_iVars->buffer.words[15] =
OFToLittleEndian32((uint32_t)(_iVars->bits >> 32));
processBlock(_iVars->state, _iVars->buffer.words);
OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer));
byteSwapVectorIfBE(_iVars->state, 5);
_calculated = true;
return (const unsigned char *)_iVars->state;
}
- (void)reset
{
[self of_resetState];
_iVars->bits = 0;
OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer));
_iVars->bufferLength = 0;
_calculated = false;
}
@end
|
Changes to src/OFRecursiveMutex.m.
| ︙ | ︙ | |||
50 51 52 53 54 55 56 |
- (void)dealloc
{
if (_initialized) {
int error = OFPlainRecursiveMutexFree(&_rmutex);
if (error != 0) {
| | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
- (void)dealloc
{
if (_initialized) {
int error = OFPlainRecursiveMutexFree(&_rmutex);
if (error != 0) {
OFEnsure(error == EBUSY);
@throw [OFStillLockedException exceptionWithLock: self];
}
}
[_name release];
|
| ︙ | ︙ |
Changes to src/OFRunLoop.m.
| ︙ | ︙ | |||
757 758 759 760 761 762 763 | return ((OFStreamSocketAsyncAcceptBlock)_block)( acceptedSocket, exception); else if ([object isKindOfClass: [OFSequencedPacketSocket class]]) return ((OFSequencedPacketSocketAsyncAcceptBlock) _block)(acceptedSocket, exception); else | | | 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 |
return ((OFStreamSocketAsyncAcceptBlock)_block)(
acceptedSocket, exception);
else if ([object isKindOfClass:
[OFSequencedPacketSocket class]])
return ((OFSequencedPacketSocketAsyncAcceptBlock)
_block)(acceptedSocket, exception);
else
OFEnsure(0);
} else {
# endif
if (![_delegate respondsToSelector:
@selector(socket:didAcceptSocket:exception:)])
return false;
return [_delegate socket: object
|
| ︙ | ︙ |
Changes to src/OFSHA1Hash.m.
| ︙ | ︙ | |||
37 38 39 40 41 42 43 |
#define I(a, b, c, d) ((b) ^ (c) ^ (d))
static OF_INLINE void
byteSwapVectorIfLE(uint32_t *vector, uint_fast8_t length)
{
#ifndef OF_BIG_ENDIAN
for (uint_fast8_t i = 0; i < length; i++)
| | | | | | 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 |
#define I(a, b, c, d) ((b) ^ (c) ^ (d))
static OF_INLINE void
byteSwapVectorIfLE(uint32_t *vector, uint_fast8_t length)
{
#ifndef OF_BIG_ENDIAN
for (uint_fast8_t i = 0; i < length; i++)
vector[i] = OFByteSwap32(vector[i]);
#endif
}
static void
processBlock(uint32_t *state, uint32_t *buffer)
{
uint32_t new[5];
uint_fast8_t i;
new[0] = state[0];
new[1] = state[1];
new[2] = state[2];
new[3] = state[3];
new[4] = state[4];
byteSwapVectorIfLE(buffer, 16);
for (i = 16; i < 80; i++) {
uint32_t tmp = buffer[i - 3] ^ buffer[i - 8] ^
buffer[i - 14] ^ buffer[i - 16];
buffer[i] = OFRotateLeft(tmp, 1);
}
#define LOOP_BODY(f, k) \
{ \
uint32_t tmp = OFRotateLeft(new[0], 5) + \
f(new[0], new[1], new[2], new[3]) + \
new[4] + k + buffer[i]; \
new[4] = new[3]; \
new[3] = new[2]; \
new[2] = OFRotateLeft(new[1], 30); \
new[1] = new[0]; \
new[0] = tmp; \
}
for (i = 0; i < 20; i++)
LOOP_BODY(F, 0x5A827999)
for (; i < 40; i++)
|
| ︙ | ︙ | |||
218 219 220 221 222 223 224 |
- (const unsigned char *)digest
{
if (_calculated)
return (const unsigned char *)_iVars->state;
_iVars->buffer.bytes[_iVars->bufferLength] = 0x80;
| | | | | | | | 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 |
- (const unsigned char *)digest
{
if (_calculated)
return (const unsigned char *)_iVars->state;
_iVars->buffer.bytes[_iVars->bufferLength] = 0x80;
OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1,
64 - _iVars->bufferLength - 1);
if (_iVars->bufferLength >= 56) {
processBlock(_iVars->state, _iVars->buffer.words);
OFZeroMemory(_iVars->buffer.bytes, 64);
}
_iVars->buffer.words[14] =
OFToBigEndian32((uint32_t)(_iVars->bits >> 32));
_iVars->buffer.words[15] =
OFToBigEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF));
processBlock(_iVars->state, _iVars->buffer.words);
OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer));
byteSwapVectorIfLE(_iVars->state, 5);
_calculated = true;
return (const unsigned char *)_iVars->state;
}
- (void)reset
{
[self of_resetState];
_iVars->bits = 0;
OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer));
_iVars->bufferLength = 0;
_calculated = false;
}
@end
|
Changes to src/OFSHA224Or256Hash.m.
| ︙ | ︙ | |||
50 51 52 53 54 55 56 |
};
static OF_INLINE void
byteSwapVectorIfLE(uint32_t *vector, uint_fast8_t length)
{
#ifndef OF_BIG_ENDIAN
for (uint_fast8_t i = 0; i < length; i++)
| | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
};
static OF_INLINE void
byteSwapVectorIfLE(uint32_t *vector, uint_fast8_t length)
{
#ifndef OF_BIG_ENDIAN
for (uint_fast8_t i = 0; i < length; i++)
vector[i] = OFByteSwap32(vector[i]);
#endif
}
static void
processBlock(uint32_t *state, uint32_t *buffer)
{
uint32_t new[8];
|
| ︙ | ︙ | |||
75 76 77 78 79 80 81 |
byteSwapVectorIfLE(buffer, 16);
for (i = 16; i < 64; i++) {
uint32_t tmp;
tmp = buffer[i - 2];
| | | | | | | | | | 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 |
byteSwapVectorIfLE(buffer, 16);
for (i = 16; i < 64; i++) {
uint32_t tmp;
tmp = buffer[i - 2];
buffer[i] = (OFRotateRight(tmp, 17) ^ OFRotateRight(tmp, 19) ^
(tmp >> 10)) + buffer[i - 7];
tmp = buffer[i - 15];
buffer[i] += (OFRotateRight(tmp, 7) ^ OFRotateRight(tmp, 18) ^
(tmp >> 3)) + buffer[i - 16];
}
for (i = 0; i < 64; i++) {
uint32_t tmp1 = new[7] + (OFRotateRight(new[4], 6) ^
OFRotateRight(new[4], 11) ^ OFRotateRight(new[4], 25)) +
((new[4] & (new[5] ^ new[6])) ^ new[6]) +
table[i] + buffer[i];
uint32_t tmp2 = (OFRotateRight(new[0], 2) ^
OFRotateRight(new[0], 13) ^ OFRotateRight(new[0], 22)) +
((new[0] & (new[1] | new[2])) | (new[1] & new[2]));
new[7] = new[6];
new[6] = new[5];
new[5] = new[4];
new[4] = new[3] + tmp1;
new[3] = new[2];
|
| ︙ | ︙ | |||
234 235 236 237 238 239 240 |
- (const unsigned char *)digest
{
if (_calculated)
return (const unsigned char *)_iVars->state;
_iVars->buffer.bytes[_iVars->bufferLength] = 0x80;
| | | | | | | | 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 |
- (const unsigned char *)digest
{
if (_calculated)
return (const unsigned char *)_iVars->state;
_iVars->buffer.bytes[_iVars->bufferLength] = 0x80;
OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1,
64 - _iVars->bufferLength - 1);
if (_iVars->bufferLength >= 56) {
processBlock(_iVars->state, _iVars->buffer.words);
OFZeroMemory(_iVars->buffer.bytes, 64);
}
_iVars->buffer.words[14] =
OFToBigEndian32((uint32_t)(_iVars->bits >> 32));
_iVars->buffer.words[15] =
OFToBigEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF));
processBlock(_iVars->state, _iVars->buffer.words);
OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer));
byteSwapVectorIfLE(_iVars->state, 8);
_calculated = true;
return (const unsigned char *)_iVars->state;
}
- (void)reset
{
[self of_resetState];
_iVars->bits = 0;
OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer));
_iVars->bufferLength = 0;
_calculated = false;
}
- (void)of_resetState
{
OF_UNRECOGNIZED_SELECTOR
}
@end
|
Changes to src/OFSHA384Or512Hash.m.
| ︙ | ︙ | |||
61 62 63 64 65 66 67 |
};
static OF_INLINE void
byteSwapVectorIfLE(uint64_t *vector, uint_fast8_t length)
{
#ifndef OF_BIG_ENDIAN
for (uint_fast8_t i = 0; i < length; i++)
| | | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
};
static OF_INLINE void
byteSwapVectorIfLE(uint64_t *vector, uint_fast8_t length)
{
#ifndef OF_BIG_ENDIAN
for (uint_fast8_t i = 0; i < length; i++)
vector[i] = OFByteSwap64(vector[i]);
#endif
}
static void
processBlock(uint64_t *state, uint64_t *buffer)
{
uint64_t new[8];
|
| ︙ | ︙ | |||
86 87 88 89 90 91 92 |
byteSwapVectorIfLE(buffer, 16);
for (i = 16; i < 80; i++) {
uint64_t tmp;
tmp = buffer[i - 2];
| | | | | | | | | | 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 |
byteSwapVectorIfLE(buffer, 16);
for (i = 16; i < 80; i++) {
uint64_t tmp;
tmp = buffer[i - 2];
buffer[i] = (OFRotateRight(tmp, 19) ^ OFRotateRight(tmp, 61) ^
(tmp >> 6)) + buffer[i - 7];
tmp = buffer[i - 15];
buffer[i] += (OFRotateRight(tmp, 1) ^ OFRotateRight(tmp, 8) ^
(tmp >> 7)) + buffer[i - 16];
}
for (i = 0; i < 80; i++) {
uint64_t tmp1 = new[7] + (OFRotateRight(new[4], 14) ^
OFRotateRight(new[4], 18) ^ OFRotateRight(new[4], 41)) +
((new[4] & (new[5] ^ new[6])) ^ new[6]) +
table[i] + buffer[i];
uint64_t tmp2 = (OFRotateRight(new[0], 28) ^
OFRotateRight(new[0], 34) ^ OFRotateRight(new[0], 39)) +
((new[0] & (new[1] | new[2])) | (new[1] & new[2]));
new[7] = new[6];
new[6] = new[5];
new[5] = new[4];
new[4] = new[3] + tmp1;
new[3] = new[2];
|
| ︙ | ︙ | |||
247 248 249 250 251 252 253 |
- (const unsigned char *)digest
{
if (_calculated)
return (const unsigned char *)_iVars->state;
_iVars->buffer.bytes[_iVars->bufferLength] = 0x80;
| | | | | | | | | 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 |
- (const unsigned char *)digest
{
if (_calculated)
return (const unsigned char *)_iVars->state;
_iVars->buffer.bytes[_iVars->bufferLength] = 0x80;
OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1,
128 - _iVars->bufferLength - 1);
if (_iVars->bufferLength >= 112) {
processBlock(_iVars->state, _iVars->buffer.words);
OFZeroMemory(_iVars->buffer.bytes, 128);
}
_iVars->buffer.words[14] = OFToBigEndian64(_iVars->bits[1]);
_iVars->buffer.words[15] = OFToBigEndian64(_iVars->bits[0]);
processBlock(_iVars->state, _iVars->buffer.words);
OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer));
byteSwapVectorIfLE(_iVars->state, 8);
_calculated = true;
return (const unsigned char *)_iVars->state;
}
- (void)reset
{
[self of_resetState];
OFZeroMemory(_iVars->bits, sizeof(_iVars->bits));
OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer));
_iVars->bufferLength = 0;
_calculated = false;
}
- (void)of_resetState
{
OF_UNRECOGNIZED_SELECTOR
}
@end
|
Changes to src/OFSandbox.m.
| ︙ | ︙ | |||
465 466 467 468 469 470 471 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAdd(&hash, _allowsStdIO);
OFHashAdd(&hash, _allowsReadingFiles);
OFHashAdd(&hash, _allowsWritingFiles);
OFHashAdd(&hash, _allowsCreatingFiles);
OFHashAdd(&hash, _allowsCreatingSpecialFiles);
OFHashAdd(&hash, _allowsTemporaryFiles);
OFHashAdd(&hash, _allowsIPSockets);
OFHashAdd(&hash, _allowsMulticastSockets);
OFHashAdd(&hash, _allowsChangingFileAttributes);
OFHashAdd(&hash, _allowsFileOwnerChanges);
OFHashAdd(&hash, _allowsFileLocks);
OFHashAdd(&hash, _allowsUNIXSockets);
OFHashAdd(&hash, _allowsDNS);
OFHashAdd(&hash, _allowsUserDatabaseReading);
OFHashAdd(&hash, _allowsFileDescriptorSending);
OFHashAdd(&hash, _allowsFileDescriptorReceiving);
OFHashAdd(&hash, _allowsTape);
OFHashAdd(&hash, _allowsTTY);
OFHashAdd(&hash, _allowsProcessOperations);
OFHashAdd(&hash, _allowsExec);
OFHashAdd(&hash, _allowsProtExec);
OFHashAdd(&hash, _allowsSetTime);
OFHashAdd(&hash, _allowsPS);
OFHashAdd(&hash, _allowsVMInfo);
OFHashAdd(&hash, _allowsChangingProcessRights);
OFHashAdd(&hash, _allowsPF);
OFHashAdd(&hash, _allowsAudio);
OFHashAdd(&hash, _allowsBPF);
OFHashAdd(&hash, _allowsUnveil);
OFHashAdd(&hash, _returnsErrors);
OFHashFinalize(&hash);
return hash;
}
#ifdef OF_HAVE_PLEDGE
- (OFString *)pledgeString
{
|
| ︙ | ︙ |
Changes to src/OFSecureData.m.
| ︙ | ︙ | |||
95 96 97 98 99 100 101 |
munmap(pointer, numPages * pageSize);
}
static struct page *
addPage(bool allowPreallocated)
{
size_t pageSize = [OFSystemInfo pageSize];
| | | | | 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 |
munmap(pointer, numPages * pageSize);
}
static struct page *
addPage(bool allowPreallocated)
{
size_t pageSize = [OFSystemInfo pageSize];
size_t mapSize = OFRoundUpToPowerOf2(CHAR_BIT, pageSize / CHUNK_SIZE) /
CHAR_BIT;
struct page *page;
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
struct page *lastPage;
# endif
if (allowPreallocated) {
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
uintptr_t numPreallocatedPages =
(uintptr_t)OFTLSKeyGet(numPreallocatedPagesKey);
# endif
if (numPreallocatedPages > 0) {
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
struct page **preallocatedPages =
OFTLSKeyGet(preallocatedPagesKey);
# endif
numPreallocatedPages--;
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OFEnsure(OFTLSKeySet(numPreallocatedPagesKey,
(void *)numPreallocatedPages) == 0);
# endif
page = preallocatedPages[numPreallocatedPages];
if (numPreallocatedPages == 0) {
OFFreeMemory(preallocatedPages);
preallocatedPages = NULL;
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OFEnsure(OFTLSKeySet(preallocatedPagesKey,
preallocatedPages) == 0);
# endif
}
return page;
}
}
|
| ︙ | ︙ | |||
149 150 151 152 153 154 155 |
@try {
page->page = mapPages(1);
} @catch (id e) {
OFFreeMemory(page->map);
OFFreeMemory(page);
@throw e;
}
| | | | | | 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 |
@try {
page->page = mapPages(1);
} @catch (id e) {
OFFreeMemory(page->map);
OFFreeMemory(page);
@throw e;
}
OFZeroMemory(page->page, pageSize);
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
lastPage = OFTLSKeyGet(lastPageKey);
# endif
page->previous = lastPage;
page->next = NULL;
if (lastPage != NULL)
lastPage->next = page;
# if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS)
lastPage = page;
if (firstPage == NULL)
firstPage = page;
# else
OFEnsure(OFTLSKeySet(lastPageKey, page) == 0);
if (OFTLSKeyGet(firstPageKey) == NULL)
OFEnsure(OFTLSKeySet(firstPageKey, page) == 0);
# endif
return page;
}
static void
removePageIfEmpty(struct page *page)
{
unsigned char *map = page->map;
size_t pageSize = [OFSystemInfo pageSize];
size_t mapSize = OFRoundUpToPowerOf2(CHAR_BIT, pageSize / CHUNK_SIZE) /
CHAR_BIT;
for (size_t i = 0; i < mapSize; i++)
if (map[i] != 0)
return;
unmapPages(page->page, 1);
|
| ︙ | ︙ | |||
203 204 205 206 207 208 209 | # if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) if (firstPage == page) firstPage = page->next; if (lastPage == page) lastPage = page->previous; # else if (OFTLSKeyGet(firstPageKey) == page) | | | | | | | | | | 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 |
# if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS)
if (firstPage == page)
firstPage = page->next;
if (lastPage == page)
lastPage = page->previous;
# else
if (OFTLSKeyGet(firstPageKey) == page)
OFEnsure(OFTLSKeySet(firstPageKey, page->next) == 0);
if (OFTLSKeyGet(lastPageKey) == page)
OFEnsure(OFTLSKeySet(lastPageKey, page->previous) == 0);
# endif
OFFreeMemory(page);
}
static void *
allocateMemory(struct page *page, size_t bytes)
{
size_t chunks, chunksLeft, pageSize, i, firstChunk;
bytes = OFRoundUpToPowerOf2(CHUNK_SIZE, bytes);
chunks = chunksLeft = bytes / CHUNK_SIZE;
firstChunk = 0;
pageSize = [OFSystemInfo pageSize];
for (i = 0; i < pageSize / CHUNK_SIZE; i++) {
if (OFBitsetIsSet(page->map, i)) {
chunksLeft = chunks;
firstChunk = i + 1;
continue;
}
if (--chunksLeft == 0)
break;
}
if (chunksLeft == 0) {
for (size_t j = firstChunk; j < firstChunk + chunks; j++)
OFBitsetSet(page->map, j);
return page->page + (CHUNK_SIZE * firstChunk);
}
return NULL;
}
static void
freeMemory(struct page *page, void *pointer, size_t bytes)
{
size_t chunks, chunkIndex;
bytes = OFRoundUpToPowerOf2(CHUNK_SIZE, bytes);
chunks = bytes / CHUNK_SIZE;
chunkIndex = ((uintptr_t)pointer - (uintptr_t)page->page) / CHUNK_SIZE;
OFZeroMemory(pointer, bytes);
for (size_t i = 0; i < chunks; i++)
OFBitsetClear(page->map, chunkIndex + i);
}
#endif
@implementation OFSecureData
@synthesize allowsSwappableMemory = _allowsSwappableMemory;
#if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) && \
|
| ︙ | ︙ | |||
280 281 282 283 284 285 286 |
}
#endif
+ (void)preallocateUnswappableMemoryWithSize: (size_t)size
{
#if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON)
size_t pageSize = [OFSystemInfo pageSize];
| | | | | 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 |
}
#endif
+ (void)preallocateUnswappableMemoryWithSize: (size_t)size
{
#if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON)
size_t pageSize = [OFSystemInfo pageSize];
size_t numPages = OFRoundUpToPowerOf2(pageSize, size) / pageSize;
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
struct page **preallocatedPages = OFTLSKeyGet(preallocatedPagesKey);
size_t numPreallocatedPages;
# endif
size_t i;
if (preallocatedPages != NULL)
@throw [OFInvalidArgumentException exception];
preallocatedPages = OFAllocZeroedMemory(numPages, sizeof(struct page));
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OFEnsure(OFTLSKeySet(preallocatedPagesKey, preallocatedPages) == 0);
# endif
@try {
for (i = 0; i < numPages; i++)
preallocatedPages[i] = addPage(false);
} @catch (id e) {
for (size_t j = 0; j < i; j++)
removePageIfEmpty(preallocatedPages[j]);
OFFreeMemory(preallocatedPages);
preallocatedPages = NULL;
@throw e;
}
numPreallocatedPages = numPages;
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OFEnsure(OFTLSKeySet(numPreallocatedPagesKey,
(void *)(uintptr_t)numPreallocatedPages) == 0);
# endif
#else
@throw [OFNotImplementedException exceptionWithSelector: _cmd
object: self];
#endif
}
|
| ︙ | ︙ | |||
416 417 418 419 420 421 422 |
if (allowsSwappableMemory) {
_items = OFAllocMemory(count, itemSize);
_freeWhenDone = true;
memset(_items, 0, count * itemSize);
#if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON)
} else if (count * itemSize >= pageSize)
| | | 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
if (allowsSwappableMemory) {
_items = OFAllocMemory(count, itemSize);
_freeWhenDone = true;
memset(_items, 0, count * itemSize);
#if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON)
} else if (count * itemSize >= pageSize)
_items = mapPages(OFRoundUpToPowerOf2(pageSize,
count * itemSize) / pageSize);
else {
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
struct page *lastPage = OFTLSKeyGet(lastPageKey);
# endif
for (struct page *page = lastPage; page != NULL;
|
| ︙ | ︙ | |||
526 527 528 529 530 531 532 |
#if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON)
if (!_allowsSwappableMemory) {
size_t pageSize = [OFSystemInfo pageSize];
if (_count * _itemSize > pageSize)
unmapPages(_items,
| | | 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
#if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON)
if (!_allowsSwappableMemory) {
size_t pageSize = [OFSystemInfo pageSize];
if (_count * _itemSize > pageSize)
unmapPages(_items,
OFRoundUpToPowerOf2(pageSize, _count * _itemSize) /
pageSize);
else if (_page != NULL) {
if (_items != NULL)
freeMemory(_page, _items, _count * _itemSize);
removePageIfEmpty(_page);
}
|
| ︙ | ︙ | |||
555 556 557 558 559 560 561 |
@throw [OFOutOfRangeException exception];
return _items + idx * _itemSize;
}
- (void)zero
{
| | | 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
@throw [OFOutOfRangeException exception];
return _items + idx * _itemSize;
}
- (void)zero
{
OFZeroMemory(_items, _count * _itemSize);
}
- (id)copy
{
OFSecureData *copy = [[OFSecureData alloc]
initWithCount: _count
itemSize: _itemSize
|
| ︙ | ︙ |
Changes to src/OFSelectKernelEventObserver.m.
| ︙ | ︙ | |||
241 242 243 244 245 246 247 |
[_delegate respondsToSelector: @selector(execSignalWasReceived:)])
[_delegate execSignalWasReceived: execSignalMask];
#else
if (FD_ISSET(_cancelFD[0], &readFDs)) {
char buffer;
# ifdef OF_HAVE_PIPE
| | | | 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
[_delegate respondsToSelector: @selector(execSignalWasReceived:)])
[_delegate execSignalWasReceived: execSignalMask];
#else
if (FD_ISSET(_cancelFD[0], &readFDs)) {
char buffer;
# ifdef OF_HAVE_PIPE
OFEnsure(read(_cancelFD[0], &buffer, 1) == 1);
# else
OFEnsure(recvfrom(_cancelFD[0], (void *)&buffer, 1, 0, NULL,
NULL) == 1);
# endif
}
#endif
pool = objc_autoreleasePoolPush();
|
| ︙ | ︙ |
Changes to src/OFStream.m.
| ︙ | ︙ | |||
307 308 309 310 311 312 313 |
return ret;
}
- (uint16_t)readBigEndianInt16
{
uint16_t ret;
[self readIntoBuffer: (char *)&ret exactLength: 2];
| | | | | | | | | | | | | | | | | | | | | | 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 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 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
return ret;
}
- (uint16_t)readBigEndianInt16
{
uint16_t ret;
[self readIntoBuffer: (char *)&ret exactLength: 2];
return OFFromBigEndian16(ret);
}
- (uint32_t)readBigEndianInt32
{
uint32_t ret;
[self readIntoBuffer: (char *)&ret exactLength: 4];
return OFFromBigEndian32(ret);
}
- (uint64_t)readBigEndianInt64
{
uint64_t ret;
[self readIntoBuffer: (char *)&ret exactLength: 8];
return OFFromBigEndian64(ret);
}
- (float)readBigEndianFloat
{
float ret;
[self readIntoBuffer: (char *)&ret exactLength: 4];
return OFFromBigEndianFloat(ret);
}
- (double)readBigEndianDouble
{
double ret;
[self readIntoBuffer: (char *)&ret exactLength: 8];
return OFFromBigEndianDouble(ret);
}
- (size_t)readBigEndianInt16sIntoBuffer: (uint16_t *)buffer count: (size_t)count
{
size_t size;
if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t))
@throw [OFOutOfRangeException exception];
size = count * sizeof(uint16_t);
[self readIntoBuffer: buffer exactLength: size];
#ifndef OF_BIG_ENDIAN
for (size_t i = 0; i < count; i++)
buffer[i] = OFByteSwap16(buffer[i]);
#endif
return size;
}
- (size_t)readBigEndianInt32sIntoBuffer: (uint32_t *)buffer count: (size_t)count
{
size_t size;
if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t))
@throw [OFOutOfRangeException exception];
size = count * sizeof(uint32_t);
[self readIntoBuffer: buffer exactLength: size];
#ifndef OF_BIG_ENDIAN
for (size_t i = 0; i < count; i++)
buffer[i] = OFByteSwap32(buffer[i]);
#endif
return size;
}
- (size_t)readBigEndianInt64sIntoBuffer: (uint64_t *)buffer count: (size_t)count
{
size_t size;
if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t))
@throw [OFOutOfRangeException exception];
size = count * sizeof(uint64_t);
[self readIntoBuffer: buffer exactLength: size];
#ifndef OF_BIG_ENDIAN
for (size_t i = 0; i < count; i++)
buffer[i] = OFByteSwap64(buffer[i]);
#endif
return size;
}
- (size_t)readBigEndianFloatsIntoBuffer: (float *)buffer count: (size_t)count
{
size_t size;
if OF_UNLIKELY (count > SIZE_MAX / sizeof(float))
@throw [OFOutOfRangeException exception];
size = count * sizeof(float);
[self readIntoBuffer: buffer exactLength: size];
#ifndef OF_FLOAT_BIG_ENDIAN
for (size_t i = 0; i < count; i++)
buffer[i] = OFByteSwapFloat(buffer[i]);
#endif
return size;
}
- (size_t)readBigEndianDoublesIntoBuffer: (double *)buffer count: (size_t)count
{
size_t size;
if OF_UNLIKELY (count > SIZE_MAX / sizeof(double))
@throw [OFOutOfRangeException exception];
size = count * sizeof(double);
[self readIntoBuffer: buffer exactLength: size];
#ifndef OF_FLOAT_BIG_ENDIAN
for (size_t i = 0; i < count; i++)
buffer[i] = OFByteSwapDouble(buffer[i]);
#endif
return size;
}
- (uint16_t)readLittleEndianInt16
{
uint16_t ret;
[self readIntoBuffer: (char *)&ret exactLength: 2];
return OFFromLittleEndian16(ret);
}
- (uint32_t)readLittleEndianInt32
{
uint32_t ret;
[self readIntoBuffer: (char *)&ret exactLength: 4];
return OFFromLittleEndian32(ret);
}
- (uint64_t)readLittleEndianInt64
{
uint64_t ret;
[self readIntoBuffer: (char *)&ret exactLength: 8];
return OFFromLittleEndian64(ret);
}
- (float)readLittleEndianFloat
{
float ret;
[self readIntoBuffer: (char *)&ret exactLength: 4];
return OFFromLittleEndianFloat(ret);
}
- (double)readLittleEndianDouble
{
double ret;
[self readIntoBuffer: (char *)&ret exactLength: 8];
return OFFromLittleEndianDouble(ret);
}
- (size_t)readLittleEndianInt16sIntoBuffer: (uint16_t *)buffer
count: (size_t)count
{
size_t size;
if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t))
@throw [OFOutOfRangeException exception];
size = count * sizeof(uint16_t);
[self readIntoBuffer: buffer exactLength: size];
#ifdef OF_BIG_ENDIAN
for (size_t i = 0; i < count; i++)
buffer[i] = OFByteSwap16(buffer[i]);
#endif
return size;
}
- (size_t)readLittleEndianInt32sIntoBuffer: (uint32_t *)buffer
count: (size_t)count
{
size_t size;
if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t))
@throw [OFOutOfRangeException exception];
size = count * sizeof(uint32_t);
[self readIntoBuffer: buffer exactLength: size];
#ifdef OF_BIG_ENDIAN
for (size_t i = 0; i < count; i++)
buffer[i] = OFByteSwap32(buffer[i]);
#endif
return size;
}
- (size_t)readLittleEndianInt64sIntoBuffer: (uint64_t *)buffer
count: (size_t)count
{
size_t size;
if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t))
@throw [OFOutOfRangeException exception];
size = count * sizeof(uint64_t);
[self readIntoBuffer: buffer exactLength: size];
#ifdef OF_BIG_ENDIAN
for (size_t i = 0; i < count; i++)
buffer[i] = OFByteSwap64(buffer[i]);
#endif
return size;
}
- (size_t)readLittleEndianFloatsIntoBuffer: (float *)buffer
count: (size_t)count
{
size_t size;
if OF_UNLIKELY (count > SIZE_MAX / sizeof(float))
@throw [OFOutOfRangeException exception];
size = count * sizeof(float);
[self readIntoBuffer: buffer exactLength: size];
#ifdef OF_FLOAT_BIG_ENDIAN
for (size_t i = 0; i < count; i++)
buffer[i] = OFByteSwapFloat(buffer[i]);
#endif
return size;
}
- (size_t)readLittleEndianDoublesIntoBuffer: (double *)buffer
count: (size_t)count
{
size_t size;
if OF_UNLIKELY (count > SIZE_MAX / sizeof(double))
@throw [OFOutOfRangeException exception];
size = count * sizeof(double);
[self readIntoBuffer: buffer exactLength: size];
#ifdef OF_FLOAT_BIG_ENDIAN
for (size_t i = 0; i < count; i++)
buffer[i] = OFByteSwapDouble(buffer[i]);
#endif
return size;
}
- (OFData *)readDataWithCount: (size_t)count
{
|
| ︙ | ︙ | |||
1210 1211 1212 1213 1214 1215 1216 |
- (void)writeInt8: (uint8_t)int8
{
[self writeBuffer: (char *)&int8 length: 1];
}
- (void)writeBigEndianInt16: (uint16_t)int16
{
| | | | | | | | 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 |
- (void)writeInt8: (uint8_t)int8
{
[self writeBuffer: (char *)&int8 length: 1];
}
- (void)writeBigEndianInt16: (uint16_t)int16
{
int16 = OFToBigEndian16(int16);
[self writeBuffer: (char *)&int16 length: 2];
}
- (void)writeBigEndianInt32: (uint32_t)int32
{
int32 = OFToBigEndian32(int32);
[self writeBuffer: (char *)&int32 length: 4];
}
- (void)writeBigEndianInt64: (uint64_t)int64
{
int64 = OFToBigEndian64(int64);
[self writeBuffer: (char *)&int64 length: 8];
}
- (void)writeBigEndianFloat: (float)float_
{
float_ = OFToBigEndianFloat(float_);
[self writeBuffer: (char *)&float_ length: 4];
}
- (void)writeBigEndianDouble: (double)double_
{
double_ = OFToBigEndianDouble(double_);
[self writeBuffer: (char *)&double_ length: 8];
}
- (size_t)writeBigEndianInt16s: (const uint16_t *)buffer count: (size_t)count
{
size_t size;
if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t))
@throw [OFOutOfRangeException exception];
size = count * sizeof(uint16_t);
#ifdef OF_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
uint16_t *tmp = OFAllocMemory(count, sizeof(uint16_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OFByteSwap16(buffer[i]);
[self writeBuffer: tmp length: size];
} @finally {
OFFreeMemory(tmp);
}
#endif
|
| ︙ | ︙ | |||
1281 1282 1283 1284 1285 1286 1287 |
#ifdef OF_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t));
@try {
for (size_t i = 0; i < count; i++)
| | | 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 |
#ifdef OF_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OFByteSwap32(buffer[i]);
[self writeBuffer: tmp length: size];
} @finally {
OFFreeMemory(tmp);
}
#endif
|
| ︙ | ︙ | |||
1308 1309 1310 1311 1312 1313 1314 |
#ifdef OF_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t));
@try {
for (size_t i = 0; i < count; i++)
| | | 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 |
#ifdef OF_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OFByteSwap64(buffer[i]);
[self writeBuffer: tmp length: size];
} @finally {
OFFreeMemory(tmp);
}
#endif
|
| ︙ | ︙ | |||
1335 1336 1337 1338 1339 1340 1341 |
#ifdef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
float *tmp = OFAllocMemory(count, sizeof(float));
@try {
for (size_t i = 0; i < count; i++)
| | | 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 |
#ifdef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
float *tmp = OFAllocMemory(count, sizeof(float));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OFByteSwapFloat(buffer[i]);
[self writeBuffer: tmp length: size];
} @finally {
OFFreeMemory(tmp);
}
#endif
|
| ︙ | ︙ | |||
1362 1363 1364 1365 1366 1367 1368 |
#ifdef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
double *tmp = OFAllocMemory(count, sizeof(double));
@try {
for (size_t i = 0; i < count; i++)
| | | | | | | | | 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 |
#ifdef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
double *tmp = OFAllocMemory(count, sizeof(double));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OFByteSwapDouble(buffer[i]);
[self writeBuffer: tmp length: size];
} @finally {
OFFreeMemory(tmp);
}
#endif
return size;
}
- (void)writeLittleEndianInt16: (uint16_t)int16
{
int16 = OFToLittleEndian16(int16);
[self writeBuffer: (char *)&int16 length: 2];
}
- (void)writeLittleEndianInt32: (uint32_t)int32
{
int32 = OFToLittleEndian32(int32);
[self writeBuffer: (char *)&int32 length: 4];
}
- (void)writeLittleEndianInt64: (uint64_t)int64
{
int64 = OFToLittleEndian64(int64);
[self writeBuffer: (char *)&int64 length: 8];
}
- (void)writeLittleEndianFloat: (float)float_
{
float_ = OFToLittleEndianFloat(float_);
[self writeBuffer: (char *)&float_ length: 4];
}
- (void)writeLittleEndianDouble: (double)double_
{
double_ = OFToLittleEndianDouble(double_);
[self writeBuffer: (char *)&double_ length: 8];
}
- (size_t)writeLittleEndianInt16s: (const uint16_t *)buffer count: (size_t)count
{
size_t size;
if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t))
@throw [OFOutOfRangeException exception];
size = count * sizeof(uint16_t);
#ifndef OF_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
uint16_t *tmp = OFAllocMemory(count, sizeof(uint16_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OFByteSwap16(buffer[i]);
[self writeBuffer: tmp length: size];
} @finally {
OFFreeMemory(tmp);
}
#endif
|
| ︙ | ︙ | |||
1446 1447 1448 1449 1450 1451 1452 |
#ifndef OF_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t));
@try {
for (size_t i = 0; i < count; i++)
| | | 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 |
#ifndef OF_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OFByteSwap32(buffer[i]);
[self writeBuffer: tmp length: size];
} @finally {
OFFreeMemory(tmp);
}
#endif
|
| ︙ | ︙ | |||
1473 1474 1475 1476 1477 1478 1479 |
#ifndef OF_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t));
@try {
for (size_t i = 0; i < count; i++)
| | | 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 |
#ifndef OF_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OFByteSwap64(buffer[i]);
[self writeBuffer: tmp length: size];
} @finally {
OFFreeMemory(tmp);
}
#endif
|
| ︙ | ︙ | |||
1500 1501 1502 1503 1504 1505 1506 |
#ifndef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
float *tmp = OFAllocMemory(count, sizeof(float));
@try {
for (size_t i = 0; i < count; i++)
| | | 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 |
#ifndef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
float *tmp = OFAllocMemory(count, sizeof(float));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OFByteSwapFloat(buffer[i]);
[self writeBuffer: tmp length: size];
} @finally {
OFFreeMemory(tmp);
}
#endif
|
| ︙ | ︙ | |||
1527 1528 1529 1530 1531 1532 1533 |
#ifndef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
double *tmp = OFAllocMemory(count, sizeof(double));
@try {
for (size_t i = 0; i < count; i++)
| | | 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 |
#ifndef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer length: size];
#else
double *tmp = OFAllocMemory(count, sizeof(double));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OFByteSwapDouble(buffer[i]);
[self writeBuffer: tmp length: size];
} @finally {
OFFreeMemory(tmp);
}
#endif
|
| ︙ | ︙ |
Changes to src/OFString.m.
| ︙ | ︙ | |||
1631 1632 1633 1634 1635 1636 1637 | OFUnichar tc = of_unicode_casefolding_table[oc >> 8][oc & 0xFF]; if (tc) oc = tc; } #else | | | | 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 |
OFUnichar tc =
of_unicode_casefolding_table[oc >> 8][oc & 0xFF];
if (tc)
oc = tc;
}
#else
c = OFASCIIToUpper(c);
oc = OFASCIIToUpper(oc);
#endif
if (c > oc) {
objc_autoreleasePoolPop(pool);
return OFOrderedDescending;
}
if (c < oc) {
|
| ︙ | ︙ | |||
1659 1660 1661 1662 1663 1664 1665 |
return OFOrderedSame;
}
- (unsigned long)hash
{
const OFUnichar *characters = self.characters;
size_t length = self.length;
| | | | | | | | 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 |
return OFOrderedSame;
}
- (unsigned long)hash
{
const OFUnichar *characters = self.characters;
size_t length = self.length;
unsigned long hash;
OFHashInit(&hash);
for (size_t i = 0; i < length; i++) {
const OFUnichar c = characters[i];
OFHashAdd(&hash, (c & 0xFF0000) >> 16);
OFHashAdd(&hash, (c & 0x00FF00) >> 8);
OFHashAdd(&hash, c & 0x0000FF);
}
OFHashFinalize(&hash);
return hash;
}
- (OFString *)description
{
return [[self copy] autorelease];
|
| ︙ | ︙ | |||
1734 1735 1736 1737 1738 1739 1740 |
if (options & OFJSONRepresentationOptionJSON5) {
[JSON replaceOccurrencesOfString: @"\n" withString: @"\\\n"];
if (options & OFJSONRepresentationOptionIsIdentifier) {
const char *cString = self.UTF8String;
| | | 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 |
if (options & OFJSONRepresentationOptionJSON5) {
[JSON replaceOccurrencesOfString: @"\n" withString: @"\\\n"];
if (options & OFJSONRepresentationOptionIsIdentifier) {
const char *cString = self.UTF8String;
if ((!OFASCIIIsAlpha(cString[0]) &&
cString[0] != '_' && cString[0] != '$') ||
strpbrk(cString, " \n\r\t\b\f\\\"'") != NULL) {
[JSON prependString: @"\""];
[JSON appendString: @"\""];
}
} else {
[JSON prependString: @"\""];
|
| ︙ | ︙ | |||
1777 1778 1779 1780 1781 1782 1783 |
uint8_t tmp = (uint8_t)length;
data = [OFMutableData dataWithCapacity: length + 2];
[data addItem: &type];
[data addItem: &tmp];
} else if (length <= UINT16_MAX) {
uint8_t type = 0xDA;
| | | | 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 |
uint8_t tmp = (uint8_t)length;
data = [OFMutableData dataWithCapacity: length + 2];
[data addItem: &type];
[data addItem: &tmp];
} else if (length <= UINT16_MAX) {
uint8_t type = 0xDA;
uint16_t tmp = OFToBigEndian16((uint16_t)length);
data = [OFMutableData dataWithCapacity: length + 3];
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else if (length <= UINT32_MAX) {
uint8_t type = 0xDB;
uint32_t tmp = OFToBigEndian32((uint32_t)length);
data = [OFMutableData dataWithCapacity: length + 5];
[data addItem: &type];
[data addItems: &tmp count: sizeof(tmp)];
} else
@throw [OFOutOfRangeException exception];
|
| ︙ | ︙ | |||
2280 2281 2282 2283 2284 2285 2286 |
- (long long)longLongValueWithBase: (int)base
{
void *pool = objc_autoreleasePoolPush();
const char *UTF8String = self.UTF8String;
bool negative = false;
long long value = 0;
| | | 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 |
- (long long)longLongValueWithBase: (int)base
{
void *pool = objc_autoreleasePoolPush();
const char *UTF8String = self.UTF8String;
bool negative = false;
long long value = 0;
while (OFASCIIIsSpace(*UTF8String))
UTF8String++;
switch (*UTF8String) {
case '-':
negative = true;
case '+':
UTF8String++;
|
| ︙ | ︙ | |||
2311 2312 2313 2314 2315 2316 2317 |
}
}
if (base == 0)
base = 10;
while (*UTF8String != '\0') {
| | | | | 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 |
}
}
if (base == 0)
base = 10;
while (*UTF8String != '\0') {
unsigned char c = OFASCIIToUpper(*UTF8String++);
if (c >= '0' && c <= '9')
c -= '0';
else if (c >= 'A' && c <= 'Z')
c -= ('A' - 10);
else if (OFASCIIIsSpace(c)) {
while (*UTF8String != '\0')
if (!OFASCIIIsSpace(*UTF8String++))
@throw [OFInvalidFormatException
exception];
break;
} else
@throw [OFInvalidFormatException exception];
|
| ︙ | ︙ | |||
2355 2356 2357 2358 2359 2360 2361 |
- (unsigned long long)unsignedLongLongValueWithBase: (int)base
{
void *pool = objc_autoreleasePoolPush();
const char *UTF8String = self.UTF8String;
unsigned long long value = 0;
| | | 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 |
- (unsigned long long)unsignedLongLongValueWithBase: (int)base
{
void *pool = objc_autoreleasePoolPush();
const char *UTF8String = self.UTF8String;
unsigned long long value = 0;
while (OFASCIIIsSpace(*UTF8String))
UTF8String++;
switch (*UTF8String) {
case '-':
@throw [OFInvalidFormatException exception];
case '+':
UTF8String++;
|
| ︙ | ︙ | |||
2386 2387 2388 2389 2390 2391 2392 |
}
}
if (base == 0)
base = 10;
while (*UTF8String != '\0') {
| | | | | 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 |
}
}
if (base == 0)
base = 10;
while (*UTF8String != '\0') {
unsigned char c = OFASCIIToUpper(*UTF8String++);
if (c >= '0' && c <= '9')
c -= '0';
else if (c >= 'A' && c <= 'Z')
c -= ('A' - 10);
else if (OFASCIIIsSpace(c)) {
while (*UTF8String != '\0')
if (!OFASCIIIsSpace(*UTF8String++))
@throw [OFInvalidFormatException
exception];
break;
} else
@throw [OFInvalidFormatException exception];
|
| ︙ | ︙ | |||
2571 2572 2573 2574 2575 2576 2577 |
OFFreeMemory(buffer);
@throw [OFInvalidEncodingException exception];
}
if (swap) {
if (c > 0xFFFF) {
c -= 0x10000;
| > | | | | 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 |
OFFreeMemory(buffer);
@throw [OFInvalidEncodingException exception];
}
if (swap) {
if (c > 0xFFFF) {
c -= 0x10000;
buffer[j++] = OFByteSwap16(0xD800 | (c >> 10));
buffer[j++] =
OFByteSwap16(0xDC00 | (c & 0x3FF));
} else
buffer[j++] = OFByteSwap16(c);
} else {
if (c > 0xFFFF) {
c -= 0x10000;
buffer[j++] = 0xD800 | (c >> 10);
buffer[j++] = 0xDC00 | (c & 0x3FF);
} else
buffer[j++] = c;
|
| ︙ | ︙ | |||
2636 2637 2638 2639 2640 2641 2642 |
buffer = OFAllocMemory(length + 1, sizeof(OFChar32));
@try {
[self getCharacters: buffer inRange: OFRangeMake(0, length)];
buffer[length] = 0;
if (byteOrder != OFByteOrderNative)
for (size_t i = 0; i < length; i++)
| | | 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 |
buffer = OFAllocMemory(length + 1, sizeof(OFChar32));
@try {
[self getCharacters: buffer inRange: OFRangeMake(0, length)];
buffer[length] = 0;
if (byteOrder != OFByteOrderNative)
for (size_t i = 0; i < length; i++)
buffer[i] = OFByteSwap32(buffer[i]);
return [[OFData dataWithItemsNoCopy: buffer
count: length + 1
itemSize: sizeof(OFChar32)
freeWhenDone: true] items];
} @catch (id e) {
OFFreeMemory(buffer);
|
| ︙ | ︙ |
Changes to src/OFTCPSocket.m.
| ︙ | ︙ | |||
406 407 408 409 410 411 412 | @throw [OFBindFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } if (address.sockaddr.sockaddr.sa_family == AF_INET) | | | | 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
@throw [OFBindFailedException exceptionWithHost: host
port: port
socket: self
errNo: errNo];
}
if (address.sockaddr.sockaddr.sa_family == AF_INET)
return OFFromBigEndian16(address.sockaddr.in.sin_port);
# ifdef OF_HAVE_IPV6
else if (address.sockaddr.sockaddr.sa_family == AF_INET6)
return OFFromBigEndian16(address.sockaddr.in6.sin6_port);
# endif
else {
closesocket(_socket);
_socket = INVALID_SOCKET;
@throw [OFBindFailedException exceptionWithHost: host
port: port
|
| ︙ | ︙ |
Changes to src/OFThread.m.
| ︙ | ︙ | |||
320 321 322 323 324 325 326 |
+ (void)terminateWithObject: (id)object
{
OFThread *thread = OFTLSKeyGet(threadSelfKey);
if (thread == mainThread)
@throw [OFInvalidArgumentException exception];
| | | 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
+ (void)terminateWithObject: (id)object
{
OFThread *thread = OFTLSKeyGet(threadSelfKey);
if (thread == mainThread)
@throw [OFInvalidArgumentException exception];
OFEnsure(thread != nil);
thread->_returnValue = [object retain];
longjmp(thread->_exitEnv, 1);
OF_UNREACHABLE
}
|
| ︙ | ︙ |
Changes to src/OFTimer.m.
| ︙ | ︙ | |||
531 532 533 534 535 536 537 | void *pool = objc_autoreleasePoolPush(); id target = [[_target retain] autorelease]; id object1 = [[_object1 retain] autorelease]; id object2 = [[_object2 retain] autorelease]; id object3 = [[_object3 retain] autorelease]; id object4 = [[_object4 retain] autorelease]; | | | 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
void *pool = objc_autoreleasePoolPush();
id target = [[_target retain] autorelease];
id object1 = [[_object1 retain] autorelease];
id object2 = [[_object2 retain] autorelease];
id object3 = [[_object3 retain] autorelease];
id object4 = [[_object4 retain] autorelease];
OFEnsure(_arguments <= 4);
if (_repeats && _valid) {
int64_t missedIntervals =
-_fireDate.timeIntervalSinceNow / _interval;
OFTimeInterval newFireDate;
OFRunLoop *runLoop;
|
| ︙ | ︙ |
Changes to src/OFTriple.m.
| ︙ | ︙ | |||
95 96 97 98 99 100 101 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, [_firstObject hash]);
OFHashAddHash(&hash, [_secondObject hash]);
OFHashAddHash(&hash, [_thirdObject hash]);
OFHashFinalize(&hash);
return hash;
}
- (id)copy
{
return [self retain];
|
| ︙ | ︙ |
Changes to src/OFUDPSocket.m.
| ︙ | ︙ | |||
138 139 140 141 142 143 144 | exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: errNo]; } if (address->sockaddr.sockaddr.sa_family == AF_INET) | | | | 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
exceptionWithHost: OFSocketAddressString(address)
port: OFSocketAddressPort(address)
socket: self
errNo: errNo];
}
if (address->sockaddr.sockaddr.sa_family == AF_INET)
return OFFromBigEndian16(address->sockaddr.in.sin_port);
# ifdef OF_HAVE_IPV6
else if (address->sockaddr.sockaddr.sa_family == AF_INET6)
return OFFromBigEndian16(address->sockaddr.in6.sin6_port);
# endif
else {
closesocket(_socket);
_socket = INVALID_SOCKET;
@throw [OFBindFailedException
exceptionWithHost: OFSocketAddressString(address)
|
| ︙ | ︙ |
Changes to src/OFURL.m.
| ︙ | ︙ | |||
111 112 113 114 115 116 117 |
bool
of_url_is_ipv6_host(OFString *host)
{
const char *UTF8String = host.UTF8String;
bool hasColon = false;
while (*UTF8String != '\0') {
| | | 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
bool
of_url_is_ipv6_host(OFString *host)
{
const char *UTF8String = host.UTF8String;
bool hasColon = false;
while (*UTF8String != '\0') {
if (!OFASCIIIsDigit(*UTF8String) && *UTF8String != ':' &&
(*UTF8String < 'a' || *UTF8String > 'f') &&
(*UTF8String < 'A' || *UTF8String > 'F'))
return false;
if (*UTF8String == ':')
hasColon = true;
|
| ︙ | ︙ | |||
149 150 151 152 153 154 155 |
return OF_RETAIN_COUNT_MAX;
}
@end
@implementation OFURLAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
| | | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
return OF_RETAIN_COUNT_MAX;
}
@end
@implementation OFURLAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
if (character < CHAR_MAX && OFASCIIIsAlnum(character))
return true;
switch (character) {
case '-':
case '.':
case '_':
case '~':
|
| ︙ | ︙ | |||
178 179 180 181 182 183 184 |
}
}
@end
@implementation OFURLSchemeAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
| | | | 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 |
}
}
@end
@implementation OFURLSchemeAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
if (character < CHAR_MAX && OFASCIIIsAlnum(character))
return true;
switch (character) {
case '+':
case '-':
case '.':
return true;
default:
return false;
}
}
@end
@implementation OFURLPathAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
if (character < CHAR_MAX && OFASCIIIsAlnum(character))
return true;
switch (character) {
case '-':
case '.':
case '_':
case '~':
|
| ︙ | ︙ | |||
227 228 229 230 231 232 233 |
}
}
@end
@implementation OFURLQueryOrFragmentAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
| | | 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
}
}
@end
@implementation OFURLQueryOrFragmentAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
if (character < CHAR_MAX && OFASCIIIsAlnum(character))
return true;
switch (character) {
case '-':
case '.':
case '_':
case '~':
|
| ︙ | ︙ | |||
260 261 262 263 264 265 266 |
}
}
@end
@implementation OFURLQueryKeyValueAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
| | | 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
}
}
@end
@implementation OFURLQueryKeyValueAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
if (character < CHAR_MAX && OFASCIIIsAlnum(character))
return true;
switch (character) {
case '-':
case '.':
case '_':
case '~':
|
| ︙ | ︙ | |||
440 441 442 443 444 445 446 |
self = [super init];
@try {
void *pool = objc_autoreleasePoolPush();
char *tmp, *tmp2;
bool isIPv6Host = false;
| | | | 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 |
self = [super init];
@try {
void *pool = objc_autoreleasePoolPush();
char *tmp, *tmp2;
bool isIPv6Host = false;
if ((UTF8String2 = OFStrdup(string.UTF8String)) == NULL)
@throw [OFOutOfMemoryException
exceptionWithRequestedSize:
string.UTF8StringLength];
UTF8String = UTF8String2;
if ((tmp = strchr(UTF8String, ':')) == NULL)
@throw [OFInvalidFormatException exception];
if (strncmp(tmp, "://", 3) != 0)
@throw [OFInvalidFormatException exception];
for (tmp2 = UTF8String; tmp2 < tmp; tmp2++)
*tmp2 = OFASCIIToLower(*tmp2);
_URLEncodedScheme = [[OFString alloc]
initWithUTF8String: UTF8String
length: tmp - UTF8String];
of_url_verify_escaped(_URLEncodedScheme,
[OFCharacterSet URLSchemeAllowedCharacterSet]);
|
| ︙ | ︙ | |||
501 502 503 504 505 506 507 |
UTF8String = tmp2;
}
if (UTF8String[0] == '[') {
tmp2 = UTF8String++;
| | | | 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 |
UTF8String = tmp2;
}
if (UTF8String[0] == '[') {
tmp2 = UTF8String++;
while (OFASCIIIsDigit(*UTF8String) ||
*UTF8String == ':' ||
(*UTF8String >= 'a' && *UTF8String <= 'f') ||
(*UTF8String >= 'A' && *UTF8String <= 'F'))
UTF8String++;
if (*UTF8String != ']')
@throw [OFInvalidFormatException exception];
UTF8String++;
_URLEncodedHost = [[OFString alloc]
initWithUTF8String: tmp2
length: UTF8String - tmp2];
if (*UTF8String == ':') {
OFString *portString;
tmp2 = ++UTF8String;
while (*UTF8String != '\0') {
if (!OFASCIIIsDigit(*UTF8String))
@throw [OFInvalidFormatException
exception];
UTF8String++;
}
portString = [OFString
|
| ︙ | ︙ | |||
631 632 633 634 635 636 637 | _URLEncodedScheme = [URL->_URLEncodedScheme copy]; _URLEncodedHost = [URL->_URLEncodedHost copy]; _port = [URL->_port copy]; _URLEncodedUser = [URL->_URLEncodedUser copy]; _URLEncodedPassword = [URL->_URLEncodedPassword copy]; | | | 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 |
_URLEncodedScheme = [URL->_URLEncodedScheme copy];
_URLEncodedHost = [URL->_URLEncodedHost copy];
_port = [URL->_port copy];
_URLEncodedUser = [URL->_URLEncodedUser copy];
_URLEncodedPassword = [URL->_URLEncodedPassword copy];
if ((UTF8String2 = OFStrdup(string.UTF8String)) == NULL)
@throw [OFOutOfMemoryException
exceptionWithRequestedSize:
string.UTF8StringLength];
UTF8String = UTF8String2;
if ((tmp = strchr(UTF8String, '#')) != NULL) {
|
| ︙ | ︙ | |||
843 844 845 846 847 848 849 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | | | 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _URLEncodedScheme.hash);
OFHashAddHash(&hash, _URLEncodedHost.hash);
OFHashAddHash(&hash, _port.hash);
OFHashAddHash(&hash, _URLEncodedUser.hash);
OFHashAddHash(&hash, _URLEncodedPassword.hash);
OFHashAddHash(&hash, _URLEncodedPath.hash);
OFHashAddHash(&hash, _URLEncodedQuery.hash);
OFHashAddHash(&hash, _URLEncodedFragment.hash);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)scheme
{
return _URLEncodedScheme.stringByURLDecoding;
|
| ︙ | ︙ |
Changes to src/OFUTF8String.m.
| ︙ | ︙ | |||
65 66 67 68 69 70 71 |
static inline int
memcasecmp(const char *first, const char *second, size_t length)
{
for (size_t i = 0; i < length; i++) {
unsigned char f = first[i];
unsigned char s = second[i];
| | | | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
static inline int
memcasecmp(const char *first, const char *second, size_t length)
{
for (size_t i = 0; i < length; i++) {
unsigned char f = first[i];
unsigned char s = second[i];
f = OFASCIIToUpper(f);
s = OFASCIIToUpper(s);
if (f > s)
return OFOrderedDescending;
if (f < s)
return OFOrderedAscending;
}
|
| ︙ | ︙ | |||
530 531 532 533 534 535 536 |
_s->cString = OFAllocMemory((length * 4) + 1, 1);
_s->length = length;
_s->freeWhenDone = true;
j = 0;
for (size_t i = 0; i < length; i++) {
OFUnichar character =
| | | | 530 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 |
_s->cString = OFAllocMemory((length * 4) + 1, 1);
_s->length = length;
_s->freeWhenDone = true;
j = 0;
for (size_t i = 0; i < length; i++) {
OFUnichar character =
(swap ? OFByteSwap16(string[i]) : string[i]);
size_t len;
/* Missing high surrogate */
if ((character & 0xFC00) == 0xDC00)
@throw [OFInvalidEncodingException exception];
if ((character & 0xFC00) == 0xD800) {
OFChar16 nextCharacter;
if (length <= i + 1)
@throw [OFInvalidEncodingException
exception];
nextCharacter = (swap
? OFByteSwap16(string[i + 1])
: string[i + 1]);
if ((nextCharacter & 0xFC00) != 0xDC00)
@throw [OFInvalidEncodingException
exception];
character = (((character & 0x3FF) << 10) |
|
| ︙ | ︙ | |||
615 616 617 618 619 620 621 |
_s->cString = OFAllocMemory((length * 4) + 1, 1);
_s->length = length;
_s->freeWhenDone = true;
j = 0;
for (size_t i = 0; i < length; i++) {
char buffer[4];
| | > | | 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
_s->cString = OFAllocMemory((length * 4) + 1, 1);
_s->length = length;
_s->freeWhenDone = true;
j = 0;
for (size_t i = 0; i < length; i++) {
char buffer[4];
size_t len = of_string_utf8_encode((swap
? OFByteSwap32(characters[i])
: characters[i]),
buffer);
switch (len) {
case 1:
_s->cString[j++] = buffer[0];
break;
case 2:
|
| ︙ | ︙ | |||
912 913 914 915 916 917 918 |
#endif
return OFOrderedSame;
}
- (unsigned long)hash
{
| | | | | | | | 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 |
#endif
return OFOrderedSame;
}
- (unsigned long)hash
{
unsigned long hash;
if (_s->hashed)
return _s->hash;
OFHashInit(&hash);
for (size_t i = 0; i < _s->cStringLength; i++) {
OFUnichar c;
ssize_t length;
if ((length = of_string_utf8_decode(_s->cString + i,
_s->cStringLength - i, &c)) <= 0)
@throw [OFInvalidEncodingException exception];
OFHashAdd(&hash, (c & 0xFF0000) >> 16);
OFHashAdd(&hash, (c & 0x00FF00) >> 8);
OFHashAdd(&hash, c & 0x0000FF);
i += length - 1;
}
OFHashFinalize(&hash);
_s->hash = hash;
_s->hashed = true;
return hash;
}
|
| ︙ | ︙ | |||
1193 1194 1195 1196 1197 1198 1199 |
if (cLen <= 0 || c > 0x10FFFF) {
OFFreeMemory(buffer);
@throw [OFInvalidEncodingException exception];
}
if (byteOrder != OFByteOrderNative)
| | | 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 |
if (cLen <= 0 || c > 0x10FFFF) {
OFFreeMemory(buffer);
@throw [OFInvalidEncodingException exception];
}
if (byteOrder != OFByteOrderNative)
buffer[j++] = OFByteSwap32(c);
else
buffer[j++] = c;
i += cLen;
}
buffer[j] = 0;
|
| ︙ | ︙ |
Changes to src/OFValue.m.
| ︙ | ︙ | |||
119 120 121 122 123 124 125 |
return ret;
}
- (unsigned long)hash
{
size_t size = of_sizeof_type_encoding(self.objCType);
unsigned char *value;
| | | | | | 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 |
return ret;
}
- (unsigned long)hash
{
size_t size = of_sizeof_type_encoding(self.objCType);
unsigned char *value;
unsigned long hash;
value = OFAllocMemory(1, size);
@try {
[self getValue: value size: size];
OFHashInit(&hash);
for (size_t i = 0; i < size; i++)
OFHashAdd(&hash, value[i]);
OFHashFinalize(&hash);
} @finally {
OFFreeMemory(value);
}
return hash;
}
|
| ︙ | ︙ |
Changes to src/OFWin32ConsoleStdIOStream.m.
| ︙ | ︙ | |||
276 277 278 279 280 281 282 | ssize_t UTF8Len; size_t toCopy; DWORD UTF16Len, bytesWritten; UTF8Len = -of_string_utf8_decode( _incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c); | | | 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | ssize_t UTF8Len; size_t toCopy; DWORD UTF16Len, bytesWritten; UTF8Len = -of_string_utf8_decode( _incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c); OFEnsure(UTF8Len > 0); toCopy = UTF8Len - _incompleteUTF8SurrogateLen; if (toCopy > length) toCopy = length; memcpy(_incompleteUTF8Surrogate + _incompleteUTF8SurrogateLen, buffer, toCopy); |
| ︙ | ︙ | |||
365 366 367 368 369 370 371 |
OFUnichar c;
ssize_t UTF8Len;
UTF8Len = of_string_utf8_decode(buffer + i, length - i,
&c);
if (UTF8Len < 0 && UTF8Len >= -4) {
| | | 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
OFUnichar c;
ssize_t UTF8Len;
UTF8Len = of_string_utf8_decode(buffer + i, length - i,
&c);
if (UTF8Len < 0 && UTF8Len >= -4) {
OFEnsure(length - i < 4);
memcpy(_incompleteUTF8Surrogate, buffer + i,
length - i);
_incompleteUTF8SurrogateLen = length - i;
break;
}
|
| ︙ | ︙ |
Changes to src/OFXMLAttribute.m.
| ︙ | ︙ | |||
136 137 138 139 140 141 142 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAddHash(&hash, _namespace.hash);
OFHashAddHash(&hash, _stringValue.hash);
OFHashFinalize(&hash);
return hash;
}
- (OFXMLElement *)XMLElementBySerializing
{
void *pool = objc_autoreleasePoolPush();
|
| ︙ | ︙ |
Changes to src/OFXMLElement.m.
| ︙ | ︙ | |||
1010 1011 1012 1013 1014 1015 1016 |
return false;
return true;
}
- (unsigned long)hash
{
| | | | | | | | | | | 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 |
return false;
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAddHash(&hash, _namespace.hash);
OFHashAddHash(&hash, _defaultNamespace.hash);
OFHashAddHash(&hash, _attributes.hash);
OFHashAddHash(&hash, _namespaces.hash);
OFHashAddHash(&hash, _children.hash);
OFHashFinalize(&hash);
return hash;
}
- (id)copy
{
return [[[self class] alloc] initWithElement: self];
|
| ︙ | ︙ |
Changes to src/OFXMLProcessingInstruction.m.
| ︙ | ︙ | |||
108 109 110 111 112 113 114 |
return true;
}
- (unsigned long)hash
{
unsigned long hash;
| | | | | | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
return true;
}
- (unsigned long)hash
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _target.hash);
OFHashAddHash(&hash, _data.hash);
OFHashFinalize(&hash);
return hash;
}
- (OFString *)stringValue
{
return @"";
|
| ︙ | ︙ |
Changes to src/exceptions/OFException.m.
| ︙ | ︙ | |||
69 70 71 72 73 74 75 |
#endif
#if !defined(HAVE_STRERROR_R) && defined(OF_HAVE_THREADS)
static OFPlainMutex mutex;
OF_CONSTRUCTOR()
{
| | | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
#endif
#if !defined(HAVE_STRERROR_R) && defined(OF_HAVE_THREADS)
static OFPlainMutex mutex;
OF_CONSTRUCTOR()
{
OFEnsure(OFPlainMutexNew(&mutex) == 0);
}
OF_DESTRUCTOR()
{
OFPlainMutexFree(&mutex);
}
#endif
|
| ︙ | ︙ |
Changes to src/macros.h.
| ︙ | ︙ | |||
348 349 350 351 352 353 354 | # endif # endif #endif #define OF_RETAIN_COUNT_MAX UINT_MAX #ifdef OBJC_COMPILING_RUNTIME | | | | 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# endif
# endif
#endif
#define OF_RETAIN_COUNT_MAX UINT_MAX
#ifdef OBJC_COMPILING_RUNTIME
# define OFEnsure(cond) \
do { \
if OF_UNLIKELY (!(cond)) \
objc_error("ObjFWRT @ " __FILE__ ":" \
OF_STRINGIFY(__LINE__), \
"Failed to ensure condition:\n" #cond); \
} while(0)
#else
# define OFEnsure(cond) \
do { \
if OF_UNLIKELY (!(cond)) { \
fprintf(stderr, "Failed to ensure condition " \
"in " __FILE__ ":%d:\n" #cond "\n", \
__LINE__); \
abort(); \
} \
|
| ︙ | ︙ | |||
407 408 409 410 411 412 413 | static void __attribute__((__constructor__(prio))) \ OF_PREPROCESSOR_CONCAT(constructor, __LINE__)(void) #define OF_DESTRUCTOR(prio) \ static void __attribute__((__destructor__(prio))) \ OF_PREPROCESSOR_CONCAT(destructor, __LINE__)(void) static OF_INLINE uint16_t OF_CONST_FUNC | | | | | | 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 |
static void __attribute__((__constructor__(prio))) \
OF_PREPROCESSOR_CONCAT(constructor, __LINE__)(void)
#define OF_DESTRUCTOR(prio) \
static void __attribute__((__destructor__(prio))) \
OF_PREPROCESSOR_CONCAT(destructor, __LINE__)(void)
static OF_INLINE uint16_t OF_CONST_FUNC
OFByteSwap16Const(uint16_t i)
{
return (i & 0xFF00) >> 8 | (i & 0x00FF) << 8;
}
static OF_INLINE uint32_t OF_CONST_FUNC
OFByteSwap32Const(uint32_t i)
{
return (i & 0xFF000000) >> 24 | (i & 0x00FF0000) >> 8 |
(i & 0x0000FF00) << 8 | (i & 0x000000FF) << 24;
}
static OF_INLINE uint64_t OF_CONST_FUNC
OFByteSwap64Const(uint64_t i)
{
return (i & 0xFF00000000000000) >> 56 | (i & 0x00FF000000000000) >> 40 |
(i & 0x0000FF0000000000) >> 24 | (i & 0x000000FF00000000) >> 8 |
(i & 0x00000000FF000000) << 8 | (i & 0x0000000000FF0000) << 24 |
(i & 0x000000000000FF00) << 40 | (i & 0x00000000000000FF) << 56;
}
static OF_INLINE uint16_t OF_CONST_FUNC
OFByteSwap16NonConst(uint16_t i)
{
#if defined(OF_HAVE_BUILTIN_BSWAP16)
return __builtin_bswap16(i);
#elif (defined(OF_X86_64) || defined(OF_X86)) && defined(__GNUC__)
__asm__ (
"xchgb %h0, %b0"
: "=Q"(i)
|
| ︙ | ︙ | |||
459 460 461 462 463 464 465 | i = (i & UINT16_C(0xFF00)) >> 8 | (i & UINT16_C(0x00FF)) << 8; #endif return i; } static OF_INLINE uint32_t OF_CONST_FUNC | | | 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
i = (i & UINT16_C(0xFF00)) >> 8 |
(i & UINT16_C(0x00FF)) << 8;
#endif
return i;
}
static OF_INLINE uint32_t OF_CONST_FUNC
OFByteSwap32NonConst(uint32_t i)
{
#if defined(OF_HAVE_BUILTIN_BSWAP32)
return __builtin_bswap32(i);
#elif (defined(OF_X86_64) || defined(OF_X86)) && defined(__GNUC__)
__asm__ (
"bswap %0"
: "=q"(i)
|
| ︙ | ︙ | |||
491 492 493 494 495 496 497 | (i & UINT32_C(0x0000FF00)) << 8 | (i & UINT32_C(0x000000FF)) << 24; #endif return i; } static OF_INLINE uint64_t OF_CONST_FUNC | | | | | | | | | | | | | | | | | | | | | | | | > > > | | | > > > > > > | | | > > > | | | | | > > | | > > > > | | > > | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | > | > > > > > | > | > > > > | | | | | | > | > > > | | > | | | < > > > | | > | > | | | | | | | | | | | | | | | | | 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 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 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 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 |
(i & UINT32_C(0x0000FF00)) << 8 |
(i & UINT32_C(0x000000FF)) << 24;
#endif
return i;
}
static OF_INLINE uint64_t OF_CONST_FUNC
OFByteSwap64NonConst(uint64_t i)
{
#if defined(OF_HAVE_BUILTIN_BSWAP64)
return __builtin_bswap64(i);
#elif defined(OF_X86_64) && defined(__GNUC__)
__asm__ (
"bswap %0"
: "=r"(i)
: "0"(i)
);
#elif defined(OF_X86) && defined(__GNUC__)
__asm__ (
"bswap %%eax\n\t"
"bswap %%edx\n\t"
"xchgl %%eax, %%edx"
: "=A"(i)
: "0"(i)
);
#else
i = (uint64_t)OFByteSwap32NonConst((uint32_t)(i & 0xFFFFFFFF)) << 32 |
OFByteSwap32NonConst((uint32_t)(i >> 32));
#endif
return i;
}
#ifdef __GNUC__
# define OFByteSwap16(i) \
(__builtin_constant_p(i) ? OFByteSwap16Const(i) : OFByteSwap16NonConst(i))
# define OFByteSwap32(i) \
(__builtin_constant_p(i) ? OFByteSwap32Const(i) : OFByteSwap32NonConst(i))
# define OFByteSwap64(i) \
(__builtin_constant_p(i) ? OFByteSwap64Const(i) : OFByteSwap64NonConst(i))
#else
# define OFByteSwap16(i) OFByteSwap16Const(i)
# define OFByteSwap32(i) OFByteSwap32Const(i)
# define OFByteSwap64(i) OFByteSwap64Const(i)
#endif
static OF_INLINE uint32_t
OFFloatToRawUInt32(float f)
{
uint32_t ret;
memcpy(&ret, &f, 4);
return ret;
}
static OF_INLINE float
OFRawUInt32ToFloat(uint32_t uInt32)
{
float ret;
memcpy(&ret, &uInt32, 4);
return ret;
}
static OF_INLINE uint64_t
OFDoubleToRawUInt64(double d)
{
uint64_t ret;
memcpy(&ret, &d, 8);
return ret;
}
static OF_INLINE double
OFRawUInt64ToDouble(uint64_t uInt64)
{
double ret;
memcpy(&ret, &uInt64, 8);
return ret;
}
static OF_INLINE float OF_CONST_FUNC
OFByteSwapFloat(float f)
{
return OFRawUInt32ToFloat(OFByteSwap32(OFFloatToRawUInt32(f)));
}
static OF_INLINE double OF_CONST_FUNC
OFByteSwapDouble(double d)
{
return OFRawUInt64ToDouble(OFByteSwap64(OFDoubleToRawUInt64(d)));
}
#ifdef OF_BIG_ENDIAN
# define OFFromBigEndian16(i) (i)
# define OFFromBigEndian32(i) (i)
# define OFFromBigEndian64(i) (i)
# define OFFromLittleEndian16(i) OFByteSwap16(i)
# define OFFromLittleEndian32(i) OFByteSwap32(i)
# define OFFromLittleEndian64(i) OFByteSwap64(i)
# define OFToBigEndian16(i) (i)
# define OFToBigEndian32(i) (i)
# define OFToBigEndian64(i) (i)
# define OFToLittleEndian16(i) OFByteSwap16(i)
# define OFToLittleEndian32(i) OFByteSwap32(i)
# define OFToLittleEndian64(i) OFByteSwap64(i)
#else
# define OFFromBigEndian16(i) OFByteSwap16(i)
# define OFFromBigEndian32(i) OFByteSwap32(i)
# define OFFromBigEndian64(i) OFByteSwap64(i)
# define OFFromLittleEndian16(i) (i)
# define OFFromLittleEndian32(i) (i)
# define OFFromLittleEndian64(i) (i)
# define OFToBigEndian16(i) OFByteSwap16(i)
# define OFToBigEndian32(i) OFByteSwap32(i)
# define OFToBigEndian64(i) OFByteSwap64(i)
# define OFToLittleEndian16(i) (i)
# define OFToLittleEndian32(i) (i)
# define OFToLittleEndian64(i) (i)
#endif
#ifdef OF_FLOAT_BIG_ENDIAN
# define OFFromBigEndianFloat(f) (f)
# define OFFromBigEndianDouble(d) (d)
# define OFFromLittleEndianFloat(f) OFByteSwapFloat(f)
# define OFFromLittleEndianDouble(i) OFByteSwapDouble(d)
# define OFToBigEndianFloat(f) (f)
# define OFToBigEndianDouble(d) (d)
# define OFToLittleEndianFloat(f) OFByteSwapFloat(f)
# define OFToLittleEndianDouble(i) OFByteSwapDouble(d)
#else
# define OFFromBigEndianFloat(f) OFByteSwapFloat(f)
# define OFFromBigEndianDouble(d) OFByteSwapDouble(d)
# define OFFromLittleEndianFloat(f) (f)
# define OFFromLittleEndianDouble(d) (d)
# define OFToBigEndianFloat(f) OFByteSwapFloat(f)
# define OFToBigEndianDouble(d) OFByteSwapDouble(d)
# define OFToLittleEndianFloat(f) (f)
# define OFToLittleEndianDouble(d) (d)
#endif
#define OFRotateLeft(value, bits) \
(((bits) % (sizeof(value) * 8)) > 0 \
? ((value) << ((bits) % (sizeof(value) * 8))) | \
((value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) \
: (value))
#define OFRotateRight(value, bits) \
(((bits) % (sizeof(value) * 8)) > 0 \
? ((value) >> ((bits) % (sizeof(value) * 8))) | \
((value) << (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) \
: (value))
#define OFRoundUpToPowerOf2(pow2, value) \
(((value) + (pow2) - 1) & ~((pow2) - 1))
extern unsigned long OFHashSeed;
static OF_INLINE void
OFHashInit(unsigned long *_Nonnull hash)
{
*hash = OFHashSeed;
}
static OF_INLINE void
OFHashAdd(unsigned long *_Nonnull hash, unsigned char byte)
{
uint32_t tmp = (uint32_t)*hash;
tmp += byte;
tmp += tmp << 10;
tmp ^= tmp >> 6;
*hash = tmp;
}
static OF_INLINE void
OFHashAddHash(unsigned long *_Nonnull hash, unsigned long otherHash)
{
OFHashAdd(hash, (otherHash >> 24) & 0xFF);
OFHashAdd(hash, (otherHash >> 16) & 0xFF);
OFHashAdd(hash, (otherHash >> 8) & 0xFF);
OFHashAdd(hash, otherHash & 0xFF);
}
static OF_INLINE void
OFHashFinalize(unsigned long *_Nonnull hash)
{
uint32_t tmp = (uint32_t)*hash;
tmp += tmp << 3;
tmp ^= tmp >> 11;
tmp += tmp << 15;
*hash = tmp;
}
static OF_INLINE bool
OFBitsetIsSet(unsigned char *_Nonnull storage, size_t idx)
{
return storage[idx / CHAR_BIT] & (1u << (idx % CHAR_BIT));
}
static OF_INLINE void
OFBitsetSet(unsigned char *_Nonnull storage, size_t idx)
{
storage[idx / CHAR_BIT] |= (1u << (idx % CHAR_BIT));
}
static OF_INLINE void
OFBitsetClear(unsigned char *_Nonnull storage, size_t idx)
{
storage[idx / CHAR_BIT] &= ~(1u << (idx % CHAR_BIT));
}
static OF_INLINE char *_Nullable
OFStrdup(const char *_Nonnull string)
{
char *copy;
size_t length = strlen(string);
if ((copy = (char *)malloc(length + 1)) == NULL)
return NULL;
memcpy(copy, string, length + 1);
return copy;
}
static OF_INLINE void
OFZeroMemory(void *_Nonnull buffer_, size_t length)
{
volatile unsigned char *buffer = (volatile unsigned char *)buffer_;
while (buffer < (unsigned char *)buffer_ + length)
*buffer++ = '\0';
}
static OF_INLINE bool
OFASCIIIsAlpha(char c)
{
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
}
static OF_INLINE bool
OFASCIIIsDigit(char c)
{
return (c >= '0' && c <= '9');
}
static OF_INLINE bool
OFASCIIIsAlnum(char c)
{
return (OFASCIIIsAlpha(c) || OFASCIIIsDigit(c));
}
static OF_INLINE bool
OFASCIIIsSpace(char c)
{
return (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' ||
c == '\v');
}
static OF_INLINE char
OFASCIIToUpper(char c)
{
return (c >= 'a' && c <= 'z' ? 'A' + (c - 'a') : c);
}
static OF_INLINE char
OFASCIIToLower(char c)
{
return (c >= 'A' && c <= 'Z' ? 'a' + (c - 'A') : c);
}
#endif
|
Changes to src/pbkdf2.m.
| ︙ | ︙ | |||
55 56 57 58 59 60 61 |
extendedSalt = [OFSecureData
dataWithCount: param.saltLength + 4
allowsSwappableMemory: param.allowsSwappableMemory];
extendedSaltItems = extendedSalt.mutableItems;
@try {
| | | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
extendedSalt = [OFSecureData
dataWithCount: param.saltLength + 4
allowsSwappableMemory: param.allowsSwappableMemory];
extendedSaltItems = extendedSalt.mutableItems;
@try {
uint32_t i = OFToBigEndian32(1);
[param.HMAC setKey: param.password
length: param.passwordLength];
memcpy(extendedSaltItems, param.salt, param.saltLength);
while (param.keyLength > 0) {
|
| ︙ | ︙ | |||
92 93 94 95 96 97 98 | if (length > param.keyLength) length = param.keyLength; memcpy(param.key, bufferItems, length); param.key += length; param.keyLength -= length; | | | 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
if (length > param.keyLength)
length = param.keyLength;
memcpy(param.key, bufferItems, length);
param.key += length;
param.keyLength -= length;
i = OFToBigEndian32(OFFromBigEndian32(i) + 1);
}
} @catch (id e) {
[extendedSalt zero];
[buffer zero];
[digest zero];
@throw e;
} @finally {
[param.HMAC zero];
}
objc_autoreleasePoolPop(pool);
}
|
Changes to src/platform/amiga/thread.m.
| ︙ | ︙ | |||
30 31 32 33 34 35 36 |
#ifndef OF_MORPHOS
extern void OFTLSKeyThreadExited(void);
#endif
static OFTLSKey threadKey;
OF_CONSTRUCTOR()
{
| | | | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#ifndef OF_MORPHOS
extern void OFTLSKeyThreadExited(void);
#endif
static OFTLSKey threadKey;
OF_CONSTRUCTOR()
{
OFEnsure(OFTLSKeyNew(&threadKey) == 0);
}
static void
functionWrapper(void)
{
bool detached = false;
OFPlainThread thread =
(OFPlainThread)((struct Process *)FindTask(NULL))->pr_ExitData;
OFEnsure(OFTLSKeySet(threadKey, thread) == 0);
thread->function(thread->object);
ObtainSemaphore(&thread->semaphore);
@try {
thread->done = true;
|
| ︙ | ︙ |
Changes to src/platform/windows/condition.m.
| ︙ | ︙ | |||
36 37 38 39 40 41 42 |
OFPlainConditionSignal(OFPlainCondition *condition)
{
if (!SetEvent(condition->event)) {
switch (GetLastError()) {
case ERROR_INVALID_HANDLE:
return EINVAL;
default:
| | | | 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 |
OFPlainConditionSignal(OFPlainCondition *condition)
{
if (!SetEvent(condition->event)) {
switch (GetLastError()) {
case ERROR_INVALID_HANDLE:
return EINVAL;
default:
OFEnsure(0);
}
}
return 0;
}
int
OFPlainConditionBroadcast(OFPlainCondition *condition)
{
int count = condition->count;
for (int i = 0; i < count; i++) {
if (!SetEvent(condition->event)) {
switch (GetLastError()) {
case ERROR_INVALID_HANDLE:
return EINVAL;
default:
OFEnsure(0);
}
}
}
return 0;
}
|
| ︙ | ︙ | |||
83 84 85 86 87 88 89 |
case WAIT_OBJECT_0:
return OFPlainMutexLock(mutex);
case WAIT_FAILED:
switch (GetLastError()) {
case ERROR_INVALID_HANDLE:
return EINVAL;
default:
| | | | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
case WAIT_OBJECT_0:
return OFPlainMutexLock(mutex);
case WAIT_FAILED:
switch (GetLastError()) {
case ERROR_INVALID_HANDLE:
return EINVAL;
default:
OFEnsure(0);
}
default:
OFEnsure(0);
}
}
int
OFPlainConditionTimedWait(OFPlainCondition *condition, OFPlainMutex *mutex,
OFTimeInterval timeout)
{
|
| ︙ | ︙ | |||
114 115 116 117 118 119 120 |
case WAIT_TIMEOUT:
return ETIMEDOUT;
case WAIT_FAILED:
switch (GetLastError()) {
case ERROR_INVALID_HANDLE:
return EINVAL;
default:
| | | | 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
case WAIT_TIMEOUT:
return ETIMEDOUT;
case WAIT_FAILED:
switch (GetLastError()) {
case ERROR_INVALID_HANDLE:
return EINVAL;
default:
OFEnsure(0);
}
default:
OFEnsure(0);
}
}
int
OFPlainConditionFree(OFPlainCondition *condition)
{
if (condition->count != 0)
return EBUSY;
return (CloseHandle(condition->event) ? 0 : EINVAL);
}
|
Changes to src/platform/windows/thread.m.
| ︙ | ︙ | |||
82 83 84 85 86 87 88 | case ERROR_NOT_ENOUGH_MEMORY: error = ENOMEM; break; case ERROR_ACCESS_DENIED: error = EACCES; break; default: | | | | | | 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 |
case ERROR_NOT_ENOUGH_MEMORY:
error = ENOMEM;
break;
case ERROR_ACCESS_DENIED:
error = EACCES;
break;
default:
OFEnsure(0);
}
free(context);
return error;
}
if (attr != NULL && attr->priority != 0)
OFEnsure(!SetThreadPriority(*thread, priority));
return 0;
}
int
OFPlainThreadJoin(OFPlainThread thread)
{
switch (WaitForSingleObject(thread, INFINITE)) {
case WAIT_OBJECT_0:
CloseHandle(thread);
return 0;
case WAIT_FAILED:
switch (GetLastError()) {
case ERROR_INVALID_HANDLE:
return EINVAL;
default:
OFEnsure(0);
}
default:
OFEnsure(0);
}
}
int
OFPlainThreadDetach(OFPlainThread thread)
{
CloseHandle(thread);
|
| ︙ | ︙ |
Changes to src/runtime/autorelease.m.
| ︙ | ︙ | |||
47 48 49 50 51 52 53 |
static uintptr_t count = 0;
static uintptr_t size = 0;
#endif
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OF_CONSTRUCTOR()
{
| | | | | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
static uintptr_t count = 0;
static uintptr_t size = 0;
#endif
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OF_CONSTRUCTOR()
{
OFEnsure(OFTLSKeyNew(&objectsKey) == 0);
OFEnsure(OFTLSKeyNew(&countKey) == 0);
OFEnsure(OFTLSKeyNew(&sizeKey) == 0);
}
#endif
void *
objc_autoreleasePoolPush()
{
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
|
| ︙ | ︙ | |||
94 95 96 97 98 99 100 |
if (freeMem) {
free(objects);
objects = NULL;
#if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS)
size = 0;
#else
| | | | | | | | | 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 |
if (freeMem) {
free(objects);
objects = NULL;
#if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS)
size = 0;
#else
OFEnsure(OFTLSKeySet(objectsKey, objects) == 0);
OFEnsure(OFTLSKeySet(sizeKey, (void *)0) == 0);
#endif
}
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OFEnsure(OFTLSKeySet(countKey, (void *)count) == 0);
#endif
}
id
_objc_rootAutorelease(id object)
{
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
id *objects = OFTLSKeyGet(objectsKey);
uintptr_t count = (uintptr_t)OFTLSKeyGet(countKey);
uintptr_t size = (uintptr_t)OFTLSKeyGet(sizeKey);
#endif
if (count >= size) {
if (size == 0)
size = 16;
else
size *= 2;
OFEnsure((objects =
realloc(objects, size * sizeof(id))) != NULL);
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OFEnsure(OFTLSKeySet(objectsKey, objects) == 0);
OFEnsure(OFTLSKeySet(sizeKey, (void *)size) == 0);
#endif
}
objects[count++] = object;
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OFEnsure(OFTLSKeySet(countKey, (void *)count) == 0);
#endif
return object;
}
|
Changes to src/runtime/class.m.
| ︙ | ︙ | |||
627 628 629 630 631 632 633 |
objc_global_mutex_lock();
if ((ret = malloc((classesCount + 1) * sizeof(Class))) == NULL)
OBJC_ERROR("Failed to allocate memory for class list!");
count = objc_getClassList(ret, classesCount);
| | | 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
objc_global_mutex_lock();
if ((ret = malloc((classesCount + 1) * sizeof(Class))) == NULL)
OBJC_ERROR("Failed to allocate memory for class list!");
count = objc_getClassList(ret, classesCount);
OFEnsure(count == classesCount);
ret[count] = Nil;
if (length != NULL)
*length = count;
objc_global_mutex_unlock();
|
| ︙ | ︙ | |||
972 973 974 975 976 977 978 | * UINT32_MAX so that it will get increased at the end * of the loop and thus become 0. */ i = UINT32_MAX; } } | | | 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 |
* UINT32_MAX so that it will get increased at the end
* of the loop and thus become 0.
*/
i = UINT32_MAX;
}
}
OFEnsure(classesCount == 0);
if (emptyDTable != NULL) {
objc_dtable_free(emptyDTable);
emptyDTable = NULL;
}
objc_sparsearray_free(fastPath);
fastPath = NULL;
objc_hashtable_free(classes);
classes = NULL;
}
|
Changes to src/runtime/exception.m.
| ︙ | ︙ | |||
334 335 336 337 338 339 340 |
static uint64_t
readValue(uint8_t enc, const uint8_t **ptr)
{
uint64_t value;
if (enc == DW_EH_PE_aligned) {
const uintptr_t *aligned = (const uintptr_t *)
| | | 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
static uint64_t
readValue(uint8_t enc, const uint8_t **ptr)
{
uint64_t value;
if (enc == DW_EH_PE_aligned) {
const uintptr_t *aligned = (const uintptr_t *)
OFRoundUpToPowerOf2(sizeof(void *), (uintptr_t)*ptr);
*ptr = (const uint8_t *)(aligned + 1);
return *aligned;
}
#define READ(type) \
|
| ︙ | ︙ |
Changes to src/runtime/method.m.
| ︙ | ︙ | |||
49 50 51 52 53 54 55 |
if ((methods = malloc((count + 1) * sizeof(Method))) == NULL)
OBJC_ERROR("Not enough memory to copy methods");
i = 0;
for (iter = class->methodList; iter != NULL; iter = iter->next)
for (unsigned int j = 0; j < iter->count; j++)
methods[i++] = &iter->methods[j];
| | | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
if ((methods = malloc((count + 1) * sizeof(Method))) == NULL)
OBJC_ERROR("Not enough memory to copy methods");
i = 0;
for (iter = class->methodList; iter != NULL; iter = iter->next)
for (unsigned int j = 0; j < iter->count; j++)
methods[i++] = &iter->methods[j];
OFEnsure(i == count);
methods[count] = NULL;
if (outCount != NULL)
*outCount = count;
objc_global_mutex_unlock();
|
| ︙ | ︙ |
Changes to src/runtime/property.m.
| ︙ | ︙ | |||
40 41 42 43 44 45 46 |
objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, bool atomic)
{
if (atomic) {
id *ptr = (id *)(void *)((char *)self + offset);
#ifdef OF_HAVE_THREADS
unsigned hash = SPINLOCK_HASH(ptr);
| | | | | | 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 |
objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, bool atomic)
{
if (atomic) {
id *ptr = (id *)(void *)((char *)self + offset);
#ifdef OF_HAVE_THREADS
unsigned hash = SPINLOCK_HASH(ptr);
OFEnsure(OFSpinlockLock(&spinlocks[hash]) == 0);
@try {
return [[*ptr retain] autorelease];
} @finally {
OFEnsure(OFSpinlockUnlock(&spinlocks[hash]) == 0);
}
#else
return [[*ptr retain] autorelease];
#endif
}
return *(id *)(void *)((char *)self + offset);
}
void
objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id value, bool atomic,
signed char copy)
{
if (atomic) {
id *ptr = (id *)(void *)((char *)self + offset);
#ifdef OF_HAVE_THREADS
unsigned hash = SPINLOCK_HASH(ptr);
OFEnsure(OFSpinlockLock(&spinlocks[hash]) == 0);
@try {
#endif
id old = *ptr;
switch (copy) {
case 0:
*ptr = [value retain];
break;
case 2:
*ptr = [value mutableCopy];
break;
default:
*ptr = [value copy];
}
[old release];
#ifdef OF_HAVE_THREADS
} @finally {
OFEnsure(OFSpinlockUnlock(&spinlocks[hash]) == 0);
}
#endif
return;
}
id *ptr = (id *)(void *)((char *)self + offset);
|
| ︙ | ︙ | |||
115 116 117 118 119 120 121 |
objc_getPropertyStruct(void *dest, const void *src, ptrdiff_t size, bool atomic,
bool strong)
{
if (atomic) {
#ifdef OF_HAVE_THREADS
unsigned hash = SPINLOCK_HASH(src);
| | | | | | 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 |
objc_getPropertyStruct(void *dest, const void *src, ptrdiff_t size, bool atomic,
bool strong)
{
if (atomic) {
#ifdef OF_HAVE_THREADS
unsigned hash = SPINLOCK_HASH(src);
OFEnsure(OFSpinlockLock(&spinlocks[hash]) == 0);
#endif
memcpy(dest, src, size);
#ifdef OF_HAVE_THREADS
OFEnsure(OFSpinlockUnlock(&spinlocks[hash]) == 0);
#endif
return;
}
memcpy(dest, src, size);
}
void
objc_setPropertyStruct(void *dest, const void *src, ptrdiff_t size, bool atomic,
bool strong)
{
if (atomic) {
#ifdef OF_HAVE_THREADS
unsigned hash = SPINLOCK_HASH(src);
OFEnsure(OFSpinlockLock(&spinlocks[hash]) == 0);
#endif
memcpy(dest, src, size);
#ifdef OF_HAVE_THREADS
OFEnsure(OFSpinlockUnlock(&spinlocks[hash]) == 0);
#endif
return;
}
memcpy(dest, src, size);
}
|
| ︙ | ︙ | |||
187 188 189 190 191 192 193 |
if (properties == NULL)
OBJC_ERROR("Not enough memory to copy properties");
i = 0;
for (iter = class->propertyList; iter != NULL; iter = iter->next)
for (unsigned int j = 0; j < iter->count; j++)
properties[i++] = &iter->properties[j];
| | | 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
if (properties == NULL)
OBJC_ERROR("Not enough memory to copy properties");
i = 0;
for (iter = class->propertyList; iter != NULL; iter = iter->next)
for (unsigned int j = 0; j < iter->count; j++)
properties[i++] = &iter->properties[j];
OFEnsure(i == count);
properties[count] = NULL;
if (outCount != NULL)
*outCount = count;
objc_global_mutex_unlock();
|
| ︙ | ︙ | |||
215 216 217 218 219 220 221 |
bool nullIsError = false;
if (strlen(name) != 1)
return NULL;
switch (*name) {
case 'T':
| | | | | 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 |
bool nullIsError = false;
if (strlen(name) != 1)
return NULL;
switch (*name) {
case 'T':
ret = OFStrdup(property->getter.typeEncoding);
nullIsError = true;
break;
case 'G':
if (property->attributes & OBJC_PROPERTY_GETTER) {
ret = OFStrdup(property->getter.name);
nullIsError = true;
}
break;
case 'S':
if (property->attributes & OBJC_PROPERTY_SETTER) {
ret = OFStrdup(property->setter.name);
nullIsError = true;
}
break;
#define BOOL_CASE(name, field, flag) \
case name: \
if (property->field & flag) { \
ret = calloc(1, 1); \
|
| ︙ | ︙ |
Changes to src/runtime/selector.m.
| ︙ | ︙ | |||
79 80 81 82 83 84 85 |
objc_global_mutex_unlock();
return (SEL)selector;
}
if ((selector = malloc(sizeof(*selector))) == NULL)
OBJC_ERROR("Not enough memory to allocate selector!");
| | | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
objc_global_mutex_unlock();
return (SEL)selector;
}
if ((selector = malloc(sizeof(*selector))) == NULL)
OBJC_ERROR("Not enough memory to allocate selector!");
if ((selector->UID = (uintptr_t)OFStrdup(name)) == 0)
OBJC_ERROR("Not enough memory to allocate selector!");
selector->typeEncoding = NULL;
if ((freeList = realloc(freeList,
sizeof(void *) * (freeListCount + 2))) == NULL)
OBJC_ERROR("Not enough memory to allocate selector!");
|
| ︙ | ︙ |
Changes to src/scrypt.m.
| ︙ | ︙ | |||
28 29 30 31 32 33 34 |
void
OFSalsa20_8Core(uint32_t buffer[16])
{
uint32_t tmp[16];
for (uint_fast8_t i = 0; i < 16; i++)
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 |
void
OFSalsa20_8Core(uint32_t buffer[16])
{
uint32_t tmp[16];
for (uint_fast8_t i = 0; i < 16; i++)
tmp[i] = OFToLittleEndian32(buffer[i]);
for (uint_fast8_t i = 0; i < 8; i += 2) {
tmp[ 4] ^= OFRotateLeft(tmp[ 0] + tmp[12], 7);
tmp[ 8] ^= OFRotateLeft(tmp[ 4] + tmp[ 0], 9);
tmp[12] ^= OFRotateLeft(tmp[ 8] + tmp[ 4], 13);
tmp[ 0] ^= OFRotateLeft(tmp[12] + tmp[ 8], 18);
tmp[ 9] ^= OFRotateLeft(tmp[ 5] + tmp[ 1], 7);
tmp[13] ^= OFRotateLeft(tmp[ 9] + tmp[ 5], 9);
tmp[ 1] ^= OFRotateLeft(tmp[13] + tmp[ 9], 13);
tmp[ 5] ^= OFRotateLeft(tmp[ 1] + tmp[13], 18);
tmp[14] ^= OFRotateLeft(tmp[10] + tmp[ 6], 7);
tmp[ 2] ^= OFRotateLeft(tmp[14] + tmp[10], 9);
tmp[ 6] ^= OFRotateLeft(tmp[ 2] + tmp[14], 13);
tmp[10] ^= OFRotateLeft(tmp[ 6] + tmp[ 2], 18);
tmp[ 3] ^= OFRotateLeft(tmp[15] + tmp[11], 7);
tmp[ 7] ^= OFRotateLeft(tmp[ 3] + tmp[15], 9);
tmp[11] ^= OFRotateLeft(tmp[ 7] + tmp[ 3], 13);
tmp[15] ^= OFRotateLeft(tmp[11] + tmp[ 7], 18);
tmp[ 1] ^= OFRotateLeft(tmp[ 0] + tmp[ 3], 7);
tmp[ 2] ^= OFRotateLeft(tmp[ 1] + tmp[ 0], 9);
tmp[ 3] ^= OFRotateLeft(tmp[ 2] + tmp[ 1], 13);
tmp[ 0] ^= OFRotateLeft(tmp[ 3] + tmp[ 2], 18);
tmp[ 6] ^= OFRotateLeft(tmp[ 5] + tmp[ 4], 7);
tmp[ 7] ^= OFRotateLeft(tmp[ 6] + tmp[ 5], 9);
tmp[ 4] ^= OFRotateLeft(tmp[ 7] + tmp[ 6], 13);
tmp[ 5] ^= OFRotateLeft(tmp[ 4] + tmp[ 7], 18);
tmp[11] ^= OFRotateLeft(tmp[10] + tmp[ 9], 7);
tmp[ 8] ^= OFRotateLeft(tmp[11] + tmp[10], 9);
tmp[ 9] ^= OFRotateLeft(tmp[ 8] + tmp[11], 13);
tmp[10] ^= OFRotateLeft(tmp[ 9] + tmp[ 8], 18);
tmp[12] ^= OFRotateLeft(tmp[15] + tmp[14], 7);
tmp[13] ^= OFRotateLeft(tmp[12] + tmp[15], 9);
tmp[14] ^= OFRotateLeft(tmp[13] + tmp[12], 13);
tmp[15] ^= OFRotateLeft(tmp[14] + tmp[13], 18);
}
for (uint_fast8_t i = 0; i < 16; i++)
buffer[i] = OFToLittleEndian32(OFFromLittleEndian32(buffer[i]) +
tmp[i]);
OFZeroMemory(tmp, sizeof(tmp));
}
void
OFScryptBlockMix(uint32_t *output, const uint32_t *input, size_t blockSize)
{
uint32_t tmp[16];
|
| ︙ | ︙ | |||
98 99 100 101 102 103 104 | /* * Even indices are stored in the first half and odd ones in * the second. */ memcpy(output + ((i / 2) + (i & 1) * blockSize) * 16, tmp, 64); } | | | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
/*
* Even indices are stored in the first half and odd ones in
* the second.
*/
memcpy(output + ((i / 2) + (i & 1) * blockSize) * 16, tmp, 64);
}
OFZeroMemory(tmp, sizeof(tmp));
}
void
OFScryptROMix(uint32_t *buffer, size_t blockSize, size_t costFactor,
uint32_t *tmp)
{
/* Check defined here and executed in OFScrypt() */
|
| ︙ | ︙ | |||
120 121 122 123 124 125 126 |
for (size_t i = 0; i < costFactor; i++) {
memcpy(tmp2 + i * 32 * blockSize, tmp, 128 * blockSize);
OFScryptBlockMix(tmp, tmp2 + i * 32 * blockSize, blockSize);
}
for (size_t i = 0; i < costFactor; i++) {
| | | | 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
for (size_t i = 0; i < costFactor; i++) {
memcpy(tmp2 + i * 32 * blockSize, tmp, 128 * blockSize);
OFScryptBlockMix(tmp, tmp2 + i * 32 * blockSize, blockSize);
}
for (size_t i = 0; i < costFactor; i++) {
uint32_t j = OFFromLittleEndian32(
tmp[(2 * blockSize - 1) * 16]) & (costFactor - 1);
for (size_t k = 0; k < 32 * blockSize; k++)
tmp[k] ^= tmp2[j * 32 * blockSize + k];
OFScryptBlockMix(buffer, tmp, blockSize);
if (i < costFactor - 1)
|
| ︙ | ︙ |
Changes to src/socket.m.
| ︙ | ︙ | |||
364 365 366 367 368 369 370 | #if defined(OF_WII) || defined(OF_NINTENDO_3DS) ret.length = 8; #else ret.length = sizeof(ret.sockaddr.in); #endif addrIn->sin_family = AF_INET; | | | 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | #if defined(OF_WII) || defined(OF_NINTENDO_3DS) ret.length = 8; #else ret.length = sizeof(ret.sockaddr.in); #endif addrIn->sin_family = AF_INET; addrIn->sin_port = OFToBigEndian16(port); #ifdef OF_WII addrIn->sin_len = ret.length; #endif components = [IPv4 componentsSeparatedByString: @"."]; if (components.count != 4) |
| ︙ | ︙ | |||
394 395 396 397 398 399 400 | if (number > UINT8_MAX) @throw [OFInvalidFormatException exception]; addr = (addr << 8) | ((uint32_t)number & 0xFF); } | | | 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | if (number > UINT8_MAX) @throw [OFInvalidFormatException exception]; addr = (addr << 8) | ((uint32_t)number & 0xFF); } addrIn->sin_addr.s_addr = OFToBigEndian32(addr); objc_autoreleasePoolPop(pool); return ret; } static uint16_t |
| ︙ | ︙ | |||
435 436 437 438 439 440 441 | ret.length = sizeof(ret.sockaddr.in6); #ifdef AF_INET6 addrIn6->sin6_family = AF_INET6; #else addrIn6->sin6_family = AF_UNSPEC; #endif | | | 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
ret.length = sizeof(ret.sockaddr.in6);
#ifdef AF_INET6
addrIn6->sin6_family = AF_INET6;
#else
addrIn6->sin6_family = AF_UNSPEC;
#endif
addrIn6->sin6_port = OFToBigEndian16(port);
doubleColon = [IPv6 rangeOfString: @"::"].location;
if (doubleColon != OFNotFound) {
OFString *left = [IPv6 substringToIndex: doubleColon];
OFString *right = [IPv6 substringFromIndex: doubleColon + 2];
OFArray OF_GENERIC(OFString *) *leftComponents;
|
| ︙ | ︙ | |||
527 528 529 530 531 532 533 | #ifdef AF_IPX ret.sockaddr.ipx.sipx_family = AF_IPX; #else ret.sockaddr.ipx.sipx_family = AF_UNSPEC; #endif memcpy(ret.sockaddr.ipx.sipx_node, node, IPX_NODE_LEN); | | | | 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
#ifdef AF_IPX
ret.sockaddr.ipx.sipx_family = AF_IPX;
#else
ret.sockaddr.ipx.sipx_family = AF_UNSPEC;
#endif
memcpy(ret.sockaddr.ipx.sipx_node, node, IPX_NODE_LEN);
network = OFToBigEndian32(network);
memcpy(&ret.sockaddr.ipx.sipx_network, &network,
sizeof(ret.sockaddr.ipx.sipx_network));
ret.sockaddr.ipx.sipx_port = OFToBigEndian16(port);
return ret;
}
bool
OFSocketAddressEqual(const OFSocketAddress *address1,
const OFSocketAddress *address2)
|
| ︙ | ︙ | |||
610 611 612 613 614 615 616 |
return true;
}
unsigned long
OFSocketAddressHash(const OFSocketAddress *address)
{
| | | | | | | | | | | | | | | | | | | | 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 |
return true;
}
unsigned long
OFSocketAddressHash(const OFSocketAddress *address)
{
unsigned long hash;
OFHashInit(&hash);
OFHashAdd(&hash, address->family);
switch (address->family) {
case OFSocketAddressFamilyIPv4:
#if defined(OF_WII) || defined(OF_NINTENDO_3DS)
if (address->length < 8)
@throw [OFInvalidArgumentException exception];
#else
if (address->length < (socklen_t)sizeof(struct sockaddr_in))
@throw [OFInvalidArgumentException exception];
#endif
OFHashAdd(&hash, address->sockaddr.in.sin_port >> 8);
OFHashAdd(&hash, address->sockaddr.in.sin_port);
OFHashAdd(&hash, address->sockaddr.in.sin_addr.s_addr >> 24);
OFHashAdd(&hash, address->sockaddr.in.sin_addr.s_addr >> 16);
OFHashAdd(&hash, address->sockaddr.in.sin_addr.s_addr >> 8);
OFHashAdd(&hash, address->sockaddr.in.sin_addr.s_addr);
break;
case OFSocketAddressFamilyIPv6:
if (address->length < (socklen_t)sizeof(struct sockaddr_in6))
@throw [OFInvalidArgumentException exception];
OFHashAdd(&hash, address->sockaddr.in6.sin6_port >> 8);
OFHashAdd(&hash, address->sockaddr.in6.sin6_port);
for (size_t i = 0;
i < sizeof(address->sockaddr.in6.sin6_addr.s6_addr); i++)
OFHashAdd(&hash,
address->sockaddr.in6.sin6_addr.s6_addr[i]);
break;
case OFSocketAddressFamilyIPX:;
unsigned char network[
sizeof(address->sockaddr.ipx.sipx_network)];
if (address->length < (socklen_t)sizeof(struct sockaddr_ipx))
@throw [OFInvalidArgumentException exception];
OFHashAdd(&hash, address->sockaddr.ipx.sipx_port >> 8);
OFHashAdd(&hash, address->sockaddr.ipx.sipx_port);
memcpy(network, &address->sockaddr.ipx.sipx_network,
sizeof(network));
for (size_t i = 0; i < sizeof(network); i++)
OFHashAdd(&hash, network[i]);
for (size_t i = 0; i < IPX_NODE_LEN; i++)
OFHashAdd(&hash, address->sockaddr.ipx.sipx_node[i]);
break;
default:
@throw [OFInvalidArgumentException exception];
}
OFHashFinalize(&hash);
return hash;
}
static OFString *
IPv4String(const OFSocketAddress *address)
{
const struct sockaddr_in *addrIn = &address->sockaddr.in;
uint32_t addr = OFFromBigEndian32(addrIn->sin_addr.s_addr);
OFString *string;
string = [OFString stringWithFormat: @"%u.%u.%u.%u",
(addr & 0xFF000000) >> 24, (addr & 0x00FF0000) >> 16,
(addr & 0x0000FF00) >> 8, addr & 0x000000FF];
return string;
|
| ︙ | ︙ | |||
774 775 776 777 778 779 780 |
}
void
OFSocketAddressSetPort(OFSocketAddress *address, uint16_t port)
{
switch (address->family) {
case OFSocketAddressFamilyIPv4:
| | | | | | | | | | 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 |
}
void
OFSocketAddressSetPort(OFSocketAddress *address, uint16_t port)
{
switch (address->family) {
case OFSocketAddressFamilyIPv4:
address->sockaddr.in.sin_port = OFToBigEndian16(port);
break;
case OFSocketAddressFamilyIPv6:
address->sockaddr.in6.sin6_port = OFToBigEndian16(port);
break;
case OFSocketAddressFamilyIPX:
address->sockaddr.ipx.sipx_port = OFToBigEndian16(port);
break;
default:
@throw [OFInvalidArgumentException exception];
}
}
uint16_t
OFSocketAddressPort(const OFSocketAddress *address)
{
switch (address->family) {
case OFSocketAddressFamilyIPv4:
return OFFromBigEndian16(address->sockaddr.in.sin_port);
case OFSocketAddressFamilyIPv6:
return OFFromBigEndian16(address->sockaddr.in6.sin6_port);
case OFSocketAddressFamilyIPX:
return OFFromBigEndian16(address->sockaddr.ipx.sipx_port);
default:
@throw [OFInvalidArgumentException exception];
}
}
void
OFSocketAddressSetIPXNetwork(OFSocketAddress *address, uint32_t network)
{
if (address->family != OFSocketAddressFamilyIPX)
@throw [OFInvalidArgumentException exception];
network = OFToBigEndian32(network);
memcpy(&address->sockaddr.ipx.sipx_network, &network,
sizeof(address->sockaddr.ipx.sipx_network));
}
uint32_t
OFSocketAddressIPXNetwork(const OFSocketAddress *address)
{
uint32_t network;
if (address->family != OFSocketAddressFamilyIPX)
@throw [OFInvalidArgumentException exception];
memcpy(&network, &address->sockaddr.ipx.sipx_network, sizeof(network));
return OFFromBigEndian32(network);
}
void
OFSocketAddressSetIPXNode(OFSocketAddress *address,
const unsigned char node[IPX_NODE_LEN])
{
if (address->family != OFSocketAddressFamilyIPX)
|
| ︙ | ︙ |
Changes to tests/ForwardingTests.m.
| ︙ | ︙ | |||
123 124 125 126 127 128 129 |
@implementation ForwardingTarget
- (uint32_t)forwardingTargetTest: (intptr_t)a0
: (intptr_t)a1
: (double)a2
: (double)a3
{
| | | | | | 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 |
@implementation ForwardingTarget
- (uint32_t)forwardingTargetTest: (intptr_t)a0
: (intptr_t)a1
: (double)a2
: (double)a3
{
OFEnsure(self == target);
if (a0 != (intptr_t)0xDEADBEEF)
return 0;
if (a1 != -1)
return 0;
if (a2 != 1.25)
return 0;
if (a3 != 2.75)
return 0;
return 0x12345678;
}
- (OFString *)forwardingTargetVarArgTest: (OFConstantString *)fmt, ...
{
va_list args;
OFString *ret;
OFEnsure(self == target);
va_start(args, fmt);
ret = [[[OFString alloc] initWithFormat: fmt
arguments: args] autorelease];
va_end(args);
return ret;
}
- (long double)forwardingTargetFPRetTest
{
OFEnsure(self == target);
return 12345678.00006103515625;
}
- (struct stret_test)forwardingTargetStRetTest
{
struct stret_test ret = { { 0 } };
OFEnsure(self == target);
memcpy(ret.s, "abcdefghijklmnopqrstuvwxyz", 27);
return ret;
}
@end
|
| ︙ | ︙ |
Changes to tests/OFHTTPClientTests.m.
| ︙ | ︙ | |||
48 49 50 51 52 53 54 | [cond signal]; [cond unlock]; client = [listener accept]; if (![[client readLine] isEqual: @"GET /foo HTTP/1.1"]) | | | | | | | | | 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 | [cond signal]; [cond unlock]; client = [listener accept]; if (![[client readLine] isEqual: @"GET /foo HTTP/1.1"]) OFEnsure(0); if (![[client readLine] hasPrefix: @"User-Agent:"]) OFEnsure(0); if (![[client readLine] isEqual: @"Content-Length: 5"]) OFEnsure(0); if (![[client readLine] isEqual: @"Content-Type: application/x-www-form-urlencoded; charset=UTF-8"]) OFEnsure(0); if (![[client readLine] isEqual: [OFString stringWithFormat: @"Host: 127.0.0.1:%" @PRIu16, _port]]) OFEnsure(0); if (![[client readLine] isEqual: @""]) OFEnsure(0); [client readIntoBuffer: buffer exactLength: 5]; if (memcmp(buffer, "Hello", 5) != 0) OFEnsure(0); [client writeString: @"HTTP/1.0 200 OK\r\n" @"cONTeNT-lENgTH: 7\r\n" @"\r\n" @"foo\n" @"bar"]; [client close]; |
| ︙ | ︙ | |||
95 96 97 98 99 100 101 |
}
- (void)client: (OFHTTPClient *)client
didPerformRequest: (OFHTTPRequest *)request
response: (OFHTTPResponse *)response_
exception: (id)exception
{
| | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
}
- (void)client: (OFHTTPClient *)client
didPerformRequest: (OFHTTPRequest *)request
response: (OFHTTPResponse *)response_
exception: (id)exception
{
OFEnsure(exception == nil);
response = [response_ retain];
[[OFRunLoop mainRunLoop] stop];
}
- (void)HTTPClientTests
|
| ︙ | ︙ |
Changes to tests/OFKernelEventObserverTests.m.
| ︙ | ︙ | |||
178 179 180 181 182 183 184 | outputFailure: @"-[observe] with closed connection" inModule: module]; _fails++; } break; default: | | | 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
outputFailure: @"-[observe] with closed connection"
inModule: module];
_fails++;
}
break;
default:
OFEnsure(0);
}
}
@end
@implementation TestsAppDelegate (OFKernelEventObserverTests)
- (void)kernelEventObserverTestsWithClass: (Class)class
{
|
| ︙ | ︙ |
Changes to tests/OFSPXSocketTests.m.
| ︙ | ︙ | |||
35 36 37 38 39 40 41 |
@end
@implementation SPXSocketDelegate
- (bool)socket: (OFSequencedPacketSocket *)sock
didAcceptSocket: (OFSequencedPacketSocket *)accepted
exception: (id)exception
{
| | | | 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 |
@end
@implementation SPXSocketDelegate
- (bool)socket: (OFSequencedPacketSocket *)sock
didAcceptSocket: (OFSequencedPacketSocket *)accepted
exception: (id)exception
{
OFEnsure(!_accepted);
_accepted = (sock == _expectedServerSocket && accepted != nil &&
exception == nil);
if (_accepted && _connected)
[[OFRunLoop mainRunLoop] stop];
return false;
}
- (void)socket: (OFSPXSocket *)sock
didConnectToNode: (unsigned char [IPX_NODE_LEN])node
network: (uint32_t)network
port: (uint16_t)port
exception: (id)exception
{
OFEnsure(!_connected);
_connected = (sock == _expectedClientSocket &&
memcmp(node, _expectedNode, IPX_NODE_LEN) == 0 &&
network == _expectedNetwork && port == _expectedPort &&
exception == nil);
if (_accepted && _connected)
|
| ︙ | ︙ |
Changes to tests/OFSPXStreamSocketTests.m.
| ︙ | ︙ | |||
35 36 37 38 39 40 41 |
@end
@implementation SPXStreamSocketDelegate
- (bool)socket: (OFStreamSocket *)sock
didAcceptSocket: (OFStreamSocket *)accepted
exception: (id)exception
{
| | | | 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 |
@end
@implementation SPXStreamSocketDelegate
- (bool)socket: (OFStreamSocket *)sock
didAcceptSocket: (OFStreamSocket *)accepted
exception: (id)exception
{
OFEnsure(!_accepted);
_accepted = (sock == _expectedServerSocket && accepted != nil &&
exception == nil);
if (_accepted && _connected)
[[OFRunLoop mainRunLoop] stop];
return false;
}
- (void)socket: (OFSPXStreamSocket *)sock
didConnectToNode: (unsigned char [IPX_NODE_LEN])node
network: (uint32_t)network
port: (uint16_t)port
exception: (id)exception
{
OFEnsure(!_connected);
_connected = (sock == _expectedClientSocket &&
memcmp(node, _expectedNode, IPX_NODE_LEN) == 0 &&
network == _expectedNetwork && port == _expectedPort &&
exception == nil);
if (_accepted && _connected)
|
| ︙ | ︙ |
Changes to tests/OFXMLElementBuilderTests.m.
| ︙ | ︙ | |||
21 22 23 24 25 26 27 |
static OFXMLNode *nodes[2];
static size_t i = 0;
@implementation TestsAppDelegate (OFXMLElementBuilderTests)
- (void)elementBuilder: (OFXMLElementBuilder *)builder
didBuildElement: (OFXMLElement *)element
{
| | | | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
static OFXMLNode *nodes[2];
static size_t i = 0;
@implementation TestsAppDelegate (OFXMLElementBuilderTests)
- (void)elementBuilder: (OFXMLElementBuilder *)builder
didBuildElement: (OFXMLElement *)element
{
OFEnsure(i == 0);
nodes[i++] = [element retain];
}
- (void)elementBuilder: (OFXMLElementBuilder *)builder
didBuildParentlessNode: (OFXMLNode *)node
{
OFEnsure(i == 1);
nodes[i++] = [node retain];
}
- (void)XMLElementBuilderTests
{
void *pool = objc_autoreleasePoolPush();
OFXMLParser *p = [OFXMLParser parser];
|
| ︙ | ︙ |
Changes to tests/SocketTests.m.
| ︙ | ︙ | |||
58 59 60 61 62 63 64 |
- (void)socketTests
{
void *pool = objc_autoreleasePoolPush();
OFSocketAddress addr;
TEST(@"Parsing an IPv4",
R(addr = OFSocketAddressParseIP(@"127.0.0.1", 1234)) &&
| | | | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
- (void)socketTests
{
void *pool = objc_autoreleasePoolPush();
OFSocketAddress addr;
TEST(@"Parsing an IPv4",
R(addr = OFSocketAddressParseIP(@"127.0.0.1", 1234)) &&
OFFromBigEndian32(addr.sockaddr.in.sin_addr.s_addr) == 0x7F000001 &&
OFFromBigEndian16(addr.sockaddr.in.sin_port) == 1234)
EXPECT_EXCEPTION(@"Refusing invalid IPv4 #1", OFInvalidFormatException,
OFSocketAddressParseIP(@"127.0.0.0.1", 1234))
EXPECT_EXCEPTION(@"Refusing invalid IPv4 #2", OFInvalidFormatException,
OFSocketAddressParseIP(@"127.0.0.256", 1234))
|
| ︙ | ︙ | |||
89 90 91 92 93 94 95 | [OFSocketAddressString(&addr) isEqual: @"127.0.0.1"]) TEST(@"Parsing an IPv6 #1", R(addr = OFSocketAddressParseIP( @"1122:3344:5566:7788:99aa:bbCc:ddee:ff00", 1234)) && COMPARE_V6(addr, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) && | | | | | | | 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 | [OFSocketAddressString(&addr) isEqual: @"127.0.0.1"]) TEST(@"Parsing an IPv6 #1", R(addr = OFSocketAddressParseIP( @"1122:3344:5566:7788:99aa:bbCc:ddee:ff00", 1234)) && COMPARE_V6(addr, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) && OFFromBigEndian16(addr.sockaddr.in6.sin6_port) == 1234) TEST(@"Parsing an IPv6 #2", R(addr = OFSocketAddressParseIP(@"::", 1234)) && COMPARE_V6(addr, 0, 0, 0, 0, 0, 0, 0, 0) && OFFromBigEndian16(addr.sockaddr.in6.sin6_port) == 1234) TEST(@"Parsing an IPv6 #3", R(addr = OFSocketAddressParseIP(@"aaAa::bBbb", 1234)) && COMPARE_V6(addr, 0xAAAA, 0, 0, 0, 0, 0, 0, 0xBBBB) && OFFromBigEndian16(addr.sockaddr.in6.sin6_port) == 1234) TEST(@"Parsing an IPv6 #4", R(addr = OFSocketAddressParseIP(@"aaAa::", 1234)) && COMPARE_V6(addr, 0xAAAA, 0, 0, 0, 0, 0, 0, 0) && OFFromBigEndian16(addr.sockaddr.in6.sin6_port) == 1234) TEST(@"Parsing an IPv6 #5", R(addr = OFSocketAddressParseIP(@"::aaAa", 1234)) && COMPARE_V6(addr, 0, 0, 0, 0, 0, 0, 0, 0xAAAA) && OFFromBigEndian16(addr.sockaddr.in6.sin6_port) == 1234) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #1", OFInvalidFormatException, OFSocketAddressParseIP(@"1:::2", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #2", OFInvalidFormatException, OFSocketAddressParseIP(@"1: ::2", 1234)) |
| ︙ | ︙ |