Differences From Artifact [b460fe3dcf]:
- File src/OFObject.m — part of check-in [778be56179] at 2008-09-14 15:29:34 on branch trunk — Coding style. (user: js, size: 1964) [annotate] [blame] [check-ins using]
To Artifact [9572084d4f]:
- File
src/OFObject.m
— part of check-in
[7b8b7cd06c]
at
2008-09-14 16:43:54
on branch trunk
— Lots of changes. See full commit message.
* Updated buildsys to fixed version.
* Implement exceptions.
* Let OFObject use exceptions.
* Write tests for OFObject.
* Fix a bug in OFObject's freeMem:. (user: js, size: 2357) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
56 57 58 59 60 61 62 | return NULL; iter->ptr = ptr; return ptr; } } | < < | | > > | < > > > > > > > > > > > > > > > > > > > | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | return NULL; iter->ptr = ptr; return ptr; } } @throw [OFMemNotPartOfObjException new: ptr fromObject: self]; return NULL; } - (void)freeMem: (void*)ptr; { struct __ofobject_allocated_mem *iter; for (iter = __mem_pool; iter != NULL; iter = iter->prev) { if (iter->ptr == ptr) { if (iter->prev != NULL) iter->prev->next = iter->next; if (iter->next != NULL) iter->next->prev = iter->prev; if (__mem_pool == iter) __mem_pool = NULL; free(iter); free(ptr); return; } } @throw [OFMemNotPartOfObjException new: ptr fromObject: self]; } - free { struct __ofobject_allocated_mem *iter, *iter2; for (iter = __mem_pool; iter != NULL; iter = iter2) { iter2 = iter->prev; free(iter->ptr); free(iter); } return [super free]; } @end @implementation OFMemNotPartOfObjException + new: (void*)ptr fromObject: (id)obj { return [[OFMemNotPartOfObjException alloc] init: ptr fromObject: obj]; } - init: (void*)ptr fromObject: (id)obj { fprintf(stderr, "ERROR: Memory at %p was not allocated as part of " "object %s!\n" "ERROR: -> Not changing memory allocation!\n" "ERROR: (Hint: It is possible that you tried to free the same " "memory twice!)\n", ptr, [obj name]); return [super init]; } @end |