-USING: math help.markup help.syntax ;
+USING: math help.markup help.syntax python.ffi ;
IN: python.errors
HELP: check-zero
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." } ;
-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
<PRIVATE
: 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 ;