Differences From 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]
To Artifact [0937ee4297]:
- File src/OFObject.m — part of check-in [98fe076bd8] at 2008-09-14 19:03:29 on branch trunk — More exceptions stuff. (user: js, size: 2137) [annotate] [blame] [check-ins using]
1 2 3 4 5 6 7 8 9 10 11 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ | < > | > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <stdlib.h> #import "OFObject.h" #import "OFExceptions.h" @implementation OFObject - init { if ((self = [super init]) != nil) __mem_pool = NULL; return self; } - (void*)getMem: (size_t)size { struct __ofobject_allocated_mem *iter; if ((iter = malloc(sizeof(struct __ofobject_allocated_mem))) == NULL) { @throw [OFNoMemException new: self withSize: sizeof( struct __ofobject_allocated_mem)]; return NULL; } if ((iter->ptr = malloc(size)) == NULL) { free(iter); @throw [OFNoMemException new: self withSize: size]; return NULL; } iter->next = NULL; iter->prev = __mem_pool; if (__mem_pool != NULL) |
︙ | ︙ | |||
48 49 50 51 52 53 54 | - (void*)resizeMem: (void*)ptr toSize: (size_t)size { struct __ofobject_allocated_mem *iter; for (iter = __mem_pool; iter != NULL; iter = iter->prev) { if (iter->ptr == ptr) { | | > > > | > | 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 | - (void*)resizeMem: (void*)ptr toSize: (size_t)size { struct __ofobject_allocated_mem *iter; for (iter = __mem_pool; iter != NULL; iter = iter->prev) { if (iter->ptr == ptr) { if ((ptr = realloc(iter->ptr, size)) == NULL) { @throw [OFNoMemException new: self withSize: size]; return NULL; } iter->ptr = ptr; return ptr; } } @throw [OFMemNotPartOfObjException new: self withPtr: ptr]; return NULL; } - (void)freeMem: (void*)ptr; { struct __ofobject_allocated_mem *iter; |
︙ | ︙ | |||
80 81 82 83 84 85 86 | free(iter); free(ptr); return; } } | | > < < < < < < < < < < < < < < < < < < < | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | free(iter); free(ptr); return; } } @throw [OFMemNotPartOfObjException new: self withPtr: ptr]; } - 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 |