Overview
Comment: | Throw OFAllocFailedException instead of returning nil. This exception is quite special, look at the documentation for details. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
a1a5bfb3cdb8eda5980786b7221c9c1f |
User & Date: | js on 2009-04-21 16:47:32 |
Other Links: | manifest | tags |
Context
2009-04-21
| ||
17:16 | The if ((self = [super init])) construct isn't needed anymore. check-in: d87df02e8b user: js tags: trunk | |
16:47 |
Throw OFAllocFailedException instead of returning nil. This exception is quite special, look at the documentation for details. check-in: a1a5bfb3cd user: js tags: trunk | |
2009-04-20
| ||
01:55 | Improve tests. check-in: 16f1025d5c user: js tags: trunk | |
Changes
Modified src/OFExceptions.h from [edbf4d480b] to [5a3910cc75].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /* * Copyright (c) 2008 - 2009 * 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 "OFObject.h" /** * The OFException class is the base class for all exceptions in ObjFW. * * IMPORTANT: Exceptions do NOT use OFAutoreleasePools!! */ @interface OFException: OFObject { | > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* * Copyright (c) 2008 - 2009 * 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 "OFObject.h" /** * An exception indicating an object could not be allocated. * * This exception is preallocated, as if there's no memory, no exception can * be allocated of course. That's why you shouldn't and even can't free it. * * This is the only exception that is not an OFException as it's special. * It does not know for which class allocation failed and it should not be * handled like other exceptions, as the exception handling code is not * allowed to allocate ANY memory. */ @interface OFAllocFailedException { Class isa; } + (Class)class; /** * \return An error message for the exception as a C string */ - (const char*)cString; @end /** * The OFException class is the base class for all exceptions in ObjFW. * * IMPORTANT: Exceptions do NOT use OFAutoreleasePools!! */ @interface OFException: OFObject { |
︙ | ︙ |
Modified src/OFExceptions.m from [6c6b7a9a76] to [22a218a9f1].
︙ | ︙ | |||
39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #endif #import "OFExceptions.h" #ifndef HAVE_ASPRINTF #import "asprintf.h" #endif @implementation OFException + newWithClass: (Class)class_ { return [[self alloc] initWithClass: class_]; } | > > > > > > > > > > > > | 39 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 | #endif #import "OFExceptions.h" #ifndef HAVE_ASPRINTF #import "asprintf.h" #endif @implementation OFAllocFailedException + (Class)class { return self; } - (const char*)cString { return "Allocating an object failed!"; } @end @implementation OFException + newWithClass: (Class)class_ { return [[self alloc] initWithClass: class_]; } |
︙ | ︙ |
Modified src/OFObject.m from [18bfba4e77] to [1a0aed77e1].
︙ | ︙ | |||
31 32 33 34 35 36 37 38 39 40 41 42 43 44 | size_t retain_count; }; /* Hopefully no arch needs more than 16 bytes padding */ #define PRE_IVAR_ALIGN ((sizeof(struct pre_ivar) + 15) & ~15) #define PRE_IVAR ((struct pre_ivar*)((char*)self - PRE_IVAR_ALIGN)) @implementation OFObject #ifndef __objc_INCLUDE_GNU + load { return self; } #endif | > > > > | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | size_t retain_count; }; /* Hopefully no arch needs more than 16 bytes padding */ #define PRE_IVAR_ALIGN ((sizeof(struct pre_ivar) + 15) & ~15) #define PRE_IVAR ((struct pre_ivar*)((char*)self - PRE_IVAR_ALIGN)) static struct { Class isa; } alloc_failed_exception; @implementation OFObject #ifndef __objc_INCLUDE_GNU + load { return self; } #endif |
︙ | ︙ | |||
53 54 55 56 57 58 59 | OFObject *instance; #ifdef __objc_INCLUDE_GNU size_t isize = class_get_instance_size(self); #else size_t isize = class_getInstanceSize(self); #endif | | | > > | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | OFObject *instance; #ifdef __objc_INCLUDE_GNU size_t isize = class_get_instance_size(self); #else size_t isize = class_getInstanceSize(self); #endif if ((instance = malloc(isize + PRE_IVAR_ALIGN)) == NULL) { alloc_failed_exception.isa = [OFAllocFailedException class]; @throw (OFAllocFailedException*)&alloc_failed_exception; } ((struct pre_ivar*)instance)->memchunks = NULL; ((struct pre_ivar*)instance)->memchunks_size = 0; ((struct pre_ivar*)instance)->retain_count = 1; instance = (OFObject*)((char*)instance + PRE_IVAR_ALIGN); memset(instance, 0, isize); |
︙ | ︙ |