diff --git a/extra/python/errors/errors-docs.factor b/extra/python/errors/errors-docs.factor index 49a35a6f50..2acb8a06ea 100644 --- a/extra/python/errors/errors-docs.factor +++ b/extra/python/errors/errors-docs.factor @@ -1,4 +1,4 @@ -USING: math help.markup help.syntax ; +USING: math help.markup help.syntax python.ffi ; IN: python.errors HELP: check-zero @@ -28,5 +28,4 @@ HELP: check-borrowed-ref HELP: unsteal-ref { $values { "ref" "a python object" } } { $description - "Increases the objects reference count. Used by wrappers that call Python functions that steal references." -} ; + "Unsteals a reference. Used by wrappers that call Python functions that steal references. Functions such as " { $link PyTuple_SetItem } " takes ownership of the references passed in and relieves Factor of its burden to decrement them." } ; diff --git a/extra/python/errors/errors.factor b/extra/python/errors/errors.factor index 6325929f6f..a82a0c4828 100644 --- a/extra/python/errors/errors.factor +++ b/extra/python/errors/errors.factor @@ -1,4 +1,6 @@ -USING: alien.c-types alien.data kernel python.ffi vocabs.loader words ; +USING: accessors alien alien.c-types alien.data combinators.short-circuit +destructors.private kernel namespaces python.ffi sequences vocabs.loader +words ; IN: python.errors : check-zero ( code -- ) 0 = [ get-error throw-error ] unless ; -: unsteal-ref ( ref -- ref ) - dup Py_IncRef ; +: unsteal-ref ( ref -- ) + always-destructors get [ + { + [ nip Py_DecRef-destructor? ] + [ alien>> [ alien-address ] bi@ = ] + } 2&& not + ] with filter! drop ;