pike.git / src / error.c

version» Context lines:

pike.git/src/error.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: error.c,v 1.118 2003/11/14 00:07:35 mast Exp $ + || $Id: error.c,v 1.119 2003/11/14 04:10:32 mast Exp $   */      #define NO_PIKE_SHORTHAND   #include "global.h"   #include "svalue.h"   #include "pike_macros.h"   #include "pike_error.h"   #include "interpret.h"   #include "stralloc.h"   #include "builtin_functions.h"   #include "array.h"   #include "object.h"   #include "main.h"   #include "builtin_functions.h"   #include "backend.h"   #include "operators.h"   #include "module_support.h"   #include "threads.h"   #include "gc.h"    - RCSID("$Id: error.c,v 1.118 2003/11/14 00:07:35 mast Exp $"); + RCSID("$Id: error.c,v 1.119 2003/11/14 04:10:32 mast Exp $");      #undef ATTRIBUTE   #define ATTRIBUTE(X)      PMOD_EXPORT const char msg_fatal_error[] =    "%s:%d: Fatal error:\n";   #ifdef PIKE_DEBUG   PMOD_EXPORT const char msg_unsetjmp_nosync_1[] =    "UNSETJMP out of sync! (last SETJMP at %s)!\n";   PMOD_EXPORT const char msg_unsetjmp_nosync_2[] =
pike.git/src/error.c:469:    *! The only supported type to cast to is @expr{"array"@}, which    *! generates and old-style error.    */   static void f_error_cast(INT32 args)   {    char *s;    get_all_args("error->cast",args,"%s",&s);    if(!strncmp(s,"array",5))    {    pop_n_elems(args); -  if(GENERIC_ERROR_THIS->desc) -  ref_push_string(GENERIC_ERROR_THIS->desc); +  if(GENERIC_ERROR_THIS->error_message) +  ref_push_string(GENERIC_ERROR_THIS->error_message);    else    push_int(0); -  if(GENERIC_ERROR_THIS->backtrace) -  ref_push_array(GENERIC_ERROR_THIS->backtrace); +  if(GENERIC_ERROR_THIS->error_backtrace) +  ref_push_array(GENERIC_ERROR_THIS->error_backtrace);    else    push_int(0);    f_aggregate(2);    }else{    SIMPLE_BAD_ARG_ERROR("error->cast", 1, "the value \"array\"");    }   }      /*! @decl array|string `[](int(0..1) index)    *!
pike.git/src/error.c:511:    */   static void f_error_index(INT32 args)   {    INT_TYPE ind;    get_all_args("error->`[]",args,"%i",&ind);       switch(ind)    {    case 0:    pop_n_elems(args); -  if(GENERIC_ERROR_THIS->desc) -  ref_push_string(GENERIC_ERROR_THIS->desc); +  if(GENERIC_ERROR_THIS->error_message) +  ref_push_string(GENERIC_ERROR_THIS->error_message);    else    push_int(0);    break;    case 1:    pop_n_elems(args); -  if(GENERIC_ERROR_THIS->backtrace) -  ref_push_array(GENERIC_ERROR_THIS->backtrace); +  if(GENERIC_ERROR_THIS->error_backtrace) +  ref_push_array(GENERIC_ERROR_THIS->error_backtrace);    else    push_int(0);    break;    default:    index_error("error->`[]", Pike_sp-args, args, NULL, Pike_sp-args,    "Index %"PRINTPIKEINT"d is out of range 0..1.\n", ind);    break;    }   }      /*! @decl string describe()    *! -  *! Make a readable error-message. -  *! -  *! @note -  *! Uses @[describe_backtrace()] to generate the message. +  *! Return a readable error report that includes the backtrace.    */   static void f_error_describe(INT32 args)   {    pop_n_elems(args);    ref_push_object(Pike_fp->current_object);    APPLY_MASTER("describe_backtrace",1);   }    -  + /*! @decl string message() +  *! +  *! Return a readable message describing the error. +  */ + static void f_error_message(INT32 args) + { +  pop_n_elems(args); +  if (GENERIC_ERROR_THIS->error_message) +  ref_push_string (GENERIC_ERROR_THIS->error_message); +  else +  push_int (0); + } +    /*! @decl array backtrace()    *! -  *! Get the backtrace from where the error occurred. +  *! Return the backtrace where the error occurred.    *!    *! @seealso    *! @[predef::backtrace()]    */   static void f_error_backtrace(INT32 args)   {    pop_n_elems(args); -  if(GENERIC_ERROR_THIS->backtrace) -  ref_push_array(GENERIC_ERROR_THIS->backtrace); +  if(GENERIC_ERROR_THIS->error_backtrace) +  ref_push_array(GENERIC_ERROR_THIS->error_backtrace);    else    push_int(0);   }      /*! @decl string _sprintf()    */   static void f_error__sprintf(INT32 args)   {    struct program *p = Pike_fp->current_object->prog;    /* FIXME: What about obscure overloadings? */
pike.git/src/error.c:578:    int mode = 0;    if(args>0 && Pike_sp[-args].type == PIKE_T_INT)    mode = Pike_sp[-args].u.integer;    pop_n_elems(args);    if(mode != 'O') {    push_undefined();    return;    }    push_svalue(&PROG_FROM_INT(p, i)->constants[id->func.offset].sval);    push_constant_text("(%O)"); -  if(GENERIC_ERROR_THIS->desc) -  ref_push_string(GENERIC_ERROR_THIS->desc); +  if(GENERIC_ERROR_THIS->error_message) +  ref_push_string(GENERIC_ERROR_THIS->error_message);    else    push_int(0);    f_sprintf(2);    f_add(2);   }      /*! @decl void create(string message)    */   static void f_error_create(INT32 args)   {    struct pike_string *msg;    get_all_args("create", args, "%W", &msg); -  do_free_string(GENERIC_ERROR_THIS->desc); -  copy_shared_string(GENERIC_ERROR_THIS->desc, msg); +  do_free_string(GENERIC_ERROR_THIS->error_message); +  copy_shared_string(GENERIC_ERROR_THIS->error_message, msg);    f_backtrace(0);    push_int (0);    push_int (Pike_sp[-2].u.array->size-2);    o_range (); -  assign_to_short_svalue ((union anything *)&GENERIC_ERROR_THIS->backtrace, +  assign_to_short_svalue ((union anything *)&GENERIC_ERROR_THIS->error_backtrace,    PIKE_T_ARRAY, Pike_sp-1);    pop_n_elems(args+1);   }      /*! @endclass    */      #ifdef ERROR_DEBUG   #define DWERROR(X) fprintf X   #else /* !ERROR_DEBUG */
pike.git/src/error.c:637:    ((struct PIKE_CONCAT(STRUCT,_error_struct) *)((O)->storage + PIKE_CONCAT(STRUCT,_error_offset)))      #define ERROR_COPY(STRUCT,X) \    ERROR_STRUCT(STRUCT,o)->X=X      #define ERROR_COPY_SVALUE(STRUCT,X) do { \    if (X) { \    assign_svalue_no_free( & ERROR_STRUCT(STRUCT,o)->X, X); \    } else { \    ERROR_STRUCT(STRUCT, o)->X.type = PIKE_T_INT; \ -  ERROR_STRUCT(STRUCT, o)->X.subtype = 0; \ +  ERROR_STRUCT(STRUCT, o)->X.subtype = NUMBER_UNDEFINED; \    ERROR_STRUCT(STRUCT, o)->X.u.integer = 0; \    } \    } while (0)         #define ERROR_COPY_REF(STRUCT,X) \    add_ref( ERROR_STRUCT(STRUCT,o)->X=X )         DECLSPEC(noreturn) void generic_error_va(struct object *o,
pike.git/src/error.c:673:    Pike_fatal("Recursive error() calls, original error: %s",tmp);    }    in_error=buf;      #if 0    if (!master_program) {    fprintf(stderr, "ERROR: %s\n", buf);    }   #endif    -  ERROR_STRUCT(generic,o)->desc=make_shared_string(buf); +  ERROR_STRUCT(generic,o)->error_message=make_shared_string(buf);    f_backtrace(0);       if(func)    {    push_int(0);    push_int(0);    push_text(func);       for (i=0;i<args;i++)    push_svalue(base_sp + i);    f_aggregate(args + 3);    f_aggregate(1);    f_add(2);    }       if(Pike_sp[-1].type!=PIKE_T_ARRAY)    Pike_fatal("Error failed to generate a backtrace!\n");    -  ERROR_STRUCT(generic,o)->backtrace=Pike_sp[-1].u.array; +  ERROR_STRUCT(generic,o)->error_backtrace=Pike_sp[-1].u.array;    Pike_sp--;    dmalloc_touch_svalue(Pike_sp);       free_svalue(& throw_value);    throw_value.type=PIKE_T_OBJECT;    throw_value.u.object=o;    throw_severity = THROW_ERROR;    in_error=0;       dmalloc_touch_svalue(& throw_value);
pike.git/src/error.c:733:    struct svalue *base_sp, int args,    const char *desc, ...) ATTRIBUTE((noreturn,format (printf, 4, 5)))   {    INIT_ERROR(generic);    ERROR_DONE(generic);   }      PMOD_EXPORT DECLSPEC(noreturn) void index_error(    const char *func,    struct svalue *base_sp, int args, -  struct svalue *val, -  struct svalue *ind, +  struct svalue *value, +  struct svalue *index,    const char *desc, ...) ATTRIBUTE((noreturn,format (printf, 6, 7)))   {    INIT_ERROR(index); -  ERROR_COPY_SVALUE(index, val); -  ERROR_COPY_SVALUE(index, ind); +  ERROR_COPY_SVALUE(index, value); +  ERROR_COPY_SVALUE(index, index);    ERROR_DONE(generic);   }      PMOD_EXPORT DECLSPEC(noreturn) void bad_arg_error(    const char *func,    struct svalue *base_sp, int args, -  int which_arg, +  int which_argument,    const char *expected_type, -  struct svalue *got, +  struct svalue *got_value,    const char *desc, ...) ATTRIBUTE((noreturn,format (printf, 7, 8)))   {    INIT_ERROR(bad_arg); -  ERROR_COPY(bad_arg, which_arg); +  ERROR_COPY(bad_arg, which_argument);    if (expected_type)    ERROR_STRUCT(bad_arg,o)->expected_type=make_shared_string(expected_type);    else    ERROR_STRUCT(bad_arg,o)->expected_type = NULL; -  if(got) -  { -  ERROR_COPY_SVALUE(bad_arg, got); -  }else{ -  ERROR_STRUCT(bad_arg,o)->got.type=PIKE_T_INT; -  ERROR_STRUCT(bad_arg,o)->got.subtype=NUMBER_UNDEFINED; -  ERROR_STRUCT(bad_arg,o)->got.u.integer=0; -  } +  ERROR_COPY_SVALUE(bad_arg, got_value);    DWERROR((stderr, "%s():Bad arg %d (expected %s)\n",    func, which_arg, expected_type));    ERROR_DONE(generic);   }      PMOD_EXPORT DECLSPEC(noreturn) void math_error(    const char *func,    struct svalue *base_sp, int args,    struct svalue *number,    const char *desc, ...) ATTRIBUTE((noreturn,format (printf, 5, 6)))