Branch: Tag:

2011-10-28

2011-10-28 13:04:55 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Atomic megapatch: Use svalue accessor macros everywhere.

119:    efun;    optflags OPT_TRY_OPTIMIZE;   { -  int t=x->type; +  int t = TYPEOF(*x);    struct program *p; -  if(x->type == T_OBJECT && (p = x->u.object->prog)) +  if(t == T_OBJECT && (p = x->u.object->prog))    { -  ptrdiff_t fun = FIND_LFUN(p->inherits[x->subtype].prog, LFUN__SPRINTF); +  ptrdiff_t fun = FIND_LFUN(p->inherits[SUBTYPEOF(*x)].prog, LFUN__SPRINTF);    if(fun != -1)    {    push_int('t');    f_aggregate_mapping(0);    apply_low(x->u.object, -  fun + p->inherits[x->subtype].identifier_level, 2); -  if(Pike_sp[-1].type == T_STRING) +  fun + p->inherits[SUBTYPEOF(*x)].identifier_level, 2); +  if(TYPEOF(Pike_sp[-1]) == T_STRING)    {    stack_swap();    pop_stack();
185:   {    int c;    struct program *p; -  if(x->type == T_OBJECT && (p = x->u.object->prog)) +  if(TYPEOF(*x) == T_OBJECT && (p = x->u.object->prog))    { -  ptrdiff_t fun = FIND_LFUN(p->inherits[x->subtype].prog, LFUN__SPRINTF); +  ptrdiff_t fun = FIND_LFUN(p->inherits[SUBTYPEOF(*x)].prog, LFUN__SPRINTF);    if(fun != -1)    {    push_int('c');    f_aggregate_mapping(0);    apply_low(x->u.object, -  fun + p->inherits[x->subtype].identifier_level, 2); -  if(Pike_sp[-1].type == T_STRING) +  fun + p->inherits[SUBTYPEOF(*x)].identifier_level, 2); +  if(TYPEOF(Pike_sp[-1]) == T_STRING)    {    stack_swap();    pop_stack();
203:    Pike_error("Non-string returned from _sprintf()\n");    }    } -  if(x->type != T_INT) +  if(TYPEOF(*x) != T_INT)    SIMPLE_BAD_ARG_ERROR("int2char", 1, "int");       c=x->u.integer;
242:    struct pike_string *s;    struct program *p;    -  if(x->type == T_OBJECT && (p = x->u.object->prog)) +  if(TYPEOF(*x) == T_OBJECT && (p = x->u.object->prog))    { -  ptrdiff_t fun = FIND_LFUN(p->inherits[x->subtype].prog, LFUN__SPRINTF); +  ptrdiff_t fun = FIND_LFUN(p->inherits[SUBTYPEOF(*x)].prog, LFUN__SPRINTF);    if(fun != -1)    {    push_int('x');    f_aggregate_mapping(0);    apply_low(x->u.object, -  fun + p->inherits[x->subtype].identifier_level, 2); -  if(Pike_sp[-1].type == T_STRING) +  fun + p->inherits[SUBTYPEOF(*x)].identifier_level, 2); +  if(TYPEOF(Pike_sp[-1]) == T_STRING)    {    stack_swap();    pop_stack();
260:    Pike_error("Non-string returned from _sprintf()\n");    }    } -  if(x->type != T_INT) +  if(TYPEOF(*x) != T_INT)    SIMPLE_BAD_ARG_ERROR("int2hex", 1, "int");       c=x->u.integer;
568:      #define HANDLE_FLOAT_FACTOR(NAME, VAR) \    HANDLE_PARAM (NAME, { \ -  if (set->type != T_FLOAT || \ +  if (TYPEOF(*set) != T_FLOAT || \    set->u.float_number < 0.0 || set->u.float_number > 1.0) \    SIMPLE_BAD_ARG_ERROR ("Pike.gc_parameters", 1, \    "float between 0.0 and 1.0 for " NAME); \    VAR = DO_NOT_WARN ((double) set->u.float_number); \    }, { \ -  get.type = T_FLOAT; \ -  get.u.float_number = DO_NOT_WARN ((FLOAT_TYPE) VAR); \ +  SET_SVAL(get, T_FLOAT, 0, float_number, \ +  DO_NOT_WARN ((FLOAT_TYPE) VAR)); \    });       HANDLE_PARAM ("enabled", { -  if (set->type != T_INT || set->u.integer < -1 || set->u.integer > 1) +  if (TYPEOF(*set) != T_INT || set->u.integer < -1 || set->u.integer > 1)    SIMPLE_BAD_ARG_ERROR ("Pike.gc_parameters", 1,    "integer in the range -1..1 for 'enabled'");    if (gc_enabled != set->u.integer) {
592:    }    }    }, { -  get.type = T_INT; -  get.subtype = NUMBER_NUMBER; -  get.u.integer = gc_enabled; +  SET_SVAL(get, T_INT, NUMBER_NUMBER, integer, gc_enabled);    });    HANDLE_FLOAT_FACTOR ("garbage_ratio_low", gc_garbage_ratio_low);    HANDLE_FLOAT_FACTOR ("time_ratio", gc_time_ratio);
1070:    rawtype tOr(tFunc(tMap(tSetvar(0,tMix),tSetvar(1,tMix)) tVar(0),tVar(1)),tFunc(tObj tMix,tMix))   {    struct program *p; -  if( map->type == T_MAPPING ) +  if( TYPEOF(*map) == T_MAPPING )    {    struct svalue s;    map_delete_no_free(map->u.mapping, index, &s);
1079:    Pike_sp++;    dmalloc_touch_svalue(Pike_sp-1);    } -  else if (map->type == T_OBJECT && (p = map->u.object->prog)) +  else if (TYPEOF(*map) == T_OBJECT && (p = map->u.object->prog))    { -  int id = FIND_LFUN(p->inherits[map->subtype].prog, LFUN__M_DELETE); +  int id = FIND_LFUN(p->inherits[SUBTYPEOF(*map)].prog, LFUN__M_DELETE);       if( id == -1 )    SIMPLE_BAD_ARG_ERROR("m_delete", 1, "object containing the _m_delete method");       apply_low(map->u.object, -  id + p->inherits[map->subtype].identifier_level, 1); +  id + p->inherits[SUBTYPEOF(*map)].identifier_level, 1);    stack_swap();    pop_stack();    } else {
1165:    efun;    optflags OPT_TRY_OPTIMIZE;   { -  switch(func->type) +  switch(TYPEOF(*func))    {    default:    SIMPLE_BAD_ARG_ERROR("function_name", 1, "function|program");
1210:    }       case PIKE_T_FUNCTION: -  if(func->subtype == FUNCTION_BUILTIN) break; +  if(SUBTYPEOF(*func) == FUNCTION_BUILTIN) break;    if(!func->u.object->prog)    bad_arg_error("function_name", Pike_sp-args, args, 1,    "function", Pike_sp-args,
1225:    t->func)->name);    }    -  RETURN delambda(ID_FROM_INT(func->u.object->prog, func->subtype)->name); +  RETURN delambda(ID_FROM_INT(func->u.object->prog, +  SUBTYPEOF(*func))->name);    }    pop_n_elems(args);    push_int(0);
1251:    optflags OPT_TRY_OPTIMIZE;    type function(function:object);   { -  switch(func->type) +  switch(TYPEOF(*func))    {    case PIKE_T_PROGRAM:    break;       case PIKE_T_FUNCTION: -  if(func->subtype == FUNCTION_BUILTIN) break; +  if(SUBTYPEOF(*func) == FUNCTION_BUILTIN) break;    if(func->u.object->prog == pike_trampoline_program)    {    struct object *o;
1267:    push_object(o);    return;    } -  func->type=T_OBJECT; -  func->subtype = 0; +  SET_SVAL(*func, T_OBJECT, 0, object, func->u.object);    return;      
1294:    efun;    optflags OPT_TRY_OPTIMIZE;   { -  switch(func->type) +  switch(TYPEOF(*func))    {    case PIKE_T_PROGRAM:    {
1309:    case PIKE_T_FUNCTION:    {    struct program *p; -  if(func->subtype == FUNCTION_BUILTIN) +  if(SUBTYPEOF(*func) == FUNCTION_BUILTIN)    p = func->u.efun->prog;    else    p = func->u.object->prog;
1633:   #ifdef __NT__    ref_push_string (var);    f_lower_case (1); -  assert (Pike_sp[-1].type == T_STRING); +  assert (TYPEOF(Pike_sp[-1]) == T_STRING);    env_alloc_var = Pike_sp[-1].u.string;    /* Let mega_apply pop. */   #else
1648:    mapping_string_insert_string (env_allocs, env_alloc_var, putenv_str);    else {    struct svalue key; -  key.type = T_STRING; -  key.u.string = env_alloc_var; +  SET_SVAL(key, T_STRING, 0, string, env_alloc_var);    map_delete (env_allocs, &key);    }   #endif /* !USE_SETENV */
1716:    * Linenumber info etc won't match.    */   #ifdef PIKE_DEBUG -  if ((val->type == T_FUNCTION) && (val->subtype != FUNCTION_BUILTIN)) { +  if ((TYPEOF(*val) == T_FUNCTION) && (SUBTYPEOF(*val) != FUNCTION_BUILTIN)) {    assign_short_svalue((union anything *)&THIS->oprog,    (union anything *)&val->u.object->prog, T_PROGRAM);    }
1743:    file = low_get_line(THIS->pc, THIS->prog, &THIS->lineno);    THIS->pc = NULL;    } -  else if (THIS->_fun.type == PIKE_T_FUNCTION) { +  else if (TYPEOF(THIS->_fun) == PIKE_T_FUNCTION) {   #ifdef PIKE_DEBUG    if (THIS->_fun.u.object->prog &&    THIS->_fun.u.object->prog != THIS->oprog) { -  struct identifier *id = ID_FROM_INT(THIS->oprog, THIS->_fun.subtype); +  struct identifier *id = ID_FROM_INT(THIS->oprog, SUBTYPEOF(THIS->_fun));    /* FIXME: Dump dmalloc info for the object? */    Pike_fatal("Lost track of function pointer! Function name was %s.\n",    id->name?id->name->str:"<no name>");    }   #endif -  file = low_get_function_line (THIS->_fun.u.object, THIS->_fun.subtype, +  file = low_get_function_line (THIS->_fun.u.object, SUBTYPEOF(THIS->_fun),    &THIS->lineno);    }    else if (THIS->prog) {
1795:    } else {    push_text("Unknown file, ");    } -  if (THIS->_fun.type == PIKE_T_FUNCTION) { +  if (TYPEOF(THIS->_fun) == PIKE_T_FUNCTION) {    if (THIS->_fun.u.object->prog) {   #ifdef PIKE_DEBUG    if (THIS->_fun.u.object->prog != THIS->oprog) { -  struct identifier *id = ID_FROM_INT(THIS->oprog, THIS->_fun.subtype); +  struct identifier *id = +  ID_FROM_INT(THIS->oprog, SUBTYPEOF(THIS->_fun));    /* FIXME: Dump dmalloc info for the object? */    Pike_fatal("Lost track of function pointer! Function name was %s.\n",    id->name?id->name->str:"<no name>");
1811:    f_add(2);    } else {    free_svalue(&THIS->_fun); -  THIS->_fun.type = PIKE_T_INT; -  THIS->_fun.u.integer = 0; -  THIS->_fun.subtype = NUMBER_DESTRUCTED; +  SET_SVAL(THIS->_fun, PIKE_T_INT, NUMBER_DESTRUCTED, integer, 0);    push_text("destructed_function(), ");    }    } else {
1866:    "Indexing with too large index (%"PRINTPIKEINT"d)\n", index);    }    } else { -  if (end_or_none->type != PIKE_T_INT) { +  if (TYPEOF(*end_or_none) != PIKE_T_INT) {    SIMPLE_BAD_ARG_ERROR("`[]",2,"int|void");    }    end = end_or_none->u.integer;
1951:    switch(index) {    case 0: /* Filename */    if (THIS->lineno == -1) fill_in_file_and_line(); -  if (value->type != PIKE_T_STRING) { -  if ((value->type != PIKE_T_INT) || +  if (TYPEOF(*value) != PIKE_T_STRING) { +  if ((TYPEOF(*value) != PIKE_T_INT) ||    (value->u.integer)) {    SIMPLE_BAD_ARG_ERROR("backtrace_frame->`[]=", 2,    "string|int(0..0)");
1972:       case 1: /* Linenumber */    if (THIS->lineno == -1) fill_in_file_and_line(); -  if (value->type != PIKE_T_INT) { +  if (TYPEOF(*value) != PIKE_T_INT) {    SIMPLE_BAD_ARG_ERROR("backtrace_frame->`[]=", 2, "int(1..)");    }    THIS->lineno = value->u.integer;
2071:       size--;    -  res->item[size].u.object = o; -  res->item[size].type = PIKE_T_OBJECT; -  res->item[size].subtype = 0; +  SET_SVAL(res->item[size], PIKE_T_OBJECT, 0, object, o);       bf = OBJ2_BACKTRACE_FRAME(o);   
2082:    bf->pc = f->pc;    }    -  if ((bf->_fun.u.object = f->current_object) && -  (bf->_fun.u.object->prog)) { -  add_ref(bf->_fun.u.object); +  if (f->current_object && f->current_object->prog) { +  SET_SVAL(bf->_fun, PIKE_T_FUNCTION, +  CHECK_IDREF_RANGE(f->fun, f->current_object->prog), +  object, f->current_object); +  add_ref(f->current_object);   #ifdef PIKE_DEBUG    add_ref(bf->oprog = bf->_fun.u.object->prog);   #endif -  bf->_fun.subtype = CHECK_IDREF_RANGE(f->fun, f->current_object->prog); -  bf->_fun.type = PIKE_T_FUNCTION; +     function = ID_FROM_INT(f->current_object->prog, f->fun);    } else { -  bf->_fun.u.integer = 0; -  bf->_fun.subtype = NUMBER_DESTRUCTED; -  bf->_fun.type = PIKE_T_INT; +  SET_SVAL(bf->_fun, PIKE_T_INT, NUMBER_DESTRUCTED, integer, 0);    }       if (f->locals) {
2113:    /* Handle varargs... */    if (function && (function->identifier_flags & IDENTIFIER_VARARGS) &&    (f->locals + numargs < stack_top) && -  (f->locals[numargs].type == T_ARRAY)) { +  (TYPEOF(f->locals[numargs]) == T_ARRAY)) {    varargs = f->locals[numargs].u.array->size;    }   
2609:    push_int(0);    return;    } -  if (from_arg && from_arg->type == T_MAPPING) { +  if (from_arg && TYPEOF(*from_arg) == T_MAPPING) {    if (to_arg) {    Pike_error("Bad number of arguments to create().\n");    }
2630:    }    pop_n_elems(args-2);    args = 2; -  if (from_arg->type != T_ARRAY) { +  if (TYPEOF(*from_arg) != T_ARRAY) {    SIMPLE_BAD_ARG_ERROR("Replace", 1,    "array(string)|mapping(string:string)");    } -  if (to_arg->type == T_STRING) { +  if (TYPEOF(*to_arg) == T_STRING) {    push_int(from_arg->u.array->size);    stack_swap();    f_allocate(2);    } -  if (to_arg->type != T_ARRAY) { +  if (TYPEOF(*to_arg) != T_ARRAY) {    SIMPLE_BAD_ARG_ERROR("Replace", 2, "array(string)|string");    }    if (from_arg->u.array->size != to_arg->u.array->size) {
2897:    PIKEFUN void _decode(array(string)|int(0..0) encoded_)    {    INT32 i = 0; -  if (encoded_->type == PIKE_T_ARRAY) { +  if (TYPEOF(*encoded_) == PIKE_T_ARRAY) {    struct array *encoded = encoded_->u.array;       for (i=0; i < encoded->size; i++) {
3376:       for(e=0;e<args;e++)    { -  if(real_args[e].type==T_OBJECT && +  if(TYPEOF(real_args[e]) == T_OBJECT &&    real_args[e].u.object->prog == automap_marker_program &&    OBJ2_AUTOMAP_MARKER(real_args[e].u.object)->depth >= d)    { -  if(tmpargs[e].type != T_ARRAY) +  if(TYPEOF(tmpargs[e]) != T_ARRAY)    index_error("__automap__",    Pike_sp-args,    args,
3405:    {    for(e=0;e<args;e++)    { -  if(real_args[e].type==T_OBJECT && +  if(TYPEOF(real_args[e]) == T_OBJECT &&    real_args[e].u.object->prog == automap_marker_program &&    OBJ2_AUTOMAP_MARKER(real_args[e].u.object)->depth >= d)    {
3424:    else    low_automap(d+1,depth,fun,real_args,args);    stack_pop_to_no_free (ITEM(ret) + x); -  types |= 1 << ITEM(ret)[x].type; +  types |= 1 << TYPEOF(ITEM(ret)[x]);    }    ret->type_field = types;    stack_unlink(args);
3439:       for(e=0;e<args-1;e++)    { -  if(tmpargs[e].type==T_OBJECT && +  if(TYPEOF(tmpargs[e]) == T_OBJECT &&    tmpargs[e].u.object->prog == automap_marker_program)    {    int tmp=OBJ2_AUTOMAP_MARKER(tmpargs[e].u.object)->depth;
3460:   #define INIT_BLOCK(NODE) do { \    (NODE)->next = (NODE)->prev = NULL; \    (NODE)->refs = 1; \ -  (NODE)->val.type = T_INT; \ -  (NODE)->val.subtype = NUMBER_UNDEFINED; \ -  (NODE)->val.u.integer = 0; \ +  SET_SVAL((NODE)->val, T_INT, NUMBER_UNDEFINED, \ +  integer, 0); \    } while(0)      #undef EXIT_BLOCK
3662:    if (!(p = o->prog)) {    Pike_error("Indexing a destructed object.\n");    } -  inh = p->inherits + Pike_sp[-args].subtype; +  inh = p->inherits + SUBTYPEOF(Pike_sp[-args]);    p = inh->prog;    f = find_shared_string_identifier(s, p);    if ((f >= 0) &&
3740:    PIKEFUN int `==(mixed other)    flags ID_PROTECTED;    { -  if (other->type != T_OBJECT) { +  if (TYPEOF(*other) != T_OBJECT) {    pop_stack();    push_int(0);    return;
3754:    ref_push_program (other->u.object->prog);    push_constant_text("is_val_null");    if (program_index_no_free (Pike_sp - 3, Pike_sp - 2, Pike_sp - 1) && -  Pike_sp[-3].type == T_INT && Pike_sp[-3].u.integer) { +  TYPEOF(Pike_sp[-3]) == T_INT && Pike_sp[-3].u.integer) {    pop_n_elems (4);    push_int (1);    }
3911:    if (o != Pike_fp->current_object) {    SIMPLE_BAD_ARG_ERROR("_serialize", 1, "this");    } -  low_serialize(Pike_sp[-args].subtype, serializer, 0, +  low_serialize(SUBTYPEOF(Pike_sp[-args]), serializer, 0,    f_Serializable_cq__serialize_variable_fun_num);    pop_n_elems(args);    push_int(0);
4045:    if (o != Pike_fp->current_object) {    SIMPLE_BAD_ARG_ERROR("_serialize", 1, "this");    } -  low_serialize(Pike_sp[-args].subtype, deserializer, 1, +  low_serialize(SUBTYPEOF(Pike_sp[-args]), deserializer, 1,    f_Serializable_cq__deserialize_variable_fun_num);    pop_n_elems(args);    push_int(0);
4073:    if (!(p = o->prog)) {    Pike_error("Indexing a destructed object.\n");    } -  inh = p->inherits + Pike_sp[-args].subtype; +  inh = p->inherits + SUBTYPEOF(Pike_sp[-args]);    p = inh->prog;    if ((fun = low_find_lfun(p, LFUN__SERIALIZE)) == -1) {    Pike_error("Serialization not supported by object.\n");
4102:    if (!(p = o->prog)) {    Pike_error("Indexing a destructed object.\n");    } -  inh = p->inherits + Pike_sp[-args].subtype; +  inh = p->inherits + SUBTYPEOF(Pike_sp[-args]);    p = inh->prog;    if ((fun = low_find_lfun(p, LFUN__DESERIALIZE)) == -1) {    Pike_error("Deserialization not supported by object.\n");
4885:    assert (!val_module);    push_constant_text ("Val");    APPLY_MASTER ("resolv", 1); -  if (Pike_sp[-1].type != T_OBJECT) +  if (TYPEOF(Pike_sp[-1]) != T_OBJECT)    Pike_error ("\"Val\" didn't resolve to a module object.\n");    val_module = (--Pike_sp)->u.object;   }
4897:    { \    struct svalue index, res; \    if (!val_module) get_val_module(); \ -  index.type = T_STRING; \ +  SET_SVAL(index, T_STRING, 0, string, NULL); \    MAKE_CONST_STRING (index.u.string, TOSTR (NAME)); \    object_index_no_free (&res, val_module, 0, &index); \ -  if (res.type != T_OBJECT) \ +  if (TYPEOF(res) != T_OBJECT) \    Pike_error ("\"Val." TOSTR (NAME) "\" didn't resolve to an object.\n"); \    return res.u.object; \    }