From 3c658a4e755a75e495303957208486e583ddb270 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 24 Aug 2014 16:28:17 +0100 Subject: py: Fix bug where GC collected native/viper/asm function data. Because (for Thumb) a function pointer has the LSB set, pointers to dynamic functions in RAM (eg native, viper or asm functions) were not being traced by the GC. This patch is a comprehensive fix for this. Addresses issue #820. --- tests/micropython/native.py | 10 ++++++++++ tests/micropython/native.py.exp | 2 ++ tests/micropython/viper.py | 9 +++++++++ tests/micropython/viper.py.exp | 2 ++ 4 files changed, 23 insertions(+) create mode 100644 tests/micropython/native.py create mode 100644 tests/micropython/native.py.exp (limited to 'tests/micropython') diff --git a/tests/micropython/native.py b/tests/micropython/native.py new file mode 100644 index 000000000..8f087c494 --- /dev/null +++ b/tests/micropython/native.py @@ -0,0 +1,10 @@ +@micropython.native +def native_test(x): + print(1, [], x) + +native_test(2) + +# check that GC doesn't collect the native function +import gc +gc.collect() +native_test(3) diff --git a/tests/micropython/native.py.exp b/tests/micropython/native.py.exp new file mode 100644 index 000000000..e1413fd79 --- /dev/null +++ b/tests/micropython/native.py.exp @@ -0,0 +1,2 @@ +1 [] 2 +1 [] 3 diff --git a/tests/micropython/viper.py b/tests/micropython/viper.py index 5d4f4fd7b..7e6ed67d4 100644 --- a/tests/micropython/viper.py +++ b/tests/micropython/viper.py @@ -79,3 +79,12 @@ except SystemError as e: #@micropython.viper #def g() -> uint: # return -1 + +# calling GC after defining the function +@micropython.viper +def viper_gc() -> int: + return 1 +print(viper_gc()) +import gc +gc.collect() +print(viper_gc()) diff --git a/tests/micropython/viper.py.exp b/tests/micropython/viper.py.exp index 28214aa17..2ea26ce99 100644 --- a/tests/micropython/viper.py.exp +++ b/tests/micropython/viper.py.exp @@ -9,3 +9,5 @@ [1, 3] [1, 3] SystemError(1,) +1 +1 -- cgit v1.2.3