+void multiname_destroy(multiname_t*m)
+{
+ if(m) {
+ if(m->name) {
+ free((void*)m->name);m->name = 0;
+ }
+ if(m->ns) {
+ namespace_destroy(m->ns);m->ns = 0;
+ }
+ if(m->namespace_set) {
+ namespace_set_destroy(m->namespace_set);m->namespace_set = 0;
+ }
+ free(m);
+ }
+}
+
+type_t multiname_type = {
+ dup: (dup_func)multiname_clone,
+ hash: (hash_func)multiname_hash,
+ free: (free_func)multiname_destroy,
+ equals: (equals_func)multiname_equals
+};
+
+// ------------------------------- pool -------------------------------------
+
+int pool_register_uint(pool_t*p, unsigned int i)
+{
+ int pos = array_append_if_new(p->x_uints, &i, 0);
+ assert(pos!=0);
+ return pos;
+}
+int pool_register_int(pool_t*p, int i)
+{
+ int pos = array_append_if_new(p->x_ints, &i, 0);
+ assert(pos!=0);
+ return pos;
+}
+int pool_register_float(pool_t*p, double d)
+{
+ int pos = array_append_if_new(p->x_floats, &d, 0);
+ assert(pos!=0);
+ return pos;
+}
+int pool_register_string(pool_t*pool, const char*s)
+{
+ if(!s) return 0;
+ int pos = array_append_if_new(pool->x_strings, s, 0);
+ assert(pos!=0);
+ return pos;
+}
+int pool_register_namespace(pool_t*pool, namespace_t*ns)
+{
+ if(!ns) return 0;
+ int pos = array_append_if_new(pool->x_namespaces, ns, 0);
+ assert(pos!=0);
+ return pos;
+}
+int pool_register_namespace_set(pool_t*pool, namespace_set_t*set)
+{
+ if(!set) return 0;
+ int pos = array_append_if_new(pool->x_namespace_sets, set, 0);
+ assert(pos!=0);
+ return pos;
+}
+int pool_register_multiname(pool_t*pool, multiname_t*n)
+{
+ if(!n) return 0;
+ int pos = array_append_if_new(pool->x_multinames, n, 0);
+ if(pos==0) {
+ *(int*)0=0xdead;
+ }
+ assert(pos!=0);
+ return pos;
+}
+int pool_register_multiname2(pool_t*pool, char*name)
+{
+ if(!name) return 0;
+ multiname_t*n = multiname_fromstring(name);
+ int pos = array_append_if_new(pool->x_multinames, n, 0);
+ multiname_destroy(n);
+ assert(pos!=0);
+ return pos;
+}
+
+
+int pool_find_uint(pool_t*pool, unsigned int x)
+{
+ int i = array_find(pool->x_uints, &x);
+ if(i<=0) {
+ fprintf(stderr, "Couldn't find uint \"%d\" in constant pool\n", x);
+ return 0;
+ }
+ return i;
+}
+int pool_find_int(pool_t*pool, int x)
+{
+ int i = array_find(pool->x_ints, &x);
+ if(i<=0) {
+ fprintf(stderr, "Couldn't find int \"%d\" in constant pool\n", x);
+ return 0;
+ }
+ return i;
+}
+int pool_find_float(pool_t*pool, double x)
+{
+ int i = array_find(pool->x_ints, &x);
+ if(i<=0) {
+ fprintf(stderr, "Couldn't find int \"%d\" in constant pool\n", x);
+ return 0;
+ }
+ return i;
+}
+int pool_find_namespace(pool_t*pool, namespace_t*ns)
+{
+ if(!ns)
+ return 0;
+ int i = array_find(pool->x_namespaces, ns);
+ if(i<=0) {
+ char*s = namespace_to_string(ns);
+ fprintf(stderr, "Couldn't find namespace \"%s\" %08x in constant pool\n", s, ns);
+ free(s);
+ return 0;
+ }
+ return i;
+}
+int pool_find_namespace_set(pool_t*pool, namespace_set_t*set)
+{
+ if(!set)
+ return 0;
+ int i = array_find(pool->x_namespace_sets, set);
+ if(i<=0) {
+ char*s = namespace_set_to_string(set);
+ fprintf(stderr, "Couldn't find namespace_set \"%s\" in constant pool\n", s);
+ free(s);
+ return 0;
+ }
+ return i;
+}
+int pool_find_string(pool_t*pool, const char*s)
+{
+ if(!s)
+ return 0;
+ int i = array_find(pool->x_strings, s);
+ if(i<=0) {
+ fprintf(stderr, "Couldn't find string \"%s\" in constant pool\n", s);
+ return 0;
+ }
+ return i;
+}
+int pool_find_multiname(pool_t*pool, multiname_t*name)
+{
+ if(!name)
+ return 0;
+ int i = array_find(pool->x_multinames, name);
+ if(i<=0) {
+ char*s = multiname_to_string(name);
+ fprintf(stderr, "Couldn't find multiname \"%s\" in constant pool\n", s);
+ free(s);
+ return 0;
+ }
+ return i;
+}
+
+int pool_lookup_int(pool_t*pool, int i)
+{
+ if(!i) return 0;
+ return *(int*)array_getkey(pool->x_ints, i);
+}
+unsigned int pool_lookup_uint(pool_t*pool, int i)
+{
+ if(!i) return 0;
+ return *(unsigned int*)array_getkey(pool->x_uints, i);
+}
+double pool_lookup_float(pool_t*pool, int i)
+{
+ if(!i) return __builtin_nan("");
+ return *(double*)array_getkey(pool->x_floats, i);
+}
+char*pool_lookup_string(pool_t*pool, int i)
+{
+ return (char*)array_getkey(pool->x_strings, i);
+}
+namespace_t*pool_lookup_namespace(pool_t*pool, int i)
+{
+ return (namespace_t*)array_getkey(pool->x_namespaces, i);
+}
+namespace_set_t*pool_lookup_namespace_set(pool_t*pool, int i)
+{
+ return (namespace_set_t*)array_getkey(pool->x_namespace_sets, i);
+}
+multiname_t*pool_lookup_multiname(pool_t*pool, int i)
+{
+ return (multiname_t*)array_getkey(pool->x_multinames, i);
+}
+