From 9da7f42a813e6d7df6d609a98128d358ce2123cd Mon Sep 17 00:00:00 2001 From: Martin Stjernholm <mast@lysator.liu.se> Date: Tue, 5 Jun 2001 02:03:57 +0200 Subject: [PATCH] Use separate weak flags for indices and values. Rev: lib/modules/Pike.pmod:1.1 Rev: src/builtin.cmod:1.30 Rev: src/builtin_functions.h:1.17 Rev: src/testsuite.in:1.420 --- .gitattributes | 2 + lib/modules/Pike.pmod | 9 +++ src/builtin.cmod | 19 +++--- src/builtin_functions.h | 8 ++- src/testsuite.in | 126 +++++++++++++++++++++++++++++++++++++++- 5 files changed, 154 insertions(+), 10 deletions(-) create mode 100644 lib/modules/Pike.pmod diff --git a/.gitattributes b/.gitattributes index 8c1f83a12c..720708a95f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -85,6 +85,7 @@ testfont binary /lib/modules/MIME.pmod foreign_ident /lib/modules/Parser.pmod/XML.pmod/Tree.pmod foreign_ident /lib/modules/Parser.pmod/module.pmod foreign_ident +/lib/modules/Pike.pmod foreign_ident /lib/modules/Protocols.pmod/DNS.pmod foreign_ident /lib/modules/Protocols.pmod/IMAP.pmod/imap_server.pike foreign_ident /lib/modules/Protocols.pmod/IMAP.pmod/requests.pmod foreign_ident @@ -167,6 +168,7 @@ testfont binary /src/backend.h foreign_ident /src/block_alloc.h foreign_ident /src/build_modlist_h foreign_ident +/src/builtin.cmod foreign_ident /src/builtin_functions.c foreign_ident /src/builtin_functions.h foreign_ident /src/builtin_functions_t.c foreign_ident diff --git a/lib/modules/Pike.pmod b/lib/modules/Pike.pmod new file mode 100644 index 0000000000..fa9f9a8f04 --- /dev/null +++ b/lib/modules/Pike.pmod @@ -0,0 +1,9 @@ +// Pike core things that don't belong anywhere else. +// +// $Id: Pike.pmod,v 1.1 2001/06/05 00:03:56 mast Exp $ + +constant WEAK_INDICES = __builtin.PIKE_WEAK_INDICES; +constant WEAK_VALUES = __builtin.PIKE_WEAK_VALUES; +constant WEAK = WEAK_INDICES|WEAK_VALUES; +//! Flags for use together with @[set_weak_flag] and @[get_weak_flag]. +//! See @[set_weak_flag] for details. diff --git a/src/builtin.cmod b/src/builtin.cmod index cb9d00e28c..ba23cc5239 100644 --- a/src/builtin.cmod +++ b/src/builtin.cmod @@ -1,4 +1,6 @@ -/* -*- c -*- */ +/* -*- c -*- + * $Id: builtin.cmod,v 1.30 2001/06/05 00:03:57 mast Exp $ + */ #include "global.h" #include "interpret.h" @@ -23,6 +25,7 @@ #include "bignum.h" #include "main.h" #include "operators.h" +#include "builtin_functions.h" /*! @decl array column(array data, mixed index) *! @@ -394,24 +397,26 @@ PIKEFUN mixed m_delete(object|mapping map, mixed index) } } -/*! @decl int(0..1) get_weak_flag(array|mapping|multiset m) +/*! @decl int get_weak_flag(array|mapping|multiset m) *! - *! Returns 1 if the weak flag has been set for @[m]. + *! Returns the weak flag settings for @[m]. It's a combination of + *! @[Pike.WEAK_INDICES] and @[Pike.WEAK_VALUES]. */ -PIKEFUN int(0 .. 1) get_weak_flag(array|mapping|multiset m) +PIKEFUN int get_weak_flag(array|mapping|multiset m) efun; optflags OPT_EXTERNAL_DEPEND; { int flag = 0; switch (m->type) { case T_ARRAY: - flag = !!(m->u.array->flags & ARRAY_WEAK_FLAG); + flag = (m->u.array->flags & ARRAY_WEAK_FLAG) ? PIKE_WEAK_VALUES : 0; break; case T_MAPPING: - flag = !!(mapping_get_flags(m->u.mapping) & MAPPING_FLAG_WEAK); + flag = mapping_get_flags(m->u.mapping) & MAPPING_WEAK; break; case T_MULTISET: - flag = !!(m->u.multiset->ind->flags & (ARRAY_WEAK_FLAG|ARRAY_WEAK_SHRINK)); + flag = (m->u.multiset->ind->flags & (ARRAY_WEAK_FLAG|ARRAY_WEAK_SHRINK)) ? + PIKE_WEAK_INDICES : 0; break; default: SIMPLE_BAD_ARG_ERROR("get_weak_flag",1,"array|mapping|multiset"); diff --git a/src/builtin_functions.h b/src/builtin_functions.h index 05bf7f8577..3cbd72f907 100644 --- a/src/builtin_functions.h +++ b/src/builtin_functions.h @@ -5,7 +5,7 @@ \*/ /* - * $Id: builtin_functions.h,v 1.16 2001/04/30 00:53:11 mast Exp $ + * $Id: builtin_functions.h,v 1.17 2001/06/05 00:03:57 mast Exp $ */ #ifndef BUILTIN_EFUNS_H #define BUILTIN_EFUNS_H @@ -14,6 +14,12 @@ #include "callback.h" +/* Weak flags for arrays, multisets and mappings. 1 is avoided for + * compatibility reasons. */ +#define PIKE_WEAK_INDICES 2 +#define PIKE_WEAK_VALUES 4 +#define PIKE_WEAK_BOTH 6 + /* Prototypes begin here */ PMOD_EXPORT void debug_f_aggregate(INT32 args); #ifdef DEBUG_MALLOC diff --git a/src/testsuite.in b/src/testsuite.in index 5f32e3d14d..edcfa091a8 100644 --- a/src/testsuite.in +++ b/src/testsuite.in @@ -1,4 +1,4 @@ -test_true([["$Id: testsuite.in,v 1.419 2001/05/31 22:16:37 grubba Exp $"]]); +test_true([["$Id: testsuite.in,v 1.420 2001/06/05 00:03:57 mast Exp $"]]); cond([[all_constants()->_verify_internals]], [[ @@ -2517,7 +2517,21 @@ ifefun(gc, gc(); return !sizeof (m); ]]) - test_true([[ + test_true([[ + object o = class{}(); + mapping m = ([class{}(): o, o: class{}()]); + set_weak_flag (m, Pike.WEAK_INDICES); + gc(); + return sizeof (m); + ]]) + test_true([[ + object o = class{}(); + mapping m = ([class{}(): o, o: class{}()]); + set_weak_flag (m, Pike.WEAK_VALUES); + gc(); + return sizeof (m); + ]]) + test_true([[ object o = class{}(); multiset m = (<o>); set_weak_flag (m, 1); @@ -3663,6 +3677,114 @@ ifefun(gc, o=o2=0; gc(); ]]) + + test_any([[ + object o = class{}(); + mapping m = set_weak_flag (([o: "x"]), Pike.WEAK_INDICES); + gc(); + return sizeof (m); + ]], 1) + test_any([[ + object o = class{}(); + mapping m = set_weak_flag (([o: "x"]), Pike.WEAK_VALUES); + gc(); + return sizeof (m); + ]], 1) + test_any([[ + object o = class{}(); + mapping m = set_weak_flag ((["x": o]), Pike.WEAK_INDICES); + gc(); + return sizeof (m); + ]], 1) + test_any([[ + object o = class{}(); + mapping m = set_weak_flag ((["x": o]), Pike.WEAK_VALUES); + gc(); + return sizeof (m); + ]], 1) + test_any([[ + mapping m = set_weak_flag (([class{}(): "x"]), Pike.WEAK_INDICES); + gc(); + return sizeof (m); + ]], 0) + test_any([[ + mapping m = set_weak_flag (([class{}(): "x"]), Pike.WEAK_VALUES); + gc(); + return sizeof (m); + ]], 1) + test_any([[ + mapping m = set_weak_flag ((["x": class{}()]), Pike.WEAK_INDICES); + gc(); + return sizeof (m); + ]], 1) + test_any([[ + mapping m = set_weak_flag ((["x": class{}()]), Pike.WEAK_VALUES); + gc(); + return sizeof (m); + ]], 0) + test_any([[ + object o = class{}(); + mapping m = set_weak_flag (([o: o]), Pike.WEAK_INDICES); + o = 0; + gc(); + return sizeof (m); + ]], 1) + test_any([[ + object o = class{}(); + mapping m = set_weak_flag (([o: o]), Pike.WEAK_VALUES); + o = 0; + gc(); + return sizeof (m); + ]], 1) + test_any([[ + object o = class{}(); + mapping m = set_weak_flag (([o: o]), Pike.WEAK); + o = 0; + gc(); + return sizeof (m); + ]], 0) + test_any([[ + object o = class{}(); + mapping m = set_weak_flag (([o: "x"]), Pike.WEAK_INDICES); + destruct (o); + gc(); + return sizeof (m); + ]], 0) + test_any([[ + object o = class{}(); + mapping m = set_weak_flag (([o: "x"]), Pike.WEAK_VALUES); + destruct (o); + gc(); + return sizeof (m); + ]], 0) + test_any([[ + object o = class{}(); + mapping m = ([o: "x"]); + destruct (o); + gc(); + return sizeof (m); + ]], 0) + test_any([[ + object o = class{}(); + mapping m = set_weak_flag ((["x": o]), Pike.WEAK_INDICES); + destruct (o); + gc(); + return sizeof (m); + ]], 1) + test_any([[ + object o = class{}(); + mapping m = set_weak_flag ((["x": o]), Pike.WEAK_VALUES); + destruct (o); + gc(); + return sizeof (m); + ]], 0) + test_any([[ + object o = class{}(); + mapping m = (["x": o]); + destruct (o); + gc(); + return sizeof (m); + ]], 1) ]]) cond([[ sizeof( cpp("__AUTO_BIGNUM__")/"__AUTO_BIGNUM__" ) == 1 ]], -- GitLab