From b52392ee290e9ca79123dd6d7ed7dd4f9459aa50 Mon Sep 17 00:00:00 2001 From: Andy C Date: Sat, 16 Nov 2024 12:53:19 -0500 Subject: [PATCH] [test] More repro for memory leak Running it under GDB. I think reviving the GDB plugin will be useful. [ASDL] Test List and Dict as first class variants in C++ Seems like it will work [devtools] Rename GDB plugin --- build/py.sh | 2 +- devtools/{oil.gdb => oils.gdb} | 2 +- devtools/{oil_gdb.py => oils_gdb.py} | 6 ++-- mycpp/demo/target_lang.cc | 48 ++++++++++++++++++++++++++++ test/bug-2123.sh | 7 ++++ test/bug-2123.ysh | 7 ++++ 6 files changed, 68 insertions(+), 4 deletions(-) rename devtools/{oil.gdb => oils.gdb} (90%) rename devtools/{oil_gdb.py => oils_gdb.py} (96%) diff --git a/build/py.sh b/build/py.sh index 2f4d71904d..9fd8233fbe 100755 --- a/build/py.sh +++ b/build/py.sh @@ -112,7 +112,7 @@ flag-gen-mypy() { # Helper gen-asdl-py() { - local asdl_path=$1 # e.g. osh/osh.asdl + local asdl_path=$1 # e.g. frontend/syntax.asdl local name name=$(basename $asdl_path .asdl) diff --git a/devtools/oil.gdb b/devtools/oils.gdb similarity index 90% rename from devtools/oil.gdb rename to devtools/oils.gdb index 8e1a5d39aa..94b96692fc 100644 --- a/devtools/oil.gdb +++ b/devtools/oils.gdb @@ -11,7 +11,7 @@ set print pretty on # TODO: save history # Our Python commands -source devtools/oil_gdb.py +source devtools/oils_gdb.py define cls shell clear diff --git a/devtools/oil_gdb.py b/devtools/oils_gdb.py similarity index 96% rename from devtools/oil_gdb.py rename to devtools/oils_gdb.py index 08e88200c4..d8b0375873 100644 --- a/devtools/oil_gdb.py +++ b/devtools/oils_gdb.py @@ -180,9 +180,11 @@ def Preprocess(t): # Each of these files defines two variables. We append them to a global list. asdl_types = [] -gdb.execute('source _devbuild/gen/syntax_asdl_debug.py') +gdb.execute('source _gen/frontend/syntax.asdl_debug.py') asdl_types.append((cpp_namespace, tags_to_types)) -gdb.execute('source _devbuild/gen/runtime_asdl_debug.py') +gdb.execute('source _gen/core/runtime.asdl_debug.py') +asdl_types.append((cpp_namespace, tags_to_types)) +gdb.execute('source _gen/core/value.asdl_debug.py') asdl_types.append((cpp_namespace, tags_to_types)) sum_type_lookup = Preprocess(asdl_types) diff --git a/mycpp/demo/target_lang.cc b/mycpp/demo/target_lang.cc index 8c96ae3d61..7da4d0a61b 100644 --- a/mycpp/demo/target_lang.cc +++ b/mycpp/demo/target_lang.cc @@ -1069,6 +1069,53 @@ TEST member_init_demo() { PASS(); } +// +// Zephyr ASDL Demo +// + +class word_t {}; + +class word__BracedTree : public word_t {}; + +// This is multiple inheritance, and also inheritance from a subtype? +// It's interesting that this works! +// TODO: test if MyPy can express this! +class CompoundWord : public word_t, public List {}; + +class value_t {}; +class Dict_ : public value_t, public Dict {}; + +TEST subtype_demo() { + CompoundWord* c = new CompoundWord(); + c->append(42); + log("CompoundWord len %d", len(c)); + + word_t* w = nullptr; + + w = c; + w = static_cast(c); + + List* mylist = new List(); + mylist->append(kEmptyString); + mylist->append(kEmptyString); + + log("List len %d", len(mylist)); + + // yes, it's an error! + // w = mylist; + + // also an error! + // w = static_cast(mylist); + + w = reinterpret_cast(mylist); + + Dict_* d = new Dict_(); + d->set(kEmptyString, nullptr); + log("Dict_ len %d", len(d)); + + PASS(); +} + GREATEST_MAIN_DEFS(); int main(int argc, char** argv) { @@ -1101,6 +1148,7 @@ int main(int argc, char** argv) { RUN_TEST(asdl_namespace_demo); RUN_TEST(member_init_demo); + RUN_TEST(subtype_demo); GREATEST_MAIN_END(); /* display results */ return 0; diff --git a/test/bug-2123.sh b/test/bug-2123.sh index 3d19e5318e..68e48906d4 100755 --- a/test/bug-2123.sh +++ b/test/bug-2123.sh @@ -11,4 +11,11 @@ demo() { /usr/bin/time --format '%e %M' $ysh test/bug-2123.ysh } +debug() { + local ysh=_bin/cxx-dbg/ysh + ninja $ysh + + gdb --args $ysh test/bug-2123.ysh +} + "$@" diff --git a/test/bug-2123.ysh b/test/bug-2123.ysh index 742a6094e0..a901370351 100644 --- a/test/bug-2123.ysh +++ b/test/bug-2123.ysh @@ -60,6 +60,13 @@ proc without-default { } echo 'FILTER without default' + + for line in (io.stdin) { + var d = fromJson8(line) + call get(d, 'missing-key') + } < $f + + #time filter [get(_val, 'missing-key', 0) === 0] < $f >/dev/null time filter [get(_val, 'missing-key')] < $f #>/dev/null write -- 'AFTER -------------------------------------------------------'