pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.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: builtin_functions.c,v 1.583 2004/12/22 12:45:37 grubba Exp $ + || $Id: builtin_functions.c,v 1.584 2004/12/22 18:46:15 grubba Exp $   */      #include "global.h"   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"
pike.git/src/builtin_functions.c:849:    } else {    mapping_search_no_free(Pike_sp,Pike_sp[-args].u.mapping,Pike_sp+1-args,0);    }    free_svalue(Pike_sp-args);    Pike_sp[-args]=*Pike_sp;    dmalloc_touch_svalue(Pike_sp);    pop_n_elems(args-1);    return;       case T_OBJECT: -  if (Pike_sp[-args].u.object->prog) { +  { +  struct program *p; +  if ((p = (Pike_sp[-args].u.object->prog))) {    struct object *o = Pike_sp[-args].u.object; -  struct program *p = o->prog; -  /* NOTE: Fake lfun! */ -  int id = low_find_lfun(p, LFUN__SEARCH); +  int id_level = p->inherits[Pike_sp[-args].subtype].identifier_level; +  int id;    int next, ind; -  +  p = p->inherits[Pike_sp[-args].subtype].prog;    -  +  /* NOTE: Fake lfun! */ +  id = low_find_lfun(p, LFUN__SEARCH);    /* First try lfun::_search(). */    if (id >= 0) { -  apply_low(o, id, args-1); +  apply_low(o, id + id_level, args-1);    stack_pop_n_elems_keep_top(1);    return;    }       /* Check if we have an iterator. */    if (((id = find_identifier("value", p)) >= 0) &&    ((next = find_identifier("next", p)) >= 0) &&    ((ind = find_identifier("index", p)) >= 0)) {    /* We have an iterator. */    -  +  id += id_level; +  next += id_level; +  ind += id_level; +     /* Set the start position if needed. */    if (args > 2) { -  apply(o, "set_index", args-2); +  int fun = find_identifier("set_index", p); +  if (fun < 0) +  Pike_error ("Cannot call unknown function \"%s\".\n", fun); +  apply_low(o, fun + id_level, args-2);    pop_stack();    }       /* At this point we have two values on the stack. */       while(1) {    apply_low(o, id, 0);    if (is_eq(Pike_sp-2, Pike_sp-1)) {    /* Found. */    apply_low(o, ind, 0);
pike.git/src/builtin_functions.c:899:    /* FIXME: Should probably indicate not found in some other way.    * On the other hand, the iterator should be false now.    */    push_undefined();    return;    }    pop_n_elems(2);    }    }    } +  }    /* FALL_THROUGH */    default:    SIMPLE_BAD_ARG_ERROR("search", 1, "string|array|mapping|object");    }   }      /*! @decl int has_prefix(string s, string prefix)    *!    *! Returns @expr{1@} if the string @[s] starts with @[prefix],    *! returns @expr{0@} (zero) otherwise.
pike.git/src/builtin_functions.c:1186:    Pike_sp[-1].u.integer = !Pike_sp[-1].u.integer;    else    PIKE_ERROR("has_value",    "Function `zero_type' gave incorrect result.\n", Pike_sp, args);    break;       case T_PROGRAM:    case T_OBJECT:    /* FIXME: It's very sad that we always have to do linear search    with `values' in case of objects. The problem is that we cannot -  use `search' directly since it's undefined weather it returns +  use `search' directly since it's undefined whether it returns    -1 (array) or 0 (mapping) during e.g. some data type emulation.       Maybe we should use object->_has_value(value) provided that    the object implements it.       /Noring */       /* FALL_THROUGH */       case T_MULTISET:
pike.git/src/builtin_functions.c:2417:       case T_MAPPING:    a=mapping_indices(Pike_sp[-args].u.mapping);    break;       case T_MULTISET:    a = multiset_indices (Pike_sp[-args].u.multiset);    break;       case T_OBJECT: +  /* FIXME: Object subtype! */    a=object_indices(Pike_sp[-args].u.object);    break;       case T_PROGRAM:    a = program_indices(Pike_sp[-args].u.program);    break;       case T_FUNCTION:    {    struct program *p = program_from_svalue(Pike_sp-args);
pike.git/src/builtin_functions.c:2715:       case T_MAPPING:    a=mapping_values(Pike_sp[-args].u.mapping);    break;       case T_MULTISET:    a = multiset_values (Pike_sp[-args].u.multiset);    break;       case T_OBJECT: +  /* FIXME: Object subtype! */    a=object_values(Pike_sp[-args].u.object);    break;       case T_PROGRAM:    a = program_values(Pike_sp[-args].u.program);    break;       case T_FUNCTION:    {    struct program *p = program_from_svalue(Pike_sp - args);
pike.git/src/builtin_functions.c:2823: Inside #if 0
   pop_n_elems (args);    push_function (o, t->func);    return;    }    }   #endif       if(p)    {    p = p->inherits[Pike_sp[-args].subtype].prog; +  /* FIXME: Does the following actually work for +  * the object subtype case? +  */    if((p->flags & PROGRAM_USES_PARENT) &&    PARENT_INFO(o)->parent &&    PARENT_INFO(o)->parent->prog)    {    INT32 id=PARENT_INFO(o)->parent_identifier;    o=PARENT_INFO(o)->parent;    add_ref(o);    pop_n_elems(args);    push_function(o, id);    return;
