factor/extra/python/errors/errors.factor

29 lines
707 B
Factor
Raw Normal View History

USING: alien.c-types alien.data kernel python.ffi vocabs.loader words ;
IN: python.errors
<PRIVATE
: get-error ( -- ptype pvalue ptraceback )
{ void* void* void* } [ PyErr_Fetch ] with-out-parameters ;
! Breaking out of a circular dependency.
: throw-error ( ptype pvalue ptraceback -- )
"throw-error" "python.throwing" lookup-word execute( a b c -- ) ;
PRIVATE>
2014-03-04 14:06:55 -05:00
: (check-ref) ( ref -- ref )
[ get-error throw-error f ] unless* ;
2014-03-04 14:06:55 -05:00
: check-new-ref ( ref -- ref )
&Py_DecRef (check-ref) ;
2014-03-04 14:06:55 -05:00
: check-borrowed-ref ( ref -- ref )
dup Py_IncRef &Py_DecRef (check-ref) ;
: check-zero ( code -- )
0 = [ get-error throw-error ] unless ;
2014-03-04 14:06:55 -05:00
: unsteal-ref ( ref -- ref )
dup Py_IncRef ;