diff --git a/auto/src/glew_head.c b/auto/src/glew_head.c index a96e9b5..80200d1 100644 --- a/auto/src/glew_head.c +++ b/auto/src/glew_head.c @@ -10,6 +10,8 @@ #endif #include /* For size_t */ +#include /* memset, etc */ +#include /* * Define glewGetContext and related helper macros. @@ -207,7 +209,6 @@ static GLuint _glewStrCLen (const GLubyte* s, GLubyte c) return (s[i] == '\0' || s[i] == c) ? i : 0; } -#if 0 static GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n) { GLuint i=0; @@ -216,7 +217,6 @@ static GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n) while (i < n && a[i] != '\0' && b[i] != '\0' && a[i] == b[i]) i++; return i == n ? GL_TRUE : GL_FALSE; } -#endif static GLboolean _glewStrSame1 (const GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb) { @@ -270,3 +270,23 @@ static GLboolean _glewStrSame3 (const GLubyte** a, GLuint* na, const GLubyte* b, } return GL_FALSE; } + +/* + * Search for name in the extensions string. Use of strstr() + * is not sufficient because extension names can be prefixes of + * other extension names. Could use strtok() but the constant + * string returned by glGetString might be in read-only memory. + */ +static GLboolean _glewSearchExtension (const char* name, const GLubyte *start, const GLubyte *end) +{ + const GLubyte* p; + GLuint len = _glewStrLen((const GLubyte*)name); + p = start; + while (p < end) + { + GLuint n = _glewStrCLen(p, ' '); + if (len == n && _glewStrSame((const GLubyte*)name, p, n)) return GL_TRUE; + p += n+1; + } + return GL_FALSE; +} diff --git a/auto/src/glew_init_gl.c b/auto/src/glew_init_gl.c index 336f9ea..c4548ad 100644 --- a/auto/src/glew_init_gl.c +++ b/auto/src/glew_init_gl.c @@ -2,7 +2,7 @@ static int _glewExtensionCompare(const void *a, const void *b) { - return strcmp((const char *) a, *(const char**) b); + return strcmp((const char *) a, *(const char * const *) b); } static GLboolean *_glewGetExtensionString(const char *name) @@ -67,11 +67,6 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) const GLubyte* s; GLuint dot; GLint major, minor; - char *begin; - char *end; - char *i; - char *j; - GLboolean *enable; /* query opengl version */ s = glGetString(GL_VERSION); @@ -121,6 +116,7 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) GLint i; PFNGLGETSTRINGIPROC getStringi; const char *ext; + GLboolean *enable; glGetIntegerv(GL_NUM_EXTENSIONS, &n); @@ -144,10 +140,18 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) } else { - begin = (char *) glGetString(GL_EXTENSIONS); - if (begin) + const char *ext; + char *begin; + char *end; + char *i; + char *j; + GLboolean *enable; + + ext = (const char *) glGetString(GL_EXTENSIONS); + + if (ext) { - begin = strdup(begin); + begin = strdup(ext); end = begin + strlen(begin); for (i=begin; i