From a3fe45e7ac13b473da3e87b2ad1fac3be6f6ba14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Fri, 24 Oct 2014 01:18:57 +0200 Subject: [PATCH] python: fix a reference leak in the (>py) word --- extra/python/python.factor | 6 ++++-- extra/python/syntax/syntax-tests.factor | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/extra/python/python.factor b/extra/python/python.factor index 016749ebb5..18f43ad55d 100644 --- a/extra/python/python.factor +++ b/extra/python/python.factor @@ -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) 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 ; diff --git a/extra/python/syntax/syntax-tests.factor b/extra/python/syntax/syntax-tests.factor index eeaa91484e..3ec5fa7b6e 100644 --- a/extra/python/syntax/syntax-tests.factor +++ b/extra/python/syntax/syntax-tests.factor @@ -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 ) @@ -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 =>