pike.git / src / sprintf.c

version» Context lines:

pike.git/src/sprintf.c:2523:       default: break;    }    }    }    /* FIXME: Convert into compile_sprintf(args[0])->format(@args[1..])? */    return ret;   }      /*! @decl type(mixed) __handle_sprintf_format(string attr, string fmt, @ -  *! type arg_type, type cont_type) +  *! type arg_type, type cont_type, @ +  *! mapping state)    *!    *! Type attribute handler for @expr{"sprintf_format"@}.    *!    *! @param attr    *! Attribute to handle, either @expr{"sprintf_format"@}    *! or @expr{"strict_sprintf_format"@}.    *!    *! @param fmt    *! Sprintf-style formatting string to generate type information from.    *!    *! @param arg_type    *! Declared type of the @[fmt] argument (typically @expr{string@}).    *!    *! @param cont_type    *! Continuation function type after the @[fmt] argument. This is    *! scanned for the type attribute @expr{"sprintf_args"@} to    *! determine where the remaining arguments to @[sprintf()] will    *! come from.    *! -  +  *! @param state +  *! State mapping. +  *!    *! This function is typically called from    *! @[PikeCompiler()->apply_attribute_constant()] and is used to perform    *! stricter compile-time argument checking of @[sprintf()]-style functions.    *!    *! It currently implements two operating modes depending on the value of    *! @[attr]:    *! @string    *! @value "strict_sprintf_format"    *! The formatting string @[fmt] is known to always be passed to    *! @[sprintf()].
pike.git/src/sprintf.c:2579:    struct pike_type *tmp;    struct pike_string *attr;    struct pike_string *fmt;    int severity = REPORT_ERROR;    int found = 0;    int fmt_count;    int marker;    int str_marker = 0;    int marker_mask;    -  if (args != 4) -  SIMPLE_WRONG_NUM_ARGS_ERROR("__handle_sprintf_format", 4); -  if (TYPEOF(Pike_sp[-4]) != PIKE_T_STRING) +  if (args != 5) +  SIMPLE_WRONG_NUM_ARGS_ERROR("__handle_sprintf_format", 5); +  if (TYPEOF(Pike_sp[-5]) != PIKE_T_STRING)    SIMPLE_ARG_TYPE_ERROR("__handle_sprintf_format", 1, "string"); -  if (TYPEOF(Pike_sp[-3]) != PIKE_T_STRING) +  if (TYPEOF(Pike_sp[-4]) != PIKE_T_STRING)    SIMPLE_ARG_TYPE_ERROR("__handle_sprintf_format", 2, "string"); -  if (TYPEOF(Pike_sp[-2]) != PIKE_T_TYPE) +  if (TYPEOF(Pike_sp[-3]) != PIKE_T_TYPE)    SIMPLE_ARG_TYPE_ERROR("__handle_sprintf_format", 3, "type"); -  if (TYPEOF(Pike_sp[-1]) != PIKE_T_TYPE) +  if (TYPEOF(Pike_sp[-2]) != PIKE_T_TYPE)    SIMPLE_ARG_TYPE_ERROR("__handle_sprintf_format", 4, "type"); -  +  if (TYPEOF(Pike_sp[-1]) != PIKE_T_MAPPING) +  SIMPLE_ARG_TYPE_ERROR("__handle_sprintf_format", 5, "mapping");    -  tmp = Pike_sp[-1].u.type; +  tmp = Pike_sp[-2].u.type;    if ((tmp->type != PIKE_T_FUNCTION) && (tmp->type != T_MANY)) {    SIMPLE_ARG_TYPE_ERROR("__handle_sprintf_format", 4, "type(function)");    }      #if 0    fprintf(stderr, "__handle_sprintf_format(\"%s\", \"%s\", ...)\n", -  Pike_sp[-4].u.string->str, Pike_sp[-3].u.string->str); +  Pike_sp[-5].u.string->str, Pike_sp[-4].u.string->str);   #endif /* 0 */       MAKE_CONST_STRING(attr, "sprintf_format"); -  if (Pike_sp[-4].u.string == attr) { +  if (Pike_sp[-5].u.string == attr) {    /* Don't complain so loud about syntax errors in    * relaxed mode.    */    severity = REPORT_NOTICE;    } else {    MAKE_CONST_STRING(attr, "strict_sprintf_format"); -  if (Pike_sp[-4].u.string != attr) { +  if (Pike_sp[-5].u.string != attr) {    Pike_error("Bad argument 1 to __handle_sprintf_format(), expected "    "\"sprintf_format\" or \"strict_sprintf_format\", " -  "got \"%S\".\n", Pike_sp[-4].u.string); +  "got \"%S\".\n", Pike_sp[-5].u.string);    }    }       /* Allocate a marker for accumulating the result type. */    marker = '0';    marker_mask = PT_FLAG_MARKER_0 | PT_FLAG_ASSIGN_0;    while (tmp->flags & marker_mask) {    marker++;    marker_mask <<= 1;    }
pike.git/src/sprintf.c:2633:    else {    str_marker = marker + 1;    marker_mask <<= 1;    while (tmp->flags & marker_mask) {    str_marker++;    marker_mask <<= 1;    }    if (str_marker > '9') str_marker = 0;    }    -  fmt = Pike_sp[-3].u.string; +  fmt = Pike_sp[-4].u.string;    MAKE_CONST_STRING(attr, "sprintf_args");       type_stack_mark();    type_stack_mark();    for (; tmp; tmp = tmp->cdr) {    struct pike_type *arg = tmp->car;    int array_cnt = 0;    while(arg) {    switch(arg->type) {    case PIKE_T_ATTRIBUTE:
pike.git/src/sprintf.c:2744:    }    push_reverse_type(T_MANY);    fmt_count = pop_stack_mark();    while (fmt_count > 1) {    push_reverse_type(T_FUNCTION);    fmt_count--;    }    if (severity < REPORT_ERROR) {    /* Add the type where the fmt isn't sent to sprintf(). */    type_stack_mark(); -  for (arg = Pike_sp[-1].u.type; arg != tmp; arg = arg->cdr) { +  for (arg = Pike_sp[-2].u.type; arg != tmp; arg = arg->cdr) {    push_finished_type(arg->car);    }    push_type(T_VOID); /* No more args */    push_finished_type(tmp->cdr); /* Return type */    push_reverse_type(T_MANY);    fmt_count = pop_stack_mark();    while (fmt_count > 1) {    push_reverse_type(T_FUNCTION);    fmt_count--;    }
pike.git/src/sprintf.c:2863:    while (fmt_count > 1) {    push_reverse_type(T_FUNCTION);    fmt_count--;    }    res = pop_unfinished_type();    pop_n_elems(args);    push_type_value(res);    } else {    /* No marker found. */   #if 0 -  simple_describe_type(Pike_sp[-1].u.type); +  simple_describe_type(Pike_sp[-2].u.type);    fprintf(stderr, " ==> No marker found.\n");   #endif /* 0 */    pop_stack_mark();    type_stack_pop_to_mark();    pop_n_elems(args);    push_undefined();    }   }      /*! @decl constant sprintf_format = __attribute__("sprintf_format")