[Mesa-dev] [PATCH 09/13] mesa: remove unnecessary 'sort by year' for the GL extensions

Emil Velikov emil.l.velikov at gmail.com
Tue Nov 7 11:54:49 UTC 2017


From: Emil Velikov <emil.velikov at collabora.com>

The sorting was originally added to work around broken games (comment
says Quake3 demo) that were copying the extensions list into small
buffer.

Sorting does not solve the problem, since we'll still overflow and cause
corruption/crash.

Better workaround is to actually trim the string ... as done with a
later commit which introduces the MESA_EXTENSION_MAX_YEAR env. variable.

Side note: On my machine, the existing sorting makes no changes to the
extensions string.

Cc: Brian Paul <brianp at vmware.com>
Cc: Jose Fonseca <jfonseca at vmware.com>
Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
 src/mesa/main/extensions.c | 53 +++-------------------------------------------
 1 file changed, 3 insertions(+), 50 deletions(-)

diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
index 6069ebccaab..ae663a1092a 100644
--- a/src/mesa/main/extensions.c
+++ b/src/mesa/main/extensions.c
@@ -349,30 +349,6 @@ _mesa_extension_supported(const struct gl_context *ctx, extension_index i)
    return (ctx->Version >= ext->version[ctx->API]) && base[ext->offset];
 }
 
-/**
- * Compare two entries of the extensions table.  Sorts first by year,
- * then by name.
- *
- * Arguments are indices into _mesa_extension_table.
- */
-static int
-extension_compare(const void *p1, const void *p2)
-{
-   extension_index i1 = * (const extension_index *) p1;
-   extension_index i2 = * (const extension_index *) p2;
-   const struct mesa_extension *e1 = &_mesa_extension_table[i1];
-   const struct mesa_extension *e2 = &_mesa_extension_table[i2];
-   int res;
-
-   res = (int)e1->year - (int)e2->year;
-
-   if (res == 0) {
-      res = strcmp(e1->name, e2->name);
-   }
-
-   return res;
-}
-
 
 /**
  * Construct the GL_EXTENSIONS string.  Called the first time that
@@ -388,7 +364,7 @@ _mesa_make_extension_string(struct gl_context *ctx)
    /* Number of extensions */
    unsigned count;
    /* Indices of the extensions sorted by year */
-   extension_index *extension_indices;
+   extension_index extension_indices[MESA_EXTENSION_COUNT];
    /* String of extra extensions. */
    const char *extra_extensions = get_extension_override(ctx);
    unsigned k;
@@ -412,8 +388,8 @@ _mesa_make_extension_string(struct gl_context *ctx)
 
       if (i->year <= maxYear &&
           _mesa_extension_supported(ctx, k)) {
-	 length += strlen(i->name) + 1; /* +1 for space */
-	 ++count;
+         length += strlen(i->name) + 1; /* +1 for space */
+         extension_indices[count++] = k;
       }
    }
    if (extra_extensions != NULL)
@@ -424,28 +400,6 @@ _mesa_make_extension_string(struct gl_context *ctx)
       return NULL;
    }
 
-   extension_indices = malloc(count * sizeof(extension_index));
-   if (extension_indices == NULL) {
-      free(exts);
-      return NULL;
-   }
-
-   /* Sort extensions in chronological order because certain old applications
-    * (e.g., Quake3 demo) store the extension list in a static size buffer so
-    * chronologically order ensure that the extensions that such applications
-    * expect will fit into that buffer.
-    */
-   j = 0;
-   for (k = 0; k < MESA_EXTENSION_COUNT; ++k) {
-      if (_mesa_extension_table[k].year <= maxYear &&
-         _mesa_extension_supported(ctx, k)) {
-         extension_indices[j++] = k;
-      }
-   }
-   assert(j == count);
-   qsort(extension_indices, count,
-         sizeof *extension_indices, extension_compare);
-
    /* Build the extension string.*/
    for (j = 0; j < count; ++j) {
       const struct mesa_extension *i = &_mesa_extension_table[extension_indices[j]];
@@ -453,7 +407,6 @@ _mesa_make_extension_string(struct gl_context *ctx)
       strcat(exts, i->name);
       strcat(exts, " ");
    }
-   free(extension_indices);
    if (extra_extensions != 0) {
       strcat(exts, extra_extensions);
    }
-- 
2.14.1



More information about the mesa-dev mailing list