Skip to content

Commit

Permalink
Handle array arguments properly.
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic committed Jul 27, 2020
1 parent 04b825e commit 2665884
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
23 changes: 22 additions & 1 deletion include/mimick/literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

# ifdef __cplusplus

# include <cstdarg>
# include <utility>

# include "preprocess.h"

template<typename T, int ID>
Expand All @@ -39,6 +42,22 @@ struct mmk_literal {
template<typename T, int ID>
T mmk_literal<T, ID>::storage;

template <typename T>
T & mmk_assign(T & dst, T src) {
return dst = std::move(dst);
}

template <typename T, size_t N>
T (& mmk_assign(T (&dst)[N], T * src))[N] {
mmk_memcpy(dst, src);
return dst;
}

va_list & mmk_assign(va_list & dst, va_list src) {
va_copy(dst, src);
return dst;
}

# define MMK_COMMA_APPEND(_, prefix, content) (void) (prefix content),

# define mmk_struct_initialize(variable, ...) \
Expand All @@ -49,10 +68,12 @@ T mmk_literal<T, ID>::storage;
mmk_struct_initialize((mmk_literal<type, __COUNTER__>::storage), __VA_ARGS__)

# define mmk_literal(type, value) \
(mmk_literal<type, __COUNTER__>::storage = value)
(mmk_assign(mmk_literal<type, __COUNTER__>::storage, value))

# else /* !defined __cplusplus */

# define mmk_assign(dst, src) (dst) = (src)

# define mmk_literal(type, value) ((type) value)

# define mmk_struct_literal(type, ...) ((type) { __VA_ARGS__ })
Expand Down
3 changes: 2 additions & 1 deletion include/mimick/mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ void mmk_reset(mmk_fn fn);
MMK_EXPAND(MMK_SET_PARAMS_VA_ ## Id (__VA_ARGS__))

# define MMK_SET_PARAMS_VA_WITH(...)

# define MMK_SET_PARAMS_VA_WITHOUT(N, Id, T, ...) \
bind->params.param ## N = param ## N;
mmk_assign(bind->params.param ## N, param ## N);

# define MMK_SET_PARAMS_(N, Id, T) \
MMK_COND_VA(MMK_SET_PARAMS_VA, (WITHOUT, N, Id, T,), (WITH,), T)
Expand Down

0 comments on commit 2665884

Please sign in to comment.