From 885bfc421ebb22796fea2d7b2ec646580c88ce9e Mon Sep 17 00:00:00 2001
From: Alex Rothberg <arothberg@4combinator.com>
Date: Fri, 6 Jun 2014 18:52:12 -0400
Subject: [PATCH] Allow passing build options with IPython Magic

---
 pyopencl/__init__.py    | 4 ++--
 pyopencl/ipython_ext.py | 5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py
index 9389f930..8007e100 100644
--- a/pyopencl/__init__.py
+++ b/pyopencl/__init__.py
@@ -174,8 +174,8 @@ class Program(object):
     # {{{ build
 
     def build(self, options=[], devices=None, cache_dir=None):
-        if isinstance(options, str):
-            options = [options]
+        if isinstance(options, basestring):
+            options = [str(options)]
 
         options = (options
                 + _DEFAULT_BUILD_OPTIONS
diff --git a/pyopencl/ipython_ext.py b/pyopencl/ipython_ext.py
index 309a6830..da5e512d 100644
--- a/pyopencl/ipython_ext.py
+++ b/pyopencl/ipython_ext.py
@@ -23,11 +23,14 @@ class PyOpenCLMagics(Magics):
             except KeyError:
                 ctx = None
 
+        if not isinstance(ctx, cl.Context):
+            ctx = None
+
         if ctx is None:
             raise RuntimeError("unable to locate cl context, which must be "
                     "present in namespace as 'cl_ctx' or 'ctx'")
 
-        prg = cl.Program(ctx, cell.encode("utf8")).build()
+        prg = cl.Program(ctx, cell.encode("utf8")).build(options=line)
 
         for knl in prg.all_kernels():
             self.shell.user_ns[knl.function_name] = knl
-- 
GitLab