[Scummvm-cvs-logs] scummvm master -> f7099c57d1bd2cbed983596abaee85c7dc9194c3
eriktorbjorn
eriktorbjorn at telia.com
Fri May 31 19:34:25 CEST 2013
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
f7099c57d1 NEVERHOOD: Made multi-line function-line macros safer
Commit: f7099c57d1bd2cbed983596abaee85c7dc9194c3
https://github.com/scummvm/scummvm/commit/f7099c57d1bd2cbed983596abaee85c7dc9194c3
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2013-05-31T10:30:36-07:00
Commit Message:
NEVERHOOD: Made multi-line function-line macros safer
Wrapped the code in the SetUpdateHandler(), SetMessageHandler(),
SetSpriteUpdate(), SetFilterX(), SetFilterY() and NextState()
macros in "do { ... } while (0)". Otherwise you may fool yourself
because in "if (condition) macro();" the "if" will only cover the
first statement of the macro.
CID 1022340, 1022341, 1022342, 1022343
Changed paths:
engines/neverhood/entity.h
engines/neverhood/sprite.h
diff --git a/engines/neverhood/entity.h b/engines/neverhood/entity.h
index fb8941a..cba1bb9 100644
--- a/engines/neverhood/entity.h
+++ b/engines/neverhood/entity.h
@@ -60,14 +60,18 @@ protected:
// TODO: Disable heavy debug stuff in release mode
#define SetUpdateHandler(handler) \
- _updateHandlerCb = static_cast <void (Entity::*)(void)> (handler); \
- debug(5, "SetUpdateHandler(" #handler ")"); \
- _updateHandlerCbName = #handler
+ do { \
+ _updateHandlerCb = static_cast <void (Entity::*)(void)> (handler); \
+ debug(5, "SetUpdateHandler(" #handler ")"); \
+ _updateHandlerCbName = #handler; \
+ } while (0)
#define SetMessageHandler(handler) \
- _messageHandlerCb = static_cast <uint32 (Entity::*)(int messageNum, const MessageParam ¶m, Entity *sender)> (handler); \
- debug(5, "SetMessageHandler(" #handler ")"); \
- _messageHandlerCbName = #handler
+ do { \
+ _messageHandlerCb = static_cast <uint32 (Entity::*)(int messageNum, const MessageParam ¶m, Entity *sender)> (handler); \
+ debug(5, "SetMessageHandler(" #handler ")"); \
+ _messageHandlerCbName = #handler; \
+ } while (0)
const uint kMaxSoundResources = 16;
diff --git a/engines/neverhood/sprite.h b/engines/neverhood/sprite.h
index 80da176..1d17bf0 100644
--- a/engines/neverhood/sprite.h
+++ b/engines/neverhood/sprite.h
@@ -30,9 +30,24 @@
namespace Neverhood {
-#define SetSpriteUpdate(callback) _spriteUpdateCb = static_cast <void (Sprite::*)(void)> (callback); debug(2, "SetSpriteUpdate(" #callback ")"); _spriteUpdateCbName = #callback
-#define SetFilterX(callback) _filterXCb = static_cast <int16 (Sprite::*)(int16)> (callback); debug(2, "SetFilterX(" #callback ")")
-#define SetFilterY(callback) _filterYCb = static_cast <int16 (Sprite::*)(int16)> (callback); debug(2, "SetFilterY(" #callback ")")
+#define SetSpriteUpdate(callback) \
+ do { \
+ _spriteUpdateCb = static_cast <void (Sprite::*)(void)> (callback); \
+ debug(2, "SetSpriteUpdate(" #callback ")"); \
+ _spriteUpdateCbName = #callback; \
+ } while (0)
+
+#define SetFilterX(callback) \
+ do { \
+ _filterXCb = static_cast <int16 (Sprite::*)(int16)> (callback); \
+ debug(2, "SetFilterX(" #callback ")"); \
+ } while (0)
+
+#define SetFilterY(callback) \
+ do { \
+ _filterYCb = static_cast <int16 (Sprite::*)(int16)> (callback); \
+ debug(2, "SetFilterY(" #callback ")"); \
+ } while (0)
const int16 kDefPosition = -32768;
@@ -113,7 +128,11 @@ protected:
#define AnimationCallback(callback) static_cast <void (AnimatedSprite::*)()> (callback)
#define GotoState(callback) gotoState(static_cast <void (AnimatedSprite::*)()> (callback))
-#define NextState(callback) _nextStateCb = static_cast <void (AnimatedSprite::*)(void)> (callback); debug(2, "NextState(" #callback ")"); _nextStateCbName = #callback
+#define NextState(callback) \
+ do { \
+ _nextStateCb = static_cast <void (AnimatedSprite::*)(void)> (callback); \
+ debug(2, "NextState(" #callback ")"); _nextStateCbName = #callback; \
+ } while (0)
#define FinalizeState(callback) setFinalizeState(static_cast <void (AnimatedSprite::*)()> (callback));
const int STICK_LAST_FRAME = -2;
More information about the Scummvm-git-logs
mailing list