Differences From Artifact [8f9360fade]:
- File
src/OFString.m
— part of check-in
[505137f25f]
at
2018-02-25 04:31:30
on branch trunk
— Reintroduce of_char{16,32}_t
There is no reliable way to check if C++ already defined those, as Clang
now defines char{16,32}_t even when it is not in C++ 11 mode. So we
cannot check if we are not in C++ 11 and then define them and otherwise
rely on the C++ 11 types. (user: js, size: 69675) [annotate] [blame] [check-ins using]
To Artifact [b00db1bc09]:
- File
src/OFString.m
— part of check-in
[81156ee75a]
at
2018-02-25 17:16:23
on branch trunk
— No self = [self init…] with self-releasing @catch
When using self = [self init…], this already releases self on an
exception, so using it inside of a @try / @catch block that releases
self would lead to a double-release. (user: js, size: 70307) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
901 902 903 904 905 906 907 | - (instancetype)initWithData: (OFData *)data encoding: (of_string_encoding_t)encoding { @try { if ([data itemSize] != 1) @throw [OFInvalidArgumentException exception]; | < < < < > > > > | 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 | - (instancetype)initWithData: (OFData *)data encoding: (of_string_encoding_t)encoding { @try { if ([data itemSize] != 1) @throw [OFInvalidArgumentException exception]; } @catch (id e) { [self release]; @throw e; } self = [self initWithCString: [data items] encoding: encoding length: [data count]]; return self; } - (instancetype)initWithString: (OFString *)string { OF_INVALID_INIT_METHOD |
︙ | ︙ | |||
1018 1019 1020 1021 1022 1023 1024 | encoding: (of_string_encoding_t)encoding { char *tmp; uintmax_t fileSize; @try { void *pool = objc_autoreleasePoolPush(); | | > > | > > > | > > > | > > > > > > > > > > > > | | | > | > > < | | < < < | < > > > > > > > < | > > | < < > > > > | 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 | encoding: (of_string_encoding_t)encoding { char *tmp; uintmax_t fileSize; @try { void *pool = objc_autoreleasePoolPush(); OFFile *file = nil; @try { fileSize = [[[OFFileManager defaultManager] attributesOfItemAtPath: path] fileSize]; } @catch (OFRetrieveItemAttributesFailedException *e) { @throw [OFOpenItemFailedException exceptionWithPath: path mode: @"r" errNo: errno]; } objc_autoreleasePoolPop(pool); # if UINTMAX_MAX > SIZE_MAX if (fileSize > SIZE_MAX) @throw [OFOutOfRangeException exception]; #endif /* * We need one extra byte for the terminating zero if we want * to use -[initWithUTF8StringNoCopy:length:freeWhenDone:]. */ if (SIZE_MAX - (size_t)fileSize < 1) @throw [OFOutOfRangeException exception]; if ((tmp = malloc((size_t)fileSize + 1)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: (size_t)fileSize]; @try { file = [[OFFile alloc] initWithPath: path mode: @"r"]; [file readIntoBuffer: tmp exactLength: (size_t)fileSize]; } @catch (id e) { free(tmp); @throw e; } @finally { [file release]; } tmp[(size_t)fileSize] = '\0'; } @catch (id e) { [self release]; @throw e; } if (encoding == OF_STRING_ENCODING_UTF_8) self = [self initWithUTF8StringNoCopy: tmp length: (size_t)fileSize freeWhenDone: true]; else { @try { self = [self initWithCString: tmp encoding: encoding length: (size_t)fileSize]; } @finally { free(tmp); } } return self; } #endif - (instancetype)initWithContentsOfURL: (OFURL *)URL { return [self initWithContentsOfURL: URL encoding: OF_STRING_ENCODING_AUTODETECT]; } - (instancetype)initWithContentsOfURL: (OFURL *)URL encoding: (of_string_encoding_t)encoding { void *pool = objc_autoreleasePoolPush(); OFData *data; @try { data = [OFData dataWithContentsOfURL: URL]; } @catch (id e) { [self release]; @throw e; } self = [self initWithCString: [data items] encoding: encoding length: [data count]]; objc_autoreleasePoolPop(pool); return self; } - (instancetype)initWithSerialization: (OFXMLElement *)element { void *pool = objc_autoreleasePoolPush(); OFString *stringValue; @try { if (![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exception]; if ([self isKindOfClass: [OFMutableString class]]) { if (![[element name] isEqual: @"OFMutableString"]) @throw [OFInvalidArgumentException exception]; } else { if (![[element name] isEqual: @"OFString"]) @throw [OFInvalidArgumentException exception]; } stringValue = [element stringValue]; } @catch (id e) { [self release]; @throw e; } self = [self initWithString: stringValue]; objc_autoreleasePoolPop(pool); return self; } - (size_t)of_getCString: (char *)cString maxLength: (size_t)maxLength encoding: (of_string_encoding_t)encoding |
︙ | ︙ |