diff --git a/doc/builtin/_next b/doc/builtin/_next new file mode 100644 index 0000000000000000000000000000000000000000..3f9465795d29b63d70c28a870458a8d760bc3dad --- /dev/null +++ b/doc/builtin/_next @@ -0,0 +1,14 @@ +NAME + _next - find the next object/array/whatever + +SYNTAX + mixed _next(mixed p); + +DESCRIPTION + This function returns the 'next' object/array/mapping/string/etc + in the linked list. It is mainly meant for debugging Pike but + can also be used to control memory usage. + +SEE ALSO + next_object, _prev + \ No newline at end of file diff --git a/doc/builtin/_prev b/doc/builtin/_prev new file mode 100644 index 0000000000000000000000000000000000000000..f39d649dd17b576535325fe6071c73766caa605e --- /dev/null +++ b/doc/builtin/_prev @@ -0,0 +1,14 @@ +NAME + _prev - find the previous object/array/whatever + +SYNTAX + mixed _next(mixed p); + +DESCRIPTION + This function returns the 'previous' object/array/mapping/etc + in the linked list. It is mainly meant for debugging Pike but + can also be used to control memory usage. Note that this function + does not work on strings. + +SEE ALSO + _next diff --git a/doc/builtin/zero_type b/doc/builtin/zero_type index 9c615153e41283918e9ab15daf0a8ecea71c87ce..5f55f8a0e0944d91a7924de7e2b4ed1127504479 100644 --- a/doc/builtin/zero_type +++ b/doc/builtin/zero_type @@ -11,7 +11,9 @@ DESCRIPTION The only way to separate these two kinds of zeros is zero_type. When doing a find_call_out or mapping lookup, zero_type on this value will return 1 if there was no such thing present in the mappping, or - no such call_out could be found. Otherwize zero_type will return zero. + no such call_out could be found. If the argument to zero type is a + destructed object or a function in a destructed object, 2 will be + returned. Otherwize zero_type will return zero. If the argument is not an int, zero will be returned. diff --git a/src/builtin_functions.c b/src/builtin_functions.c index b68fbdd0c89ffc37a6e0237b2d8d69b7007715cb..71e7dd2f5e2665db1913f20c2d986ebc4d9beccf 100644 --- a/src/builtin_functions.c +++ b/src/builtin_functions.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: builtin_functions.c,v 1.17 1996/12/05 02:32:35 hubbe Exp $"); +RCSID("$Id: builtin_functions.c,v 1.18 1996/12/05 04:49:38 hubbe Exp $"); #include "interpret.h" #include "svalue.h" #include "macros.h" @@ -515,7 +515,14 @@ void f_zero_type(INT32 args) { pop_n_elems(args); push_int(0); - }else{ + } + else if((sp[-args].type==T_OBJECT || sp[-args].type==T_FUNCTION) + && !sp[-args].u.object->prog) + { + pop_n_elems(args); + push_int(NUMBER_DESTRUCTED); + } + { pop_n_elems(args-1); sp[-1].u.integer=sp[-1].subtype; sp[-1].subtype=NUMBER_NUMBER; @@ -1509,6 +1516,61 @@ void f__memory_usage(INT32 args) f_aggregate_mapping(sp-ss); } +void f__next(INT32 args) +{ + struct svalue tmp; + if(!args) + error("Too few arguments to _next()\n"); + + pop_n_elems(args-1); + tmp=sp[-1]; + switch(tmp.type) + { + case T_OBJECT: tmp.u.object=tmp.u.object->next; break; + case T_ARRAY: tmp.u.array=tmp.u.array->next; break; + case T_MAPPING: tmp.u.mapping=tmp.u.mapping->next; break; + case T_MULTISET:tmp.u.multiset=tmp.u.multiset->next; break; + case T_PROGRAM: tmp.u.program=tmp.u.program->next; break; + case T_STRING: tmp.u.string=tmp.u.string->next; break; + default: + error("Bad argument 1 to _next()\n"); + } + if(tmp.u.refs) + { + assign_svalue(sp-1,&tmp); + }else{ + pop_stack(); + push_int(0); + } +} + +void f__prev(INT32 args) +{ + struct svalue tmp; + if(!args) + error("Too few arguments to _next()\n"); + + pop_n_elems(args-1); + tmp=sp[-1]; + switch(tmp.type) + { + case T_OBJECT: tmp.u.object=tmp.u.object->prev; break; + case T_ARRAY: tmp.u.array=tmp.u.array->prev; break; + case T_MAPPING: tmp.u.mapping=tmp.u.mapping->prev; break; + case T_MULTISET:tmp.u.multiset=tmp.u.multiset->prev; break; + case T_PROGRAM: tmp.u.program=tmp.u.program->prev; break; + default: + error("Bad argument 1 to _prev()\n"); + } + if(tmp.u.refs) + { + assign_svalue(sp-1,&tmp); + }else{ + pop_stack(); + push_int(0); + } +} + void init_builtin_efuns() { init_operators(); @@ -1547,6 +1609,8 @@ void init_builtin_efuns() add_efun("mappingp",f_mappingp,"function(mixed:int)",OPT_TRY_OPTIMIZE); add_efun("mkmapping",f_mkmapping,"function(mixed *,mixed *:mapping)",OPT_TRY_OPTIMIZE); add_efun("next_object",f_next_object,"function(void|object:object)",OPT_EXTERNAL_DEPEND); + add_efun("_next",f__next,"function(string:string)|function(object:object)|function(mapping:mapping)|function(multiset:multiset)|function(program:program)|function(array:array)",OPT_EXTERNAL_DEPEND); + add_efun("_prev",f__prev,"function(object:object)|function(mapping:mapping)|function(multiset:multiset)|function(program:program)|function(array:array)",OPT_EXTERNAL_DEPEND); add_efun("object_program",f_object_program,"function(mixed:program)",0); add_efun("objectp", f_objectp, "function(mixed:int)",0); add_efun("programp",f_programp,"function(mixed:int)",0); diff --git a/src/testsuite.in b/src/testsuite.in index d533b24b6f0546fdff5bfdc19fbd7fc97ae6f749..b2cb49479b1815861aeb3349c821f1725104162f 100644 --- a/src/testsuite.in +++ b/src/testsuite.in @@ -1,4 +1,10 @@ -test_true([["$Id: testsuite.in,v 1.11 1996/12/02 07:02:57 hubbe Exp $"]]) +test_true(mappingp(_memory_usage())) +test_true(objectp( _next(this_object()) || _prev(this_object()))) +test_true(arrayp( _next(({})) || _prev(({})))) +test_any(object o=this_object(); while(o=_next(o))); +test_any(object o=this_object(); while(o=_prev(o))); + +test_true([["$Id: testsuite.in,v 1.12 1996/12/05 04:49:38 hubbe Exp $"]]) test_any([[object(File) o=File(); return objectp(o);]],1) test_any([[object o=Regexp("foo"); return objectp(o);]],1) test_any([[object o=Regexp("foo"); return object_program(o);]],Regexp)