python: tests and plug a reference leak in the exception throwing code

db4
Björn Lindqvist 2014-10-02 15:15:50 +02:00 committed by John Benediktsson
parent ab75bcb60f
commit a530a10187
3 changed files with 29 additions and 10 deletions

View 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

View 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

View 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 ;