From c9a40e3cee06ac3aa3587e33fcc255348b00d8af Mon Sep 17 00:00:00 2001 From: ikits Date: Mon, 19 Mar 2007 13:33:36 +0000 Subject: [PATCH] const correctness change git-svn-id: https://glew.svn.sourceforge.net/svnroot/glew/trunk/glew@498 783a27ee-832a-0410-bc00-9f386506c6dd --- auto/bin/make_list.pl | 6 ++-- auto/src/glew_head.c | 6 +++- auto/src/glew_init_gl.c | 74 ++++++++++++++++++++-------------------- auto/src/glew_init_glx.c | 16 ++++----- auto/src/glew_tail.h | 5 ++- 5 files changed, 55 insertions(+), 52 deletions(-) diff --git a/auto/bin/make_list.pl b/auto/bin/make_list.pl index 4de3f78..2d37b54 100755 --- a/auto/bin/make_list.pl +++ b/auto/bin/make_list.pl @@ -43,16 +43,16 @@ if (@ARGV) #my $pextvar = prefix_varname($extvar); print "#ifdef $extname\n"; - print " " . $extvar . " = " . $extpre . "GetExtension(\"$extname\");\n"; + print " CONST_CAST(" . $extvar . ") = " . $extpre . "GetExtension(\"$extname\");\n"; if (keys %$functions) { if ($extname =~ /WGL_.*/) { - print " if (glewExperimental || " . $extvar . "|| crippled) " . $extvar . "= !_glewInit_$extname(GLEW_CONTEXT_ARG_VAR_INIT);\n"; + print " if (glewExperimental || " . $extvar . "|| crippled) CONST_CAST(" . $extvar . ")= !_glewInit_$extname(GLEW_CONTEXT_ARG_VAR_INIT);\n"; } else { - print " if (glewExperimental || " . $extvar . ") " . $extvar . " = !_glewInit_$extname(GLEW_CONTEXT_ARG_VAR_INIT);\n"; + print " if (glewExperimental || " . $extvar . ") CONST_CAST(" . $extvar . ") = !_glewInit_$extname(GLEW_CONTEXT_ARG_VAR_INIT);\n"; } } print "#endif /* $extname */\n"; diff --git a/auto/src/glew_head.c b/auto/src/glew_head.c index 01c9a83..c24fa57 100644 --- a/auto/src/glew_head.c +++ b/auto/src/glew_head.c @@ -101,11 +101,15 @@ void* dlGetProcAddress (const GLubyte* name) # endif #endif +/* + * Define GLboolean const cast. + */ +#define CONST_CAST(x) (*(GLboolean*)&x) + /* * GLEW, just like OpenGL or GLU, does not rely on the standard C library. * These functions implement the functionality required in this file. */ - static GLuint _glewStrLen (const GLubyte* s) { GLuint i=0; diff --git a/auto/src/glew_init_gl.c b/auto/src/glew_init_gl.c index baf61f9..aaba1d5 100644 --- a/auto/src/glew_init_gl.c +++ b/auto/src/glew_init_gl.c @@ -45,65 +45,65 @@ GLenum glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) } else { - GLEW_VERSION_1_1 = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_1) = GL_TRUE; if (s[major] >= '2') { - GLEW_VERSION_1_2 = GL_TRUE; - GLEW_VERSION_1_3 = GL_TRUE; - GLEW_VERSION_1_4 = GL_TRUE; - GLEW_VERSION_1_5 = GL_TRUE; - GLEW_VERSION_2_0 = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_2) = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_3) = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_4) = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_5) = GL_TRUE; + CONST_CAST(GLEW_VERSION_2_0) = GL_TRUE; if (s[minor] >= '1') { - GLEW_VERSION_2_1 = GL_TRUE; + CONST_CAST(GLEW_VERSION_2_1) = GL_TRUE; } } else { if (s[minor] >= '5') { - GLEW_VERSION_1_2 = GL_TRUE; - GLEW_VERSION_1_3 = GL_TRUE; - GLEW_VERSION_1_4 = GL_TRUE; - GLEW_VERSION_1_5 = GL_TRUE; - GLEW_VERSION_2_0 = GL_FALSE; - GLEW_VERSION_2_1 = GL_FALSE; + CONST_CAST(GLEW_VERSION_1_2) = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_3) = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_4) = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_5) = GL_TRUE; + CONST_CAST(GLEW_VERSION_2_0) = GL_FALSE; + CONST_CAST(GLEW_VERSION_2_1) = GL_FALSE; } if (s[minor] == '4') { - GLEW_VERSION_1_2 = GL_TRUE; - GLEW_VERSION_1_3 = GL_TRUE; - GLEW_VERSION_1_4 = GL_TRUE; - GLEW_VERSION_1_5 = GL_FALSE; - GLEW_VERSION_2_0 = GL_FALSE; - GLEW_VERSION_2_1 = GL_FALSE; + CONST_CAST(GLEW_VERSION_1_2) = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_3) = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_4) = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_5) = GL_FALSE; + CONST_CAST(GLEW_VERSION_2_0) = GL_FALSE; + CONST_CAST(GLEW_VERSION_2_1) = GL_FALSE; } if (s[minor] == '3') { - GLEW_VERSION_1_2 = GL_TRUE; - GLEW_VERSION_1_3 = GL_TRUE; - GLEW_VERSION_1_4 = GL_FALSE; - GLEW_VERSION_1_5 = GL_FALSE; - GLEW_VERSION_2_0 = GL_FALSE; - GLEW_VERSION_2_1 = GL_FALSE; + CONST_CAST(GLEW_VERSION_1_2) = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_3) = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_4) = GL_FALSE; + CONST_CAST(GLEW_VERSION_1_5) = GL_FALSE; + CONST_CAST(GLEW_VERSION_2_0) = GL_FALSE; + CONST_CAST(GLEW_VERSION_2_1) = GL_FALSE; } if (s[minor] == '2') { - GLEW_VERSION_1_2 = GL_TRUE; - GLEW_VERSION_1_3 = GL_FALSE; - GLEW_VERSION_1_4 = GL_FALSE; - GLEW_VERSION_1_5 = GL_FALSE; - GLEW_VERSION_2_0 = GL_FALSE; - GLEW_VERSION_2_1 = GL_FALSE; + CONST_CAST(GLEW_VERSION_1_2) = GL_TRUE; + CONST_CAST(GLEW_VERSION_1_3) = GL_FALSE; + CONST_CAST(GLEW_VERSION_1_4) = GL_FALSE; + CONST_CAST(GLEW_VERSION_1_5) = GL_FALSE; + CONST_CAST(GLEW_VERSION_2_0) = GL_FALSE; + CONST_CAST(GLEW_VERSION_2_1) = GL_FALSE; } if (s[minor] < '2') { - GLEW_VERSION_1_2 = GL_FALSE; - GLEW_VERSION_1_3 = GL_FALSE; - GLEW_VERSION_1_4 = GL_FALSE; - GLEW_VERSION_1_5 = GL_FALSE; - GLEW_VERSION_2_0 = GL_FALSE; - GLEW_VERSION_2_1 = GL_FALSE; + CONST_CAST(GLEW_VERSION_1_2) = GL_FALSE; + CONST_CAST(GLEW_VERSION_1_3) = GL_FALSE; + CONST_CAST(GLEW_VERSION_1_4) = GL_FALSE; + CONST_CAST(GLEW_VERSION_1_5) = GL_FALSE; + CONST_CAST(GLEW_VERSION_2_0) = GL_FALSE; + CONST_CAST(GLEW_VERSION_2_1) = GL_FALSE; } } } diff --git a/auto/src/glew_init_glx.c b/auto/src/glew_init_glx.c index 3556466..369b4ad 100644 --- a/auto/src/glew_init_glx.c +++ b/auto/src/glew_init_glx.c @@ -26,11 +26,11 @@ GLenum glxewContextInit (GLXEW_CONTEXT_ARG_DEF_LIST) /* initialize core GLX 1.2 */ if (_glewInit_GLX_VERSION_1_2(GLEW_CONTEXT_ARG_VAR_INIT)) return GLEW_ERROR_GLX_VERSION_11_ONLY; /* initialize flags */ - GLXEW_VERSION_1_0 = GL_TRUE; - GLXEW_VERSION_1_1 = GL_TRUE; - GLXEW_VERSION_1_2 = GL_TRUE; - GLXEW_VERSION_1_3 = GL_TRUE; - GLXEW_VERSION_1_4 = GL_TRUE; + CONST_CAST(GLXEW_VERSION_1_0) = GL_TRUE; + CONST_CAST(GLXEW_VERSION_1_1) = GL_TRUE; + CONST_CAST(GLXEW_VERSION_1_2) = GL_TRUE; + CONST_CAST(GLXEW_VERSION_1_3) = GL_TRUE; + CONST_CAST(GLXEW_VERSION_1_4) = GL_TRUE; /* query GLX version */ glXQueryVersion(glXGetCurrentDisplay(), &major, &minor); if (major == 1 && minor <= 3) @@ -38,11 +38,11 @@ GLenum glxewContextInit (GLXEW_CONTEXT_ARG_DEF_LIST) switch (minor) { case 3: - GLXEW_VERSION_1_4 = GL_FALSE; + CONST_CAST(GLXEW_VERSION_1_4) = GL_FALSE; break; case 2: - GLXEW_VERSION_1_4 = GL_FALSE; - GLXEW_VERSION_1_3 = GL_FALSE; + CONST_CAST(GLXEW_VERSION_1_4) = GL_FALSE; + CONST_CAST(GLXEW_VERSION_1_3) = GL_FALSE; break; default: return GLEW_ERROR_GLX_VERSION_11_ONLY; diff --git a/auto/src/glew_tail.h b/auto/src/glew_tail.h index 39d5c34..9f9336a 100644 --- a/auto/src/glew_tail.h +++ b/auto/src/glew_tail.h @@ -21,11 +21,10 @@ GLEWAPI GLboolean glewContextIsSupported (GLEWContext* ctx, const char* name); #define glewIsSupported(x) glewContextIsSupported(glewGetContext(), x) #define glewIsExtensionSupported(x) glewIsSupported(x) +#define GLEW_GET_VAR(x) (*(const GLboolean*)&(glewGetContext()->x)) #ifdef _WIN32 -# define GLEW_GET_VAR(x) glewGetContext()->x # define GLEW_GET_FUN(x) glewGetContext()->x #else -# define GLEW_GET_VAR(x) glewGetContext()->x # define GLEW_GET_FUN(x) x #endif @@ -35,7 +34,7 @@ GLEWAPI GLenum glewInit (); GLEWAPI GLboolean glewIsSupported (const char* name); #define glewIsExtensionSupported(x) glewIsSupported(x) -#define GLEW_GET_VAR(x) x +#define GLEW_GET_VAR(x) (*(const GLboolean*)&x) #define GLEW_GET_FUN(x) x #endif /* GLEW_MX */