Modify macro to prevent simple-but-hard-to-find bugs

One of them is to forget to replace the struct name during a line copy,
leading to write bad data in the recording file and to its corruption.
This commit is contained in:
Daniel Zaoui 2016-09-22 07:52:27 +03:00
parent 95327a0f7c
commit 1ad03a2e49
1 changed files with 26 additions and 43 deletions

View File

@ -96,19 +96,19 @@ _is_hook_duplicate(const Variant_st *v, Tsuite_Event_Type ev_type, const void *i
} }
/* Adding variant to list, this list is later written to EET file */ /* Adding variant to list, this list is later written to EET file */
#define ADD_TO_LIST(EVT_TYPE, EVT_STRUCT_NAME, INFO) \ #define ADD_TO_LIST(EVT_TYPE, INFO) \
do { /* This macro will add event to EET data list */ \ do { /* This macro will add event to EET data list */ \
if (vr_list && _hook_setting->recording) \ if (vr_list && _hook_setting->recording) \
{ \ { \
const Variant_st *prev_v = eina_list_last_data_get(vr_list->variant_list); \ const Variant_st *prev_v = eina_list_last_data_get(vr_list->variant_list); \
if (!prev_v || !_is_hook_duplicate(prev_v, EVT_TYPE, &INFO, sizeof(EVT_STRUCT_NAME))) \ if (!prev_v || !_is_hook_duplicate(prev_v, EVT_TYPE, &INFO, sizeof(INFO))) \
{ \ { \
printf("Recording %s\n", tsuite_event_mapping_type_str_get(EVT_TYPE)); \ printf("Recording %s\n", tsuite_event_mapping_type_str_get(EVT_TYPE)); \
Variant_st *v = malloc(sizeof(Variant_st)); \ Variant_st *v = malloc(sizeof(Variant_st)); \
v->data = malloc(sizeof(EVT_STRUCT_NAME)); \ v->data = malloc(sizeof(INFO)); \
_variant_type_set(tsuite_event_mapping_type_str_get(EVT_TYPE), \ _variant_type_set(tsuite_event_mapping_type_str_get(EVT_TYPE), \
&v->t, EINA_FALSE); \ &v->t, EINA_FALSE); \
memcpy(v->data, &INFO, sizeof(EVT_STRUCT_NAME)); \ memcpy(v->data, &INFO, sizeof(INFO)); \
vr_list->variant_list = eina_list_append(vr_list->variant_list, v); \ vr_list->variant_list = eina_list_append(vr_list->variant_list, v); \
} \ } \
} \ } \
@ -444,7 +444,7 @@ _event_pointer_cb(void *data, const Efl_Event *event)
int x = 0, y = 0; int x = 0, y = 0;
efl_input_pointer_position_get(evp, &x, &y); efl_input_pointer_position_get(evp, &x, &y);
multi_move t = { tool, x, y, rad, radx, rady, pres, ang, fx, fy, timestamp, n_evas }; multi_move t = { tool, x, y, rad, radx, rady, pres, ang, fx, fy, timestamp, n_evas };
if (t.n_evas >= 0) ADD_TO_LIST(evt, multi_move, t); if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
break; break;
} }
case EFL_POINTER_ACTION_DOWN: case EFL_POINTER_ACTION_UP: case EFL_POINTER_ACTION_DOWN: case EFL_POINTER_ACTION_UP:
@ -457,13 +457,13 @@ _event_pointer_cb(void *data, const Efl_Event *event)
Efl_Pointer_Flags flags = efl_input_pointer_button_flags_get(evp); Efl_Pointer_Flags flags = efl_input_pointer_button_flags_get(evp);
multi_event t = { tool, b, x, y, rad, radx, rady, pres, ang, multi_event t = { tool, b, x, y, rad, radx, rady, pres, ang,
fx, fy, flags, timestamp, n_evas }; fx, fy, flags, timestamp, n_evas };
if (t.n_evas >= 0) ADD_TO_LIST(evt, multi_event, t); if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
break; break;
} }
case EFL_POINTER_ACTION_IN: case EFL_POINTER_ACTION_OUT: case EFL_POINTER_ACTION_IN: case EFL_POINTER_ACTION_OUT:
{ {
mouse_in_mouse_out t = { timestamp, n_evas }; mouse_in_mouse_out t = { timestamp, n_evas };
if (t.n_evas >= 0) ADD_TO_LIST(evt, mouse_in_mouse_out, t); if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
break; break;
} }
case EFL_POINTER_ACTION_WHEEL: case EFL_POINTER_ACTION_WHEEL:
@ -471,7 +471,7 @@ _event_pointer_cb(void *data, const Efl_Event *event)
int direction = efl_input_pointer_wheel_direction_get(evp); int direction = efl_input_pointer_wheel_direction_get(evp);
int z = efl_input_pointer_wheel_delta_get(evp); int z = efl_input_pointer_wheel_delta_get(evp);
mouse_wheel t = { direction, z, timestamp, n_evas }; mouse_wheel t = { direction, z, timestamp, n_evas };
if (t.n_evas >= 0) ADD_TO_LIST(evt, mouse_wheel, t); if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
break; break;
} }
default: default:
@ -498,8 +498,7 @@ _event_key_cb(void *data, const Efl_Event *event)
printf("Take Screenshot: %s timestamp=<%u>\n", __func__, timestamp); printf("Take Screenshot: %s timestamp=<%u>\n", __func__, timestamp);
#endif #endif
take_screenshot t = { timestamp, n_evas }; take_screenshot t = { timestamp, n_evas };
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(TSUITE_EVENT_TAKE_SHOT, t);
ADD_TO_LIST(TSUITE_EVENT_TAKE_SHOT, take_screenshot, t);
return; return;
} }
if (!strcmp(key, SAVE_KEY_STR)) if (!strcmp(key, SAVE_KEY_STR))
@ -530,7 +529,7 @@ _event_key_cb(void *data, const Efl_Event *event)
t.compose = eina_stringshare_add(efl_input_key_compose_get(evk)); t.compose = eina_stringshare_add(efl_input_key_compose_get(evk));
t.keycode = efl_input_key_code_get(evk); t.keycode = efl_input_key_code_get(evk);
t.n_evas = n_evas; t.n_evas = n_evas;
if (t.n_evas >= 0) ADD_TO_LIST(evt, key_down_key_up_with_keycode, t); if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
} }
} }
@ -953,8 +952,7 @@ evas_event_feed_mouse_in(Evas *e, unsigned int timestamp, const void *data)
#endif #endif
mouse_in_mouse_out t = { timestamp, evas_list_find(e) }; mouse_in_mouse_out t = { timestamp, evas_list_find(e) };
int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_IN); int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_IN);
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, mouse_in_mouse_out, t);
void (*orig) (Evas *e, unsigned int timestamp, const void *data) = void (*orig) (Evas *e, unsigned int timestamp, const void *data) =
dlsym(RTLD_NEXT, __func__); dlsym(RTLD_NEXT, __func__);
@ -971,8 +969,7 @@ evas_event_feed_mouse_out(Evas *e, unsigned int timestamp, const void *data)
#endif #endif
mouse_in_mouse_out t = { timestamp, evas_list_find(e) }; mouse_in_mouse_out t = { timestamp, evas_list_find(e) };
int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_OUT); int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_OUT);
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, mouse_in_mouse_out, t);
void (*orig) (Evas *e, unsigned int timestamp, const void *data) = void (*orig) (Evas *e, unsigned int timestamp, const void *data) =
dlsym(RTLD_NEXT, __func__); dlsym(RTLD_NEXT, __func__);
@ -990,8 +987,7 @@ evas_event_feed_mouse_down(Evas *e, int b, Evas_Button_Flags flags,
#endif #endif
mouse_down_mouse_up t = { b, flags, timestamp, evas_list_find(e) }; mouse_down_mouse_up t = { b, flags, timestamp, evas_list_find(e) };
int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_DOWN); int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_DOWN);
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, mouse_down_mouse_up, t);
void (*orig) (Evas *e, int b, Evas_Button_Flags flags, void (*orig) (Evas *e, int b, Evas_Button_Flags flags,
unsigned int timestamp, const void *data) = unsigned int timestamp, const void *data) =
@ -1010,8 +1006,7 @@ evas_event_feed_mouse_up(Evas *e, int b, Evas_Button_Flags flags,
#endif #endif
mouse_down_mouse_up t = { b, flags, timestamp, evas_list_find(e) }; mouse_down_mouse_up t = { b, flags, timestamp, evas_list_find(e) };
int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_UP); int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_UP);
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, mouse_down_mouse_up, t);
void (*orig) (Evas *e, int b, Evas_Button_Flags flags, void (*orig) (Evas *e, int b, Evas_Button_Flags flags,
unsigned int timestamp, const void *data) = unsigned int timestamp, const void *data) =
@ -1030,8 +1025,7 @@ evas_event_feed_mouse_move(Evas *e, int x, int y, unsigned int timestamp,
printf("Calling %s timestamp=<%u>\n", __func__, timestamp); printf("Calling %s timestamp=<%u>\n", __func__, timestamp);
#endif #endif
int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_MOVE); int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_MOVE);
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, mouse_move, t);
void (*orig) (Evas *e, int x, int y, unsigned int timestamp, void (*orig) (Evas *e, int x, int y, unsigned int timestamp,
const void *data) = dlsym(RTLD_NEXT, __func__); const void *data) = dlsym(RTLD_NEXT, __func__);
@ -1049,8 +1043,7 @@ evas_event_input_mouse_move(Evas *e, int x, int y, unsigned int timestamp,
printf("Calling %s timestamp=<%u>\n", __func__, timestamp); printf("Calling %s timestamp=<%u>\n", __func__, timestamp);
#endif #endif
int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_MOVE); int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_MOVE);
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, mouse_move, t);
void (*orig) (Evas *e, int x, int y, unsigned int timestamp, void (*orig) (Evas *e, int x, int y, unsigned int timestamp,
const void *data) = dlsym(RTLD_NEXT, __func__); const void *data) = dlsym(RTLD_NEXT, __func__);
@ -1067,8 +1060,7 @@ evas_event_feed_mouse_wheel(Evas *e, int direction, int z,
#endif #endif
mouse_wheel t = { direction, z, timestamp, evas_list_find(e) }; mouse_wheel t = { direction, z, timestamp, evas_list_find(e) };
int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_WHEEL); int evt = tsuite_event_type_get(EVAS_CALLBACK_MOUSE_WHEEL);
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, mouse_wheel, t);
void (*orig) (Evas *e, int direction, int z, unsigned int timestamp, void (*orig) (Evas *e, int direction, int z, unsigned int timestamp,
const void *data) = dlsym(RTLD_NEXT, __func__); const void *data) = dlsym(RTLD_NEXT, __func__);
@ -1090,8 +1082,7 @@ evas_event_feed_multi_down(Evas *e, int d, int x, int y,
fx, fy, flags, timestamp, evas_list_find(e)}; fx, fy, flags, timestamp, evas_list_find(e)};
int evt = tsuite_event_type_get(EVAS_CALLBACK_MULTI_DOWN); int evt = tsuite_event_type_get(EVAS_CALLBACK_MULTI_DOWN);
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, multi_event, t);
void (*orig) (Evas *e, int d, int x, int y, double rad, void (*orig) (Evas *e, int d, int x, int y, double rad,
double radx, double rady, double pres, double ang, double radx, double rady, double pres, double ang,
@ -1113,8 +1104,7 @@ evas_event_feed_multi_up(Evas *e, int d, int x, int y,
#endif #endif
multi_event t = { d, 0, x, y, rad, radx, rady, pres, ang, fx, fy, flags, timestamp, evas_list_find(e) }; multi_event t = { d, 0, x, y, rad, radx, rady, pres, ang, fx, fy, flags, timestamp, evas_list_find(e) };
int evt = tsuite_event_type_get(EVAS_CALLBACK_MULTI_UP); int evt = tsuite_event_type_get(EVAS_CALLBACK_MULTI_UP);
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, multi_event, t);
void (*orig) (Evas *e, int d, int x, int y, double rad, void (*orig) (Evas *e, int d, int x, int y, double rad,
double radx, double rady, double pres, double ang, double radx, double rady, double pres, double ang,
@ -1136,8 +1126,7 @@ evas_event_feed_multi_move(Evas *e, int d, int x, int y, double rad,
#endif #endif
multi_move t = { d, x, y, rad, radx, rady, pres, ang, fx, fy, timestamp, evas_list_find(e) }; multi_move t = { d, x, y, rad, radx, rady, pres, ang, fx, fy, timestamp, evas_list_find(e) };
int evt = tsuite_event_type_get(EVAS_CALLBACK_MULTI_MOVE); int evt = tsuite_event_type_get(EVAS_CALLBACK_MULTI_MOVE);
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, multi_move, t);
void (*orig) (Evas *e, int d, int x, int y, double rad, void (*orig) (Evas *e, int d, int x, int y, double rad,
double radx, double rady, double pres, double ang, double radx, double rady, double pres, double ang,
@ -1167,8 +1156,7 @@ evas_event_feed_key_down(Evas *e, const char *keyname, const char *key,
printf("Take Screenshot: %s timestamp=<%u>\n", __func__, timestamp); printf("Take Screenshot: %s timestamp=<%u>\n", __func__, timestamp);
#endif #endif
take_screenshot t = { timestamp, evas_list_find(e) }; take_screenshot t = { timestamp, evas_list_find(e) };
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(TSUITE_EVENT_TAKE_SHOT, t);
ADD_TO_LIST(TSUITE_EVENT_TAKE_SHOT, take_screenshot, t);
orig(e, keyname, key, string, compose, timestamp, data); orig(e, keyname, key, string, compose, timestamp, data);
return; return;
@ -1196,8 +1184,7 @@ evas_event_feed_key_down(Evas *e, const char *keyname, const char *key,
t.string = eina_stringshare_add(string); t.string = eina_stringshare_add(string);
t.compose = eina_stringshare_add(compose); t.compose = eina_stringshare_add(compose);
t.n_evas = evas_list_find(e); t.n_evas = evas_list_find(e);
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, key_down_key_up, t);
} }
orig(e, keyname, key, string, compose, timestamp, data); orig(e, keyname, key, string, compose, timestamp, data);
@ -1246,8 +1233,7 @@ evas_event_feed_key_up(Evas *e, const char *keyname, const char *key,
t.string = eina_stringshare_add(string); t.string = eina_stringshare_add(string);
t.compose = eina_stringshare_add(compose); t.compose = eina_stringshare_add(compose);
t.n_evas = evas_list_find(e); t.n_evas = evas_list_find(e);
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, key_down_key_up, t);
} }
orig(e, keyname, key, string, compose, timestamp, data); orig(e, keyname, key, string, compose, timestamp, data);
@ -1273,8 +1259,7 @@ evas_event_feed_key_down_with_keycode(Evas *e, const char *keyname, const char *
printf("Take Screenshot: %s timestamp=<%u>\n", __func__, timestamp); printf("Take Screenshot: %s timestamp=<%u>\n", __func__, timestamp);
#endif #endif
take_screenshot t = { timestamp, evas_list_find(e) }; take_screenshot t = { timestamp, evas_list_find(e) };
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(TSUITE_EVENT_TAKE_SHOT, t);
ADD_TO_LIST(TSUITE_EVENT_TAKE_SHOT, take_screenshot, t);
orig(e, keyname, key, string, compose, timestamp, data, keycode); orig(e, keyname, key, string, compose, timestamp, data, keycode);
return; return;
@ -1303,8 +1288,7 @@ evas_event_feed_key_down_with_keycode(Evas *e, const char *keyname, const char *
t.compose = eina_stringshare_add(compose); t.compose = eina_stringshare_add(compose);
t.n_evas = evas_list_find(e); t.n_evas = evas_list_find(e);
t.keycode = keycode; t.keycode = keycode;
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, key_down_key_up, t);
} }
orig(e, keyname, key, string, compose, timestamp, data, keycode); orig(e, keyname, key, string, compose, timestamp, data, keycode);
@ -1354,8 +1338,7 @@ evas_event_feed_key_up_with_keycode(Evas *e, const char *keyname, const char *ke
t.compose = eina_stringshare_add(compose); t.compose = eina_stringshare_add(compose);
t.n_evas = evas_list_find(e); t.n_evas = evas_list_find(e);
t.keycode = keycode; t.keycode = keycode;
if (t.n_evas >= 0) if (t.n_evas >= 0) ADD_TO_LIST(evt, t);
ADD_TO_LIST(evt, key_down_key_up, t);
} }
orig(e, keyname, key, string, compose, timestamp, data, keycode); orig(e, keyname, key, string, compose, timestamp, data, keycode);