pike.git / src / interpret.c

version» Context lines:

pike.git/src/interpret.c:50:   #include "dtrace_probes.h"   #else   #include "dtrace/dtrace_probes_disabled.h"   #endif      /*    * Define the default evaluator stack size, used for just about everything.    */   #define EVALUATOR_STACK_SIZE 100000    - #define TRACE_LEN (100 + Pike_interpreter.trace_level * 10) + #define TRACE_LEN (size_t)(100 + Pike_interpreter.trace_level * 10)      /* Keep some margin on the stack space checks. They're lifted when    * handle_error runs to give it some room. */   /* Observed in 7.1: 40 was enough, 30 wasn't. */   #define SVALUE_STACK_MARGIN (100 + LOW_SVALUE_STACK_MARGIN)   /* Observed in 7.4: 11000 was enough, 10000 wasn't. */   #define C_STACK_MARGIN (20000 + LOW_C_STACK_MARGIN)      /* Another extra margin to use while dumping the raw error in    * exit_on_error, so that backtrace_frame._sprintf can be called
pike.git/src/interpret.c:98: Inside #if defined(INTERNAL_PROFILING)
     #ifdef INTERNAL_PROFILING   PMOD_EXPORT unsigned long evaluator_callback_calls = 0;   #endif         int fast_check_threads_counter = 0;      PMOD_EXPORT int Pike_stack_size = EVALUATOR_STACK_SIZE;    - static void do_trace_call(INT32 args, dynamic_buffer *old_buf); + static void do_trace_call(struct byte_buffer *buf, INT32 args);   static void do_trace_func_return (int got_retval, struct object *o, int fun); - static void do_trace_return (int got_retval, dynamic_buffer *old_buf); + static void do_trace_return (struct byte_buffer *buf, int got_retval);      void push_sp_mark(void)   {    if(Pike_mark_sp == Pike_interpreter.mark_stack + Pike_stack_size)    Pike_error("No more mark stack!\n");    *Pike_mark_sp++=Pike_sp;   }   ptrdiff_t pop_sp_mark(void)   {   #ifdef PIKE_DEBUG
