Guarantee consistency of names/addresses in glutGetProcAddress by

using a macro. In addition, this avoids any non-constant initializer
issues which might be raised when using WinDoze GCCs. The additional
code overhead is negligible, at least for x86 (a few instructions per
name).


git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@621 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
spanne 2005-05-22 09:45:53 +00:00
parent e317fc93be
commit d0df3bd759
2 changed files with 157 additions and 150 deletions

View File

@ -1016,3 +1016,8 @@ mouse pointers don't work) on the way:
************************************************************************** **************************************************************************
(265) Lowering minimum autoconf version required. (265) Lowering minimum autoconf version required.
(266) Guarantee consistency of names/addresses in glutGetProcAddress by
using a macro. In addition, this avoids any non-constant initializer
issues which might be raised when using WinDoze GCCs. The additional code
overhead is negligible, at least for x86 (a few instructions per name).

View File

@ -29,168 +29,170 @@
#include <GL/freeglut.h> #include <GL/freeglut.h>
#include "freeglut_internal.h" #include "freeglut_internal.h"
struct name_address_pair static GLUTproc fghGetProcAddress( const char* procName )
{ {
const char *name; /* optimization: quick initial check */
GLUTproc address; if( strncmp( procName, "glut", 4 ) != 0 )
}; return NULL;
static struct name_address_pair glut_functions[] = #define CHECK_NAME(x) if( strcmp( procName, #x ) == 0) return (GLUTproc)x;
{ CHECK_NAME(glutInit);
{ "glutInit", (GLUTproc) glutInit }, CHECK_NAME(glutInitDisplayMode);
{ "glutInitDisplayMode", (GLUTproc) glutInitDisplayMode }, CHECK_NAME(glutInitDisplayString);
{ "glutInitDisplayString", (GLUTproc) glutInitDisplayString }, CHECK_NAME(glutInitWindowPosition);
{ "glutInitWindowPosition", (GLUTproc) glutInitWindowPosition }, CHECK_NAME(glutInitWindowSize);
{ "glutInitWindowSize", (GLUTproc) glutInitWindowSize }, CHECK_NAME(glutMainLoop);
{ "glutMainLoop", (GLUTproc) glutMainLoop }, CHECK_NAME(glutCreateWindow);
{ "glutCreateWindow", (GLUTproc) glutCreateWindow }, CHECK_NAME(glutCreateSubWindow);
{ "glutCreateSubWindow", (GLUTproc) glutCreateSubWindow }, CHECK_NAME(glutDestroyWindow);
{ "glutDestroyWindow", (GLUTproc) glutDestroyWindow }, CHECK_NAME(glutPostRedisplay);
{ "glutPostRedisplay", (GLUTproc) glutPostRedisplay }, CHECK_NAME(glutPostWindowRedisplay);
{ "glutPostWindowRedisplay", (GLUTproc) glutPostWindowRedisplay }, CHECK_NAME(glutSwapBuffers);
{ "glutSwapBuffers", (GLUTproc) glutSwapBuffers }, CHECK_NAME(glutGetWindow);
{ "glutGetWindow", (GLUTproc) glutGetWindow }, CHECK_NAME(glutSetWindow);
{ "glutSetWindow", (GLUTproc) glutSetWindow }, CHECK_NAME(glutSetWindowTitle);
{ "glutSetWindowTitle", (GLUTproc) glutSetWindowTitle }, CHECK_NAME(glutSetIconTitle);
{ "glutSetIconTitle", (GLUTproc) glutSetIconTitle }, CHECK_NAME(glutPositionWindow);
{ "glutPositionWindow", (GLUTproc) glutPositionWindow }, CHECK_NAME(glutReshapeWindow);
{ "glutReshapeWindow", (GLUTproc) glutReshapeWindow }, CHECK_NAME(glutPopWindow);
{ "glutPopWindow", (GLUTproc) glutPopWindow }, CHECK_NAME(glutPushWindow);
{ "glutPushWindow", (GLUTproc) glutPushWindow }, CHECK_NAME(glutIconifyWindow);
{ "glutIconifyWindow", (GLUTproc) glutIconifyWindow }, CHECK_NAME(glutShowWindow);
{ "glutShowWindow", (GLUTproc) glutShowWindow }, CHECK_NAME(glutHideWindow);
{ "glutHideWindow", (GLUTproc) glutHideWindow }, CHECK_NAME(glutFullScreen);
{ "glutFullScreen", (GLUTproc) glutFullScreen }, CHECK_NAME(glutSetCursor);
{ "glutSetCursor", (GLUTproc) glutSetCursor }, CHECK_NAME(glutWarpPointer);
{ "glutWarpPointer", (GLUTproc) glutWarpPointer }, CHECK_NAME(glutEstablishOverlay);
{ "glutEstablishOverlay", (GLUTproc) glutEstablishOverlay }, CHECK_NAME(glutRemoveOverlay);
{ "glutRemoveOverlay", (GLUTproc) glutRemoveOverlay }, CHECK_NAME(glutUseLayer);
{ "glutUseLayer", (GLUTproc) glutUseLayer }, CHECK_NAME(glutPostOverlayRedisplay);
{ "glutPostOverlayRedisplay", (GLUTproc) glutPostOverlayRedisplay }, CHECK_NAME(glutPostWindowOverlayRedisplay);
{ "glutPostWindowOverlayRedisplay", (GLUTproc) glutPostWindowOverlayRedisplay }, CHECK_NAME(glutShowOverlay);
{ "glutShowOverlay", (GLUTproc) glutShowOverlay }, CHECK_NAME(glutHideOverlay);
{ "glutHideOverlay", (GLUTproc) glutHideOverlay }, CHECK_NAME(glutCreateMenu);
{ "glutCreateMenu", (GLUTproc) glutCreateMenu }, CHECK_NAME(glutDestroyMenu);
{ "glutDestroyMenu", (GLUTproc) glutDestroyMenu }, CHECK_NAME(glutGetMenu);
{ "glutGetMenu", (GLUTproc) glutGetMenu }, CHECK_NAME(glutSetMenu);
{ "glutSetMenu", (GLUTproc) glutSetMenu }, CHECK_NAME(glutAddMenuEntry);
{ "glutAddMenuEntry", (GLUTproc) glutAddMenuEntry }, CHECK_NAME(glutAddSubMenu);
{ "glutAddSubMenu", (GLUTproc) glutAddSubMenu }, CHECK_NAME(glutChangeToMenuEntry);
{ "glutChangeToMenuEntry", (GLUTproc) glutChangeToMenuEntry }, CHECK_NAME(glutChangeToSubMenu);
{ "glutChangeToSubMenu", (GLUTproc) glutChangeToSubMenu }, CHECK_NAME(glutRemoveMenuItem);
{ "glutRemoveMenuItem", (GLUTproc) glutRemoveMenuItem }, CHECK_NAME(glutAttachMenu);
{ "glutAttachMenu", (GLUTproc) glutAttachMenu }, CHECK_NAME(glutDetachMenu);
{ "glutDetachMenu", (GLUTproc) glutDetachMenu }, CHECK_NAME(glutDisplayFunc);
{ "glutDisplayFunc", (GLUTproc) glutDisplayFunc }, CHECK_NAME(glutReshapeFunc);
{ "glutReshapeFunc", (GLUTproc) glutReshapeFunc }, CHECK_NAME(glutKeyboardFunc);
{ "glutKeyboardFunc", (GLUTproc) glutKeyboardFunc }, CHECK_NAME(glutMouseFunc);
{ "glutMouseFunc", (GLUTproc) glutMouseFunc }, CHECK_NAME(glutMotionFunc);
{ "glutMotionFunc", (GLUTproc) glutMotionFunc }, CHECK_NAME(glutPassiveMotionFunc);
{ "glutPassiveMotionFunc", (GLUTproc) glutPassiveMotionFunc }, CHECK_NAME(glutEntryFunc);
{ "glutEntryFunc", (GLUTproc) glutEntryFunc }, CHECK_NAME(glutVisibilityFunc);
{ "glutVisibilityFunc", (GLUTproc) glutVisibilityFunc }, CHECK_NAME(glutIdleFunc);
{ "glutIdleFunc", (GLUTproc) glutIdleFunc }, CHECK_NAME(glutTimerFunc);
{ "glutTimerFunc", (GLUTproc) glutTimerFunc }, CHECK_NAME(glutMenuStateFunc);
{ "glutMenuStateFunc", (GLUTproc) glutMenuStateFunc }, CHECK_NAME(glutSpecialFunc);
{ "glutSpecialFunc", (GLUTproc) glutSpecialFunc }, CHECK_NAME(glutSpaceballMotionFunc);
{ "glutSpaceballMotionFunc", (GLUTproc) glutSpaceballMotionFunc }, CHECK_NAME(glutSpaceballRotateFunc);
{ "glutSpaceballRotateFunc", (GLUTproc) glutSpaceballRotateFunc }, CHECK_NAME(glutSpaceballButtonFunc);
{ "glutSpaceballButtonFunc", (GLUTproc) glutSpaceballButtonFunc }, CHECK_NAME(glutButtonBoxFunc);
{ "glutButtonBoxFunc", (GLUTproc) glutButtonBoxFunc }, CHECK_NAME(glutDialsFunc);
{ "glutDialsFunc", (GLUTproc) glutDialsFunc }, CHECK_NAME(glutTabletMotionFunc);
{ "glutTabletMotionFunc", (GLUTproc) glutTabletMotionFunc }, CHECK_NAME(glutTabletButtonFunc);
{ "glutTabletButtonFunc", (GLUTproc) glutTabletButtonFunc }, CHECK_NAME(glutMenuStatusFunc);
{ "glutMenuStatusFunc", (GLUTproc) glutMenuStatusFunc }, CHECK_NAME(glutOverlayDisplayFunc);
{ "glutOverlayDisplayFunc", (GLUTproc) glutOverlayDisplayFunc }, CHECK_NAME(glutWindowStatusFunc);
{ "glutWindowStatusFunc", (GLUTproc) glutWindowStatusFunc }, CHECK_NAME(glutKeyboardUpFunc);
{ "glutKeyboardUpFunc", (GLUTproc) glutKeyboardUpFunc }, CHECK_NAME(glutSpecialUpFunc);
{ "glutSpecialUpFunc", (GLUTproc) glutSpecialUpFunc },
#if !TARGET_HOST_WINCE #if !TARGET_HOST_WINCE
{ "glutJoystickFunc", (GLUTproc) glutJoystickFunc }, CHECK_NAME(glutJoystickFunc);
#endif /* !TARGET_HOST_WINCE */ #endif /* !TARGET_HOST_WINCE */
{ "glutSetColor", (GLUTproc) glutSetColor }, CHECK_NAME(glutSetColor);
{ "glutGetColor", (GLUTproc) glutGetColor }, CHECK_NAME(glutGetColor);
{ "glutCopyColormap", (GLUTproc) glutCopyColormap }, CHECK_NAME(glutCopyColormap);
{ "glutGet", (GLUTproc) glutGet }, CHECK_NAME(glutGet);
{ "glutDeviceGet", (GLUTproc) glutDeviceGet }, CHECK_NAME(glutDeviceGet);
{ "glutExtensionSupported", (GLUTproc) glutExtensionSupported }, CHECK_NAME(glutExtensionSupported);
{ "glutGetModifiers", (GLUTproc) glutGetModifiers }, CHECK_NAME(glutGetModifiers);
{ "glutLayerGet", (GLUTproc) glutLayerGet }, CHECK_NAME(glutLayerGet);
{ "glutBitmapCharacter", (GLUTproc) glutBitmapCharacter }, CHECK_NAME(glutBitmapCharacter);
{ "glutBitmapWidth", (GLUTproc) glutBitmapWidth }, CHECK_NAME(glutBitmapWidth);
{ "glutStrokeCharacter", (GLUTproc) glutStrokeCharacter }, CHECK_NAME(glutStrokeCharacter);
{ "glutStrokeWidth", (GLUTproc) glutStrokeWidth }, CHECK_NAME(glutStrokeWidth);
{ "glutBitmapLength", (GLUTproc) glutBitmapLength }, CHECK_NAME(glutBitmapLength);
{ "glutStrokeLength", (GLUTproc) glutStrokeLength }, CHECK_NAME(glutStrokeLength);
{ "glutWireSphere", (GLUTproc) glutWireSphere }, CHECK_NAME(glutWireSphere);
{ "glutSolidSphere", (GLUTproc) glutSolidSphere }, CHECK_NAME(glutSolidSphere);
{ "glutWireCone", (GLUTproc) glutWireCone }, CHECK_NAME(glutWireCone);
{ "glutSolidCone", (GLUTproc) glutSolidCone }, CHECK_NAME(glutSolidCone);
{ "glutWireCube", (GLUTproc) glutWireCube }, CHECK_NAME(glutWireCube);
{ "glutSolidCube", (GLUTproc) glutSolidCube }, CHECK_NAME(glutSolidCube);
{ "glutWireTorus", (GLUTproc) glutWireTorus }, CHECK_NAME(glutWireTorus);
{ "glutSolidTorus", (GLUTproc) glutSolidTorus }, CHECK_NAME(glutSolidTorus);
{ "glutWireDodecahedron", (GLUTproc) glutWireDodecahedron }, CHECK_NAME(glutWireDodecahedron);
{ "glutSolidDodecahedron", (GLUTproc) glutSolidDodecahedron }, CHECK_NAME(glutSolidDodecahedron);
{ "glutWireTeapot", (GLUTproc) glutWireTeapot }, CHECK_NAME(glutWireTeapot);
{ "glutSolidTeapot", (GLUTproc) glutSolidTeapot }, CHECK_NAME(glutSolidTeapot);
{ "glutWireOctahedron", (GLUTproc) glutWireOctahedron }, CHECK_NAME(glutWireOctahedron);
{ "glutSolidOctahedron", (GLUTproc) glutSolidOctahedron }, CHECK_NAME(glutSolidOctahedron);
{ "glutWireTetrahedron", (GLUTproc) glutWireTetrahedron }, CHECK_NAME(glutWireTetrahedron);
{ "glutSolidTetrahedron", (GLUTproc) glutSolidTetrahedron }, CHECK_NAME(glutSolidTetrahedron);
{ "glutWireIcosahedron", (GLUTproc) glutWireIcosahedron }, CHECK_NAME(glutWireIcosahedron);
{ "glutSolidIcosahedron", (GLUTproc) glutSolidIcosahedron }, CHECK_NAME(glutSolidIcosahedron);
{ "glutVideoResizeGet", (GLUTproc) glutVideoResizeGet }, CHECK_NAME(glutVideoResizeGet);
{ "glutSetupVideoResizing", (GLUTproc) glutSetupVideoResizing }, CHECK_NAME(glutSetupVideoResizing);
{ "glutStopVideoResizing", (GLUTproc) glutStopVideoResizing }, CHECK_NAME(glutStopVideoResizing);
{ "glutVideoResize", (GLUTproc) glutVideoResize }, CHECK_NAME(glutVideoResize);
{ "glutVideoPan", (GLUTproc) glutVideoPan }, CHECK_NAME(glutVideoPan);
{ "glutReportErrors", (GLUTproc) glutReportErrors }, CHECK_NAME(glutReportErrors);
{ "glutIgnoreKeyRepeat", (GLUTproc) glutIgnoreKeyRepeat }, CHECK_NAME(glutIgnoreKeyRepeat);
{ "glutSetKeyRepeat", (GLUTproc) glutSetKeyRepeat }, CHECK_NAME(glutSetKeyRepeat);
#if !TARGET_HOST_WINCE #if !TARGET_HOST_WINCE
{ "glutForceJoystickFunc", (GLUTproc) glutForceJoystickFunc }, CHECK_NAME(glutForceJoystickFunc);
{ "glutGameModeString", (GLUTproc) glutGameModeString }, CHECK_NAME(glutGameModeString);
{ "glutEnterGameMode", (GLUTproc) glutEnterGameMode }, CHECK_NAME(glutEnterGameMode);
{ "glutLeaveGameMode", (GLUTproc) glutLeaveGameMode }, CHECK_NAME(glutLeaveGameMode);
{ "glutGameModeGet", (GLUTproc) glutGameModeGet }, CHECK_NAME(glutGameModeGet);
#endif /* !TARGET_HOST_WINCE */ #endif /* !TARGET_HOST_WINCE */
/* freeglut extensions */ /* freeglut extensions */
{ "glutMainLoopEvent", (GLUTproc) glutMainLoopEvent }, CHECK_NAME(glutMainLoopEvent);
{ "glutLeaveMainLoop", (GLUTproc) glutLeaveMainLoop }, CHECK_NAME(glutLeaveMainLoop);
{ "glutCloseFunc", (GLUTproc) glutCloseFunc }, CHECK_NAME(glutCloseFunc);
{ "glutWMCloseFunc", (GLUTproc) glutWMCloseFunc }, CHECK_NAME(glutWMCloseFunc);
{ "glutMenuDestroyFunc", (GLUTproc) glutMenuDestroyFunc }, CHECK_NAME(glutMenuDestroyFunc);
{ "glutSetOption", (GLUTproc) glutSetOption }, CHECK_NAME(glutSetOption);
{ "glutSetWindowData", (GLUTproc) glutSetWindowData }, CHECK_NAME(glutSetWindowData);
{ "glutGetWindowData", (GLUTproc) glutGetWindowData }, CHECK_NAME(glutGetWindowData);
{ "glutSetMenuData", (GLUTproc) glutSetMenuData }, CHECK_NAME(glutSetMenuData);
{ "glutGetMenuData", (GLUTproc) glutGetMenuData }, CHECK_NAME(glutGetMenuData);
{ "glutBitmapHeight", (GLUTproc) glutBitmapHeight }, CHECK_NAME(glutBitmapHeight);
{ "glutStrokeHeight", (GLUTproc) glutStrokeHeight }, CHECK_NAME(glutStrokeHeight);
{ "glutBitmapString", (GLUTproc) glutBitmapString }, CHECK_NAME(glutBitmapString);
{ "glutStrokeString", (GLUTproc) glutStrokeString }, CHECK_NAME(glutStrokeString);
{ "glutWireRhombicDodecahedron", (GLUTproc) glutWireRhombicDodecahedron }, CHECK_NAME(glutWireRhombicDodecahedron);
{ "glutSolidRhombicDodecahedron", (GLUTproc) glutSolidRhombicDodecahedron }, CHECK_NAME(glutSolidRhombicDodecahedron);
{ "glutWireSierpinskiSponge", (GLUTproc) glutWireSierpinskiSponge }, CHECK_NAME(glutWireSierpinskiSponge);
{ "glutSolidSierpinskiSponge", (GLUTproc) glutSolidSierpinskiSponge }, CHECK_NAME(glutSolidSierpinskiSponge);
{ "glutWireCylinder", (GLUTproc) glutWireCylinder }, CHECK_NAME(glutWireCylinder);
{ "glutSolidCylinder", (GLUTproc) glutSolidCylinder }, CHECK_NAME(glutSolidCylinder);
{ "glutGetProcAddress", (GLUTproc) glutGetProcAddress }, CHECK_NAME(glutGetProcAddress);
{ "glutMouseWheelFunc", (GLUTproc) glutMouseWheelFunc }, CHECK_NAME(glutMouseWheelFunc);
{ NULL, NULL } #undef CHECK_NAME
};
return NULL;
}
GLUTproc FGAPIENTRY GLUTproc FGAPIENTRY
glutGetProcAddress( const char *procName ) glutGetProcAddress( const char *procName )
{ {
/* Try GLUT functions first */ GLUTproc p;
int i;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetProcAddress" ); FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetProcAddress" );
for( i = 0; glut_functions[ i ].name; i++ )
if( strcmp( glut_functions[ i ].name, procName ) == 0) /* Try GLUT functions first */
return glut_functions[ i ].address; p = fghGetProcAddress( procName );
if( p != NULL )
return p;
/* Try core GL functions */ /* Try core GL functions */
#if TARGET_HOST_WIN32 || TARGET_HOST_WINCE #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE