diff --git a/lib/err.c b/lib/err.c index 3b526f5..1de87d7 100644 --- a/lib/err.c +++ b/lib/err.c @@ -297,8 +297,17 @@ const hcl_ooch_t* hcl_backuperrmsg (hcl_t* hcl) return hcl->errmsg.tmpbuf.ooch; } +void hcl_seterrnum (hcl_t* hcl, hcl_errnum_t errnum) +{ + if (hcl->shuterr) return; + hcl->errnum = errnum; + hcl->errmsg.len = 0; +} + void hcl_seterrwithsyserr (hcl_t* hcl, int syserr) { + if (hcl->shuterr) return; + if (hcl->vmprim.syserrstrb) { hcl->vmprim.syserrstrb (hcl, syserr, hcl->errmsg.tmpbuf.bch, HCL_COUNTOF(hcl->errmsg.tmpbuf.bch)); @@ -323,6 +332,8 @@ void hcl_setsynerrbfmt (hcl_t* hcl, hcl_synerrnum_t num, const hcl_ioloc_t* loc, { static hcl_bch_t syntax_error[] = "syntax error - "; + if (hcl->shuterr) return; + if (msgfmt) { va_list ap; @@ -372,6 +383,8 @@ void hcl_setsynerrufmt (hcl_t* hcl, hcl_synerrnum_t num, const hcl_ioloc_t* loc, { static hcl_bch_t syntax_error[] = "syntax error - "; + if (hcl->shuterr) return; + if (msgfmt) { va_list ap; diff --git a/lib/hcl-prv.h b/lib/hcl-prv.h index 33b0080..5912c20 100644 --- a/lib/hcl-prv.h +++ b/lib/hcl-prv.h @@ -645,6 +645,15 @@ typedef hcl_ooi_t (*hcl_outbfmt_t) ( ); +/* i don't want an error raised inside the callback to override + * the existing error number and message. */ +#define vmprim_log_write(hcl,mask,ptr,len) do { \ + int shuterr = (hcl)->shuterr; \ + (hcl)->shuterr = 1; \ + (hcl)->vmprim.log_write (hcl, mask, ptr, len); \ + (hcl)->shuterr = shuterr; \ + } while(0) + #if defined(__cplusplus) extern "C" { #endif diff --git a/lib/hcl.c b/lib/hcl.c index 9dcabd4..27f7020 100644 --- a/lib/hcl.c +++ b/lib/hcl.c @@ -169,7 +169,7 @@ void hcl_fini (hcl_t* hcl) { /* flush pending log messages just in case. */ HCL_ASSERT (hcl, hcl->log.ptr != HCL_NULL); - hcl->vmprim.log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); + vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); } for (cb = hcl->cblist; cb; cb = cb->next) @@ -184,7 +184,7 @@ void hcl_fini (hcl_t* hcl) * this point because one of the callbacks could arrange to stop * logging */ HCL_ASSERT (hcl, hcl->log.ptr != HCL_NULL); - hcl->vmprim.log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); + vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); } /* deregister all callbacks */ diff --git a/lib/hcl.h b/lib/hcl.h index 07c4324..c8f9a2e 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -940,8 +940,8 @@ struct hcl_t { hcl_mmgr_t* mmgr; hcl_cmgr_t* cmgr; - hcl_errnum_t errnum; + hcl_errnum_t errnum; struct { union @@ -953,6 +953,7 @@ struct hcl_t hcl_ooch_t buf[2048]; hcl_oow_t len; } errmsg; + int shuterr; struct { @@ -1342,11 +1343,11 @@ HCL_EXPORT void hcl_fini ( static HCL_INLINE hcl_mmgr_t* hcl_getmmgr (hcl_t* hcl) { return hcl->mmgr; } static HCL_INLINE void* hcl_getxtn (hcl_t* hcl) { return (void*)(hcl + 1); } - /*static HCL_INLINE hcl_cmgr_t* hcl_getcmgr (hcl_t* hcl) { return hcl->cmgr; } - static HCL_INLINE void hcl_setcmgr (hcl_t* hcl, hcl_cmgr_t* cmgr) { hcl->cmgr = cmgr; }*/ + static HCL_INLINE hcl_cmgr_t* hcl_getcmgr (hcl_t* hcl) { return hcl->cmgr; } + static HCL_INLINE void hcl_setcmgr (hcl_t* hcl, hcl_cmgr_t* cmgr) { hcl->cmgr = cmgr; } static HCL_INLINE hcl_errnum_t hcl_geterrnum (hcl_t* hcl) { return hcl->errnum; } - static HCL_INLINE void hcl_seterrnum (hcl_t* hcl, hcl_errnum_t errnum) { hcl->errnum = errnum; hcl->errmsg.len = 0; } + #else # define hcl_getmmgr(hcl) ((hcl)->mmgr) # define hcl_getxtn(hcl) ((void*)((hcl) + 1)) @@ -1355,9 +1356,18 @@ HCL_EXPORT void hcl_fini ( # define hcl_setcmgr(hcl,mgr) ((hcl)->cmgr = (mgr)) # define hcl_geterrnum(hcl) ((hcl)->errnum) -# define hcl_seterrnum(hcl,num) ((hcl)->errmsg.len = 0, (hcl)->errnum = (num)) #endif +HCL_EXPORT void hcl_seterrnum ( + hcl_t* hcl, + hcl_errnum_t errnum +); + +HCL_EXPORT void hcl_seterrwithsyserr ( + hcl_t* hcl, + int syserr +); + HCL_EXPORT void hcl_seterrbfmt ( hcl_t* hcl, hcl_errnum_t errnum, @@ -1372,11 +1382,6 @@ HCL_EXPORT void hcl_seterrufmt ( ... ); -HCL_EXPORT void hcl_seterrwithsyserr ( - hcl_t* hcl, - int syserr -); - HCL_EXPORT const hcl_ooch_t* hcl_geterrstr ( hcl_t* hcl ); diff --git a/lib/logfmt.c b/lib/logfmt.c index 6ebfd55..1e69801 100644 --- a/lib/logfmt.c +++ b/lib/logfmt.c @@ -200,7 +200,7 @@ static int put_ooch (hcl_t* hcl, hcl_oow_t mask, hcl_ooch_t ch, hcl_oow_t len) /* no line ending - append a line terminator */ hcl->log.ptr[hcl->log.len++] = '\n'; } - hcl->vmprim.log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); + vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); hcl->log.len = 0; } @@ -244,7 +244,7 @@ redo: /* no line ending - append a line terminator */ hcl->log.ptr[hcl->log.len++] = '\n'; } - hcl->vmprim.log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); + vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); hcl->log.len = 0; } @@ -294,7 +294,7 @@ static int put_oocs (hcl_t* hcl, hcl_oow_t mask, const hcl_ooch_t* ptr, hcl_oow_ hcl->log.ptr[hcl->log.len++] = '\n'; } - hcl->vmprim.log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); + vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); hcl->log.len = 0; } @@ -338,7 +338,7 @@ redo: /* no line ending - append a line terminator */ hcl->log.ptr[hcl->log.len++] = '\n'; } - hcl->vmprim.log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); + vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); hcl->log.len = 0; } @@ -435,7 +435,7 @@ hcl_ooi_t hcl_logbfmt (hcl_t* hcl, hcl_oow_t mask, const hcl_bch_t* fmt, ...) if (hcl->log.len > 0 && hcl->log.ptr[hcl->log.len - 1] == '\n') { - hcl->vmprim.log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); + vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); hcl->log.len = 0; } return (x <= -1)? -1: fo.count; @@ -463,7 +463,7 @@ hcl_ooi_t hcl_logufmt (hcl_t* hcl, hcl_oow_t mask, const hcl_uch_t* fmt, ...) if (hcl->log.len > 0 && hcl->log.ptr[hcl->log.len - 1] == '\n') { - hcl->vmprim.log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); + vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); hcl->log.len = 0; }