mesa: add EXT_dsa NamedCopyBufferSubDataEXT function
[mesa.git] / src / mapi / glapi / gen / gl_marshal.py
index 51475e17adffd0071394f1b954280ac2175e2ee4..4fd2bc2a5b9143dee0b0f00d31cc0b1d8b2955f7 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 
 # Copyright (C) 2012 Intel Corporation
 #
@@ -21,6 +20,8 @@
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 # IN THE SOFTWARE.
 
+from __future__ import print_function
+
 import contextlib
 import getopt
 import gl_XML
@@ -43,9 +44,9 @@ current_indent = 0
 
 def out(str):
     if str:
-        print ' '*current_indent + str
+        print(' '*current_indent + str)
     else:
-        print ''
+        print('')
 
 
 @contextlib.contextmanager
@@ -65,21 +66,18 @@ class PrintCode(gl_XML.gl_print_base):
             'Copyright (C) 2012 Intel Corporation', 'INTEL CORPORATION')
 
     def printRealHeader(self):
-        print header
-        print '#ifdef HAVE_PTHREAD'
-        print
-        print 'static inline int safe_mul(int a, int b)'
-        print '{'
-        print '    if (a < 0 || b < 0) return -1;'
-        print '    if (a == 0 || b == 0) return 0;'
-        print '    if (a > INT_MAX / b) return -1;'
-        print '    return a * b;'
-        print '}'
-        print
+        print(header)
+        print('static inline int safe_mul(int a, int b)')
+        print('{')
+        print('    if (a < 0 || b < 0) return -1;')
+        print('    if (a == 0 || b == 0) return 0;')
+        print('    if (a > INT_MAX / b) return -1;')
+        print('    return a * b;')
+        print('}')
+        print()
 
     def printRealFooter(self):
-        print
-        print '#endif'
+        pass
 
     def print_sync_call(self, func):
         call = 'CALL_{0}(ctx->CurrentServerDispatch, ({1}))'.format(
@@ -90,7 +88,6 @@ class PrintCode(gl_XML.gl_print_base):
             out('return {0};'.format(call))
 
     def print_sync_dispatch(self, func):
-        out('_mesa_glthread_finish(ctx);')
         out('debug_print_sync_fallback("{0}");'.format(func.name))
         self.print_sync_call(func)
 
@@ -177,11 +174,19 @@ class PrintCode(gl_XML.gl_print_base):
         with indent():
             for p in func.fixed_params:
                 if p.count:
-                    out('const {0} * {1} = cmd->{1};'.format(
-                            p.get_base_type_string(), p.name))
+                    p_decl = '{0} * {1} = cmd->{1};'.format(
+                            p.get_base_type_string(), p.name)
                 else:
-                    out('const {0} {1} = cmd->{1};'.format(
-                            p.type_string(), p.name))
+                    p_decl = '{0} {1} = cmd->{1};'.format(
+                            p.type_string(), p.name)
+
+                if not p_decl.startswith('const '):
+                    # Declare all local function variables as const, even if
+                    # the original parameter is not const.
+                    p_decl = 'const ' + p_decl
+
+                out(p_decl)
+
             if func.variable_params:
                 for p in func.variable_params:
                     out('const {0} * {1};'.format(
@@ -244,7 +249,7 @@ class PrintCode(gl_XML.gl_print_base):
                 out('if ({0}) {{'.format(func.marshal_fail))
                 with indent():
                     out('_mesa_glthread_finish(ctx);')
-                    out('_mesa_glthread_restore_dispatch(ctx);')
+                    out('_mesa_glthread_restore_dispatch(ctx, __func__);')
                     self.print_sync_dispatch(func)
                     out('return;')
                 out('}')
@@ -259,6 +264,7 @@ class PrintCode(gl_XML.gl_print_base):
         if need_fallback_sync:
             out('fallback_to_sync:')
         with indent():
+            out('_mesa_glthread_finish(ctx);')
             self.print_sync_dispatch(func)
 
         out('}')
@@ -338,7 +344,7 @@ class PrintCode(gl_XML.gl_print_base):
 
 
 def show_usage():
-    print 'Usage: %s [-f input_file_name]' % sys.argv[0]
+    print('Usage: %s [-f input_file_name]' % sys.argv[0])
     sys.exit(1)
 
 
@@ -347,7 +353,7 @@ if __name__ == '__main__':
 
     try:
         (args, trail) = getopt.getopt(sys.argv[1:], 'm:f:')
-    except Exception,e:
+    except Exception:
         show_usage()
 
     for (arg,val) in args: