pike.git/
src/
builtin_functions.c
Branch:
Tag:
Non-build tags
All tags
No tags
2003-06-03
2003-06-03 18:45:51 by Martin Stjernholm <mast@lysator.liu.se>
01587a83c1d50b6fd1c6c74418890988262be73d (
34
lines) (+
23
/-
11
)
[
Show
|
Annotate
]
Branch:
7.9
Better argument checking in has_value and has_index.
Rev: src/builtin_functions.c:1.494
2:
|| 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.
493
2003/
05
/
15
15
:
33
:
30
mast Exp $
+
|| $Id: builtin_functions.c,v 1.
494
2003/
06
/
03
18
:
45
:
51
mast Exp $
*/ #include "global.h"
-
RCSID("$Id: builtin_functions.c,v 1.
493
2003/
05
/
15
15
:
33
:
30
mast Exp $");
+
RCSID("$Id: builtin_functions.c,v 1.
494
2003/
06
/
03
18
:
45
:
51
mast Exp $");
#include "interpret.h" #include "svalue.h" #include "pike_macros.h"
882:
/*! @decl int has_index(string haystack, int index) *! @decl int has_index(array haystack, int index)
-
*! @decl int has_index(mapping haystack, mixed index)
+
*! @decl int has_index(mapping
|multiset|object|program
haystack, mixed index)
*! *! Search for @[index] in @[haystack]. *!
944:
break; case T_OBJECT:
+
case T_PROGRAM:
/* FIXME: If the object behaves like an array, it will throw an error for non-valid indices. Therefore it's not a good idea to use the index operator.
953:
/Noring */
-
/* Fall-through. */
-
-
default:
+
stack_swap(); f_indices(1); stack_swap();
966:
else PIKE_ERROR("has_index", "Function `search' gave incorrect result.\n", Pike_sp, args);
+
break;
+
+
default:
+
SIMPLE_ARG_TYPE_ERROR ("has_index", 1,
+
"string|array|mapping|multiset|object|program");
} } /*! @decl int has_value(string haystack, string value) *! @decl int has_value(string haystack, int value)
-
*! @decl int has_value(array
haystack, int value)
-
*! @decl int has_value(
mapping haystack, mixed value)
+
*! @decl int has_value(array
|
mapping
|object|program
haystack, mixed value)
*! *! Search for @[value] in @[haystack]. *!
1016:
"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
1029:
/* FALL_THROUGH */
-
default
:
+
case T_MULTISET
:
+
/* FIXME: This behavior for multisets isn't clean. It should be
+
* compat only. */
stack_swap(); f_values(1); stack_swap();
-
+
/* FALL_THROUGH */
+
case T_STRING: /* Strings are odd. /Noring */ case T_ARRAY: f_search(2);
1042:
Pike_sp[-1].u.integer = (Pike_sp[-1].u.integer != -1); else PIKE_ERROR("has_value", "Search gave incorrect result.\n", Pike_sp, args);
+
break;
+
+
default:
+
SIMPLE_ARG_TYPE_ERROR ("has_value", 1, "string|array|mapping|object|program");
} }