python.throwing: new module to support capturing python tracebacks

db4
Björn Lindqvist 2014-09-26 20:04:33 +02:00 committed by John Benediktsson
parent 90094dffac
commit ab75bcb60f
2 changed files with 20 additions and 8 deletions

View File

@ -1,16 +1,14 @@
USING: alien.c-types alien.data kernel python.ffi ;
USING: alien.c-types alien.data kernel python.ffi vocabs.loader words ;
IN: python.errors
ERROR: python-error type message ;
<PRIVATE
: get-error ( -- ptype pvalue )
{ void* void* void* } [ PyErr_Fetch ] with-out-parameters drop ;
: get-error ( -- ptype pvalue ptraceback )
{ void* void* void* } [ PyErr_Fetch ] with-out-parameters ;
: throw-error ( ptype pvalue -- )
[ "__name__" PyObject_GetAttrString ] [ PyObject_Str ] bi*
[ &Py_DecRef PyString_AsString ] bi@ python-error ;
! Breaking out of a circular dependency.
: throw-error ( ptype pvalue ptraceback -- )
"throw-error" "python.throwing" lookup-word execute( a b c -- ) ;
PRIVATE>

View File

@ -0,0 +1,14 @@
USING: arrays kernel python python.syntax sequences ;
IN: python.throwing
ERROR: python-error type message traceback ;
PY-FROM: traceback => format_tb ( tb -- seq ) ;
PY-METHODS: obj =>
__name__ ( o -- str )
__str__ ( o -- str ) ;
: throw-error ( ptype pvalue ptraceback -- )
[ $__name__ py> ] [ __str__ py> ] [ [ format_tb py> ] [ f ] if* ] tri*
python-error ;