mirror of
https://github.com/nigels-com/glew.git
synced 2024-11-11 08:43:49 +00:00
Eliminate malloc and free dependencies, recently introduced
This commit is contained in:
parent
b1c272b93a
commit
d96c978748
@ -10,7 +10,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stddef.h> /* For size_t */
|
#include <stddef.h> /* For size_t */
|
||||||
#include <stdlib.h> /* For malloc, free */
|
#include <stdlib.h> /* For bsearch */
|
||||||
#include <string.h> /* For memset */
|
#include <string.h> /* For memset */
|
||||||
|
|
||||||
#if defined(GLEW_REGAL)
|
#if defined(GLEW_REGAL)
|
||||||
@ -65,7 +65,7 @@ void* NSGLGetProcAddress (const GLubyte *name)
|
|||||||
{
|
{
|
||||||
static void* image = NULL;
|
static void* image = NULL;
|
||||||
void* addr;
|
void* addr;
|
||||||
if (NULL == image)
|
if (NULL == image)
|
||||||
{
|
{
|
||||||
image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
|
image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
|
||||||
}
|
}
|
||||||
@ -166,23 +166,16 @@ static GLuint _glewStrCLen (const GLubyte* s, GLubyte c)
|
|||||||
GLuint i=0;
|
GLuint i=0;
|
||||||
if (s == NULL) return 0;
|
if (s == NULL) return 0;
|
||||||
while (s[i] != '\0' && s[i] != c) i++;
|
while (s[i] != '\0' && s[i] != c) i++;
|
||||||
return (s[i] == '\0' || s[i] == c) ? i : 0;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLubyte *_glewStrDup (const GLubyte *s)
|
static GLuint _glewStrCopy(char *d, const char *s, char c)
|
||||||
{
|
{
|
||||||
int n = _glewStrLen(s);
|
GLuint i=0;
|
||||||
GLubyte *dup = malloc(n+1);
|
if (s == NULL) return 0;
|
||||||
if (dup)
|
while (s[i] != '\0' && s[i] != c) { d[i] = s[i]; i++; }
|
||||||
{
|
d[i] = '\0';
|
||||||
GLubyte *i = dup;
|
return i;
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
*i = *s;
|
|
||||||
if (*i) { ++i; ++s; } else break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
|
#if !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
|
||||||
|
@ -33,17 +33,17 @@ static GLboolean *_glewGetExtensionEnable(const char *name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *_glewNextSpace(char *i)
|
static const char *_glewNextSpace(const char *i)
|
||||||
{
|
{
|
||||||
char *j = i;
|
const char *j = i;
|
||||||
if (j)
|
if (j)
|
||||||
while (*j!=' ' && *j) ++j;
|
while (*j!=' ' && *j) ++j;
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *_glewNextNonSpace(char *i)
|
static const char *_glewNextNonSpace(const char *i)
|
||||||
{
|
{
|
||||||
char *j = i;
|
const char *j = i;
|
||||||
if (j)
|
if (j)
|
||||||
while (*j==' ') ++j;
|
while (*j==' ') ++j;
|
||||||
return j;
|
return j;
|
||||||
@ -70,7 +70,7 @@ static GLenum GLEWAPIENTRY glewContextInit ()
|
|||||||
dot = _glewStrCLen(s, '.');
|
dot = _glewStrCLen(s, '.');
|
||||||
if (dot == 0)
|
if (dot == 0)
|
||||||
return GLEW_ERROR_NO_GL_VERSION;
|
return GLEW_ERROR_NO_GL_VERSION;
|
||||||
|
|
||||||
major = s[dot-1]-'0';
|
major = s[dot-1]-'0';
|
||||||
minor = s[dot+1]-'0';
|
minor = s[dot+1]-'0';
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ static GLenum GLEWAPIENTRY glewContextInit ()
|
|||||||
minor = 0;
|
minor = 0;
|
||||||
if (major<0 || major>9)
|
if (major<0 || major>9)
|
||||||
return GLEW_ERROR_NO_GL_VERSION;
|
return GLEW_ERROR_NO_GL_VERSION;
|
||||||
|
|
||||||
if (major == 1 && minor == 0)
|
if (major == 1 && minor == 0)
|
||||||
{
|
{
|
||||||
return GLEW_ERROR_GL_VERSION_10_ONLY;
|
return GLEW_ERROR_GL_VERSION_10_ONLY;
|
||||||
@ -95,12 +95,12 @@ static GLenum GLEWAPIENTRY glewContextInit ()
|
|||||||
GLEW_VERSION_3_2 = GLEW_VERSION_3_3 == GL_TRUE || ( major == 3 && minor >= 2 ) ? GL_TRUE : GL_FALSE;
|
GLEW_VERSION_3_2 = GLEW_VERSION_3_3 == GL_TRUE || ( major == 3 && minor >= 2 ) ? GL_TRUE : GL_FALSE;
|
||||||
GLEW_VERSION_3_1 = GLEW_VERSION_3_2 == GL_TRUE || ( major == 3 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
|
GLEW_VERSION_3_1 = GLEW_VERSION_3_2 == GL_TRUE || ( major == 3 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
|
||||||
GLEW_VERSION_3_0 = GLEW_VERSION_3_1 == GL_TRUE || ( major == 3 ) ? GL_TRUE : GL_FALSE;
|
GLEW_VERSION_3_0 = GLEW_VERSION_3_1 == GL_TRUE || ( major == 3 ) ? GL_TRUE : GL_FALSE;
|
||||||
GLEW_VERSION_2_1 = GLEW_VERSION_3_0 == GL_TRUE || ( major == 2 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
|
GLEW_VERSION_2_1 = GLEW_VERSION_3_0 == GL_TRUE || ( major == 2 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
|
||||||
GLEW_VERSION_2_0 = GLEW_VERSION_2_1 == GL_TRUE || ( major == 2 ) ? GL_TRUE : GL_FALSE;
|
GLEW_VERSION_2_0 = GLEW_VERSION_2_1 == GL_TRUE || ( major == 2 ) ? GL_TRUE : GL_FALSE;
|
||||||
GLEW_VERSION_1_5 = GLEW_VERSION_2_0 == GL_TRUE || ( major == 1 && minor >= 5 ) ? GL_TRUE : GL_FALSE;
|
GLEW_VERSION_1_5 = GLEW_VERSION_2_0 == GL_TRUE || ( major == 1 && minor >= 5 ) ? GL_TRUE : GL_FALSE;
|
||||||
GLEW_VERSION_1_4 = GLEW_VERSION_1_5 == GL_TRUE || ( major == 1 && minor >= 4 ) ? GL_TRUE : GL_FALSE;
|
GLEW_VERSION_1_4 = GLEW_VERSION_1_5 == GL_TRUE || ( major == 1 && minor >= 4 ) ? GL_TRUE : GL_FALSE;
|
||||||
GLEW_VERSION_1_3 = GLEW_VERSION_1_4 == GL_TRUE || ( major == 1 && minor >= 3 ) ? GL_TRUE : GL_FALSE;
|
GLEW_VERSION_1_3 = GLEW_VERSION_1_4 == GL_TRUE || ( major == 1 && minor >= 3 ) ? GL_TRUE : GL_FALSE;
|
||||||
GLEW_VERSION_1_2_1 = GLEW_VERSION_1_3 == GL_TRUE ? GL_TRUE : GL_FALSE;
|
GLEW_VERSION_1_2_1 = GLEW_VERSION_1_3 == GL_TRUE ? GL_TRUE : GL_FALSE;
|
||||||
GLEW_VERSION_1_2 = GLEW_VERSION_1_2_1 == GL_TRUE || ( major == 1 && minor >= 2 ) ? GL_TRUE : GL_FALSE;
|
GLEW_VERSION_1_2 = GLEW_VERSION_1_2_1 == GL_TRUE || ( major == 1 && minor >= 2 ) ? GL_TRUE : GL_FALSE;
|
||||||
GLEW_VERSION_1_1 = GLEW_VERSION_1_2 == GL_TRUE || ( major == 1 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
|
GLEW_VERSION_1_1 = GLEW_VERSION_1_2 == GL_TRUE || ( major == 1 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
|
||||||
}
|
}
|
||||||
@ -137,35 +137,37 @@ static GLenum GLEWAPIENTRY glewContextInit ()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const GLubyte *ext;
|
const char *extensions;
|
||||||
char *begin;
|
const char *end;
|
||||||
char *end;
|
const char *i;
|
||||||
char *i;
|
const char *j;
|
||||||
char *j;
|
char ext[128];
|
||||||
GLboolean *enable;
|
GLboolean *enable;
|
||||||
|
|
||||||
ext = glGetString(GL_EXTENSIONS);
|
extensions = (const char *) glGetString(GL_EXTENSIONS);
|
||||||
|
|
||||||
if (ext)
|
if (extensions)
|
||||||
{
|
{
|
||||||
begin = (char *) _glewStrDup(ext);
|
end = extensions + _glewStrLen((const GLubyte *) extensions);
|
||||||
end = begin + _glewStrLen((GLubyte *) begin);
|
for (i=extensions; i<end; i = j + 1)
|
||||||
for (i=begin; i<end; i = j + 1)
|
|
||||||
{
|
{
|
||||||
i = _glewNextNonSpace(i);
|
i = _glewNextNonSpace(i);
|
||||||
j = _glewNextSpace(i);
|
j = _glewNextSpace(i);
|
||||||
*j = 0;
|
|
||||||
|
/* Copy extension into NUL terminated string */
|
||||||
|
if (j-i >= (ptrdiff_t) sizeof(ext))
|
||||||
|
continue;
|
||||||
|
_glewStrCopy(ext, i, ' ');
|
||||||
|
|
||||||
/* Based on extension string(s), glewGetExtension purposes */
|
/* Based on extension string(s), glewGetExtension purposes */
|
||||||
enable = _glewGetExtensionString(i);
|
enable = _glewGetExtensionString(ext);
|
||||||
if (enable)
|
if (enable)
|
||||||
*enable = GL_TRUE;
|
*enable = GL_TRUE;
|
||||||
|
|
||||||
/* Based on extension string(s), experimental mode, glewIsSupported purposes */
|
/* Based on extension string(s), experimental mode, glewIsSupported purposes */
|
||||||
enable = _glewGetExtensionEnable(i);
|
enable = _glewGetExtensionEnable(ext);
|
||||||
if (enable)
|
if (enable)
|
||||||
*enable = GL_TRUE;
|
*enable = GL_TRUE;
|
||||||
}
|
}
|
||||||
free(begin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user