]> gitweb.factorcode.org Git - factor.git/commitdiff
python: tests and plug a reference leak in the exception throwing code
authorBjörn Lindqvist <bjourne@gmail.com>
Thu, 2 Oct 2014 13:15:50 +0000 (15:15 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 2 Oct 2014 15:32:39 +0000 (08:32 -0700)
extra/python/python-tests.factor
extra/python/syntax/syntax-tests.factor
extra/python/throwing/throwing.factor

index 582e6bfe0c3867c23015194f8a07e1a73a9b2ae3..837e73475b480d11515774efef6891903911796f 100644 (file)
@@ -17,8 +17,10 @@ IN: python
 [ t ] [ Py_IsInitialized ] py-test
 
 ! py-importing
-[ { "ImportError" "No module named kolobi" } ] [
-    [ "kolobi" py-import ] [ [ type>> ] [ message>> ] bi 2array ] recover
+[ { "ImportError" "No module named kolobi" f } ] [
+    [ "kolobi" py-import ] [
+        [ type>> ] [ message>> ] [ traceback>> ] tri 3array
+    ] recover
 ] py-test
 
 ! setattr
index 23599661e0875b0c0b0e60e590c0a1d1cb108a2d..c107dce225c312723ba5f04e9170f0983e4c4d33 100644 (file)
@@ -1,7 +1,7 @@
-USING: arrays assocs destructors fry io.files.temp kernel math
-namespaces python python.ffi python.objects sequences sets
-splitting tools.test unicode.categories ;
-IN: python.syntax
+USING: accessors arrays assocs continuations destructors fry io.files.temp
+kernel math namespaces python python.ffi python.objects python.syntax
+sequences sets splitting tools.test unicode.categories ;
+IN: python.syntax.tests
 
 : py-test ( result quot -- )
     '[ _ with-destructors ] unit-test ; inline
@@ -13,7 +13,7 @@ PY-FROM: os =>
 
 [ t ] [ getpid py> integer? ] unit-test
 
-! Automatic tuple unpacking
+! Automatic tuple unpacking
 PY-FROM: os.path =>
     basename ( x -- x' )
     splitext ( x -- base ext ) ;
@@ -153,3 +153,16 @@ PY-METHODS: ArgumentParser =>
 
 ! Can you pass a callback written in factor to a python function?
 PY-FROM: wsgiref.simple_server => make_server ( iface port callback -- httpd ) ;
+
+{ t } [
+    [ 987 >py basename ] [ traceback>> ] recover length 0 >
+] unit-test
+
+! Test if exceptions leak references. If so, the test will leak a few
+! hundred megs of memory. Enough to be noticed but not to slow down
+! the tests too much.
+{ } [
+    100000 [
+        [ [ 987 >py basename drop ] ignore-errors ] with-destructors
+    ] times
+] unit-test
index f18aedfff7b2252ded17aeee453c9390fd4cb8e5..e12bd263e309660675973af68459567ced4029af 100644 (file)
@@ -1,4 +1,4 @@
-USING: arrays kernel python python.syntax sequences ;
+USING: arrays kernel python python.ffi python.syntax sequences ;
 IN: python.throwing
 
 ERROR: python-error type message traceback ;
@@ -10,5 +10,9 @@ PY-METHODS: obj =>
     __str__ ( o -- str ) ;
 
 : throw-error ( ptype pvalue ptraceback -- )
-    [ $__name__ py> ] [ __str__ py> ] [ [ format_tb py> ] [ f ] if* ] tri*
-    python-error ;
+    [
+        [ $__name__ py> ]
+        [ __str__ py> ]
+        [ [ format_tb py> ] [ f ] if* ] tri*
+    ] 3keep
+    [ Py_DecRef ] tri@ python-error ;