python: fix a reference leak in the (>py) word

db4
Björn Lindqvist 2014-10-24 01:18:57 +02:00 committed by John Benediktsson
parent 4029bf7a17
commit a3fe45e7ac
2 changed files with 13 additions and 2 deletions

View File

@ -59,17 +59,19 @@ SPECIALIZED-ARRAY: void*
: py-list>vector ( py-list -- vector ) : py-list>vector ( py-list -- vector )
dup py-list-size iota [ py-list-get-item ] with V{ } map-as ; dup py-list-size iota [ py-list-get-item ] with V{ } map-as ;
DEFER: >py
GENERIC: (>py) ( obj -- obj' ) GENERIC: (>py) ( obj -- obj' )
M: string (>py) utf8>py-unicode ; M: string (>py) utf8>py-unicode ;
M: math:fixnum (>py) PyLong_FromLong ; M: math:fixnum (>py) PyLong_FromLong ;
M: math:float (>py) PyFloat_FromDouble ; M: math:float (>py) PyFloat_FromDouble ;
M: array (>py) [ (>py) ] map array>py-tuple ; M: array (>py) [ >py ] map array>py-tuple ;
M: hashtable (>py) M: hashtable (>py)
<py-dict> swap dupd [ <py-dict> swap dupd [
swapd [ (>py) ] bi@ py-dict-set-item swapd [ (>py) ] bi@ py-dict-set-item
] with assoc-each ; ] with assoc-each ;
M: vector (>py) M: vector (>py)
[ (>py) ] map vector>py-list ; [ >py ] map vector>py-list ;
: >py ( obj -- py-obj ) : >py ( obj -- py-obj )
(>py) &Py_DecRef ; (>py) &Py_DecRef ;

View File

@ -83,6 +83,8 @@ PY-FROM: sys => getrefcount ( obj -- n ) ;
[ always-destructors get [ alien>> = ] with count ] bi = [ always-destructors get [ alien>> = ] with count ] bi =
] py-test ] py-test
PY-METHODS: file => PY-METHODS: file =>
close ( self -- ) close ( self -- )
fileno ( self -- n ) fileno ( self -- n )
@ -173,6 +175,13 @@ PY-FROM: wsgiref.simple_server => make_server ( iface port callback -- httpd ) ;
] times ] times
] unit-test ] unit-test
! Another leaky test
{ } [
1000000 [
[ { 9 8 7 6 5 4 3 2 1 } >py ] with-destructors drop
] times
] unit-test
! Working with types ! Working with types
PY-METHODS: obj => PY-METHODS: obj =>