This machine mirrors various open-source projects.
20 Gbit/s uplink.
If there are any issues or you want another project mirrored, please contact
mirror-service -=AT=- netcologne DOT de !
00001 /*===-- runtime/crt_types.c -----------------------------------------------=== 00002 * 00003 * This file is distributed under the MIT license. See LICENSE.txt for details. 00004 * 00005 * Copyright (C) 2009, Stephen Wilson 00006 * 00007 *===----------------------------------------------------------------------===*/ 00008 00009 #include "comma/runtime/crt_types.h" 00010 #include "comma/runtime/crt_itable.h" 00011 00012 #include <stdarg.h> 00013 #include <stdbool.h> 00014 #include <stdlib.h> 00015 #include <string.h> 00016 00017 static bool lookup_instance(domain_info_t info, 00018 domain_instance_t *args, domain_instance_t *instance) 00019 { 00020 if (!info->instance_table) 00021 info->instance_table = alloc_itable(); 00022 00023 return itable_lookup(info->instance_table, info, args, instance); 00024 } 00025 00026 /* 00027 * Get a domain instance. 00028 */ 00029 domain_instance_t _comma_get_domain(domain_info_t info, ...) 00030 { 00031 domain_instance_t instance; 00032 unsigned i; 00033 domain_instance_t *args; 00034 00035 if (info->arity) { 00036 args = malloc(sizeof(domain_instance_t)*info->arity); 00037 for (i = 0; i < info->arity; ++i) { 00038 va_list ap; 00039 va_start(ap, info); 00040 args[i] = va_arg(ap, domain_instance_t); 00041 } 00042 } 00043 else 00044 args = 0; 00045 00046 /* 00047 * Lookup the instance in a hash table and return it if found. 00048 * Otherwise, this function updates instance to point at an entry which 00049 * we can fill in (the instance was allocated using 00050 * alloc_domain_instance, and therefore has the capacity to hold all of 00051 * the items written to the structure). 00052 */ 00053 if (lookup_instance(info, args, &instance)) 00054 return instance; 00055 00056 instance->info = info; 00057 instance->params = args; 00058 00059 /* 00060 * If the constructor is non-null, call it. 00061 */ 00062 if (info->ctor != 0) 00063 info->ctor(instance); 00064 00065 return instance; 00066 } 00067 00068 /* 00069 * Allocates a domain instance which is large enough to hold all of the data 00070 * required by the given info. 00071 */ 00072 domain_instance_t alloc_domain_instance(domain_info_t info) 00073 { 00074 return malloc(sizeof(struct domain_instance)); 00075 }