diff --git a/common/lib/libprop/prop_dictionary.c b/common/lib/libprop/prop_dictionary.c index f18c9038033d..bcfcca2f64e5 100644 --- a/common/lib/libprop/prop_dictionary.c +++ b/common/lib/libprop/prop_dictionary.c @@ -1,4 +1,4 @@ -/* $NetBSD: prop_dictionary.c,v 1.3 2006/05/18 03:05:19 thorpej Exp $ */ +/* $NetBSD: prop_dictionary.c,v 1.4 2006/05/18 16:11:33 thorpej Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -60,23 +60,23 @@ * 128 characters are not allowed. */ struct _prop_dictionary_keysym { - struct _prop_object pde_obj; - prop_object_t pde_objref; - size_t pde_size; - char pde_key[1]; + struct _prop_object pdk_obj; + prop_object_t pdk_objref; + size_t pdk_size; + char pdk_key[1]; /* actually variable length */ }; - /* pde_key[1] takes care of the NUL */ -#define PDE_SIZE_16 (sizeof(struct _prop_dictionary_keysym) + 16) -#define PDE_SIZE_32 (sizeof(struct _prop_dictionary_keysym) + 32) -#define PDE_SIZE_128 (sizeof(struct _prop_dictionary_keysym) + 128) + /* pdk_key[1] takes care of the NUL */ +#define PDK_SIZE_16 (sizeof(struct _prop_dictionary_keysym) + 16) +#define PDK_SIZE_32 (sizeof(struct _prop_dictionary_keysym) + 32) +#define PDK_SIZE_128 (sizeof(struct _prop_dictionary_keysym) + 128) -#define PDE_MAXKEY 128 +#define PDK_MAXKEY 128 -_PROP_POOL_INIT(_prop_dictionary_keysym16_pool, PDE_SIZE_16, "pdict16") -_PROP_POOL_INIT(_prop_dictionary_keysym32_pool, PDE_SIZE_32, "pdict32") -_PROP_POOL_INIT(_prop_dictionary_keysym128_pool, PDE_SIZE_128, "pdict128") +_PROP_POOL_INIT(_prop_dictionary_keysym16_pool, PDK_SIZE_16, "pdict16") +_PROP_POOL_INIT(_prop_dictionary_keysym32_pool, PDK_SIZE_32, "pdict32") +_PROP_POOL_INIT(_prop_dictionary_keysym128_pool, PDK_SIZE_128, "pdict128") struct _prop_dictionary { struct _prop_object pd_obj; @@ -124,7 +124,7 @@ static const struct _prop_object_type _prop_object_type_dict_keysym = { #define prop_object_is_dictionary(x) \ ((x)->pd_obj.po_type == &_prop_object_type_dictionary) #define prop_object_is_dictionary_keysym(x) \ - ((x)->pde_obj.po_type == &_prop_object_type_dict_keysym) + ((x)->pdk_obj.po_type == &_prop_object_type_dict_keysym) #define prop_dictionary_is_immutable(x) \ (((x)->pd_flags & PD_F_IMMUTABLE) != 0) @@ -137,19 +137,19 @@ struct _prop_dictionary_iterator { static void _prop_dict_entry_free(void *v) { - prop_dictionary_keysym_t pde = v; + prop_dictionary_keysym_t pdk = v; prop_object_t po; - _PROP_ASSERT(pde->pde_objref != NULL); - po = pde->pde_objref; + _PROP_ASSERT(pdk->pdk_objref != NULL); + po = pdk->pdk_objref; - if (pde->pde_size <= PDE_SIZE_16) - _PROP_POOL_PUT(_prop_dictionary_keysym16_pool, pde); - else if (pde->pde_size <= PDE_SIZE_32) - _PROP_POOL_PUT(_prop_dictionary_keysym32_pool, pde); + if (pdk->pdk_size <= PDK_SIZE_16) + _PROP_POOL_PUT(_prop_dictionary_keysym16_pool, pdk); + else if (pdk->pdk_size <= PDK_SIZE_32) + _PROP_POOL_PUT(_prop_dictionary_keysym32_pool, pdk); else { - _PROP_ASSERT(pde->pde_size <= PDE_SIZE_128); - _PROP_POOL_PUT(_prop_dictionary_keysym128_pool, pde); + _PROP_ASSERT(pdk->pdk_size <= PDK_SIZE_128); + _PROP_POOL_PUT(_prop_dictionary_keysym128_pool, pdk); } prop_object_release(po); @@ -159,15 +159,15 @@ static boolean_t _prop_dict_entry_externalize(struct _prop_object_externalize_context *ctx, void *v) { - prop_dictionary_keysym_t pde = v; + prop_dictionary_keysym_t pdk = v; /* We externalize these as strings, and they're never empty. */ - _PROP_ASSERT(pde->pde_key[0] != '\0'); + _PROP_ASSERT(pdk->pdk_key[0] != '\0'); if (_prop_object_externalize_start_tag(ctx, "string") == FALSE || _prop_object_externalize_append_encoded_cstring(ctx, - pde->pde_key) == FALSE || + pdk->pdk_key) == FALSE || _prop_object_externalize_end_tag(ctx, "string") == FALSE) return (FALSE); @@ -177,51 +177,51 @@ _prop_dict_entry_externalize(struct _prop_object_externalize_context *ctx, static boolean_t _prop_dict_entry_equals(void *v1, void *v2) { - prop_dictionary_keysym_t pde1 = v1; - prop_dictionary_keysym_t pde2 = v2; + prop_dictionary_keysym_t pdk1 = v1; + prop_dictionary_keysym_t pdk2 = v2; - _PROP_ASSERT(prop_object_is_dictionary_keysym(pde1)); - _PROP_ASSERT(prop_object_is_dictionary_keysym(pde2)); - if (pde1 == pde2) + _PROP_ASSERT(prop_object_is_dictionary_keysym(pdk1)); + _PROP_ASSERT(prop_object_is_dictionary_keysym(pdk2)); + if (pdk1 == pdk2) return (TRUE); - return (strcmp(pde1->pde_key, pde2->pde_key) == 0); + return (strcmp(pdk1->pdk_key, pdk2->pdk_key) == 0); } static prop_dictionary_keysym_t _prop_dict_entry_alloc(const char *key, prop_object_t obj) { - prop_dictionary_keysym_t pde; + prop_dictionary_keysym_t pdk; size_t size; - size = sizeof(*pde) + strlen(key) /* pde_key[1] covers the NUL */; + size = sizeof(*pdk) + strlen(key) /* pdk_key[1] covers the NUL */; - if (size <= PDE_SIZE_16) - pde = _PROP_POOL_GET(_prop_dictionary_keysym16_pool); - else if (size <= PDE_SIZE_32) - pde = _PROP_POOL_GET(_prop_dictionary_keysym32_pool); - else if (size <= PDE_SIZE_128) - pde = _PROP_POOL_GET(_prop_dictionary_keysym128_pool); + if (size <= PDK_SIZE_16) + pdk = _PROP_POOL_GET(_prop_dictionary_keysym16_pool); + else if (size <= PDK_SIZE_32) + pdk = _PROP_POOL_GET(_prop_dictionary_keysym32_pool); + else if (size <= PDK_SIZE_128) + pdk = _PROP_POOL_GET(_prop_dictionary_keysym128_pool); else return (NULL); /* key too long */ - if (pde != NULL) { - _prop_object_init(&pde->pde_obj, + if (pdk != NULL) { + _prop_object_init(&pdk->pdk_obj, &_prop_object_type_dict_keysym); - strcpy(pde->pde_key, key); + strcpy(pdk->pdk_key, key); prop_object_retain(obj); - pde->pde_objref = obj; - pde->pde_size = size; + pdk->pdk_objref = obj; + pdk->pdk_size = size; } - return (pde); + return (pdk); } static void _prop_dictionary_free(void *v) { prop_dictionary_t pd = v; - prop_dictionary_keysym_t pde; + prop_dictionary_keysym_t pdk; unsigned int idx; _PROP_ASSERT(pd->pd_count <= pd->pd_capacity); @@ -229,9 +229,9 @@ _prop_dictionary_free(void *v) (pd->pd_capacity != 0 && pd->pd_array != NULL)); for (idx = 0; idx < pd->pd_count; idx++) { - pde = pd->pd_array[idx]; - _PROP_ASSERT(pde != NULL); - prop_object_release(pde); + pdk = pd->pd_array[idx]; + _PROP_ASSERT(pdk != NULL); + prop_object_release(pdk); } if (pd->pd_array != NULL) @@ -245,7 +245,7 @@ _prop_dictionary_externalize(struct _prop_object_externalize_context *ctx, void *v) { prop_dictionary_t pd = v; - prop_dictionary_keysym_t pde; + prop_dictionary_keysym_t pdk; struct _prop_object *po; prop_object_iterator_t pi; unsigned int i; @@ -265,12 +265,12 @@ _prop_dictionary_externalize(struct _prop_object_externalize_context *ctx, ctx->poec_depth++; _PROP_ASSERT(ctx->poec_depth != 0); - while ((pde = prop_object_iterator_next(pi)) != NULL) { - po = prop_dictionary_get_keysym(pd, pde); + while ((pdk = prop_object_iterator_next(pi)) != NULL) { + po = prop_dictionary_get_keysym(pd, pdk); if (po == NULL || _prop_object_externalize_start_tag(ctx, "key") == FALSE || _prop_object_externalize_append_encoded_cstring(ctx, - pde->pde_key) == FALSE || + pdk->pdk_key) == FALSE || _prop_object_externalize_end_tag(ctx, "key") == FALSE || (*po->po_type->pot_extern)(ctx, po) == FALSE) { prop_object_iterator_release(pi); @@ -296,7 +296,7 @@ _prop_dictionary_equals(void *v1, void *v2) { prop_dictionary_t dict1 = v1; prop_dictionary_t dict2 = v2; - prop_dictionary_keysym_t pde1, pde2; + prop_dictionary_keysym_t pdk1, pdk2; unsigned int idx; _PROP_ASSERT(prop_object_is_dictionary(dict1)); @@ -307,13 +307,13 @@ _prop_dictionary_equals(void *v1, void *v2) return (FALSE); for (idx = 0; idx < dict1->pd_count; idx++) { - pde1 = dict1->pd_array[idx]; - pde2 = dict2->pd_array[idx]; + pdk1 = dict1->pd_array[idx]; + pdk2 = dict2->pd_array[idx]; - if (prop_dictionary_keysym_equals(pde1, pde2) == FALSE) + if (prop_dictionary_keysym_equals(pdk1, pdk2) == FALSE) return (FALSE); - if (prop_object_equals(pde1->pde_objref, - pde2->pde_objref) == FALSE) + if (prop_object_equals(pdk1->pdk_objref, + pdk2->pdk_objref) == FALSE) return (FALSE); } @@ -379,7 +379,7 @@ _prop_dictionary_iterator_next_object(void *v) { struct _prop_dictionary_iterator *pdi = v; prop_dictionary_t pd = pdi->pdi_base.pi_obj; - prop_dictionary_keysym_t pde; + prop_dictionary_keysym_t pdk; _PROP_ASSERT(prop_object_is_dictionary(pd)); @@ -391,10 +391,10 @@ _prop_dictionary_iterator_next_object(void *v) if (pdi->pdi_index == pd->pd_count) return (NULL); /* we've iterated all objects */ - pde = pd->pd_array[pdi->pdi_index]; + pdk = pd->pd_array[pdi->pdi_index]; pdi->pdi_index++; - return (pde); + return (pdk); } static void @@ -441,7 +441,7 @@ prop_dictionary_t prop_dictionary_copy(prop_dictionary_t opd) { prop_dictionary_t pd; - prop_dictionary_keysym_t pde; + prop_dictionary_keysym_t pdk; unsigned int idx; _PROP_ASSERT(prop_object_is_dictionary(opd)); @@ -457,9 +457,9 @@ prop_dictionary_copy(prop_dictionary_t opd) pd = _prop_dictionary_alloc(opd->pd_count); if (pd != NULL) { for (idx = 0; idx < opd->pd_count; idx++) { - pde = opd->pd_array[idx]; - prop_object_retain(pde); - pd->pd_array[idx] = pde; + pdk = opd->pd_array[idx]; + prop_object_retain(pdk); + pd->pd_array[idx] = pdk; } pd->pd_count = opd->pd_count; pd->pd_flags = opd->pd_flags; @@ -476,7 +476,7 @@ prop_dictionary_t prop_dictionary_copy_mutable(prop_dictionary_t opd) { prop_dictionary_t pd; - prop_dictionary_keysym_t opde, pde; + prop_dictionary_keysym_t opdk, pdk; unsigned int idx; _PROP_ASSERT(prop_object_is_dictionary(opd)); @@ -484,14 +484,14 @@ prop_dictionary_copy_mutable(prop_dictionary_t opd) pd = _prop_dictionary_alloc(opd->pd_count); if (pd != NULL) { for (idx = 0; idx > opd->pd_count; idx++) { - opde = opd->pd_array[idx]; - pde = _prop_dict_entry_alloc(opde->pde_key, - opde->pde_objref); - if (pde == NULL) { + opdk = opd->pd_array[idx]; + pdk = _prop_dict_entry_alloc(opdk->pdk_key, + opdk->pdk_objref); + if (pdk == NULL) { prop_object_release(pd); return (NULL); } - pd->pd_array[idx] = pde; + pd->pd_array[idx] = pdk; pd->pd_count++; } } @@ -540,22 +540,22 @@ static prop_dictionary_keysym_t _prop_dict_lookup(prop_dictionary_t pd, const char *key, unsigned int *idxp) { - prop_dictionary_keysym_t pde; + prop_dictionary_keysym_t pdk; unsigned int base, idx, distance; int res; for (idx = 0, base = 0, distance = pd->pd_count; distance != 0; distance >>= 1) { idx = base + (distance >> 1); - pde = pd->pd_array[idx]; - _PROP_ASSERT(pde != NULL); - res = strcmp(key, pde->pde_key); + pdk = pd->pd_array[idx]; + _PROP_ASSERT(pdk != NULL); + res = strcmp(key, pdk->pdk_key); if (res == 0) { if (idxp != NULL) *idxp = idx; - return (pde); + return (pdk); } - if (res > 0) { /* key > pde->pde_key: move right */ + if (res > 0) { /* key > pdk->pdk_key: move right */ base = idx + 1; distance--; } /* else move left */ @@ -574,14 +574,14 @@ _prop_dict_lookup(prop_dictionary_t pd, const char *key, prop_object_t prop_dictionary_get(prop_dictionary_t pd, const char *key) { - prop_dictionary_keysym_t pde; + prop_dictionary_keysym_t pdk; _PROP_ASSERT(prop_object_is_dictionary(pd)); - pde = _prop_dict_lookup(pd, key, NULL); - if (pde != NULL) { - _PROP_ASSERT(pde->pde_objref != NULL); - return (pde->pde_objref); + pdk = _prop_dict_lookup(pd, key, NULL); + if (pdk != NULL) { + _PROP_ASSERT(pdk->pdk_objref != NULL); + return (pdk->pdk_objref); } return (NULL); } @@ -591,14 +591,14 @@ prop_dictionary_get(prop_dictionary_t pd, const char *key) * Return the object stored at the location encoded by the keysym. */ prop_object_t -prop_dictionary_get_keysym(prop_dictionary_t pd, prop_dictionary_keysym_t pde) +prop_dictionary_get_keysym(prop_dictionary_t pd, prop_dictionary_keysym_t pdk) { _PROP_ASSERT(prop_object_is_dictionary(pd)); - _PROP_ASSERT(prop_object_is_dictionary_keysym(pde)); - _PROP_ASSERT(pde->pde_objref != NULL); + _PROP_ASSERT(prop_object_is_dictionary_keysym(pdk)); + _PROP_ASSERT(pdk->pdk_objref != NULL); - return (pde->pde_objref); + return (pdk->pdk_objref); } /* @@ -609,7 +609,7 @@ prop_dictionary_get_keysym(prop_dictionary_t pd, prop_dictionary_keysym_t pde) boolean_t prop_dictionary_set(prop_dictionary_t pd, const char *key, prop_object_t po) { - prop_dictionary_keysym_t pde, opde; + prop_dictionary_keysym_t pdk, opdk; unsigned int idx; _PROP_ASSERT(prop_object_is_dictionary(pd)); @@ -618,38 +618,38 @@ prop_dictionary_set(prop_dictionary_t pd, const char *key, prop_object_t po) if (prop_dictionary_is_immutable(pd)) return (FALSE); - pde = _prop_dict_lookup(pd, key, &idx); - if (pde != NULL) { - prop_object_t opo = pde->pde_objref; + pdk = _prop_dict_lookup(pd, key, &idx); + if (pdk != NULL) { + prop_object_t opo = pdk->pdk_objref; prop_object_retain(po); - pde->pde_objref = po; + pdk->pdk_objref = po; prop_object_release(opo); return (TRUE); } - pde = _prop_dict_entry_alloc(key, po); - if (pde == NULL) + pdk = _prop_dict_entry_alloc(key, po); + if (pdk == NULL) return (FALSE); if (pd->pd_count == pd->pd_capacity && _prop_dictionary_expand(pd, EXPAND_STEP) == FALSE) { - _prop_dict_entry_free(pde); + _prop_dict_entry_free(pdk); return (FALSE); } if (pd->pd_count == 0) { - pd->pd_array[0] = pde; + pd->pd_array[0] = pdk; pd->pd_count++; pd->pd_version++; return (TRUE); } - opde = pd->pd_array[idx]; - _PROP_ASSERT(opde != NULL); + opdk = pd->pd_array[idx]; + _PROP_ASSERT(opdk != NULL); - if (strcmp(key, opde->pde_key) < 0) { + if (strcmp(key, opdk->pdk_key) < 0) { /* - * key < opde->pde_key: insert to the left. This is + * key < opdk->pdk_key: insert to the left. This is * the same as inserting to the right, except we decrement * the current index first. * @@ -658,8 +658,8 @@ prop_dictionary_set(prop_dictionary_t pd, const char *key, prop_object_t po) */ if (idx == 0) { memmove(&pd->pd_array[1], &pd->pd_array[0], - pd->pd_count * sizeof(*pde)); - pd->pd_array[0] = pde; + pd->pd_count * sizeof(*pdk)); + pd->pd_array[0] = pdk; pd->pd_count++; pd->pd_version++; return (TRUE); @@ -668,8 +668,8 @@ prop_dictionary_set(prop_dictionary_t pd, const char *key, prop_object_t po) } memmove(&pd->pd_array[idx + 2], &pd->pd_array[idx + 1], - (pd->pd_count - (idx + 1)) * sizeof(*pde)); - pd->pd_array[idx + 1] = pde; + (pd->pd_count - (idx + 1)) * sizeof(*pdk)); + pd->pd_array[idx + 1] = pdk; pd->pd_count++; pd->pd_version++; @@ -683,41 +683,41 @@ prop_dictionary_set(prop_dictionary_t pd, const char *key, prop_object_t po) * the keysym. */ boolean_t -prop_dictionary_set_keysym(prop_dictionary_t pd, prop_dictionary_keysym_t pde, +prop_dictionary_set_keysym(prop_dictionary_t pd, prop_dictionary_keysym_t pdk, prop_object_t po) { prop_object_t opo; _PROP_ASSERT(prop_object_is_dictionary(pd)); - _PROP_ASSERT(prop_object_is_dictionary_keysym(pde)); - _PROP_ASSERT(pde->pde_objref != NULL); + _PROP_ASSERT(prop_object_is_dictionary_keysym(pdk)); + _PROP_ASSERT(pdk->pdk_objref != NULL); if (prop_dictionary_is_immutable(pd)) return (FALSE); - opo = pde->pde_objref; + opo = pdk->pdk_objref; prop_object_retain(po); - pde->pde_objref = po; + pdk->pdk_objref = po; prop_object_release(opo); return (TRUE); } static void -_prop_dictionary_remove(prop_dictionary_t pd, prop_dictionary_keysym_t pde, +_prop_dictionary_remove(prop_dictionary_t pd, prop_dictionary_keysym_t pdk, unsigned int idx) { _PROP_ASSERT(pd->pd_count != 0); _PROP_ASSERT(idx < pd->pd_count); - _PROP_ASSERT(pd->pd_array[idx] == pde); + _PROP_ASSERT(pd->pd_array[idx] == pdk); idx++; memmove(&pd->pd_array[idx - 1], &pd->pd_array[idx], - (pd->pd_count - idx) * sizeof(*pde)); + (pd->pd_count - idx) * sizeof(*pdk)); pd->pd_count--; pd->pd_version++; - prop_object_release(pde); + prop_object_release(pdk); } /* @@ -728,7 +728,7 @@ _prop_dictionary_remove(prop_dictionary_t pd, prop_dictionary_keysym_t pde, void prop_dictionary_remove(prop_dictionary_t pd, const char *key) { - prop_dictionary_keysym_t pde; + prop_dictionary_keysym_t pdk; unsigned int idx; _PROP_ASSERT(prop_object_is_dictionary(pd)); @@ -737,12 +737,12 @@ prop_dictionary_remove(prop_dictionary_t pd, const char *key) if (prop_dictionary_is_immutable(pd)) return; - pde = _prop_dict_lookup(pd, key, &idx); + pdk = _prop_dict_lookup(pd, key, &idx); /* XXX Should this be a _PROP_ASSERT()? */ - if (pde == NULL) + if (pdk == NULL) return; - _prop_dictionary_remove(pd, pde, idx); + _prop_dictionary_remove(pd, pdk, idx); } /* @@ -752,23 +752,23 @@ prop_dictionary_remove(prop_dictionary_t pd, const char *key) */ void prop_dictionary_remove_keysym(prop_dictionary_t pd, - prop_dictionary_keysym_t pde) + prop_dictionary_keysym_t pdk) { - prop_dictionary_keysym_t opde; + prop_dictionary_keysym_t opdk; unsigned int idx; _PROP_ASSERT(prop_object_is_dictionary(pd)); - _PROP_ASSERT(prop_object_is_dictionary_keysym(pde)); - _PROP_ASSERT(pde->pde_objref != NULL); + _PROP_ASSERT(prop_object_is_dictionary_keysym(pdk)); + _PROP_ASSERT(pdk->pdk_objref != NULL); /* XXX Should this be a _PROP_ASSERT()? */ if (prop_dictionary_is_immutable(pd)) return; - opde = _prop_dict_lookup(pd, pde->pde_key, &idx); - _PROP_ASSERT(opde == pde); + opdk = _prop_dict_lookup(pd, pdk->pdk_key, &idx); + _PROP_ASSERT(opdk == pdk); - _prop_dictionary_remove(pd, opde, idx); + _prop_dictionary_remove(pd, opdk, idx); } /* @@ -788,11 +788,11 @@ prop_dictionary_equals(prop_dictionary_t dict1, prop_dictionary_t dict2) * Return an immutable reference to the keysym's value. */ const char * -prop_dictionary_keysym_cstring_nocopy(prop_dictionary_keysym_t pde) +prop_dictionary_keysym_cstring_nocopy(prop_dictionary_keysym_t pdk) { - _PROP_ASSERT(prop_object_is_dictionary_keysym(pde)); - return (pde->pde_key); + _PROP_ASSERT(prop_object_is_dictionary_keysym(pdk)); + return (pdk->pdk_key); } /* @@ -801,11 +801,11 @@ prop_dictionary_keysym_cstring_nocopy(prop_dictionary_keysym_t pde) * Note: We do not compare the object references. */ boolean_t -prop_dictionary_keysym_equals(prop_dictionary_keysym_t pde1, - prop_dictionary_keysym_t pde2) +prop_dictionary_keysym_equals(prop_dictionary_keysym_t pdk1, + prop_dictionary_keysym_t pdk2) { - return (_prop_dict_entry_equals(pde1, pde2)); + return (_prop_dict_entry_equals(pdk1, pdk2)); } /* @@ -866,7 +866,7 @@ _prop_dictionary_internalize(struct _prop_object_internalize_context *ctx) if (ctx->poic_is_empty_element) return (dict); - tmpkey = _PROP_MALLOC(PDE_MAXKEY + 1, M_TEMP); + tmpkey = _PROP_MALLOC(PDK_MAXKEY + 1, M_TEMP); if (tmpkey == NULL) goto bad; @@ -888,11 +888,11 @@ _prop_dictionary_internalize(struct _prop_object_internalize_context *ctx) goto bad; if (_prop_object_internalize_decode_string(ctx, - tmpkey, PDE_MAXKEY, &keylen, + tmpkey, PDK_MAXKEY, &keylen, &ctx->poic_cp) == FALSE) goto bad; - _PROP_ASSERT(keylen <= PDE_MAXKEY); + _PROP_ASSERT(keylen <= PDK_MAXKEY); tmpkey[keylen] = '\0'; if (_prop_object_internalize_find_tag(ctx, "key",