Differences From Artifact [996b4908b2]:
- File src/OFDate.m — part of check-in [83f4c928a6] at 2020-09-29 22:28:56 on branch trunk — OFDate: Use more autorelease pools (user: js, size: 20163) [annotate] [blame] [check-ins using] [more...]
To Artifact [cf1b1da641]:
- File
src/OFDate.m
— part of check-in
[3d8286feee]
at
2020-11-04 23:18:25
on branch trunk
— Remove of_free()
While it makes sense to wrap malloc and calloc to replace the error
checking with exceptions, it does not make sense to wrap free. (user: js, size: 20087) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
219 220 221 222 223 224 225 | 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, }; static double | | | 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, }; static double tmAndTzToTime(const struct tm *tm, short tz) { double seconds; /* Years */ seconds = (int64_t)(tm->tm_year - 70) * 31536000; /* Days of leap years, excluding the year to look at */ seconds += (((tm->tm_year + 1899) / 4) - 492) * 86400; |
︙ | ︙ | |||
247 248 249 250 251 252 253 | /* Hours */ seconds += tm->tm_hour * 3600; /* Minutes */ seconds += tm->tm_min * 60; /* Seconds */ seconds += tm->tm_sec; /* Time zone */ | | | 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | /* Hours */ seconds += tm->tm_hour * 3600; /* Minutes */ seconds += tm->tm_min * 60; /* Seconds */ seconds += tm->tm_sec; /* Time zone */ seconds += -(double)tz * 60; return seconds; } @implementation OFDateSingleton - (instancetype)autorelease { |
︙ | ︙ | |||
438 439 440 441 442 443 444 | - (instancetype)initWithDateString: (OFString *)string format: (OFString *)format { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; struct tm tm = { .tm_isdst = -1 }; | | | | | | | | 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 | - (instancetype)initWithDateString: (OFString *)string format: (OFString *)format { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; struct tm tm = { .tm_isdst = -1 }; short tz = 0; if (of_strptime(UTF8String, format.UTF8String, &tm, &tz) != UTF8String + string.UTF8StringLength) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return [self initWithTimeIntervalSince1970: tmAndTzToTime(&tm, tz)]; } - (instancetype)initWithLocalDateString: (OFString *)string format: (OFString *)format { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; struct tm tm = { .tm_isdst = -1 }; /* * of_strptime() can never set this to SHRT_MAX, no matter what is * passed to it, so this is a safe way to figure out if the date * contains a time zone. */ short tz = SHRT_MAX; of_time_interval_t seconds; if (of_strptime(UTF8String, format.UTF8String, &tm, &tz) != UTF8String + string.UTF8StringLength) @throw [OFInvalidFormatException exception]; if (tz == SHRT_MAX) { #ifdef OF_WINDOWS if (func__mktime64 != NULL) { if ((seconds = func__mktime64(&tm)) == -1) @throw [OFInvalidFormatException exception]; } else { #endif if ((seconds = mktime(&tm)) == -1) @throw [OFInvalidFormatException exception]; #ifdef OF_WINDOWS } #endif } else seconds = tmAndTzToTime(&tm, tz); objc_autoreleasePoolPop(pool); return [self initWithTimeIntervalSince1970: seconds]; } - (instancetype)initWithSerialization: (OFXMLElement *)element |
︙ | ︙ | |||
534 535 536 537 538 539 540 | if (otherDate.timeIntervalSince1970 != self.timeIntervalSince1970) return false; return true; } | | | 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 | if (otherDate.timeIntervalSince1970 != self.timeIntervalSince1970) return false; return true; } - (unsigned long)hash { uint32_t hash; double tmp; OF_HASH_INIT(hash); tmp = OF_BSWAP_DOUBLE_IF_BE(self.timeIntervalSince1970); |
︙ | ︙ | |||
654 655 656 657 658 659 660 | [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } | | | | | | | | | | | | | | | | | | | 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 | [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (unsigned long)microsecond { of_time_interval_t timeInterval = self.timeIntervalSince1970; return (unsigned long)((timeInterval - trunc(timeInterval)) * 1000000); } - (unsigned char)second { GMTIME_RET(tm_sec) } - (unsigned char)minute { GMTIME_RET(tm_min) } - (unsigned char)localMinute { LOCALTIME_RET(tm_min) } - (unsigned char)hour { GMTIME_RET(tm_hour) } - (unsigned char)localHour { LOCALTIME_RET(tm_hour) } - (unsigned char)dayOfMonth { GMTIME_RET(tm_mday) } - (unsigned char)localDayOfMonth { LOCALTIME_RET(tm_mday) } - (unsigned char)monthOfYear { GMTIME_RET(tm_mon + 1) } - (unsigned char)localMonthOfYear { LOCALTIME_RET(tm_mon + 1) } - (unsigned short)year { GMTIME_RET(tm_year + 1900) } - (unsigned short)localYear { LOCALTIME_RET(tm_year + 1900) } - (unsigned char)dayOfWeek { GMTIME_RET(tm_wday) } - (unsigned char)localDayOfWeek { LOCALTIME_RET(tm_wday) } - (unsigned short)dayOfYear { GMTIME_RET(tm_yday + 1) } - (unsigned short)localDayOfYear { LOCALTIME_RET(tm_yday + 1) } - (OFString *)dateStringWithFormat: (OFConstantString *)format { OFString *ret; |
︙ | ︙ | |||
775 776 777 778 779 780 781 | } @finally { [mutex unlock]; } # endif #endif pageSize = [OFSystemInfo pageSize]; | < < < | | 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 | } @finally { [mutex unlock]; } # endif #endif pageSize = [OFSystemInfo pageSize]; buffer = of_malloc(1, pageSize); @try { #ifndef OF_WINDOWS if (strftime(buffer, pageSize, format.UTF8String, &tm) == 0) @throw [OFOutOfRangeException exception]; ret = [OFString stringWithUTF8String: buffer]; #else |
︙ | ︙ | |||
838 839 840 841 842 843 844 | } @finally { [mutex unlock]; } # endif #endif pageSize = [OFSystemInfo pageSize]; | < < < | | 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 | } @finally { [mutex unlock]; } # endif #endif pageSize = [OFSystemInfo pageSize]; buffer = of_malloc(1, pageSize); @try { #ifndef OF_WINDOWS if (strftime(buffer, pageSize, format.UTF8String, &tm) == 0) @throw [OFOutOfRangeException exception]; ret = [OFString stringWithUTF8String: buffer]; #else |
︙ | ︙ |