diff --git a/src/iterators.cmod b/src/iterators.cmod index 01de6dfe2619c501ff28e520ed1a1c371f8a3935..ca37724df3a3e3c7f8334fdb8f748cabf60af3f8 100644 --- a/src/iterators.cmod +++ b/src/iterators.cmod @@ -2,11 +2,11 @@ || 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: iterators.cmod,v 1.41 2003/04/28 00:32:43 mast Exp $ +|| $Id: iterators.cmod,v 1.42 2003/05/30 23:19:26 mast Exp $ */ #include "global.h" -RCSID("$Id: iterators.cmod,v 1.41 2003/04/28 00:32:43 mast Exp $"); +RCSID("$Id: iterators.cmod,v 1.42 2003/05/30 23:19:26 mast Exp $"); #include "main.h" #include "object.h" #include "mapping.h" @@ -1787,6 +1787,8 @@ PIKEFUN object(Iterator) get_iterator(object|array|mapping|multiset|string data) /* sp[-4] = index; sp[-2] = value */ int foreach_iterate(struct object *o) { + int fun; + if(!o->prog) Pike_error("foreach on destructed iterator.\n"); if(o->prog->flags & PROGRAM_HAS_C_METHODS) @@ -1958,26 +1960,34 @@ int foreach_iterate(struct object *o) } /* Generic iteration */ - apply_lfun(o,LFUN_NOT,0); + fun = FIND_LFUN (o->prog, LFUN_NOT); + if (fun < 0) Pike_error ("Iterator object lacks `!.\n"); + apply_low(o, fun, 0); if(UNSAFE_IS_ZERO(Pike_sp-1)) { pop_stack(); if(Pike_sp[-4].type != T_INT) { - apply(o,"index",0); + fun = find_identifier ("index", o->prog); + if (fun < 0) Pike_error ("Iterator object lacks index().\n"); + apply_low(o, fun, 0); assign_lvalue(Pike_sp-5,Pike_sp-1); pop_stack(); } if(Pike_sp[-2].type != T_INT) { - apply(o,"value",0); + fun = find_identifier ("value", o->prog); + if (fun < 0) Pike_error ("Iterator object lacks value().\n"); + apply_low(o, fun, 0); assign_lvalue(Pike_sp-3,Pike_sp-1); pop_stack(); } push_int(1); + fun = FIND_LFUN (o->prog, LFUN_ADD_EQ); + if (fun < 0) Pike_error ("Iterator object lacks `+=.\n"); apply_lfun(o,LFUN_ADD_EQ,1); pop_stack(); return 1; diff --git a/src/testsuite.in b/src/testsuite.in index 90262900e4fcbf8001a21462c06ec8a50a5b3b41..c6f521a0077fcef337198835044a5203e8b6180b 100644 --- a/src/testsuite.in +++ b/src/testsuite.in @@ -1,4 +1,4 @@ -test_true([["$Id: testsuite.in,v 1.649 2003/05/30 19:38:06 grubba Exp $"]]); +test_true([["$Id: testsuite.in,v 1.650 2003/05/30 23:19:26 mast Exp $"]]); // This triggered a bug only if run sufficiently early. test_compile_any([[#pike 7.2]]) @@ -6718,6 +6718,12 @@ test_any([[ return ret; ]],315) +test_eval_error([[ + int i; + foreach (class{}(); mixed a; mixed b) i++; + return i; +]]) + // do-while test_any(int e;string t=""; e=0; do{ t+=e; }while(++e<6); return t,"012345";)