Artifact f2156324ce07500755a0a22b0aff30c3918a8e7447a8400a3febc39c4763719d:
- File
src/runtime/static-instances.m
— part of check-in
[79011c5f56]
at
2017-06-07 21:38:21
on branch trunk
— runtime: Move all globals into a single struct
This is required to create a .library on MorphOS. (user: js, size: 2541) [annotate] [blame] [check-ins using]
/* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 * Jonathan Schleifer <js@heap.zone> * * 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" #include <stdio.h> #include <stdlib.h> #import "runtime.h" #import "runtime-private.h" #import "globals.h" #define static_instances objc_globals.static_instances #define static_instances_cnt objc_globals.static_instances_cnt void objc_init_static_instances(struct objc_abi_symtab *symtab) { struct objc_abi_static_instances **si; /* Check if the class for a static instance became available */ for (size_t i = 0; i < static_instances_cnt; i++) { Class cls = objc_lookUpClass(static_instances[i]->class_name); if (cls != Nil) { for (id *instances = static_instances[i]->instances; *instances != nil; instances++) object_setClass(*instances, cls); static_instances_cnt--; if (static_instances_cnt == 0) { free(static_instances); static_instances = NULL; continue; } static_instances[i] = static_instances[static_instances_cnt]; static_instances = realloc(static_instances, sizeof(struct objc_abi_static_instances *) * static_instances_cnt); if (static_instances == NULL) OBJC_ERROR("Not enough memory for list of " "static instances!"); } } si = (struct objc_abi_static_instances **) symtab->defs[symtab->cls_def_cnt + symtab->cat_def_cnt]; if (si == NULL) return; for (; *si != NULL; si++) { Class cls = objc_lookUpClass((*si)->class_name); if (cls != Nil) { for (id *instances = (*si)->instances; *instances != nil; instances++) object_setClass(*instances, cls); } else { static_instances = realloc(static_instances, sizeof(struct objc_abi_static_instances *) * (static_instances_cnt + 1)); if (static_instances == NULL) OBJC_ERROR("Not enough memory for list of " "static instances!"); static_instances[static_instances_cnt++] = *si; } } } void objc_forget_pending_static_instances() { free(static_instances); static_instances = NULL; static_instances_cnt = 0; }