pike.git / src / operators.c

version» Context lines:

pike.git/src/operators.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: operators.c,v 1.239 2008/08/22 14:13:20 srb Exp $ + || $Id: operators.c,v 1.240 2008/08/24 21:32:00 srb Exp $   */      #include "global.h"   #include <math.h>   #include "interpret.h"   #include "svalue.h"   #include "multiset.h"   #include "mapping.h"   #include "array.h"   #include "stralloc.h"
pike.git/src/operators.c:32:   #include "pike_security.h"   #include "pike_compiler.h"      #define sp Pike_sp      #define OP_DIVISION_BY_ZERO_ERROR(FUNC) \    math_error(FUNC, sp-2, 2, 0, "Division by zero.\n")   #define OP_MODULO_BY_ZERO_ERROR(FUNC) \    math_error(FUNC, sp-2, 2, 0, "Modulo by zero.\n")    -  /* These calculations should always give some margin based on the size. */ -  /* One extra char for the sign. */ - #define MAX_INT_SPRINTF_LEN (1 + (SIZEOF_INT_TYPE * 5 + 1) / 2) -  /* Six extra chars: Mantissa sign, decimal point, zero before the -  * decimal point, the 'e', exponent sign, and an extra digit due -  * to the mantissa/exponent split. */ - #define MAX_FLOAT_SPRINTF_LEN (6 + (SIZEOF_FLOAT_TYPE * 5 + 1) / 2) -  +    /* The destructive multiset merge code is broken.    * l->msd gets -1 refs.    *    * Disable it for now.    * /grubba 2008-07-08    */   #undef PIKE_MERGE_DESTR_A   #define PIKE_MERGE_DESTR_A 0      void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind)
pike.git/src/operators.c:344:    break;       default:    Pike_error("Cannot cast %s to int.\n", get_name_of_type(sp[-1].type));    }   }      /* Special case for casting to string. */   PMOD_EXPORT void o_cast_to_string(void)   { +  char buf[200];    switch(sp[-1].type)    {    case PIKE_T_STRING: -  break; +  return;       case T_OBJECT:    if(!sp[-1].u.object->prog) {    /* Casting a destructed object should be like casting a zero. */    pop_stack();    push_constant_text("0");    } else {    {    struct object *o = sp[-1].u.object;    int f = FIND_LFUN(o->prog->inherits[sp[-1].subtype].prog, LFUN_CAST);
pike.git/src/operators.c:387:    apply_low(o, f, 1);    f=!UNSAFE_IS_ZERO(sp-1);    pop_stack();    if(f) return;    }    }    Pike_error("Cast failed, wanted string, got %s\n",    get_name_of_type(sp[-1].type));    }    } -  break; +  return;       case T_INT: -  { -  INT_TYPE org; -  char buf[MAX_INT_SPRINTF_LEN]; -  register char*b = buf+sizeof buf-1; -  register unsigned INT_TYPE i; -  org = sp[-1].u.integer; -  pop_stack(); -  *b-- = '\0'; -  i = org; -  -  if( org < 0 ) -  i = -i; -  -  goto jin; /* C as a macro assembler :-) */ -  do { -  i /= 10; - jin: *b-- = '0'+(i%10); -  } -  while( i >= 10 ); -  -  if( org<0 ) -  *b = '-'; -  else -  b++; -  push_text( b ); -  } +  sprintf(buf, "%"PRINTPIKEINT"d", sp[-1].u.integer);    break;       case T_ARRAY:    {    int i;    struct array *a = sp[-1].u.array;    struct pike_string *s;    int shift = 0;       for(i = a->size; i--; ) {
pike.git/src/operators.c:487:    for(i = a->size; i--; ) {    str2[i] = (p_wchar2) a->item[i].u.integer;    }    }    break;    }    s = end_shared_string(s);    pop_stack();    push_string(s);    } -  break; +  return;    -  case T_FLOAT: { -  char buf[MAX_FLOAT_SPRINTF_LEN+1+1+1+1+7+1]; -  snprintf(buf, sizeof buf, "%.*g", -  MAX_FLOAT_SPRINTF_LEN, (double)sp[-1].u.float_number); -  pop_stack(); -  push_text(buf); +  case T_FLOAT: +  sprintf(buf, "%f", (double)sp[-1].u.float_number);    break; -  } +        default:    Pike_error("Cannot cast %s to string.\n", get_name_of_type(sp[-1].type));    } -  +  +  sp[-1].type = PIKE_T_STRING; +  sp[-1].u.string = make_shared_string(buf);   }      PMOD_EXPORT void o_cast(struct pike_type *type, INT32 run_time_type)   {    if(run_time_type != sp[-1].type)    {    if(run_time_type == T_MIXED)    return;       if (sp[-1].type == T_OBJECT && !sp[-1].u.object->prog) {
pike.git/src/operators.c:1583:    }   #endif /* PIKE_DEBUG */    /* Adjust the stack. */    save_sp[-args] = sp[-1];    sp = save_sp + 1 - args;    return;    } else {    e = -args;    }    +  /* These calculations should always give some margin based on the size. */ +  /* One extra char for the sign. */ + #define MAX_INT_SPRINTF_LEN (1 + (SIZEOF_INT_TYPE * 5 + 1) / 2) +  /* Six extra chars: Mantissa sign, decimal point, zero before the +  * decimal point, the 'e', exponent sign, and an extra digit due +  * to the mantissa/exponent split. */ + #define MAX_FLOAT_SPRINTF_LEN (6 + (SIZEOF_FLOAT_TYPE * 5 + 1) / 2) +     size=0;    for(e=-args;e<0;e++)    {    switch(sp[e].type)    {    case T_STRING:    size+=sp[e].u.string->len;    if(sp[e].u.string->size_shift > max_shift)    max_shift=sp[e].u.string->size_shift;    break;