Branch: Tag:

2014-08-18

2014-08-18 15:38:59 by Martin Nilsson <nilsson@opera.com>

Improved cast.

15:   #include "operators.h"   #include "program_id.h"   #include "file_machine.h" + #include "pike_types.h"      #include <sys/stat.h>   #ifdef HAVE_SYS_PARAM_H
790:      static void stat_cast(INT32 args)   { -  if (!args) -  SIMPLE_TOO_FEW_ARGS_ERROR("Stat cast",1); -  if (TYPEOF(sp[-args]) == T_STRING && !sp[-args].u.string->size_shift) +  struct pike_string *type = Pike_sp[-args].u.string; +  pop_stack(); /* type have at least one more reference. */ +  +  if (type == literal_array_string)    { -  /* NB: We only look at the prefix, and let the main cast function -  * handle any subtypes. -  */ -  if (!strncmp(sp[-args].u.string->str, "array", 5)) -  { -  pop_n_elems(args); +     push_int(0);    push_int(6);    stat_index(2); -  return; +     } -  if (!strncmp(sp[-args].u.string->str, "mapping", 7)) +  else if (type == literal_mapping_string)    {    stat_indices(0);    stat_values(0);    push_mapping(mkmapping(Pike_sp[-2].u.array, Pike_sp[-1].u.array));    stack_pop_n_elems_keep_top(2); -  return; +     } -  +  else +  push_undefined();   } -  SIMPLE_BAD_ARG_ERROR("Stat cast",1, -  "string(\"array\"|\"mapping\")"); - } +       static void stat__sprintf(INT32 args)   {
1036:    tOr(tFunc(tInt06 tSetvar(0,tInt),tVar(0)),    tFunc(tString tSetvar(1,tOr(tInt,tString)),tVar(1))), 0);    -  ADD_FUNCTION("cast",stat_cast,tFunc(tStr,tArray),0); +  ADD_FUNCTION("cast",stat_cast,tFunc(tStr,tArray),ID_PRIVATE);    ADD_FUNCTION("_sprintf",stat__sprintf,    tFunc(tInt tOr(tVoid,tMapping),tString),0);    ADD_FUNCTION("_indices",stat_indices,