python.errors: new semantics for unsteal-ref
							parent
							
								
									37b5ef7577
								
							
						
					
					
						commit
						3feec7b14b
					
				| 
						 | 
				
			
			@ -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." } ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue