From 87f2e9c6294200aa51805c08fa1a651f0a8a8705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Mon, 10 Jun 2013 15:47:45 +0200 Subject: [PATCH] Errors: Improved emulation of arrays in object errors. Implement _sizeof(), _indices() and _values() in the generic error class. Fixes "Index 2 is out of range 0..1." from describe_backtrace(). --- src/error.c | 22 ++++++++++++++++++++++ src/errors.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/src/error.c b/src/error.c index 237728036a..7728770912 100644 --- a/src/error.c +++ b/src/error.c @@ -673,6 +673,28 @@ static void f_error_index(INT32 args) } } +static void f_error__sizeof(INT32 args) +{ + pop_n_elems(args); + push_int(2); +} + +static void f_error__indices(INT32 args) +{ + pop_n_elems(args); + push_int(0); + push_int(1); + f_aggregate(2); +} + +static void f_error__values(INT32 args) +{ + pop_n_elems(args); + apply_current(generic_err_message_fun, 0); + apply_current(generic_err_backtrace_fun, 0); + f_aggregate(2); +} + /*! @decl string describe() *! *! Return a readable error report that includes the backtrace. diff --git a/src/errors.h b/src/errors.h index 64d41f011d..d0d9d659b7 100644 --- a/src/errors.h +++ b/src/errors.h @@ -114,6 +114,9 @@ DECLARE_ERROR(generic, Generic, EMPTY , ERR_VAR(struct array *,tArray,PIKE_T_ARRAY,error_backtrace) ERR_FUNC("cast",f_error_cast,tFunc(tString,tArray),ID_PROTECTED) ERR_FUNC("`[]",f_error_index,tFunc(tInt01,tMixed),ID_PROTECTED) + ERR_FUNC("_sizeof",f_error__sizeof,tFunc(tNone,tInt2),ID_PROTECTED) + ERR_FUNC("_indices",f_error__indices,tFunc(tNone,tArr(tInt01)),ID_PROTECTED) + ERR_FUNC("_values",f_error__values,tFunc(tNone,tArr(tOr(tStr,tArr(tMixed)))),ID_PROTECTED) ERR_FUNC("describe",f_error_describe,tFunc(tVoid,tString),0) ERR_FUNC_SAVE_ID (generic_err_message_fun, "message", f_error_message, tFunc(tVoid,tString), 0) -- GitLab