diff options
Diffstat (limited to 'src/libmowgli/base/argstack.c')
-rw-r--r-- | src/libmowgli/base/argstack.c | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/src/libmowgli/base/argstack.c b/src/libmowgli/base/argstack.c index ea67da2..560c83e 100644 --- a/src/libmowgli/base/argstack.c +++ b/src/libmowgli/base/argstack.c @@ -30,7 +30,8 @@ static mowgli_object_class_t klass; * * \param vptr pointer to mowgli_argstack_t to destroy. */ -static void mowgli_argstack_destroy(void *vptr) +static void +mowgli_argstack_destroy(void *vptr) { mowgli_argstack_t *self = (mowgli_argstack_t *) vptr; mowgli_node_t *n, *tn; @@ -48,17 +49,18 @@ static void mowgli_argstack_destroy(void *vptr) /* * \brief Initialization code for the mowgli.argstack library. - * + * * Side Effects: * - the mowgli_argstack_t object class is registered. */ -void mowgli_argstack_bootstrap(void) +void +mowgli_argstack_bootstrap(void) { mowgli_object_class_init(&klass, "mowgli_argstack_t", mowgli_argstack_destroy, FALSE); } /* - * \brief Creates an argument stack from a va_list and an appropriate + * \brief Creates an argument stack from a va_list and an appropriate * description schema. * * \param descstr a description string which describes the argument stack, where: @@ -70,20 +72,20 @@ void mowgli_argstack_bootstrap(void) * * \return a mowgli_argstack_t (mowgli.argstack) object. */ -mowgli_argstack_t *mowgli_argstack_create_from_va_list(const char *descstr, va_list va) +mowgli_argstack_t * +mowgli_argstack_create_from_va_list(const char *descstr, va_list va) { + return_null_if_fail(descstr != NULL); + const char *cp = descstr; mowgli_argstack_t *out = mowgli_alloc(sizeof(mowgli_argstack_t)); mowgli_object_init(mowgli_object(out), descstr, &klass, NULL); - if (descstr == NULL) - mowgli_throw_exception_val(mowgli.argstack.invalid_description, NULL); - while (*cp) { mowgli_argstack_element_t *e = mowgli_alloc(sizeof(mowgli_argstack_element_t)); - switch(*cp) + switch (*cp) { case 's': e->data.string = va_arg(va, char *); @@ -104,7 +106,8 @@ mowgli_argstack_t *mowgli_argstack_create_from_va_list(const char *descstr, va_l default: va_end(va); mowgli_object_unref(out); - mowgli_throw_exception_val(mowgli.argstack.invalid_description, NULL); + mowgli_log_warning("invalid description"); + return NULL; break; } @@ -127,14 +130,14 @@ mowgli_argstack_t *mowgli_argstack_create_from_va_list(const char *descstr, va_l * * \return a mowgli_argstack_t (mowgli.argstack) object. */ -mowgli_argstack_t *mowgli_argstack_create(const char *descstr, ...) +mowgli_argstack_t * +mowgli_argstack_create(const char *descstr, ...) { + return_null_if_fail(descstr != NULL); + va_list va; mowgli_argstack_t *out; - if (descstr == NULL) - mowgli_throw_exception_val(mowgli.argstack.invalid_description, NULL); - va_start(va, descstr); out = mowgli_argstack_create_from_va_list(descstr, va); va_end(va); @@ -152,14 +155,14 @@ mowgli_argstack_t *mowgli_argstack_create(const char *descstr, ...) * Side Effects: * - the argument is removed from the argstack. */ -const char *mowgli_argstack_pop_string(mowgli_argstack_t *self) +const char * +mowgli_argstack_pop_string(mowgli_argstack_t *self) { + return_null_if_fail(self != NULL); + mowgli_node_t *n; mowgli_argstack_element_t *e; - if (self == NULL) - mowgli_throw_exception_val(mowgli.null_pointer_exception, NULL); - n = self->stack.head; mowgli_node_delete(n, &self->stack); e = n->data; @@ -178,14 +181,14 @@ const char *mowgli_argstack_pop_string(mowgli_argstack_t *self) * Side Effects: * - the argument is removed from the argstack. */ -int mowgli_argstack_pop_numeric(mowgli_argstack_t *self) +int +mowgli_argstack_pop_numeric(mowgli_argstack_t *self) { + return_val_if_fail(self != NULL, 0); + mowgli_node_t *n; mowgli_argstack_element_t *e; - if (self == NULL) - mowgli_throw_exception_val(mowgli.null_pointer_exception, 0); - n = self->stack.head; mowgli_node_delete(n, &self->stack); e = n->data; @@ -204,14 +207,14 @@ int mowgli_argstack_pop_numeric(mowgli_argstack_t *self) * Side Effects: * - the argument is removed from the argstack. */ -mowgli_boolean_t mowgli_argstack_pop_boolean(mowgli_argstack_t *self) +mowgli_boolean_t +mowgli_argstack_pop_boolean(mowgli_argstack_t *self) { + return_val_if_fail(self != NULL, false); + mowgli_node_t *n; mowgli_argstack_element_t *e; - if (self == NULL) - mowgli_throw_exception_val(mowgli.null_pointer_exception, FALSE); - n = self->stack.head; mowgli_node_delete(n, &self->stack); e = n->data; @@ -230,14 +233,14 @@ mowgli_boolean_t mowgli_argstack_pop_boolean(mowgli_argstack_t *self) * Side Effects: * - the argument is removed from the argstack. */ -void *mowgli_argstack_pop_pointer(mowgli_argstack_t *self) +void * +mowgli_argstack_pop_pointer(mowgli_argstack_t *self) { + return_null_if_fail(self != NULL); + mowgli_node_t *n; mowgli_argstack_element_t *e; - if (self == NULL) - mowgli_throw_exception_val(mowgli.null_pointer_exception, NULL); - n = self->stack.head; mowgli_node_delete(n, &self->stack); e = n->data; |