1
0
Fork 0

Fix #9756: Network command unpack proc was not generated in all cases.

The case where the callback proc takes all command results but not any of
the command parameters was not handled properly.
pull/9758/head
Michael Lutz 2021-12-20 16:59:07 +01:00
parent 9c18236f2c
commit b11bd185e3
2 changed files with 7 additions and 1 deletions

View File

@ -409,12 +409,14 @@ template <typename T> struct CommandFunctionTraitHelper;
template <typename... Targs> template <typename... Targs>
struct CommandFunctionTraitHelper<CommandCost(*)(DoCommandFlag, Targs...)> { struct CommandFunctionTraitHelper<CommandCost(*)(DoCommandFlag, Targs...)> {
using Args = std::tuple<std::decay_t<Targs>...>; using Args = std::tuple<std::decay_t<Targs>...>;
using RetTypes = void;
using CbArgs = Args; using CbArgs = Args;
using CbProcType = void(*)(Commands, const CommandCost &); using CbProcType = void(*)(Commands, const CommandCost &);
}; };
template <template <typename...> typename Tret, typename... Tretargs, typename... Targs> template <template <typename...> typename Tret, typename... Tretargs, typename... Targs>
struct CommandFunctionTraitHelper<Tret<CommandCost, Tretargs...>(*)(DoCommandFlag, Targs...)> { struct CommandFunctionTraitHelper<Tret<CommandCost, Tretargs...>(*)(DoCommandFlag, Targs...)> {
using Args = std::tuple<std::decay_t<Targs>...>; using Args = std::tuple<std::decay_t<Targs>...>;
using RetTypes = std::tuple<std::decay_t<Tretargs>...>;
using CbArgs = std::tuple<std::decay_t<Tretargs>..., std::decay_t<Targs>...>; using CbArgs = std::tuple<std::decay_t<Tretargs>..., std::decay_t<Targs>...>;
using CbProcType = void(*)(Commands, const CommandCost &, Tretargs...); using CbProcType = void(*)(Commands, const CommandCost &, Tretargs...);
}; };
@ -426,6 +428,7 @@ template <Commands Tcmd> struct CommandTraits;
template<> struct CommandTraits<cmd_> { \ template<> struct CommandTraits<cmd_> { \
using ProcType = decltype(&proc_); \ using ProcType = decltype(&proc_); \
using Args = typename CommandFunctionTraitHelper<ProcType>::Args; \ using Args = typename CommandFunctionTraitHelper<ProcType>::Args; \
using RetTypes = typename CommandFunctionTraitHelper<ProcType>::RetTypes; \
using CbArgs = typename CommandFunctionTraitHelper<ProcType>::CbArgs; \ using CbArgs = typename CommandFunctionTraitHelper<ProcType>::CbArgs; \
using RetCallbackProc = typename CommandFunctionTraitHelper<ProcType>::CbProcType; \ using RetCallbackProc = typename CommandFunctionTraitHelper<ProcType>::CbProcType; \
static constexpr Commands cmd = cmd_; \ static constexpr Commands cmd = cmd_; \

View File

@ -136,7 +136,10 @@ constexpr UnpackNetworkCommandProc MakeUnpackNetworkCommandCallback() noexcept
{ {
/* Check if the callback matches with the command arguments. If not, don't generate an Unpack proc. */ /* Check if the callback matches with the command arguments. If not, don't generate an Unpack proc. */
using Tcallback = std::tuple_element_t<Tcb, decltype(_callback_tuple)>; using Tcallback = std::tuple_element_t<Tcb, decltype(_callback_tuple)>;
if constexpr (std::is_same_v<Tcallback, CommandCallback * const> || std::is_same_v<Tcallback, CommandCallbackData * const> || std::is_same_v<typename CommandTraits<Tcmd>::CbArgs, typename CallbackArgsHelper<Tcallback>::Args>) { if constexpr (std::is_same_v<Tcallback, CommandCallback * const> || // Callback type is CommandCallback.
std::is_same_v<Tcallback, CommandCallbackData * const> || // Callback type is CommandCallbackData.
std::is_same_v<typename CommandTraits<Tcmd>::CbArgs, typename CallbackArgsHelper<Tcallback>::Args> || // Callback proc takes all command return values and parameters.
(!std::is_void_v<typename CommandTraits<Tcmd>::RetTypes> && std::is_same_v<typename CallbackArgsHelper<typename CommandTraits<Tcmd>::RetCallbackProc const>::Args, typename CallbackArgsHelper<Tcallback>::Args>)) { // Callback return is more than CommandCost and the proc takes all return values.
return &UnpackNetworkCommand<Tcmd, Tcb>; return &UnpackNetworkCommand<Tcmd, Tcb>;
} else { } else {
return nullptr; return nullptr;