From ca0f2e436f19e17799217406702cf1f798f0516d Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Tue, 27 May 2014 23:56:52 -0500 Subject: [PATCH] Some error handling fixes --- pyopencl/__init__.py | 11 +++-------- pyopencl/cache.py | 1 - pyopencl/cffi_cl.py | 2 ++ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 099af587..716cd4f4 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -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 diff --git a/pyopencl/cache.py b/pyopencl/cache.py index 9971b1e3..9a6a2cf6 100644 --- a/pyopencl/cache.py +++ b/pyopencl/cache.py @@ -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): diff --git a/pyopencl/cffi_cl.py b/pyopencl/cffi_cl.py index 0f311f64..456813b2 100644 --- a/pyopencl/cffi_cl.py +++ b/pyopencl/cffi_cl.py @@ -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) -- GitLab