X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fq.c;h=f7f79804bb7f530dfa994d18c15806650884dae9;hb=b78c0fcd093d913860d445b1f8b28451711f7fa1;hp=0d0d944529a40e7681b9ab895d99c39b26be1e23;hpb=35bef20c4bea1a43ea4072f0ea7ff5bbc68412ee;p=swftools.git diff --git a/lib/q.c b/lib/q.c index 0d0d944..f7f7980 100644 --- a/lib/q.c +++ b/lib/q.c @@ -523,6 +523,23 @@ void stringarray_destroy(stringarray_t*sa) // ------------------------------- type_t ------------------------------- +char ptr_equals(const void*o1, const void*o2) +{ + return o1==o2; +} +unsigned int ptr_hash(const void*o) +{ + return string_hash3(o, sizeof(o)); +} +void* ptr_dup(const void*o) +{ + return (void*)o; +} +void ptr_free(void*o) +{ + return; +} + char charptr_equals(const void*o1, const void*o2) { if(!o1 || !o2) @@ -547,6 +564,7 @@ void charptr_free(void*o) rfx_free(o); } } + char stringstruct_equals(const void*o1, const void*o2) { string_t*s1 = (string_t*)o1; @@ -574,6 +592,12 @@ void stringstruct_free(void*o) rfx_free((void*)o); } +type_t ptr_type = { + equals: ptr_equals, + hash: ptr_hash, + dup: ptr_dup, + free: ptr_free, +}; type_t charptr_type = { equals: charptr_equals, @@ -625,14 +649,16 @@ dict_t*dict_clone(dict_t*o) memcpy(h, o, sizeof(dict_t)); h->slots = h->hashsize?(dictentry_t**)rfx_calloc(sizeof(dictentry_t*)*h->hashsize):0; int t; - for(t=0;thashsize;t++) { - dictentry_t*e = h->slots[t]; + for(t=0;thashsize;t++) { + dictentry_t*e = o->slots[t]; while(e) { dictentry_t*n = (dictentry_t*)rfx_alloc(sizeof(dictentry_t)); memcpy(n, e, sizeof(dictentry_t)); - n->data = h->key_type->dup(e->data); + n->key = h->key_type->dup(e->key); + n->data = e->data; n->next = h->slots[t]; h->slots[t] = n; + e = e->next; } } return h; @@ -684,7 +710,7 @@ void dict_dump(dict_t*h, FILE*fi, const char*prefix) for(t=0;thashsize;t++) { dictentry_t*e = h->slots[t]; while(e) { - if(h->key_type==&charptr_type) { + if(h->key_type!=&charptr_type) { fprintf(fi, "%s%08x=%08x\n", prefix, e->key, e->data); } else { fprintf(fi, "%s%s=%08x\n", prefix, e->key, e->data);