Branch: Tag:

2001-06-08

2001-06-08 14:26:42 by Martin Stjernholm <mast@lysator.liu.se>

Backported the separate weak indices and values feature from 7.3.

Rev: lib/modules/Pike.pmod:1.1
Rev: src/builtin.cmod:1.18
Rev: src/builtin_functions.c:1.341
Rev: src/builtin_functions.h:1.16
Rev: src/mapping.c:1.117
Rev: src/mapping.h:1.35
Rev: src/svalue.c:1.96
Rev: src/svalue.h:1.76
Rev: src/testsuite.in:1.387

5:   \*/   /**/   #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.340 2001/06/06 02:22:36 mast Exp $"); + RCSID("$Id: builtin_functions.c,v 1.341 2001/06/08 14:26:40 mast Exp $");   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"
3165:   }       - /*! @decl array|mapping|multiset set_weak_flag(array|mapping|multiset m, -  *! int(0..1) state) + /*! @decl array|mapping|multiset set_weak_flag(array|mapping|multiset m, @ +  *! int state)    *! -  *! Set the value @[m] to hold weak references if @[state] is @tt{1@}. -  *! Reset to strong references otherwise. +  *! Set the value @[m] to use weak or normal references in its indices +  *! and/or values (whatever is applicable). @[state] is a bitfield +  *! built by using @tt{|@} between the following flags:    *! -  +  *! @dl +  *! @item @[Pike.WEAK_INDICES] +  *! Use weak references for indices. Only applicable for multisets +  *! and mappings. +  *! @item @[Pike.WEAK_VALUES] +  *! Use weak references for values. Only applicable for arrays and +  *! mappings. +  *! @item @[Pike.WEAK] +  *! Shorthand for @tt{Pike.WEAK_INDICES|Pike.WEAK_VALUES@}. +  *! @enddl +  *! +  *! If a flag is absent, the corresponding field will use normal +  *! references. @[state] can also be @tt{1@} as a compatibility +  *! measure; it's treated like @[Pike.WEAK]. +  *!    *! @returns    *! @[m] will be returned.    */
3184:       get_all_args("set_weak_flag",args,"%*%i",&s,&ret);    +  if (ret == 1) ret = PIKE_WEAK_BOTH; +     switch(s->type)    {    case T_ARRAY:    flags = array_get_flags(s->u.array); -  SETFLAG(flags,ARRAY_WEAK_FLAG,ret); +  SETFLAG(flags,ARRAY_WEAK_FLAG,ret & PIKE_WEAK_VALUES);    s->u.array = array_set_flags(s->u.array, flags);    break;    case T_MAPPING:    flags = mapping_get_flags(s->u.mapping); -  SETFLAG(flags,MAPPING_FLAG_WEAK,ret); +  flags = (flags & ~PIKE_WEAK_BOTH) | (ret & PIKE_WEAK_BOTH);    mapping_set_flags(s->u.mapping, flags);    break;    case T_MULTISET:    flags = array_get_flags(s->u.multiset->ind); -  SETFLAG(flags,(ARRAY_WEAK_FLAG|ARRAY_WEAK_SHRINK),ret); +  SETFLAG(flags,(ARRAY_WEAK_FLAG|ARRAY_WEAK_SHRINK),ret & PIKE_WEAK_INDICES);    s->u.multiset->ind = array_set_flags(s->u.multiset->ind, flags);    break;    default:
7525:    ADD_EFUN("set_weak_flag",f_set_weak_flag,    tFunc(tSetvar(1,tMix) tInt,tVar(1)),OPT_SIDE_EFFECT);    +  ADD_INT_CONSTANT("PIKE_WEAK_INDICES", PIKE_WEAK_INDICES, 0); +  ADD_INT_CONSTANT("PIKE_WEAK_VALUES", PIKE_WEAK_VALUES, 0); +    /* function(void|object:object) */    ADD_EFUN("next_object",f_next_object,    tFunc(tOr(tVoid,tObj),tObj),OPT_EXTERNAL_DEPEND);