Artifact 79b4177a357f8d5773b07074011f68b8151d456a1883a416472e31904816f1d2:
- File
src/instance.m
— part of check-in
[fa6496efc7]
at
2013-12-05 17:48:11
on branch trunk
— Make coding style consistent.
A file documenting the coding style will be written soon. This will
hopefully prevent conflicts in the future, such as whether static
functions are written in camelCase or_with_underscores, like was the
case here. (user: js, size: 2032) [annotate] [blame] [check-ins using]
/* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFObject.h" static SEL constructSel = NULL; static SEL destructSel = NULL; static bool callConstructors(Class cls, id obj) { Class super = class_getSuperclass(cls); id (*construct)(id, SEL); id (*last)(id, SEL); if (super != nil) if (!callConstructors(super, obj)) return false; if (constructSel == NULL) constructSel = sel_registerName(".cxx_construct"); if (!class_respondsToSelector(cls, constructSel)) return true; construct = (id(*)(id, SEL)) class_getMethodImplementation(cls, constructSel); last = (id(*)(id, SEL)) class_getMethodImplementation(super, constructSel); if (construct == last) return true; return (construct(obj, constructSel) != nil); } id objc_constructInstance(Class cls, void *bytes) { id obj = (id)bytes; if (cls == Nil || bytes == NULL) return nil; object_setClass(obj, cls); if (!callConstructors(cls, obj)) return nil; return obj; } void* objc_destructInstance(id obj) { Class cls; void (*last)(id, SEL) = NULL; if (destructSel == NULL) destructSel = sel_registerName(".cxx_destruct"); for (cls = object_getClass(obj); cls != Nil; cls = class_getSuperclass(cls)) { void (*destruct)(id, SEL); if (class_respondsToSelector(cls, destructSel)) { if ((destruct = (void(*)(id, SEL)) class_getMethodImplementation(cls, destructSel)) != last) destruct(obj, destructSel); last = destruct; } else break; } return obj; }