Skip to content

Commit

Permalink
[test] More repro for memory leak
Browse files Browse the repository at this point in the history
Running it under GDB.  I think reviving the GDB plugin will be useful.

[ASDL] Test List<T> and Dict<K, V> as first class variants in C++

Seems like it will work

[devtools] Rename GDB plugin
  • Loading branch information
Andy C committed Nov 17, 2024
1 parent f4283e5 commit b52392e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build/py.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion devtools/oil.gdb → devtools/oils.gdb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions devtools/oil_gdb.py → devtools/oils_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 48 additions & 0 deletions mycpp/demo/target_lang.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> {};

class value_t {};
class Dict_ : public value_t, public Dict<BigStr*, value_t*> {};

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<word_t*>(c);

List<BigStr*>* mylist = new List<BigStr*>();
mylist->append(kEmptyString);
mylist->append(kEmptyString);

log("List<BigStr*> len %d", len(mylist));

// yes, it's an error!
// w = mylist;

// also an error!
// w = static_cast<word_t*>(mylist);

w = reinterpret_cast<word_t*>(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) {
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions test/bug-2123.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

"$@"
7 changes: 7 additions & 0 deletions test/bug-2123.ysh
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------------------------------------------------------'
Expand Down

0 comments on commit b52392e

Please sign in to comment.