]> gitweb.factorcode.org Git - factor.git/commitdiff
python.errors: new semantics for unsteal-ref
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 26 Oct 2014 23:21:54 +0000 (00:21 +0100)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 27 Oct 2014 16:52:04 +0000 (09:52 -0700)
extra/python/errors/errors-docs.factor
extra/python/errors/errors.factor

index 49a35a6f5021d84e26bf9281138d71e3b8b694fc..2acb8a06ea758277ee1a7f09c4301fcb52db7008 100644 (file)
@@ -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." } ;
index 6325929f6f6d83cdd0a8f1309cd8f9dc06420a18..a82a0c4828924ced450434b4b92067ccbe130c36 100644 (file)
@@ -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
 
 <PRIVATE
@@ -24,5 +26,10 @@ 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 ;