pike.git/src/interpret.c:789:    loc->parent_identifier,    p ? ID_FROM_INT(p,loc->parent_identifier)->name->str : "N/A"    ));   }      #ifdef PIKE_DEBUG   void print_return_value(void)   {    if(Pike_interpreter.trace_level>3)    { -  char *s; -  dynamic_buffer save_buf; +  struct byte_buffer buf = BUFFER_INIT();    -  init_buf(&save_buf); -  safe_describe_svalue(Pike_sp-1,0,0); -  s=simple_free_buf(&save_buf); -  if((size_t)strlen(s) > (size_t)TRACE_LEN) +  safe_describe_svalue(&buf, Pike_sp-1,0,0); +  if(buffer_content_length(&buf) > TRACE_LEN)    { -  s[TRACE_LEN]=0; -  s[TRACE_LEN-1]='.'; -  s[TRACE_LEN-2]='.'; -  s[TRACE_LEN-3]='.'; +  buffer_remove(&buf, buffer_content_length(&buf) - TRACE_LEN - 3); +  buffer_add_str(&buf, "...");    } -  fprintf(stderr,"- value: %s\n",s); -  free(s); +  fprintf(stderr,"- value: %s\n",buffer_get_string(&buf)); +  buffer_free(&buf);    }   }   #else   #define print_return_value()   #endif      struct callback_list evaluator_callbacks;         /*
pike.git/src/interpret.c:1759:   #endif         #endif /* PIKE_USE_MACHINE_CODE */      #undef REAL_PIKE_DEBUG   #undef DO_IF_REAL_DEBUG   #undef DO_IF_NOT_REAL_DEBUG       - static void do_trace_call(INT32 args, dynamic_buffer *old_buf) + static void do_trace_call(struct byte_buffer *b, INT32 args)   {    struct pike_string *filep = NULL; -  char *file, *s; +  char *file; +  const char *s;    INT_TYPE linep;    INT32 e;    ptrdiff_t len = 0;    -  my_strcat("("); +  buffer_add_str(b, "(");    for(e=0;e<args;e++)    { -  if(e) my_strcat(","); -  safe_describe_svalue(Pike_sp-args+e,0,0); +  if(e) buffer_add_str(b, ","); +  safe_describe_svalue(b, Pike_sp-args+e,0,0);    } -  my_strcat(")"); +  buffer_add_str(b, ")");    -  s=simple_free_buf(old_buf); -  if((size_t)strlen(s) > (size_t)TRACE_LEN) +  if(buffer_content_length(b) > TRACE_LEN)    { -  s[TRACE_LEN]=0; -  s[TRACE_LEN-1]='.'; -  s[TRACE_LEN-2]='.'; -  s[TRACE_LEN-3]='.'; +  buffer_remove(b, buffer_content_length(b) - TRACE_LEN - 3); +  buffer_add_str(b, "...");    }       if(Pike_fp && Pike_fp->pc)    {    char *f;    filep = get_line(Pike_fp->pc,Pike_fp->context->prog,&linep);    if (filep->size_shift)    file = "...";    else {    file = filep->str;
pike.git/src/interpret.c:1805:   #endif /* __NT__ */    )    file=f+1;    len = filep->len - (file - filep->str);    }    }else{    linep=0;    file="-";    }    +  s = buffer_get_string(b); +     if (len < 30)    {    char buf[40];    if (linep)    snprintf(buf, sizeof (buf), "%s:%ld:", file, (long)linep);    else    snprintf(buf, sizeof (buf), "%s:", file);    fprintf(stderr, "- %-20s %s\n",buf,s);    } else if (linep) {    fprintf(stderr, "- %s:%ld: %s\n", file, (long)linep, s);    } else {    fprintf(stderr, "- %s: %s\n", file, s);    }       if (filep) {    free_string(filep);    } -  free(s); +  buffer_free(b);   }      static void do_trace_func_return (int got_retval, struct object *o, int fun)   { -  dynamic_buffer save_buf; -  init_buf (&save_buf); +  struct byte_buffer b = BUFFER_INIT();    if (o) {    if (o->prog) {    struct identifier *id = ID_FROM_INT (o->prog, fun);    char buf[50];    sprintf(buf, "%lx->", (long) PTR_TO_INT (o)); -  my_strcat(buf); +  buffer_add_str(&b, buf);    if (id->name->size_shift) -  my_strcat ("[widestring function name]"); +  buffer_add_str (&b, "[widestring function name]");    else -  my_strcat(id->name->str); -  my_strcat ("() "); +  buffer_add_str(&b, id->name->str); +  buffer_add_str (&b, "() ");    }    else -  my_strcat ("function in destructed object "); +  buffer_add_str (&b, "function in destructed object ");    } -  do_trace_return (got_retval, &save_buf); +  do_trace_return (&b, got_retval);   }    - static void do_trace_return (int got_retval, dynamic_buffer *old_buf) + static void do_trace_return (struct byte_buffer *b, int got_retval)   {    struct pike_string *filep = NULL; -  char *file, *s; +  char *file; +  const char *s;    INT_TYPE linep;       if (got_retval) { -  my_strcat ("returns: "); -  safe_describe_svalue(Pike_sp-1,0,0); +  buffer_add_str (b, "returns: "); +  safe_describe_svalue(b, Pike_sp-1,0,0);    }    else -  my_strcat ("returns with no value"); +  buffer_add_str (b, "returns with no value");    -  s=simple_free_buf(old_buf); -  if((size_t)strlen(s) > (size_t)TRACE_LEN) +  if(buffer_content_length(b) > TRACE_LEN)    { -  s[TRACE_LEN]=0; -  s[TRACE_LEN-1]='.'; -  s[TRACE_LEN-2]='.'; -  s[TRACE_LEN-3]='.'; +  buffer_remove(b, buffer_content_length(b) - TRACE_LEN - 3); +  buffer_add_str(b, "...");    }    -  +  s = buffer_get_string(b); +     if(Pike_fp && Pike_fp->pc)    {    char *f;    filep = get_line(Pike_fp->pc,Pike_fp->context->prog,&linep);    if (filep->size_shift)    file = "...";    else {    file = filep->str;    while((f=strchr(file,'/')))    file=f+1;
pike.git/src/interpret.c:1897:    if (linep)    snprintf(buf, sizeof (buf), "%s:%ld:", file, (long)linep);    else    snprintf(buf, sizeof (buf), "%s:", file);    fprintf(stderr,"- %-20s %s\n",buf,s);    }       if (filep) {    free_string(filep);    } -  free(s); +  buffer_free(b);   }      static struct pike_frame_chunk {    struct pike_frame_chunk *next;   } *pike_frame_chunks;   static int num_pike_frame_chunks;   static int num_pike_frames;      PMOD_EXPORT void really_free_pike_frame( struct pike_frame *X )   {
pike.git/src/interpret.c:2090:   #endif       if( !constant )    {    if (PIKE_FN_START_ENABLED())    {    /* DTrace enter probe    arg0: function name    arg1: object    */ -  dynamic_buffer save_buf; -  dynbuf_string obj_name; +  struct byte_buffer obj_name = BUFFER_INIT();    struct svalue obj_sval;    SET_SVAL(obj_sval, T_OBJECT, 0, object, o); -  init_buf(&save_buf); -  safe_describe_svalue(&obj_sval, 0, NULL); -  obj_name = complex_free_buf(&save_buf); +  safe_describe_svalue(&obj_name, &obj_sval, 0, NULL);    PIKE_FN_START(function->name->size_shift == 0 ?    function->name->str : "[widestring fn name]", -  obj_name.str); +  buffer_get_string(s)); +  buffer_free(&obj_name);    }    if(UNLIKELY(Pike_interpreter.trace_level))    { -  dynamic_buffer save_buf; +  struct byte_buffer buffer = BUFFER_INIT();    char buf[50];    -  init_buf(&save_buf); +     sprintf(buf, "%lx->", (long) PTR_TO_INT (o)); -  my_strcat(buf); +  buffer_add_str(&buffer, buf);    if (function->name->size_shift) -  my_strcat ("[widestring function name]"); +  buffer_add_str (&buffer, "[widestring function name]");    else -  my_strcat(function->name->str); -  do_trace_call(args, &save_buf); +  buffer_add_str(&buffer, function->name->str); +  do_trace_call(&buffer, args);    }    new_frame->current_storage = o->storage+context->storage_offset;    if( type == IDENTIFIER_C_FUNCTION )    {    new_frame->num_args = args;    new_frame->num_locals = args;    new_frame->pc = 0;   #ifndef PIKE_USE_MACHINE_CODE    FAST_CHECK_THREADS_ON_CALL();   #endif
pike.git/src/interpret.c:2264:    break;       case T_FUNCTION:    if(SUBTYPEOF(*s) == FUNCTION_BUILTIN)    {   #ifdef PIKE_DEBUG    struct svalue *expected_stack = Pike_sp-args;   #endif    if(Pike_interpreter.trace_level>1)    { -  dynamic_buffer save_buf; -  init_buf(&save_buf); +  struct byte_buffer buf = BUFFER_INIT();    if (s->u.efun->name->size_shift) -  my_strcat ("[widestring function name]"); +  buffer_add_str (&buf, "[widestring function name]");    else -  my_strcat (s->u.efun->name->str); -  do_trace_call(args, &save_buf); +  buffer_add_str (&buf, s->u.efun->name->str); +  do_trace_call(&buf, args);    }    if (PIKE_FN_START_ENABLED()) {    /* DTrace enter probe    arg0: function name    arg1: object    */    PIKE_FN_START(s->u.efun->name->size_shift == 0 ?    s->u.efun->name->str : "[widestring fn name]",    "");    }
pike.git/src/interpret.c:2329:    scope=((struct pike_trampoline *)(o->storage))->frame;    o=scope->current_object;    }    goto apply_low;    }    break;       case T_ARRAY:    if(Pike_interpreter.trace_level)    { -  dynamic_buffer save_buf; -  init_buf(&save_buf); -  safe_describe_svalue(s,0,0); -  do_trace_call(args, &save_buf); +  struct byte_buffer buf = BUFFER_INIT(); +  safe_describe_svalue(&buf, s,0,0); +  do_trace_call(&buf, args);    }    if (PIKE_FN_START_ENABLED()) {    /* DTrace enter probe    arg0: function name    arg1: object    */    PIKE_FN_START("[array]", "");    }    apply_array(s->u.array, args, (type == APPLY_STACK));    break;
pike.git/src/interpret.c:2355:    if (args != 1) {    /* FIXME: Casts to object ought to propagate to apply program below. */    SIMPLE_WRONG_NUM_ARGS_ERROR("cast", 1);    }    o_cast(s->u.type, compile_type_to_runtime_type(s->u.type));    break;       case T_PROGRAM:    if(Pike_interpreter.trace_level)    { -  dynamic_buffer save_buf; -  init_buf(&save_buf); -  safe_describe_svalue(s,0,0); -  do_trace_call(args, &save_buf); +  struct byte_buffer buf = BUFFER_INIT(); +  safe_describe_svalue(&buf, s,0,0); +  do_trace_call(&buf, args);    }    if (PIKE_FN_START_ENABLED()) {    /* DTrace enter probe    arg0: function name    arg1: object    */ -  dynamic_buffer save_buf; -  dynbuf_string prog_name; -  init_buf(&save_buf); -  safe_describe_svalue(s,0,0); -  prog_name = complex_free_buf(&save_buf); -  PIKE_FN_START("[program]", prog_name.str); +  struct byte_buffer buf = BUFFER_INIT(); +  safe_describe_svalue(&buf, s,0,0); +  PIKE_FN_START("[program]", buffer_get_string(&buf)); +  buffer_free(&buf);    }    push_object(clone_object(s->u.program,args));    break;       case T_OBJECT:    /* FIXME: Object subtypes! */    o=s->u.object;    if(o->prog == pike_trampoline_program)    {    fun=((struct pike_trampoline *)(o->storage))->func;
pike.git/src/interpret.c:2773:    move_svalue (Pike_sp++, &throw_value);    mark_free_svalue (&throw_value);       if (get_master()) { /* May return NULL at odd times. */    ONERROR tmp;    SET_ONERROR(tmp,exit_on_error,"Error in handle_error in master object!");    APPLY_MASTER("handle_error", 1);    UNSET_ONERROR(tmp);    }    else { -  dynamic_buffer save_buf; -  char *s; +  struct byte_buffer buf = BUFFER_INIT();    fprintf (stderr, "There's no master to handle the error. Dumping it raw:\n"); -  init_buf(&save_buf); -  safe_describe_svalue (Pike_sp - 1, 0, 0); -  s=simple_free_buf(&save_buf); -  fprintf(stderr,"%s\n",s); -  free(s); +  safe_describe_svalue (&buf, Pike_sp - 1, 0, 0); +  fprintf(stderr,"%s\n",buffer_get_string(&buf)); +  buffer_free(&buf);    if (TYPEOF(Pike_sp[-1]) == PIKE_T_OBJECT && Pike_sp[-1].u.object->prog) {    int fun = find_identifier("backtrace", Pike_sp[-1].u.object->prog);    if (fun != -1) {    fprintf(stderr, "Attempting to extract the backtrace.\n");    safe_apply_low2(Pike_sp[-1].u.object, fun, 0, 0); -  init_buf(&save_buf); -  safe_describe_svalue(Pike_sp - 1, 0, 0); +  buf = BUFFER_INIT(); +  safe_describe_svalue(&buf, Pike_sp - 1, 0, 0);    pop_stack(); -  s=simple_free_buf(&save_buf); -  fprintf(stderr,"%s\n",s); -  free(s); +  fprintf(stderr,"%s\n",buffer_get_string(&buf)); +  buffer_free(&buf);    }    }    }       pop_stack();    Pike_interpreter.svalue_stack_margin = SVALUE_STACK_MARGIN;    Pike_interpreter.c_stack_margin = C_STACK_MARGIN;    Pike_interpreter.trace_level = old_t_flag;    }