Skip to content
Snippets Groups Projects
Commit ca0f2e43 authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Some error handling fixes

parent 0323a0a9
Branches yuyichao-cffi-fixes
No related tags found
No related merge requests found
......@@ -232,10 +232,7 @@ class Program(object):
what = what + "\n(source saved as %s)" % srcfile.name
code = e.code
routine = e.routine
err = _cl.RuntimeError(routine, code, what)
err = _cl.RuntimeError(msg=what, routine=e.routine, code=e.code)
# Python 3.2 outputs the whole list of currently active exceptions
# This serves to remove one (redundant) level from that nesting.
......@@ -415,14 +412,12 @@ def _add_functionality():
err = None
try:
self._build(options=options, devices=devices)
except Exception, e:
except Error, e:
what = e.what + "\n\n" + (75*"="+"\n").join(
"Build on %s:\n\n%s" % (dev, log)
for dev, log in self._get_build_logs())
code = e.code
routine = e.routine
err = _cl.RuntimeError(routine, code, what)
err = _cl.RuntimeError(msg=what, routine=e.routine, code=e.code)
if err is not None:
# Python 3.2 outputs the whole list of currently active exceptions
......
......@@ -479,7 +479,6 @@ def create_built_program_from_source_cached(ctx, src, options=[], devices=None,
already_built = False
except Exception, e:
raise
from pyopencl import Error
if (isinstance(e, Error)
and e.code == _cl.status_code.BUILD_PROGRAM_FAILURE):
......
......@@ -261,6 +261,7 @@ for type_, d in _constants.iteritems():
class Error(Exception):
def __init__(self, msg='', routine='', code=0):
self.routine = routine
assert isinstance(code, int)
self.code = code
self.what = msg
super(Error, self).__init__(msg)
......@@ -296,6 +297,7 @@ def _handle_error(error):
klass = RuntimeError
else:
klass = Error
e = klass(routine=_ffi.string(error.routine),
code=error.code, msg=_ffi.string(error.msg))
_lib.pyopencl_free_pointer(error.routine)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment