Skip to content

Commit

Permalink
python: fix a reference leak in the (>py) word
Browse files Browse the repository at this point in the history
  • Loading branch information
bjourne authored and mrjbq7 committed Oct 24, 2014
1 parent 4029bf7 commit a3fe45e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions extra/python/python.factor
Expand Up @@ -59,17 +59,19 @@ SPECIALIZED-ARRAY: void*
: py-list>vector ( py-list -- vector )
dup py-list-size iota [ py-list-get-item ] with V{ } map-as ;

DEFER: >py

GENERIC: (>py) ( obj -- obj' )
M: string (>py) utf8>py-unicode ;
M: math:fixnum (>py) PyLong_FromLong ;
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)
<py-dict> swap dupd [
swapd [ (>py) ] bi@ py-dict-set-item
] with assoc-each ;
M: vector (>py)
[ (>py) ] map vector>py-list ;
[ >py ] map vector>py-list ;

: >py ( obj -- py-obj )
(>py) &Py_DecRef ;
Expand Down
9 changes: 9 additions & 0 deletions extra/python/syntax/syntax-tests.factor
Expand Up @@ -83,6 +83,8 @@ PY-FROM: sys => getrefcount ( obj -- n ) ;
[ always-destructors get [ alien>> = ] with count ] bi =
] py-test



PY-METHODS: file =>
close ( self -- )
fileno ( self -- n )
Expand Down Expand Up @@ -173,6 +175,13 @@ PY-FROM: wsgiref.simple_server => make_server ( iface port callback -- httpd ) ;
] times
] 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
PY-METHODS: obj =>
Expand Down

0 comments on commit a3fe45e

Please sign in to comment.