From a7d846c36b16fb226b4d0768573221540ebdebae Mon Sep 17 00:00:00 2001 From: rkrolib Date: Fri, 19 Dec 2003 00:54:27 +0000 Subject: [PATCH] Wrote SET_WCB() to set a window callback. This lets us out of using the FETCH_WCB() as an lvalue (which it shouldn't, since the value of the FETCH is cast to the correct function-pointer type). git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@410 7f0cb862-5218-0410-a997-914c9d46530a --- freeglut/freeglut/src/freeglut_callbacks.c | 2 +- freeglut/freeglut/src/freeglut_internal.h | 32 ++++++++++++++++++++++ freeglut/freeglut/src/freeglut_structure.c | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/freeglut/freeglut/src/freeglut_callbacks.c b/freeglut/freeglut/src/freeglut_callbacks.c index 00d7ba1..7f2e23b 100644 --- a/freeglut/freeglut/src/freeglut_callbacks.c +++ b/freeglut/freeglut/src/freeglut_callbacks.c @@ -41,7 +41,7 @@ #define SET_CALLBACK(a) \ if( fgStructure.Window == NULL ) \ return; \ - FETCH_WCB( ( *( fgStructure.Window ) ), a ) = callback; + SET_WCB( ( *( fgStructure.Window ) ), a, callback ); /* * Sets the Display callback for the current window diff --git a/freeglut/freeglut/src/freeglut_internal.h b/freeglut/freeglut/src/freeglut_internal.h index 7ffb4b6..9044853 100644 --- a/freeglut/freeglut/src/freeglut_internal.h +++ b/freeglut/freeglut/src/freeglut_internal.h @@ -372,6 +372,38 @@ struct tagSFG_WindowState }; +/* + * SET_WCB() is used as: + * + * SET_WCB( window, Visibility, func ); + * + * ...where {window} is the freeglut window to set the callback, + * {Visibility} is the window-specific callback to set, + * {func} is a function-pointer. + * + * Originally, {FETCH_WCB( ... ) = func} was rather sloppily used, + * but this can cause warnings because the FETCH_WCB() macro type- + * casts its result, and a type-cast value shouldn't be an lvalue. + * + * XXX Note that there is no type-checking to make sure that {func} is + * XXX a suitable type. We could add a safety-check of the form: + * XXX + * XXX if( FETCH_WCB( ... ) != func ) + * XXX ... + * XXX + * XXX ...is this desired? + * + * XXX The {if( FETCH_WCB( ... ) != func )} test is to do type-checking + * XXX and for no other reason. Since it's hidden in the macro, the + * XXX ugliness is felt to be rather benign. + */ +#define SET_WCB(window,cbname,func) \ +do \ +{ \ + if( FETCH_WCB( window, cbname ) != func ) \ + (((window).CallBacks[CB_ ## cbname]) = func); \ +} while( 0 ) \ + /* * FETCH_WCB() is used as: * diff --git a/freeglut/freeglut/src/freeglut_structure.c b/freeglut/freeglut/src/freeglut_structure.c index 2c5f1fe..b4834a7 100644 --- a/freeglut/freeglut/src/freeglut_structure.c +++ b/freeglut/freeglut/src/freeglut_structure.c @@ -201,7 +201,7 @@ void fgAddToWindowDestroyList( SFG_Window* window ) { void *destroy = FETCH_WCB( *window, Destroy ); fgClearCallBacks( window ); - FETCH_WCB( *window, Destroy ) = destroy; + SET_WCB( *window, Destroy, destroy ); } }