pike.git/src/builtin_functions.c:3407:    0);       check_c_stack(65536);       o=0;    switch(args)    {    case 3:    SIMPLE_BAD_ARG_ERROR("compile", 4, "int");    default: -  if(Pike_sp[5-args].type == T_OBJECT) +  if(Pike_sp[5-args].type == T_OBJECT) { +  if (Pike_sp[5-args].subtype) { +  Pike_error("compile: " +  "Subtyped placeholder objects are not supported yet.\n"); +  }    placeholder=Pike_sp[5-args].u.object; -  +  }       case 5:    if(Pike_sp[4-args].type == T_PROGRAM)    p=Pike_sp[4-args].u.program;       case 4:    major=Pike_sp[2-args].u.integer;    minor=Pike_sp[3-args].u.integer;       case 2: -  if(Pike_sp[1-args].type == T_OBJECT) +  if(Pike_sp[1-args].type == T_OBJECT) { +  if (Pike_sp[5-args].subtype) { +  Pike_error("compile: " +  "Subtyped handler objects are not supported yet.\n"); +  }    o=Pike_sp[1-args].u.object; -  +  }       case 0: case 1: break;    }       p = compile(Pike_sp[-args].u.string, o, major, minor, p, placeholder);       pop_n_elems(args);    push_program(p);   }   
pike.git/src/builtin_functions.c:3564:    case T_FUNCTION:    if( Pike_sp[-args].subtype != FUNCTION_BUILTIN    && !Pike_sp[-args].u.object->prog)    break;    res = 1;    break;    case T_PROGRAM:    res = 1;    break;    case T_OBJECT: -  if( Pike_sp[-args].u.object->prog && -  FIND_LFUN( Pike_sp[-args].u.object->prog, LFUN_CALL ) != -1 ) +  { +  struct program *p; +  if((p = Pike_sp[-args].u.object->prog) && +  FIND_LFUN(p->inherits[Pike_sp[-args].subtype].prog, +  LFUN_CALL ) != -1)    res = 1; -  +  }    break;    case T_ARRAY: -  +  /* FIXME: What about the recursive case? */    array_fix_type_field(Pike_sp[-args].u.array);    if( (Pike_sp[-args].u.array->type_field==BIT_CALLABLE) ||    !Pike_sp[-args].u.array->type_field) {    res = 1;    }    else if( !(Pike_sp[-args].u.array->type_field &    ~(BIT_CALLABLE|BIT_INT)) ) {    struct array *a = Pike_sp[-args].u.array;    int i;    res = 1;
pike.git/src/builtin_functions.c:3864:   {    pop_n_elems(args);    push_int(do_gc(NULL, 1));   }      #ifdef TYPEP   #undef TYPEP   #endif       - #define TYPEP(ID,NAME,TYPE,TYPE_NAME) \ - PMOD_EXPORT void ID(INT32 args) \ - { \ -  int t; \ -  if(args<1) \ + #define TYPEP(ID,NAME,TYPE,TYPE_NAME) \ +  PMOD_EXPORT void ID(INT32 args) \ +  { \ +  int t; \ +  struct program *p; \ +  if (args<1) \    SIMPLE_TOO_FEW_ARGS_ERROR(NAME, 1); \ -  if(Pike_sp[-args].type == T_OBJECT && Pike_sp[-args].u.object->prog) \ -  { \ -  int fun=FIND_LFUN(Pike_sp[-args].u.object->prog,LFUN__IS_TYPE); \ -  if(fun != -1) \ -  { \ -  push_constant_text(TYPE_NAME); \ -  apply_low(Pike_sp[-args-1].u.object,fun,1); \ -  stack_unlink(args); \ -  return; \ -  } \ -  } \ -  t=Pike_sp[-args].type == TYPE; \ -  pop_n_elems(args); \ +  if (Pike_sp[-args].type == T_OBJECT && \ +  (p = Pike_sp[-args].u.object->prog)) \ +  { \ +  int fun = FIND_LFUN(p->inherits[Pike_sp[-args].subtype].prog, \ +  LFUN__IS_TYPE); \ +  if (fun != -1) \ +  { \ +  int id_level = \ +  p->inherits[Pike_sp[-args].subtype].identifier_level; \ +  push_constant_text(TYPE_NAME); \ +  apply_low(Pike_sp[-args-1].u.object, fun + id_level, 1); \ +  stack_unlink(args); \ +  return; \ +  } \ +  } \ +  t = Pike_sp[-args].type == TYPE; \ +  pop_n_elems(args); \    push_int(t); \   }         /*! @decl int programp(mixed arg)    *!    *! Returns @expr{1@} if @[arg] is a program, @expr{0@} (zero) otherwise.    *!    *! @seealso    *! @[mappingp()], @[intp()], @[arrayp()], @[stringp()], @[objectp()],
pike.git/src/builtin_functions.c:6419:    ASSERT_SECURITY_ROOT("replace_master");       if(!args)    SIMPLE_TOO_FEW_ARGS_ERROR("replace_master", 1);    if(Pike_sp[-args].type != T_OBJECT)    SIMPLE_BAD_ARG_ERROR("replace_master", 1, "object");    if(!Pike_sp[-args].u.object->prog)    bad_arg_error("replace_master", Pike_sp-args, args, 1, "object", Pike_sp-args,    "Called with destructed object.\n");    +  if (Pike_sp[-args].subtype) +  bad_arg_error("replace_master", Pike_sp-args, args, 1, "object", Pike_sp-args, +  "Subtyped master objects are not supported yet.\n"); +     free_object(master_object);    master_object=Pike_sp[-args].u.object;    add_ref(master_object);       free_program(master_program);    master_program=master_object->prog;    add_ref(master_program);       pop_n_elems(args);   }
pike.git/src/builtin_functions.c:7188:    mysp=Pike_sp+3-args;       push_svalue(mysp-3);    push_constant_text("cast");    f_arrow(2);    if (!UNSAFE_IS_ZERO(Pike_sp-1))    {    pop_stack();       push_constant_text("array"); +  /* FIXME: Object subtype! */    safe_apply(mysp[-3].u.object,"cast",1);    if (Pike_sp[-1].type==T_ARRAY)    {    free_svalue(mysp-3);    mysp[-3]=*(--Pike_sp);    dmalloc_touch_svalue(Pike_sp);    f_map(args);    return;    }    pop_stack();       push_constant_text("mapping"); -  +  /* FIXME: Object subtype! */    safe_apply(mysp[-3].u.object,"cast",1);    if (Pike_sp[-1].type==T_MAPPING)    {    free_svalue(mysp-3);    mysp[-3]=*(--Pike_sp);    dmalloc_touch_svalue(Pike_sp);    f_map(args);    return;    }    pop_stack();       push_constant_text("multiset"); -  +  /* FIXME: Object subtype! */    safe_apply(mysp[-3].u.object,"cast",1);    if (Pike_sp[-1].type==T_MULTISET)    {    free_svalue(mysp-3);    mysp[-3]=*(--Pike_sp);    dmalloc_touch_svalue(Pike_sp);    f_map(args);    return;    }    pop_stack();
pike.git/src/builtin_functions.c:7616:    mysp=Pike_sp+3-args;       push_svalue(mysp-3);    push_constant_text("cast");    f_arrow(2);    if (!UNSAFE_IS_ZERO(Pike_sp-1))    {    pop_stack();       push_constant_text("array"); +  /* FIXME: Object subtype! */    safe_apply(mysp[-3].u.object,"cast",1);    if (Pike_sp[-1].type==T_ARRAY)    {    free_svalue(mysp-3);    mysp[-3]=*(--Pike_sp);    dmalloc_touch_svalue(Pike_sp);    f_filter(args);    return;    }    pop_stack();       push_constant_text("mapping"); -  +  /* FIXME: Object subtype! */    safe_apply(mysp[-3].u.object,"cast",1);    if (Pike_sp[-1].type==T_MAPPING)    {    free_svalue(mysp-3);    mysp[-3]=*(--Pike_sp);    dmalloc_touch_svalue(Pike_sp);    f_filter(args);    return;    }    pop_stack();       push_constant_text("multiset"); -  +  /* FIXME: Object subtype! */    safe_apply(mysp[-3].u.object,"cast",1);    if (Pike_sp[-1].type==T_MULTISET)    {    free_svalue(mysp-3);    mysp[-3]=*(--Pike_sp);    dmalloc_touch_svalue(Pike_sp);    f_filter(args);    return;    }    pop_stack();