diff --git a/loopy/compiled.py b/loopy/compiled.py
index 4111b8f530cbc4c8e7fb8d79aabf005a44924574..55feff66a83cbca5dacfb6717e7cb94fc69ed51d 100644
--- a/loopy/compiled.py
+++ b/loopy/compiled.py
@@ -192,7 +192,7 @@ def generate_integer_arg_finding_from_shapes(gen, kernel, implemented_data_info)
             for arg_name, value_expr in sources:
                 gen("%s %s is not None:" % (if_stmt, arg_name))
                 with Indentation(gen):
-                    gen("%s = int(%s)"
+                    gen("%s = %s"
                             % (iarg_name, StringifyMapper()(value_expr)))
 
                 if_stmt = "elif"
@@ -226,10 +226,10 @@ def generate_integer_arg_finding_from_offsets(gen, kernel, implemented_data_info
                 gen("else:")
                 with Indentation(gen):
                     if not options.no_numpy:
-                        gen("_lpy_offset = int(getattr(%s, \"offset\", 0))"
+                        gen("_lpy_offset = getattr(%s, \"offset\", 0)"
                                 % impl_array_name)
                     else:
-                        gen("_lpy_offset = int(%s.offset)" % impl_array_name)
+                        gen("_lpy_offset = %s.offset" % impl_array_name)
 
                     base_arg = kernel.impl_arg_to_arg[impl_array_name]
 
@@ -287,9 +287,8 @@ def generate_integer_arg_finding_from_strides(gen, kernel, implemented_data_info
                                 "not divisible by its dtype itemsize\""
                                 % (stride_impl_axis, impl_array_name))
                         gen("del _lpy_remdr")
-                        gen("%s = int(%s)" % (arg.name, arg.name))
                     else:
-                        gen("%s = int(_lpy_offset // %d)"
+                        gen("%s = _lpy_offset // %d"
                                 % (arg.name, base_arg.dtype.itemsize))
 
     gen("# }}}")
diff --git a/loopy/target/pyopencl.py b/loopy/target/pyopencl.py
index a0f0767880ac62d57aad7d327364df0f871b68cc..779abc02e7d3aa86149128a686d45c4aada8e2b0 100644
--- a/loopy/target/pyopencl.py
+++ b/loopy/target/pyopencl.py
@@ -449,9 +449,14 @@ def generate_value_arg_setup(kernel, devices, implemented_data_info):
                 Raise('RuntimeError("input argument \'{name}\' '
                         'must be supplied")'.format(name=idi.name))))
 
-        if sys.version_info < (2, 7) and idi.dtype.is_integral():
-            gen(Comment("cast to long to avoid trouble with struct packing"))
-            gen(Assign(idi.name, "long(%s)" % idi.name))
+        if idi.dtype.is_integral():
+            gen(Comment("cast to Python int to avoid trouble with struct packing or Boost.Python"))
+            if sys.version_info < (3,):
+                py_type = "long"
+            else:
+                py_type = "int"
+
+            gen(Assign(idi.name, "%s(%s)" % (py_type, idi.name)))
             gen(Line())
 
         if idi.dtype.is_composite():