[Beignet] [PATCH] Allow building with Python 3

Rebecca N. Palmer rebecca_palmer at zoho.com
Wed Apr 29 03:03:12 PDT 2015


> "-61,[8] +62[,8]" means the following block adds one more line:
No, that means the _preceding_ block(s) add one more line, which they do.

>>       raise
>>   all_vector = 1,2,3,4,8,16
There was a space-only line between these: has the email system lost it?

Make the build scripts work in both Python 2 and Python 3.
(CMake prefers Python 2 if both are available, but will use
Python 3 if only it is installed.)

Signed-off-by: Rebecca Palmer <rebecca_palmer at zoho.com>

diff --git a/backend/src/libocl/script/gen_vector.py b/backend/src/libocl/script/gen_vector.py
index ffc573a..92582f5 100755
--- a/backend/src/libocl/script/gen_vector.py
+++ b/backend/src/libocl/script/gen_vector.py
@@ -20,13 +20,14 @@
  
  # This file is to generate inline code to lower down those builtin
  # vector functions to scalar functions.
+from __future__ import print_function
  import re
  import sys
  import os
  
  if len(sys.argv) != 4:
-    print "Invalid argument {0}".format(sys.argv)
-    print "use {0} spec_file_name output_file_name just_proto".format(sys.argv[0])
+    print("Invalid argument {0}".format(sys.argv))
+    print("use {0} spec_file_name output_file_name just_proto".format(sys.argv[0]))
      raise
  
  all_vector = 1,2,3,4,8,16
@@ -61,8 +62,8 @@ all_type = all_int_type + all_float_type
  
  # all vector/scalar types
  for t in all_type:
-    exec "{0}n = [\"{0}n\", gen_vector_type([\"{0}\"])]".format(t)
-    exec "s{0} = [\"{0}\", gen_vector_type([\"{0}\"], [1])]".format(t)
+    exec("{0}n = [\"{0}n\", gen_vector_type([\"{0}\"])]".format(t))
+    exec("s{0} = [\"{0}\", gen_vector_type([\"{0}\"], [1])]".format(t))
  
  # Predefined type sets according to the Open CL spec.
  math_gentype = ["math_gentype", gen_vector_type(all_float_type)]
@@ -124,8 +125,8 @@ def check_type(types):
      for t in types:
          memspace, t = stripMemSpace(t)
          if not t in type_dict:
-            print t
-            raise "found invalid type."
+            print(t)
+            raise TypeError("found invalid type.")
  
  def match_unsigned(dtype):
      if dtype[0] == 'float':
@@ -187,8 +188,8 @@ def fixup_type(dstType, srcType, n):
          if (len(dstType) == len(srcType)):
              return dstType[n]
  
-    print dstType, srcType
-    raise "type mispatch"
+    print(dstType, srcType)
+    raise TypeError("type mispatch")
  
  class builtinProto():
      valueTypeStr = ""
@@ -226,7 +227,7 @@ class builtinProto():
  
      def init_from_line(self, t):
          self.append('//{0}'.format(t))
-        line = filter(None, re.split(',| |\(', t.rstrip(')\n')))
+        line = [_f for _f in re.split(',| |\(', t.rstrip(')\n')) if _f]
          self.paramCount = 0
          stripped = 0
          memSpace = ''
@@ -310,7 +311,7 @@ class builtinProto():
                  vtype = fixup_type(vtypeSeq, ptypeSeqs[n], i)
                  if vtype[1] != ptype[1]:
                      if ptype[1] != 1:
-                        raise "parameter is not a scalar but has different width with result value."
+                        raise TypeError("parameter is not a scalar but has different width with result value.")
                      if isPointer(ptype):
                          formatStr += '&'
                      formatStr += 'param{0}'.format(n)
@@ -333,7 +334,7 @@ class builtinProto():
  
      def output(self):
          for line in self.outputStr:
-            print line
+            print(line)
  
      def output(self, outFile):
          for line in self.outputStr:
diff --git a/utests/utest_generator.py b/utests/utest_generator.py
index 510c41a..7d2d3a0 100644
--- a/utests/utest_generator.py
+++ b/utests/utest_generator.py
@@ -1,4 +1,5 @@
  #!/usr/bin/python
+from __future__ import print_function
  import os,sys,re
  
  FLT_MAX_POSI='0x1.fffffep127f'
@@ -326,7 +327,7 @@ which can print more values and information to assist debuging the issue.
      file_object.close()
  
    def nameForCmake(self,content,namesuffix):
-    print("generated/%s_%s.cpp"%(self.fileName,namesuffix)),
+    print("generated/%s_%s.cpp"%(self.fileName,namesuffix),end=" ")
  
    def utestFunc(self,index):
      funcLines=[]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python3.patch
Type: text/x-diff
Size: 3849 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/beignet/attachments/20150429/9c5d5ce6/attachment-0001.patch>


More information about the Beignet mailing list