From b69bc02c022955c00243cbcdd1b97276fb470190 Mon Sep 17 00:00:00 2001 From: Stefan Schmidt Date: Mon, 9 Mar 2020 17:25:03 +0100 Subject: [PATCH] exactness: factor out duplicated code for debug session handling No need to have these macros ducplicated in two file, we can just share them and reduce maintenance. Reviewed-by: Mike Blumenkrantz Differential Revision: https://phab.enlightenment.org/D11459 --- src/bin/exactness/common.h | 91 ++++++++++++++++++++++++++++++++++++ src/bin/exactness/injector.c | 75 ----------------------------- src/bin/exactness/player.c | 76 ------------------------------ 3 files changed, 91 insertions(+), 151 deletions(-) diff --git a/src/bin/exactness/common.h b/src/bin/exactness/common.h index 1f84d80db7..2581c63392 100644 --- a/src/bin/exactness/common.h +++ b/src/bin/exactness/common.h @@ -6,4 +6,95 @@ #include #include +typedef struct +{ + Eina_Debug_Session *session; + int srcid; + void *buffer; + unsigned int size; +} _Main_Loop_Info; + +#define WRAPPER_TO_XFER_MAIN_LOOP(foo) \ +static void \ +_intern_main_loop ## foo(void *data) \ +{ \ + _Main_Loop_Info *info = data; \ + _main_loop ## foo(info->session, info->srcid, info->buffer, info->size); \ + free(info->buffer); \ + free(info); \ +} \ +static Eina_Bool \ +foo(Eina_Debug_Session *session, int srcid, void *buffer, int size) \ +{ \ + _Main_Loop_Info *info = calloc(1, sizeof(*info)); \ + info->session = session; \ + info->srcid = srcid; \ + info->size = size; \ + if (info->size) \ + { \ + info->buffer = malloc(info->size); \ + memcpy(info->buffer, buffer, info->size); \ + } \ + ecore_main_loop_thread_safe_call_async(_intern_main_loop ## foo, info); \ + return EINA_TRUE; \ +} + +#ifndef WORDS_BIGENDIAN +#define SWAP_64(x) x +#define SWAP_32(x) x +#define SWAP_16(x) x +#define SWAP_DBL(x) x +#else +#define SWAP_64(x) eina_swap64(x) +#define SWAP_32(x) eina_swap32(x) +#define SWAP_16(x) eina_swap16(x) +#define SWAP_DBL(x) SWAP_64(x) +#endif + +#define EXTRACT_INT(_buf) \ +({ \ + int __i; \ + memcpy(&__i, _buf, sizeof(int)); \ + _buf += sizeof(int); \ + SWAP_32(__i); \ +}) + +#define EXTRACT_DOUBLE(_buf) \ +({ \ + double __d; \ + memcpy(&__d, _buf, sizeof(double)); \ + _buf += sizeof(double); \ + SWAP_DBL(__d); \ +}) + +#define EXTRACT_STRING(_buf) \ +({ \ + char *__s = _buf ? strdup(_buf) : NULL; \ + int __len = (__s ? strlen(__s) : 0) + 1; \ + _buf += __len; \ + __s; \ +}) + +#define STORE_INT(_buf, __i) \ +({ \ + int __si = SWAP_32(__i); \ + memcpy(_buf, &__si, sizeof(int)); \ + _buf += sizeof(int); \ +}) + +#define STORE_DOUBLE(_buf, __d) \ +{ \ + double __d2 = SWAP_DBL(__d); \ + memcpy(_buf, &__d2, sizeof(double)); \ + _buf += sizeof(double); \ +} + +#define STORE_STRING(_buf, __s) \ +{ \ + int __len = (__s ? strlen(__s) : 0) + 1; \ + if (__s) memcpy(_buf, __s, __len); \ + else *_buf = '\0'; \ + _buf += __len; \ +} + void ex_printf(int verbose, const char *fmt, ...); diff --git a/src/bin/exactness/injector.c b/src/bin/exactness/injector.c index 882752620d..928de47a62 100644 --- a/src/bin/exactness/injector.c +++ b/src/bin/exactness/injector.c @@ -16,81 +16,6 @@ #include #include "common.h" -typedef struct -{ - Eina_Debug_Session *session; - int srcid; - void *buffer; - unsigned int size; -} _Main_Loop_Info; - -#define WRAPPER_TO_XFER_MAIN_LOOP(foo) \ -static void \ -_intern_main_loop ## foo(void *data) \ -{ \ - _Main_Loop_Info *info = data; \ - _main_loop ## foo(info->session, info->srcid, info->buffer, info->size); \ - free(info->buffer); \ - free(info); \ -} \ -static Eina_Bool \ -foo(Eina_Debug_Session *session, int srcid, void *buffer, int size) \ -{ \ - _Main_Loop_Info *info = calloc(1, sizeof(*info)); \ - info->session = session; \ - info->srcid = srcid; \ - info->size = size; \ - if (info->size) \ - { \ - info->buffer = malloc(info->size); \ - memcpy(info->buffer, buffer, info->size); \ - } \ - ecore_main_loop_thread_safe_call_async(_intern_main_loop ## foo, info); \ - return EINA_TRUE; \ -} - -#ifndef WORDS_BIGENDIAN -#define SWAP_64(x) x -#define SWAP_32(x) x -#define SWAP_16(x) x -#define SWAP_DBL(x) x -#else -#define SWAP_64(x) eina_swap64(x) -#define SWAP_32(x) eina_swap32(x) -#define SWAP_16(x) eina_swap16(x) -#define SWAP_DBL(x) SWAP_64(x) -#endif - -#define EXTRACT_INT(_buf) \ -({ \ - int __i; \ - memcpy(&__i, _buf, sizeof(int)); \ - _buf += sizeof(int); \ - SWAP_32(__i); \ -}) - -#define STORE_INT(_buf, __i) \ -{ \ - int __i2 = SWAP_32(__i); \ - memcpy(_buf, &__i2, sizeof(int)); \ - _buf += sizeof(int); \ -} - -#define STORE_DOUBLE(_buf, __d) \ -{ \ - double __d2 = SWAP_DBL(__d); \ - memcpy(_buf, &__d2, sizeof(double)); \ - _buf += sizeof(double); \ -} - -#define STORE_STRING(_buf, __s) \ -{ \ - int __len = (__s ? strlen(__s) : 0) + 1; \ - if (__s) memcpy(_buf, __s, __len); \ - else *_buf = '\0'; \ - _buf += __len; \ -} - static Eina_Stringshare *_src_filename = NULL; static Exactness_Unit *_src_unit = NULL; static int _verbose = 0; diff --git a/src/bin/exactness/player.c b/src/bin/exactness/player.c index b11a843205..fa9f0c63d3 100644 --- a/src/bin/exactness/player.c +++ b/src/bin/exactness/player.c @@ -36,82 +36,6 @@ #define IMAGE_FILENAME_EXT ".png" #define PAUSE_KEY_STR "F2" -typedef struct -{ - Eina_Debug_Session *session; - int srcid; - void *buffer; - unsigned int size; -} _Main_Loop_Info; - -#define WRAPPER_TO_XFER_MAIN_LOOP(foo) \ -static void \ -_intern_main_loop ## foo(void *data) \ -{ \ - _Main_Loop_Info *info = data; \ - _main_loop ## foo(info->session, info->srcid, info->buffer, info->size); \ - free(info->buffer); \ - free(info); \ -} \ -static Eina_Bool \ -foo(Eina_Debug_Session *session, int srcid, void *buffer, int size) \ -{ \ - _Main_Loop_Info *info = calloc(1, sizeof(*info)); \ - info->session = session; \ - info->srcid = srcid; \ - info->size = size; \ - if (info->size) \ - { \ - info->buffer = malloc(info->size); \ - memcpy(info->buffer, buffer, info->size); \ - } \ - ecore_main_loop_thread_safe_call_async(_intern_main_loop ## foo, info); \ - return EINA_TRUE; \ -} - -#ifndef WORDS_BIGENDIAN -#define SWAP_64(x) x -#define SWAP_32(x) x -#define SWAP_16(x) x -#define SWAP_DBL(x) x -#else -#define SWAP_64(x) eina_swap64(x) -#define SWAP_32(x) eina_swap32(x) -#define SWAP_16(x) eina_swap16(x) -#define SWAP_DBL(x) SWAP_64(x) -#endif - -#define EXTRACT_INT(_buf) \ -({ \ - int __i; \ - memcpy(&__i, _buf, sizeof(int)); \ - _buf += sizeof(int); \ - SWAP_32(__i); \ -}) - -#define EXTRACT_DOUBLE(_buf) \ -({ \ - double __d; \ - memcpy(&__d, _buf, sizeof(double)); \ - _buf += sizeof(double); \ - SWAP_DBL(__d); \ -}) - -#define EXTRACT_STRING(_buf) \ -({ \ - char *__s = _buf ? strdup(_buf) : NULL; \ - int __len = (__s ? strlen(__s) : 0) + 1; \ - _buf += __len; \ - __s; \ -}) - -#define STORE_INT(_buf, __i) \ -({ \ - int __si = SWAP_32(__i); \ - memcpy(_buf, &__si, sizeof(int)); \ - _buf += sizeof(int); \ -}) - typedef enum { FTYPE_UNKNOWN,