From 7d2587ad2b8176937601bdfd188d6b92107bd7b0 Mon Sep 17 00:00:00 2001 From: Lukas Joergensen Date: Sat, 21 Apr 2018 09:22:12 +0200 Subject: [PATCH] Use FixedTuple in EngineTrampoline, to make memory-layout consistent --- Engine/source/console/engineAPI.h | 43 ++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/Engine/source/console/engineAPI.h b/Engine/source/console/engineAPI.h index ab1717745..5fa20a82c 100644 --- a/Engine/source/console/engineAPI.h +++ b/Engine/source/console/engineAPI.h @@ -26,6 +26,10 @@ #include #include +#ifndef _FIXEDTUPLE_H_ +#include "fixedTuple.h" +#endif + #ifndef _CONSOLETYPES_H_ #include "console/consoleTypes.h" #endif @@ -347,6 +351,8 @@ struct _EngineTrampoline< R( ArgTs ... ) > { typedef std::tuple Args; std::tuple argT; + typedef fixed_tuple FixedArgs; + fixed_tuple fixedArgT; }; template< typename T > @@ -365,6 +371,7 @@ struct _EngineFunctionTrampoline< R(ArgTs...) > : public _EngineFunctionTrampoli private: using Super = _EngineFunctionTrampolineBase< R(ArgTs...) >; using ArgsType = typename Super::Args; + using FixedArgsType = typename Super::FixedArgs; template struct Seq {}; template struct Gens : Gens {}; @@ -374,6 +381,11 @@ private: static R dispatchHelper(typename Super::FunctionType fn, const ArgsType& args, Seq) { return R( fn(std::get(args) ...) ); } + + template + static R dispatchHelper(typename Super::FunctionType fn, const FixedArgsType& args, Seq) { + return R( fn(fixed_tuple_accessor::get(args) ...) ); + } using SeqType = typename Gens::type; public: @@ -381,6 +393,11 @@ public: { return dispatchHelper(fn, args, SeqType()); } + + static R jmp(typename Super::FunctionType fn, const FixedArgsType& args ) + { + return dispatchHelper(fn, args, SeqType()); + } }; // Trampolines for engine methods @@ -398,6 +415,7 @@ struct _EngineMethodTrampoline< Frame, R(ArgTs ...) > : public _EngineMethodTram private: using Super = _EngineMethodTrampolineBase< R(ArgTs ...) >; using ArgsType = typename _EngineFunctionTrampolineBase< R(ArgTs ...) >::Args; + using FixedArgsType = typename Super::FixedArgs; template struct Seq {}; template struct Gens : Gens {}; @@ -408,6 +426,11 @@ private: return R( f._exec(std::get(args) ...) ); } + template + static R dispatchHelper(Frame f, const FixedArgsType& args, Seq) { + return R( f._exec(fixed_tuple_accessor::get(args) ...) ); + } + using SeqType = typename Gens::type; public: static R jmp( typename Frame::ObjectType* object, const ArgsType& args ) @@ -417,6 +440,14 @@ public: f.object = object; return dispatchHelper(f, args, SeqType()); } + + static R jmp( typename Frame::ObjectType* object, const FixedArgsType& args ) + { + + Frame f; + f.object = object; + return dispatchHelper(f, args, SeqType()); + } }; /// @} @@ -683,7 +714,7 @@ public: #define DefineEngineFunction( name, returnType, args, defaultArgs, usage ) \ static inline returnType _fn ## name ## impl args; \ TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## name \ - ( _EngineFunctionTrampoline< returnType args >::Args a ) \ + ( _EngineFunctionTrampoline< returnType args >::FixedArgs a ) \ { \ _CHECK_ENGINE_INITIALIZED( name, returnType ); \ return EngineTypeTraits< returnType >::ReturnValue( \ @@ -702,7 +733,7 @@ public: ( void* ) &fn ## name, \ 0 \ ); \ - static _EngineConsoleThunkType< returnType >::ReturnType _ ## name ## caster( SimObject*, S32 argc, ConsoleValueRef *argv ) \ + static _EngineConsoleThunkType< returnType >::ReturnType _ ## name ## caster( SimObject*, S32 argc, ConsoleValueRef *argv ) \ { \ return _EngineConsoleThunkType< returnType >::ReturnType( _EngineConsoleThunk< 1, returnType args >::thunk( \ argc, argv, &_fn ## name ## impl, _fn ## name ## DefaultArgs \ @@ -737,7 +768,7 @@ public: #define _DefineMethodTrampoline( className, name, returnType, args ) \ TORQUE_API EngineTypeTraits< returnType >::ReturnValueType \ - fn ## className ## _ ## name ( className* object, _EngineMethodTrampoline< _ ## className ## name ## frame, returnType args >::Args a ) \ + fn ## className ## _ ## name ( className* object, _EngineMethodTrampoline< _ ## className ## name ## frame, returnType args >::FixedArgs a )\ { \ _CHECK_ENGINE_INITIALIZED( className::name, returnType ); \ return EngineTypeTraits< returnType >::ReturnValue( \ @@ -820,7 +851,7 @@ public: #define DefineEngineStaticMethod( className, name, returnType, args, defaultArgs, usage ) \ static inline returnType _fn ## className ## name ## impl args; \ TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## className ## _ ## name \ - ( _EngineFunctionTrampoline< returnType args >::Args a ) \ + ( _EngineFunctionTrampoline< returnType args >::FixedArgs a ) \ { \ _CHECK_ENGINE_INITIALIZED( className::name, returnType ); \ return EngineTypeTraits< returnType >::ReturnValue( \ @@ -920,7 +951,7 @@ public: #define DefineNewEngineFunction( name, returnType, args, defaultArgs, usage ) \ static inline returnType _fn ## name ## impl args; \ TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## name \ - ( _EngineFunctionTrampoline< returnType args >::Args a ) \ + ( _EngineFunctionTrampoline< returnType args >::FixedArgs a ) \ { \ _CHECK_ENGINE_INITIALIZED( name, returnType ); \ return EngineTypeTraits< returnType >::ReturnValue( \ @@ -967,7 +998,7 @@ public: #define DefineNewEngineStaticMethod( className, name, returnType, args, defaultArgs, usage ) \ static inline returnType _fn ## className ## name ## impl args; \ TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## className ## _ ## name \ - ( _EngineFunctionTrampoline< returnType args >::Args a ) \ + ( _EngineFunctionTrampoline< returnType args >::FixedArgs a ) \ { \ _CHECK_ENGINE_INITIALIZED( className::name, returnType ); \ return EngineTypeTraits< returnType >::ReturnValue( \