From b401b023225b09d469e616786c60f165a0d2f9ef Mon Sep 17 00:00:00 2001 From: Angel Ortega Date: Wed, 1 Dec 2010 12:16:11 +0100 Subject: [PATCH] New functions mpdm_void() and mpdm_is_null(). --- mpdm.h | 3 +++ mpdm_t.c | 6 +----- mpdm_v.c | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/mpdm.h b/mpdm.h index 937f7ee..6101f14 100644 --- a/mpdm.h +++ b/mpdm.h @@ -89,6 +89,9 @@ int mpdm_size(const mpdm_t v); mpdm_t mpdm_clone(const mpdm_t v); mpdm_t mpdm_root(void); +void mpdm_void(mpdm_t v); +int mpdm_is_null(mpdm_t v); + mpdm_t mpdm_exec(mpdm_t c, mpdm_t args, mpdm_t ctxt); mpdm_t mpdm_exec_1(mpdm_t c, mpdm_t a1, mpdm_t ctxt); mpdm_t mpdm_exec_2(mpdm_t c, mpdm_t a1, mpdm_t a2, mpdm_t ctxt); diff --git a/mpdm_t.c b/mpdm_t.c index 0f46b19..a039b05 100644 --- a/mpdm_t.c +++ b/mpdm_t.c @@ -250,11 +250,7 @@ void mpdm_semaphore_post(mpdm_t sem) static void thread_caller(mpdm_t a) { /* ignore return value */ - mpdm_unref( - mpdm_ref( - mpdm_exec(mpdm_aget(a, 0), mpdm_aget(a, 1), mpdm_aget(a, 2)) - ) - ); + mpdm_void(mpdm_exec(mpdm_aget(a, 0), mpdm_aget(a, 1), mpdm_aget(a, 2))); /* was referenced in mpdm_exec_thread() */ mpdm_unref(a); diff --git a/mpdm_v.c b/mpdm_v.c index 24cfeb3..5450d9b 100644 --- a/mpdm_v.c +++ b/mpdm_v.c @@ -213,7 +213,7 @@ mpdm_t mpdm_root(void) /** - * mpdm_set_ival - Sets the integer value + * mpdm_set_ival - Sets the integer value. * @v: the value * @ival: the integer * @@ -231,7 +231,7 @@ mpdm_t mpdm_set_ival(mpdm_t v, int ival) /** - * mpdm_set_rval - Sets the real value + * mpdm_set_rval - Sets the real value. * @v: the value * @rval: the real * @@ -249,6 +249,39 @@ mpdm_t mpdm_set_rval(mpdm_t v, double rval) /** + * mpdm_void - Refs then unrefs a value. + * @v: the value + * + * References and unreferences a value. To be used to receive + * the output of mpdm_exec() in case of it being void (i.e. + * its return value ignored). + */ +void mpdm_void(mpdm_t v) +{ + mpdm_ref(v); + mpdm_unref(v); +} + + +/** + * mpdm_is_null - Returns 1 if a value is NULL. + * @v: the value + * + * Returns 1 if a value is NULL. The reference count is touched. + */ +int mpdm_is_null(mpdm_t v) +{ + int r; + + mpdm_ref(v); + r = v == NULL ? 1 : 0; + mpdm_unref(v); + + return r; +} + + +/** * mpdm_exec - Executes an executable value. * @c: the code value * @args: the arguments -- 2.11.4.GIT