Comment: | A few renames.
OFArray: OFAutoreleasePool: OFDataArray: OFObject: |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
526d04018df1b77543b844afcfd69440 |
User & Date: | js on 2009-05-23 21:53:20 |
Other Links: | manifest | tags |
2009-05-23
| ||
22:07 | Add a new convenience method to OFString. check-in: 88163bd172 user: js tags: trunk | |
21:53 | A few renames. check-in: 526d04018d user: js tags: trunk | |
21:02 | Add replaceOccurrencesOfString:withString: to OFString. check-in: bc71bde0dd user: js tags: trunk | |
Modified src/OFArray.h from [74b613ec1f] to [ac035c3b46].
︙ | ︙ | |||
96 97 98 99 100 101 102 | * \return The specified object of the OFArray */ - (id)objectAtIndex: (size_t)index; /** * \return The last object of the OFDataArray */ | | | | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | * \return The specified object of the OFArray */ - (id)objectAtIndex: (size_t)index; /** * \return The last object of the OFDataArray */ - (id)lastObject; /** * Adds an object to the OFDataArray. * * \param obj An object to add */ - addObject: (OFObject*)obj; /** * Removes the specified amount of object from the end of the OFDataArray. * * \param nobjects The number of objects to remove */ - removeNObjects: (size_t)nobjects; |
︙ | ︙ |
Modified src/OFArray.m from [dbe234c97f] to [c29a774dc8].
︙ | ︙ | |||
65 66 67 68 69 70 71 | } - initWithObject: (OFObject*)obj { self = [self init]; @try { | | | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | } - initWithObject: (OFObject*)obj { self = [self init]; @try { [array addItem: &obj]; } @catch (OFException *e) { [self dealloc]; @throw e; } [obj retain]; |
︙ | ︙ | |||
97 98 99 100 101 102 103 | andArgList: (va_list)args { id obj; self = [self init]; @try { | | | | | 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 | andArgList: (va_list)args { id obj; self = [self init]; @try { [array addItem: &first]; while ((obj = va_arg(args, id)) != nil) { [array addItem: &obj]; [obj retain]; } } @catch (OFException *e) { [self dealloc]; @throw e; } return self; } - initWithCArray: (OFObject**)objs { id *obj; self = [self init]; @try { for (obj = objs; *obj != nil; obj++) { [array addItem: obj]; [*obj retain]; } } @catch (OFException *e) { [self dealloc]; @throw e; } |
︙ | ︙ | |||
167 168 169 170 171 172 173 | } - (id)objectAtIndex: (size_t)index { return *((OFObject**)[array itemAtIndex: index]); } | | | | 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | } - (id)objectAtIndex: (size_t)index { return *((OFObject**)[array itemAtIndex: index]); } - (id)lastObject { return *((OFObject**)[array lastItem]); } - (BOOL)isEqual: (id)obj { OFObject **objs, **objs2; size_t i, len, len2; |
︙ | ︙ | |||
196 197 198 199 200 201 202 | for (i = 0; i < len; i++) if (![objs[i] isEqual: objs2[i]]) return NO; return YES; } | | | 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | for (i = 0; i < len; i++) if (![objs[i] isEqual: objs2[i]]) return NO; return YES; } - addObject: (OFObject*)obj { @throw [OFNotImplementedException newWithClass: isa andSelector: _cmd]; } - removeNObjects: (size_t)nobjects { |
︙ | ︙ |
Modified src/OFAutoreleasePool.h from [d4653e60d0] to [9729efb348].
︙ | ︙ | |||
26 27 28 29 30 31 32 | /** * Adds an object to the autorelease pool at the top of the thread-specific * stack. * * \param obj The object to add to the autorelease pool */ | | < | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | /** * Adds an object to the autorelease pool at the top of the thread-specific * stack. * * \param obj The object to add to the autorelease pool */ + (void)addObjectToTopmostPool: (OFObject*)obj; /** * Adds an object to the specific autorelease pool. * * \param obj The object to add to the autorelease pool */ - addObject: (OFObject*)obj; /** * Releases all objects in the autorelease pool. */ - releaseObjects; @end |
Modified src/OFAutoreleasePool.m from [2fd942db62] to [bd25c897fc].
︙ | ︙ | |||
40 41 42 43 44 45 46 | { if (self != [OFAutoreleasePool class]) return; pool_list_key = [[OFTLSKey alloc] initWithDestructor: release_list]; } | | | | 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 | { if (self != [OFAutoreleasePool class]) return; pool_list_key = [[OFTLSKey alloc] initWithDestructor: release_list]; } + (void)addObjectToTopmostPool: (OFObject*)obj { OFList *pool_list = [OFThread objectForTLSKey: pool_list_key]; if (pool_list == nil || [pool_list last] == NULL) { @try { [[self alloc] init]; pool_list = [OFThread objectForTLSKey: pool_list_key]; } @catch (OFException *e) { [obj release]; @throw e; } } if (pool_list == nil || [pool_list last] == NULL) { [obj release]; @throw [OFInitializationFailedException newWithClass: self]; } @try { [[pool_list last]->object addObject: obj]; } @catch (OFException *e) { [obj release]; @throw e; } } - init |
︙ | ︙ | |||
121 122 123 124 125 126 127 | [self releaseObjects]; [[OFThread objectForTLSKey: pool_list_key] remove: listobj]; [super dealloc]; } | | | | 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | [self releaseObjects]; [[OFThread objectForTLSKey: pool_list_key] remove: listobj]; [super dealloc]; } - addObject: (OFObject*)obj { if (objects == nil) objects = [[OFMutableArray alloc] init]; [objects addObject: obj]; [obj release]; return self; } - (void)release { |
︙ | ︙ |
Modified src/OFDataArray.h from [2aac6c3e48] to [399b8674b6].
︙ | ︙ | |||
73 74 75 76 77 78 79 | * \return The specified item of the OFDataArray */ - (void*)itemAtIndex: (size_t)index; /** * \return The last item of the OFDataArray */ | | | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | * \return The specified item of the OFDataArray */ - (void*)itemAtIndex: (size_t)index; /** * \return The last item of the OFDataArray */ - (void*)lastItem; /** * Adds an item to the OFDataArray. * * \param item A pointer to an arbitrary item */ - addItem: (void*)item; /** * Adds items from a C array to the OFDataArray. * * \param nitems The number of items to add * \param carray A C array containing the items to add */ |
︙ | ︙ |
Modified src/OFDataArray.m from [2e56b1156a] to [388224bcd6].
︙ | ︙ | |||
67 68 69 70 71 72 73 | { if (index >= count) @throw [OFOutOfRangeException newWithClass: isa]; return data + index * itemsize; } | | | | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | { if (index >= count) @throw [OFOutOfRangeException newWithClass: isa]; return data + index * itemsize; } - (void*)lastItem { return data + (count - 1) * itemsize; } - addItem: (void*)item { if (SIZE_MAX - count < 1) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMem: data toNItems: count + 1 withSize: itemsize]; |
︙ | ︙ | |||
189 190 191 192 193 194 195 | if (lastpagebyte == 0) lastpagebyte = getpagesize() - 1; return self; } | | | 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | if (lastpagebyte == 0) lastpagebyte = getpagesize() - 1; return self; } - addItem: (void*)item { size_t nsize; if (SIZE_MAX - count < 1 || count + 1 > SIZE_MAX / itemsize) @throw [OFOutOfRangeException newWithClass: isa]; nsize = ((count + 1) * itemsize + lastpagebyte) & ~lastpagebyte; |
︙ | ︙ |
Modified src/OFMutableArray.m from [2c171c36e2] to [b43784b0eb].
︙ | ︙ | |||
29 30 31 32 33 34 35 | for (i = 0; i < len; i++) [objs[i] retain]; return new; } | | | | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | for (i = 0; i < len; i++) [objs[i] retain]; return new; } - addObject: (OFObject*)obj { [array addItem: &obj]; [obj retain]; return self; } - removeNObjects: (size_t)nobjects { |
︙ | ︙ |
Modified src/OFObject.h from [ee8a3d67d3] to [7205341d87].
︙ | ︙ | |||
130 131 132 133 134 135 136 | * Adds a pointer to the memory pool. * * This is useful to add memory allocated by functions such as asprintf to the * pool so it gets free'd automatically when the object is deallocated. * * \param ptr A pointer to add to the memory pool */ | | | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | * Adds a pointer to the memory pool. * * This is useful to add memory allocated by functions such as asprintf to the * pool so it gets free'd automatically when the object is deallocated. * * \param ptr A pointer to add to the memory pool */ - addItemToMemoryPool: (void*)ptr; /** * Allocate memory and store it in the objects memory pool so it can be free'd * automatically when the object is deallocated. * * \param size The size of the memory to allocate * \return A pointer to the allocated memory |
︙ | ︙ |
Modified src/OFObject.m from [74f9d21734] to [8454e38c50].
︙ | ︙ | |||
182 183 184 185 186 187 188 | - (uint32_t)hash { /* Classes containing data should reimplement this! */ return (uint32_t)(intptr_t)self; } | | | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | - (uint32_t)hash { /* Classes containing data should reimplement this! */ return (uint32_t)(intptr_t)self; } - addItemToMemoryPool: (void*)ptr { void **memchunks; size_t memchunks_size; memchunks_size = PRE_IVAR->memchunks_size + 1; if (SIZE_MAX - PRE_IVAR->memchunks_size < 1 || |
︙ | ︙ | |||
354 355 356 357 358 359 360 | PRE_IVAR->retain_count++; return self; } - autorelease { | | | 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | PRE_IVAR->retain_count++; return self; } - autorelease { [OFAutoreleasePool addObjectToTopmostPool: self]; return self; } - (size_t)retainCount { return PRE_IVAR->retain_count; |
︙ | ︙ |
Modified src/OFString.m from [f339ad2a58] to [7338b9f854].
︙ | ︙ | |||
218 219 220 221 222 223 224 | free(string); c = isa; [super dealloc]; @throw [OFInvalidEncodingException newWithClass: c]; } @try { | | | 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | free(string); c = isa; [super dealloc]; @throw [OFInvalidEncodingException newWithClass: c]; } @try { [self addItemToMemoryPool: string]; } @catch (OFException *e) { free(string); @throw e; } return self; } |
︙ | ︙ | |||
350 351 352 353 354 355 356 | array = [OFMutableArray array]; if (delim_len > length) { str = [self copy]; @try { | | | 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | array = [OFMutableArray array]; if (delim_len > length) { str = [self copy]; @try { [array addObject: str]; } @finally { [str release]; } [array retain]; [pool release]; |
︙ | ︙ | |||
382 383 384 385 386 387 388 | tmp[i - last] = '\0'; @try { str = [OFString stringWithCString: tmp]; } @finally { free(tmp); } | | | | 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | tmp[i - last] = '\0'; @try { str = [OFString stringWithCString: tmp]; } @finally { free(tmp); } [array addObject: str]; [array retain]; [pool releaseObjects]; i += delim_len - 1; last = i + 1; } [array addObject: [OFString stringWithCString: string + last]]; [array retain]; [pool release]; return array; } @end |
Modified tests/OFArray/OFArray.m from [3882b8f32d] to [26a02ce961].
︙ | ︙ | |||
41 42 43 44 45 46 47 | int main() { OFArray *a = [OFArray arrayWithObjects: @"Foo", @"Bar", @"Baz", nil]; OFArray *b = [OFMutableArray array]; OFArray *c = [OFArray arrayWithCArray: c_array]; | | | | | | | | 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 | int main() { OFArray *a = [OFArray arrayWithObjects: @"Foo", @"Bar", @"Baz", nil]; OFArray *b = [OFMutableArray array]; OFArray *c = [OFArray arrayWithCArray: c_array]; [b addObject: @"Foo"]; [b addObject: @"Bar"]; [b addObject: @"Baz"]; assert([a count] == 3); assert([b count] == 3); assert([c count] == 3); assert([a isEqual: b]); assert([a isEqual: c]); [b removeNObjects: 1]; [b addObject: @"Baz"]; assert([a isEqual: b]); [b removeNObjects: 1]; [b addObject: @"Qux"]; assert(![a isEqual: b]); CATCH_EXCEPTION([a objectAtIndex: 3], OFOutOfRangeException) CATCH_EXCEPTION([a addObject: @"foo"], OFNotImplementedException) return 0; } |
Modified tests/OFDataArray/OFDataArray.m from [6aad159bdb] to [ec34977a16].
︙ | ︙ | |||
40 41 42 43 44 45 46 | CATCH_EXCEPTION([a addNItems: SIZE_MAX \ fromCArray: NULL], \ OFOutOfRangeException) \ \ puts("Trying to add something after that error..."); \ p = [a allocWithSize: 4096]; \ memset(p, 255, 4096); \ | | | | | | | | | | | | | | | 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 | CATCH_EXCEPTION([a addNItems: SIZE_MAX \ fromCArray: NULL], \ OFOutOfRangeException) \ \ puts("Trying to add something after that error..."); \ p = [a allocWithSize: 4096]; \ memset(p, 255, 4096); \ [a addItem: p]; \ if (!memcmp([a lastItem], p, 4096)) \ puts("[a lastItem] matches with p!"); \ else { \ puts("[a lastItem] does not match p!"); \ abort(); \ } \ [a freeMem: p]; \ \ puts("Adding more data..."); \ q = [a allocWithSize: 4096]; \ memset(q, 42, 4096); \ [a addItem: q]; \ if (!memcmp([a lastItem], q, 4096)) \ puts("[a lastItem] matches with q!"); \ else { \ puts("[a lastItem] does not match q!"); \ abort(); \ } \ [a freeMem: q]; \ \ puts("Adding multiple items at once..."); \ p = [a allocWithSize: 8192]; \ memset(p, 64, 8192); \ [a addNItems: 2 \ fromCArray: p]; \ if (!memcmp([a lastItem], [a itemAtIndex: [a count] - 2], 4096) && \ !memcmp([a itemAtIndex: [a count] - 2], p, 4096)) \ puts("[a lastItem], [a itemAtIndex: [a count] - 2] " \ "and p match!"); \ else { \ puts("[a lastItem], [a itemAtIndex: [a count] - 2] " \ "and p do not match!"); \ abort(); \ } \ [a freeMem: p]; \ \ i = [a count]; \ puts("Removing 2 items..."); \ [a removeNItems: 2]; \ |
︙ | ︙ | |||
99 100 101 102 103 104 105 | \ [a release]; \ \ puts("Creating new array and using it to build a string..."); \ a = [[type alloc] initWithItemSize: 1]; \ \ for (i = 0; i < strlen(str); i++) \ | | | | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | \ [a release]; \ \ puts("Creating new array and using it to build a string..."); \ a = [[type alloc] initWithItemSize: 1]; \ \ for (i = 0; i < strlen(str); i++) \ [a addItem: (void*)&str[i]]; \ [a addItem: ""]; \ \ if (!strcmp([a data], str)) \ puts("Built string matches!"); \ else { \ puts("Built string does not match!"); \ abort(); \ } \ |
︙ | ︙ | |||
140 141 142 143 144 145 146 | } if ([x hash] != [y hash]) { puts("FAIL 2!"); return 1; } | | | 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | } if ([x hash] != [y hash]) { puts("FAIL 2!"); return 1; } [x addItem: "x"]; if ([x isEqual: y]) { puts("FAIL 3!"); return 1; } [pool releaseObjects]; x = [OFDataArray dataArrayWithItemSize: 2]; |
︙ | ︙ | |||
165 166 167 168 169 170 171 | fromCArray: "abc"]; y = [x copy]; if ([x compare: y]) { puts("FAIL 5!"); return 1; } | | | 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | fromCArray: "abc"]; y = [x copy]; if ([x compare: y]) { puts("FAIL 5!"); return 1; } [y addItem: "de"]; if ([x compare: y] != -100) { puts("FAIL 6!"); return 1; } if ([y hash] != 0xCD8B6206) { puts("FAIL 7!"); return 1; } [pool release]; return 0; } |