Fix an issue introduced with the prop_stack change: It's not a good idea to

return a 3-value enum from a function declared to return bool.  This broke
the recurse case for prop_object_equals().  Instead, declare the object type
equals routine to return a _prop_object_equals_rv_t.

Give the same treatment to the object type free routines: declare them to
return a _prop_object_free_rv_t, and consistently check those return values
againt the enum type.

Tidy up some whitespace while we're here.
This commit is contained in:
thorpej 2008-08-03 04:00:12 +00:00
parent 108e11a80a
commit 4ce0dc3a15
8 changed files with 179 additions and 158 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_array.c,v 1.18 2008/05/24 14:32:48 yamt Exp $ */
/* $NetBSD: prop_array.c,v 1.19 2008/08/03 04:00:12 thorpej Exp $ */
/*-
* Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
@ -53,17 +53,21 @@ _PROP_POOL_INIT(_prop_array_pool, sizeof(struct _prop_array), "proparay")
_PROP_MALLOC_DEFINE(M_PROP_ARRAY, "prop array",
"property array container object")
static int _prop_array_free(prop_stack_t, prop_object_t *);
static _prop_object_free_rv_t
_prop_array_free(prop_stack_t, prop_object_t *);
static void _prop_array_emergency_free(prop_object_t);
static bool _prop_array_externalize(
struct _prop_object_externalize_context *,
void *);
static bool _prop_array_equals(prop_object_t, prop_object_t,
static _prop_object_equals_rv_t
_prop_array_equals(prop_object_t, prop_object_t,
void **, void **,
prop_object_t *, prop_object_t *);
static void _prop_array_equals_finish(prop_object_t, prop_object_t);
static prop_object_iterator_t _prop_array_iterator_locked(prop_array_t);
static prop_object_t _prop_array_iterator_next_object_locked(void *);
static prop_object_iterator_t
_prop_array_iterator_locked(prop_array_t);
static prop_object_t
_prop_array_iterator_next_object_locked(void *);
static void _prop_array_iterator_reset_locked(void *);
static const struct _prop_object_type _prop_object_type_array = {
@ -87,7 +91,7 @@ struct _prop_array_iterator {
#define EXPAND_STEP 16
static int
static _prop_object_free_rv_t
_prop_array_free(prop_stack_t stack, prop_object_t *obj)
{
prop_array_t pa = *obj;
@ -195,7 +199,7 @@ _prop_array_externalize(struct _prop_object_externalize_context *ctx,
}
/* ARGSUSED */
static bool
static _prop_object_equals_rv_t
_prop_array_equals(prop_object_t v1, prop_object_t v2,
void **stored_pointer1, void **stored_pointer2,
prop_object_t *next_obj1, prop_object_t *next_obj2)
@ -203,7 +207,7 @@ _prop_array_equals(prop_object_t v1, prop_object_t v2,
prop_array_t array1 = v1;
prop_array_t array2 = v2;
uintptr_t idx;
bool rv = _PROP_OBJECT_EQUALS_FALSE;
_prop_object_equals_rv_t rv = _PROP_OBJECT_EQUALS_FALSE;
if (array1 == array2)
return (_PROP_OBJECT_EQUALS_TRUE);
@ -225,7 +229,7 @@ _prop_array_equals(prop_object_t v1, prop_object_t v2,
if (array1->pa_count != array2->pa_count)
goto out;
if (idx == array1->pa_count) {
rv = true;
rv = _PROP_OBJECT_EQUALS_TRUE;
goto out;
}
_PROP_ASSERT(idx < array1->pa_count);

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_bool.c,v 1.15 2008/04/28 20:22:53 martin Exp $ */
/* $NetBSD: prop_bool.c,v 1.16 2008/08/03 04:00:12 thorpej Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -43,11 +43,13 @@ static struct _prop_bool _prop_bool_false;
_PROP_MUTEX_DECL_STATIC(_prop_bool_initialized_mutex)
static bool _prop_bool_initialized;
static int _prop_bool_free(prop_stack_t, prop_object_t *);
static _prop_object_free_rv_t
_prop_bool_free(prop_stack_t, prop_object_t *);
static bool _prop_bool_externalize(
struct _prop_object_externalize_context *,
void *);
static bool _prop_bool_equals(prop_object_t, prop_object_t,
static _prop_object_equals_rv_t
_prop_bool_equals(prop_object_t, prop_object_t,
void **, void **,
prop_object_t *, prop_object_t *);
@ -62,7 +64,7 @@ static const struct _prop_object_type _prop_object_type_bool = {
((x) != NULL && (x)->pb_obj.po_type == &_prop_object_type_bool)
/* ARGSUSED */
static int
static _prop_object_free_rv_t
_prop_bool_free(prop_stack_t stack, prop_object_t *obj)
{
/*
@ -85,7 +87,7 @@ _prop_bool_externalize(struct _prop_object_externalize_context *ctx,
}
/* ARGSUSED */
static bool
static _prop_object_equals_rv_t
_prop_bool_equals(prop_object_t v1, prop_object_t v2,
void **stored_pointer1, void **stored_pointer2,
prop_object_t *next_obj1, prop_object_t *next_obj2)

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_data.c,v 1.12 2008/05/15 21:23:33 dyoung Exp $ */
/* $NetBSD: prop_data.c,v 1.13 2008/08/03 04:00:12 thorpej Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -62,11 +62,13 @@ _PROP_POOL_INIT(_prop_data_pool, sizeof(struct _prop_data), "propdata")
_PROP_MALLOC_DEFINE(M_PROP_DATA, "prop data",
"property data container object")
static int _prop_data_free(prop_stack_t, prop_object_t *);
static _prop_object_free_rv_t
_prop_data_free(prop_stack_t, prop_object_t *);
static bool _prop_data_externalize(
struct _prop_object_externalize_context *,
void *);
static bool _prop_data_equals(prop_object_t, prop_object_t,
static _prop_object_equals_rv_t
_prop_data_equals(prop_object_t, prop_object_t,
void **, void **,
prop_object_t *, prop_object_t *);
@ -81,7 +83,7 @@ static const struct _prop_object_type _prop_object_type_data = {
((x) != NULL && (x)->pd_obj.po_type == &_prop_object_type_data)
/* ARGSUSED */
static int
static _prop_object_free_rv_t
_prop_data_free(prop_stack_t stack, prop_object_t *obj)
{
prop_data_t pd = *obj;
@ -173,7 +175,7 @@ _prop_data_externalize(struct _prop_object_externalize_context *ctx, void *v)
}
/* ARGSUSED */
static bool
static _prop_object_equals_rv_t
_prop_data_equals(prop_object_t v1, prop_object_t v2,
void **stored_pointer1, void **stored_pointer2,
prop_object_t *next_obj1, prop_object_t *next_obj2)

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_dictionary.c,v 1.31 2008/06/17 21:29:47 thorpej Exp $ */
/* $NetBSD: prop_dictionary.c,v 1.32 2008/08/03 04:00:12 thorpej Exp $ */
/*-
* Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
@ -104,23 +104,26 @@ _PROP_POOL_INIT(_prop_dictionary_pool, sizeof(struct _prop_dictionary),
_PROP_MALLOC_DEFINE(M_PROP_DICT, "prop dictionary",
"property dictionary container object")
static int _prop_dictionary_free(prop_stack_t, prop_object_t *);
static _prop_object_free_rv_t
_prop_dictionary_free(prop_stack_t, prop_object_t *);
static void _prop_dictionary_emergency_free(prop_object_t);
static bool _prop_dictionary_externalize(
struct _prop_object_externalize_context *,
void *);
static bool _prop_dictionary_equals(prop_object_t, prop_object_t,
static _prop_object_equals_rv_t
_prop_dictionary_equals(prop_object_t, prop_object_t,
void **, void **,
prop_object_t *, prop_object_t *);
static void _prop_dictionary_equals_finish(prop_object_t, prop_object_t);
static prop_object_iterator_t _prop_dictionary_iterator_locked(
prop_dictionary_t);
static prop_object_t _prop_dictionary_iterator_next_object_locked(void *);
static prop_object_t _prop_dictionary_get_keysym(prop_dictionary_t,
prop_dictionary_keysym_t,
bool);
static prop_object_t _prop_dictionary_get(prop_dictionary_t, const char *,
bool);
static prop_object_iterator_t
_prop_dictionary_iterator_locked(prop_dictionary_t);
static prop_object_t
_prop_dictionary_iterator_next_object_locked(void *);
static prop_object_t
_prop_dictionary_get_keysym(prop_dictionary_t,
prop_dictionary_keysym_t, bool);
static prop_object_t
_prop_dictionary_get(prop_dictionary_t, const char *, bool);
static const struct _prop_object_type _prop_object_type_dictionary = {
.pot_type = PROP_TYPE_DICTIONARY,
@ -131,11 +134,13 @@ static const struct _prop_object_type _prop_object_type_dictionary = {
.pot_equals_finish = _prop_dictionary_equals_finish,
};
static int _prop_dict_keysym_free(prop_stack_t, prop_object_t *);
static _prop_object_free_rv_t
_prop_dict_keysym_free(prop_stack_t, prop_object_t *);
static bool _prop_dict_keysym_externalize(
struct _prop_object_externalize_context *,
void *);
static bool _prop_dict_keysym_equals(prop_object_t, prop_object_t,
static _prop_object_equals_rv_t
_prop_dict_keysym_equals(prop_object_t, prop_object_t,
void **, void **,
prop_object_t *, prop_object_t *);
@ -210,7 +215,7 @@ _prop_dict_keysym_put(prop_dictionary_keysym_t pdk)
}
/* ARGSUSED */
static int
static _prop_object_free_rv_t
_prop_dict_keysym_free(prop_stack_t stack, prop_object_t *obj)
{
prop_dictionary_keysym_t pdk = *obj;
@ -244,7 +249,7 @@ _prop_dict_keysym_externalize(struct _prop_object_externalize_context *ctx,
}
/* ARGSUSED */
static bool
static _prop_object_equals_rv_t
_prop_dict_keysym_equals(prop_object_t v1, prop_object_t v2,
void **stored_pointer1, void **stored_pointer2,
prop_object_t *next_obj1, prop_object_t *next_obj2)
@ -332,9 +337,7 @@ _prop_dict_keysym_alloc(const char *key)
return (pdk);
}
int dont_free = 1;
static int
static _prop_object_free_rv_t
_prop_dictionary_free(prop_stack_t stack, prop_object_t *obj)
{
prop_dictionary_t pd = *obj;
@ -458,7 +461,7 @@ _prop_dictionary_externalize(struct _prop_object_externalize_context *ctx,
}
/* ARGSUSED */
static bool
static _prop_object_equals_rv_t
_prop_dictionary_equals(prop_object_t v1, prop_object_t v2,
void **stored_pointer1, void **stored_pointer2,
prop_object_t *next_obj1, prop_object_t *next_obj2)
@ -466,7 +469,7 @@ _prop_dictionary_equals(prop_object_t v1, prop_object_t v2,
prop_dictionary_t dict1 = v1;
prop_dictionary_t dict2 = v2;
uintptr_t idx;
bool rv = _PROP_OBJECT_EQUALS_FALSE;
_prop_object_equals_rv_t rv = _PROP_OBJECT_EQUALS_FALSE;
if (dict1 == dict2)
return (_PROP_OBJECT_EQUALS_TRUE);
@ -1163,7 +1166,7 @@ prop_dictionary_keysym_equals(prop_dictionary_keysym_t pdk1,
{
if (!prop_object_is_dictionary_keysym(pdk1) ||
!prop_object_is_dictionary_keysym(pdk2))
return (_PROP_OBJECT_EQUALS_FALSE);
return (false);
return (prop_object_equals(pdk1, pdk2));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_number.c,v 1.18 2008/06/17 21:29:47 thorpej Exp $ */
/* $NetBSD: prop_number.c,v 1.19 2008/08/03 04:00:12 thorpej Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -64,11 +64,13 @@ struct _prop_number {
_PROP_POOL_INIT(_prop_number_pool, sizeof(struct _prop_number), "propnmbr")
static int _prop_number_free(prop_stack_t, prop_object_t *);
static _prop_object_free_rv_t
_prop_number_free(prop_stack_t, prop_object_t *);
static bool _prop_number_externalize(
struct _prop_object_externalize_context *,
void *);
static bool _prop_number_equals(prop_object_t, prop_object_t,
static _prop_object_equals_rv_t
_prop_number_equals(prop_object_t, prop_object_t,
void **, void **,
prop_object_t *, prop_object_t *);
@ -145,7 +147,7 @@ static bool _prop_number_tree_initialized;
_PROP_MUTEX_DECL_STATIC(_prop_number_tree_mutex)
/* ARGSUSED */
static int
static _prop_object_free_rv_t
_prop_number_free(prop_stack_t stack, prop_object_t *obj)
{
prop_number_t pn = *obj;
@ -184,7 +186,7 @@ _prop_number_externalize(struct _prop_object_externalize_context *ctx,
}
/* ARGSUSED */
static bool
static _prop_object_equals_rv_t
_prop_number_equals(prop_object_t v1, prop_object_t v2,
void **stored_pointer1, void **stored_pointer2,
prop_object_t *next_obj1, prop_object_t *next_obj2)
@ -205,7 +207,7 @@ _prop_number_equals(prop_object_t v1, prop_object_t v2,
* cannot be equal because they would have had pointer equality.
*/
if (num1->pn_value.pnv_is_unsigned == num2->pn_value.pnv_is_unsigned)
return (_PROP_OBJECT_EQUALS_TRUE);
return (_PROP_OBJECT_EQUALS_FALSE);
/*
* We now have one signed value and one unsigned value. We can

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_object.c,v 1.21 2008/04/28 20:22:53 martin Exp $ */
/* $NetBSD: prop_object.c,v 1.22 2008/08/03 04:00:12 thorpej Exp $ */
/*-
* Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
@ -1035,7 +1035,8 @@ prop_object_release_emergency(prop_object_t obj)
break;
_PROP_ASSERT(po->po_type);
if ((po->po_type->pot_free)(NULL, &obj) == 0)
if ((po->po_type->pot_free)(NULL, &obj) ==
_PROP_OBJECT_FREE_DONE)
break;
parent = po;
@ -1129,7 +1130,7 @@ prop_object_equals_with_error(prop_object_t obj1, prop_object_t obj2,
void *stored_pointer1, *stored_pointer2;
prop_object_t next_obj1, next_obj2;
struct _prop_stack stack;
int ret;
_prop_object_equals_rv_t ret;
_prop_stack_init(&stack);
if (error_flag)
@ -1145,7 +1146,8 @@ prop_object_equals_with_error(prop_object_t obj1, prop_object_t obj2,
return (false);
continue_subtree:
ret = (*po1->po_type->pot_equals)(obj1, obj2, &stored_pointer1, &stored_pointer2,
ret = (*po1->po_type->pot_equals)(obj1, obj2,
&stored_pointer1, &stored_pointer2,
&next_obj1, &next_obj2);
if (ret == _PROP_OBJECT_EQUALS_FALSE)
goto finish;

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_object_impl.h,v 1.26 2008/05/24 14:24:04 yamt Exp $ */
/* $NetBSD: prop_object_impl.h,v 1.27 2008/08/03 04:00:12 thorpej Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -98,17 +98,17 @@ struct _prop_object_internalize_context {
_prop_tag_type_t poic_tag_type;
};
enum {
typedef enum {
_PROP_OBJECT_FREE_DONE,
_PROP_OBJECT_FREE_RECURSE,
_PROP_OBJECT_FREE_FAILED
};
} _prop_object_free_rv_t;
enum {
typedef enum {
_PROP_OBJECT_EQUALS_FALSE,
_PROP_OBJECT_EQUALS_TRUE,
_PROP_OBJECT_EQUALS_RECURSE
};
} _prop_object_equals_rv_t;
#define _PROP_EOF(c) ((c) == '\0')
#define _PROP_ISSPACE(c) \
@ -164,8 +164,10 @@ void _prop_object_internalize_unmap_file(
typedef bool (*prop_object_internalizer_t)(prop_stack_t, prop_object_t *,
struct _prop_object_internalize_context *);
typedef bool (*prop_object_internalizer_continue_t)(prop_stack_t, prop_object_t *,
struct _prop_object_internalize_context *, void *, prop_object_t);
typedef bool (*prop_object_internalizer_continue_t)(prop_stack_t,
prop_object_t *,
struct _prop_object_internalize_context *,
void *, prop_object_t);
/* These are here because they're required by shared code. */
bool _prop_array_internalize(prop_stack_t, prop_object_t *,
@ -185,7 +187,8 @@ struct _prop_object_type {
/* type indicator */
uint32_t pot_type;
/* func to free object */
int (*pot_free)(prop_stack_t, prop_object_t *);
_prop_object_free_rv_t
(*pot_free)(prop_stack_t, prop_object_t *);
/*
* func to free the child returned by pot_free with stack == NULL.
*
@ -197,7 +200,8 @@ struct _prop_object_type {
bool (*pot_extern)(struct _prop_object_externalize_context *,
void *);
/* func to test quality */
bool (*pot_equals)(prop_object_t, prop_object_t,
_prop_object_equals_rv_t
(*pot_equals)(prop_object_t, prop_object_t,
void **, void **,
prop_object_t *, prop_object_t *);
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_string.c,v 1.10 2008/04/28 20:22:53 martin Exp $ */
/* $NetBSD: prop_string.c,v 1.11 2008/08/03 04:00:12 thorpej Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -51,11 +51,13 @@ _PROP_POOL_INIT(_prop_string_pool, sizeof(struct _prop_string), "propstng")
_PROP_MALLOC_DEFINE(M_PROP_STRING, "prop string",
"property string container object")
static int _prop_string_free(prop_stack_t, prop_object_t *);
static _prop_object_free_rv_t
_prop_string_free(prop_stack_t, prop_object_t *);
static bool _prop_string_externalize(
struct _prop_object_externalize_context *,
void *);
static bool _prop_string_equals(prop_object_t, prop_object_t,
static _prop_object_equals_rv_t
_prop_string_equals(prop_object_t, prop_object_t,
void **, void **,
prop_object_t *, prop_object_t *);
@ -71,7 +73,7 @@ static const struct _prop_object_type _prop_object_type_string = {
#define prop_string_contents(x) ((x)->ps_immutable ? (x)->ps_immutable : "")
/* ARGSUSED */
static int
static _prop_object_free_rv_t
_prop_string_free(prop_stack_t stack, prop_object_t *obj)
{
prop_string_t ps = *obj;
@ -102,7 +104,7 @@ _prop_string_externalize(struct _prop_object_externalize_context *ctx,
}
/* ARGSUSED */
static bool
static _prop_object_equals_rv_t
_prop_string_equals(prop_object_t v1, prop_object_t v2,
void **stored_pointer1, void **stored_pointer2,
prop_object_t *next_obj1, prop_object_t *next_obj2)