From 21cddab62f6dfa32ebea2300dfa71b8611a1d96f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 17 Feb 2018 16:45:17 +0000 Subject: [PATCH] change dic.get to return an error code upon search failure --- lib/hcl.h | 3 ++- mod/dic.c | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/hcl.h b/lib/hcl.h index fe7be01..f115c7b 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -1138,7 +1138,8 @@ struct hcl_t HCL_STACK_SETTOP(hcl, (retv)); \ } while(0) -#define HCL_STACK_SETRETTORCV(hcl,nargs) (HCL_STACK_POPS(hcl, nargs)) +#define HCL_STACK_SETRETTOERRNUM(hcl,nargs) HCL_STACK_SETRET(hcl, nargs, HCL_ERROR_TO_OOP(hcl->errnum)) +#define HCL_STACK_SETRETTOERROR(hcl,nargs,ec) HCL_STACK_SETRET(hcl, nargs, HCL_ERROR_TO_OOP(ec)) /* ========================================================================= diff --git a/mod/dic.c b/mod/dic.c index 545af7e..68872dc 100644 --- a/mod/dic.c +++ b/mod/dic.c @@ -45,10 +45,8 @@ static hcl_pfrc_t pf_dic_get (hcl_t* hcl, hcl_ooi_t nargs) pair = hcl_getatdic(hcl, (hcl_oop_dic_t)dic, key); if (!pair) { - /* TODO: arrange to return ERROR instead of returnin HCL_PF_FAILURE*/ - hcl_seterrbfmt (hcl, HCL_EINVAL, "invalid key - %O", key); - return HCL_PF_FAILURE; - + HCL_STACK_SETRETTOERROR (hcl, nargs, HCL_ENOENT); + return HCL_PF_SUCCESS; } HCL_STACK_SETRET (hcl, nargs, HCL_CONS_CDR(pair));