mesa: Fix array out-of-bounds access by _mesa_TexParameteri.
[mesa.git] / src / mesa / main / get_gen.py
index 5666ad0e42e8df93e848df847c33e4858501b9c7..c7babd1c816570cd53814a191f7fcad5b87843a1 100644 (file)
@@ -35,6 +35,7 @@ GLfloat = 3
 GLdouble = 4
 GLboolean = 5
 GLfloatN = 6    # A normalized value, such as a color or depth range
+GLint64 = 7
 
 
 TypeStrings = {
@@ -42,7 +43,8 @@ TypeStrings = {
        GLenum : "GLenum",
        GLfloat : "GLfloat",
        GLdouble : "GLdouble",
-       GLboolean : "GLboolean"
+       GLboolean : "GLboolean",
+       GLint64 : "GLint64"
 }
 
 
@@ -176,7 +178,8 @@ StateVars = [
           "ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][1]",
           "ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][2]",
           "ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][3]"],
-         "const GLuint texUnit = ctx->Texture.CurrentUnit;", None ),
+         """const GLuint texUnit = ctx->Texture.CurrentUnit;
+         FLUSH_CURRENT(ctx, 0);""", None ),
        ( "GL_DEPTH_BIAS", GLfloat, ["ctx->Pixel.DepthBias"], "", None ),
        ( "GL_DEPTH_BITS", GLint, ["ctx->DrawBuffer->Visual.depthBits"],
          "", None ),
@@ -1015,6 +1018,14 @@ StateVars = [
        # GL_APPLE_vertex_array_object
        ( "GL_VERTEX_ARRAY_BINDING_APPLE", GLint, ["ctx->Array.ArrayObj->Name"], "",
          ["APPLE_vertex_array_object"] ),
+
+       # GL_ARB_seamless_cube_map
+       ( "GL_TEXTURE_CUBE_MAP_SEAMLESS", GLboolean, ["ctx->Texture.CubeMapSeamless"], "",
+         ["ARB_seamless_cube_map"] ),
+
+       # GL_ARB_sync
+       ( "GL_MAX_SERVER_WAIT_TIMEOUT", GLint64, ["ctx->Const.MaxServerWaitTimeout"], "",
+         ["ARB_sync"] ),
 ]
 
 
@@ -1024,10 +1035,16 @@ def ConversionFunc(fromType, toType):
                return ""
        elif fromType == GLfloat and toType == GLint:
                return "IROUND"
+       elif fromType == GLfloat and toType == GLint64:
+               return "IROUND64"
        elif fromType == GLfloatN and toType == GLfloat:
                return ""
        elif fromType == GLint and toType == GLfloat: # but not GLfloatN!
                return "(GLfloat)"
+       elif fromType == GLint and toType == GLint64:
+               return "(GLint64)"
+       elif fromType == GLint64 and toType == GLfloat: # but not GLfloatN!
+               return "(GLfloat)"
        else:
                if fromType == GLfloatN:
                        fromType = GLfloat
@@ -1042,6 +1059,7 @@ def EmitGetFunction(stateVars, returnType):
        """Emit the code to implement glGetBooleanv, glGetIntegerv or glGetFloatv."""
        assert (returnType == GLboolean or
                        returnType == GLint or
+                       returnType == GLint64 or
                        returnType == GLfloat)
 
        strType = TypeStrings[returnType]
@@ -1052,9 +1070,14 @@ def EmitGetFunction(stateVars, returnType):
                function = "GetBooleanv"
        elif returnType == GLfloat:
                function = "GetFloatv"
+       elif returnType == GLint64:
+               function = "GetInteger64v"
        else:
                abort()
 
+       if returnType == GLint64:
+               print "#if FEATURE_ARB_sync"
+
        print "void GLAPIENTRY"
        print "_mesa_%s( GLenum pname, %s *params )" % (function, strType)
        print "{"
@@ -1108,6 +1131,8 @@ def EmitGetFunction(stateVars, returnType):
        print '         _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(pname=0x%%x)", pname);' % function
        print "   }"
        print "}"
+       if returnType == GLint64:
+               print "#endif /* FEATURE_ARB_sync */"
        print ""
        return
 
@@ -1136,9 +1161,15 @@ def EmitHeader():
 
 #define INT_TO_BOOLEAN(I)     ( (I) ? GL_TRUE : GL_FALSE )
 
+#define INT64_TO_BOOLEAN(I)   ( (I) ? GL_TRUE : GL_FALSE )
+#define INT64_TO_INT(I)       ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
+
 #define BOOLEAN_TO_INT(B)     ( (GLint) (B) )
+#define BOOLEAN_TO_INT64(B)   ( (GLint64) (B) )
 #define BOOLEAN_TO_FLOAT(B)   ( (B) ? 1.0F : 0.0F )
 
+#define ENUM_TO_INT64(E)      ( (GLint64) (E) )
+
 
 /*
  * Check if named extension is enabled, if not generate error and return.
@@ -1216,5 +1247,6 @@ EmitHeader()
 EmitGetFunction(StateVars, GLboolean)
 EmitGetFunction(StateVars, GLfloat)
 EmitGetFunction(StateVars, GLint)
+EmitGetFunction(StateVars, GLint64)
 EmitGetDoublev()