Mesa (opengl-es-v2): mesa/es: Add a sanity check to APIspec.py.

Brian Paul brianp at kemper.freedesktop.org
Mon Jan 4 21:17:44 UTC 2010


Module: Mesa
Branch: opengl-es-v2
Commit: c3bd85791766e4a6f3896ea724e18640e56c6808
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c3bd85791766e4a6f3896ea724e18640e56c6808

Author: Chia-I Wu <olvaffe at gmail.com>
Date:   Mon Nov 23 13:49:08 2009 +0800

mesa/es: Add a sanity check to APIspec.py.

Some attributes are constant in a switch.  Raise an exception if they
are not.

Signed-off-by: Chia-I Wu <olvaffe at gmail.com>

---

 src/mesa/es/main/APIspec.py |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/src/mesa/es/main/APIspec.py b/src/mesa/es/main/APIspec.py
index f07e426..7d27e46 100644
--- a/src/mesa/es/main/APIspec.py
+++ b/src/mesa/es/main/APIspec.py
@@ -323,12 +323,27 @@ class Checker(object):
 
     def __init__(self):
         self.switches = {}
+        self.switch_constants = {}
 
     def add_desc(self, desc):
         """Add a description."""
-        # TODO take index into consideration
+        # TODO allow index to vary
+        const_attrs = ["index", "error", "convert", "size_str"]
         if desc.name not in self.switches:
             self.switches[desc.name] = []
+            self.switch_constants[desc.name] = {}
+            for attr in const_attrs:
+                self.switch_constants[desc.name][attr] = None
+
+        # some attributes, like error code, should be the same for all descs
+        consts = self.switch_constants[desc.name]
+        for attr in const_attrs:
+            if getattr(desc, attr) is not None:
+                if (consts[attr] is not None and
+                    consts[attr] != getattr(desc, attr)):
+                    raise SpecError("mismatch %s for %s" % (attr, desc.name))
+                consts[attr] = getattr(desc, attr)
+
         self.switches[desc.name].append(desc)
 
     def validate(self, func, param_nodes):
@@ -348,6 +363,7 @@ class Checker(object):
                     tmp.add_desc(desc)
 
         self.switches = tmp.switches
+        self.switch_constants = tmp.switch_constants
         return True
 
     def flatten(self, name=None):




More information about the mesa-commit mailing list