pui*: define PUI_MAGICs and add check logic of them 15/220715/1
authorSung-Jin Park <sj76.park@samsung.com>
Wed, 16 Oct 2019 10:43:01 +0000 (19:43 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Fri, 20 Dec 2019 09:57:44 +0000 (18:57 +0900)
Change-Id: Ia74fc9e6756fa9929632351505b574989386e21e
Signed-off-by: Sung-Jin Park <sj76.park@samsung.com>
src/PUI.c
src/PUI_ani.c
src/PUI_backend.c
src/PUI_internal.h

index 9eab3e0..cf76ce9 100644 (file)
--- a/src/PUI.c
+++ b/src/PUI.c
@@ -48,6 +48,59 @@ int PUI_EVENT_ANI_READY_TO_RESUME = 0;
 static int KEY_WL_BUFFER = 0xabcdbeaf;
 static int KEY_CLIENT = 0xdcbabeaf;
 
+static const char *
+_pui_magic_string_get(PUI_Magic m)
+{
+       switch (m)
+       {
+               case PUI_MAGIC_NONE:
+                       return "None (Freed Object)";
+                       break;
+
+               case PUI_MAGIC_PUI_M:
+                       return "PUI MODULE (PUI_M)";
+                       break;
+
+               case PUI_MAGIC_PUI_H:
+                       return "PUI HANDLE (PUI_H)";
+                       break;
+
+               case PUI_MAGIC_ANI_H:
+                       return "PUI ANI HANDLE (ANI_H)";
+                       break;
+
+               case PUI_MAGIC_ANI_T:
+                       return "PUI ANI RUNTIME HANDLE (ANI_T)";
+                       break;
+
+               default:
+                       return "<Unknown>";
+       }
+}
+
+PUI_API void
+_pui_magic_fail(const void *p, PUI_Magic m, PUI_Magic req_m, const char *fname)
+{
+       pui_err(" ### PUI ERROR : PUI Magic Check Failed !!! in %s().\n", fname);
+
+       if (!p)
+               pui_err("   Given handle/pointer is NULL !\n");
+       else if (m == PUI_MAGIC_NONE)
+               pui_err("   Given handle/pointer has been freed !\n");
+       else if (m != req_m)
+               pui_err("   Given handle/pointer is wrong type\n"
+                               "      Expected: %08x - %s\n"
+                               "      Supplied: %08x - %s",
+                               (unsigned int)req_m, _pui_magic_string_get(req_m),
+                               (unsigned int)m, _pui_magic_string_get(m));
+
+       //if (getenv("ECORE_ERROR_ABORT"))
+       {
+               pui_err("### Abort ! ###\n");
+               abort();
+       }
+}
+
 pui_error_string
 pui_error_to_string(pui_error e)
 {
@@ -109,9 +162,9 @@ pui_display_get_buffer(pui_h handle)
        tbm_surface_h surface;
        pui_ani_control_buffer *buffer = NULL;
 
-       if (!handle)
+       if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
        {
-               pui_err("Error : PUI_INT_ERROR_INVALID_HANDLE\n");
+               PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
                return NULL;
        }
 
@@ -145,9 +198,9 @@ pui_display_get_buffer(pui_h handle)
 pui_error
 pui_display_set_buffer(pui_h handle, pui_ani_control_buffer *buffer)
 {
-       if (!handle)
+       if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
        {
-               pui_err("Error : PUI_ERROR_INVALID_HANDLE\n");
+               PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
                return PUI_ERROR_INVALID_HANDLE;
        }
 
@@ -172,9 +225,9 @@ pui_display_update(pui_h handle)
        tbm_surface_error_e ret;
        struct wl_buffer *wl_buffer = NULL;
 
-       if (!handle)
+       if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
        {
-               pui_err("Error : PUI_ERROR_INVALID_HANDLE\n");
+               PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
                return PUI_ERROR_INVALID_HANDLE;
        }
 
@@ -247,9 +300,9 @@ pui_display_manual_render_set(pui_h handle, pui_bool set)
 {
        pui_ani_h ani_h = NULL;
 
-       if (!handle)
+       if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
        {
-               pui_err("Error : PUI_ERROR_INVALID_HANDLE\n");
+               PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
                return PUI_ERROR_INVALID_HANDLE;
        }
 
@@ -273,9 +326,9 @@ pui_display_manual_render_set(pui_h handle, pui_bool set)
 pui_bool
 pui_display_manual_render_get(pui_h handle)
 {
-       if (!handle)
+       if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
        {
-               pui_err("Error : PUI_ERROR_INVALID_HANDLE\n");
+               PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
                return 0;
        }
 
@@ -290,8 +343,15 @@ pui_display_geometry_get(pui_h handle, int *width, int *height)
 
        *width = 0;
        *height = 0;
+       (void) handle;
+
+       if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
+       {
+               PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
+               return 0;
+       }
 
-       if (!pui_module || !pui_module->backend_module_data) {
+       if (!pui_module->backend_module_data) {
                pui_err("pui module data is not loaded\n");
                return 0;
        }
@@ -318,6 +378,12 @@ pui_create(Ecore_Wl2_Window *win)
                return NULL;
        }
 
+       if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
+       {
+               PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
+               return NULL;
+       }
+
        wl_tbm_client = wayland_tbm_client_init(ecore_wl2_display_get(ewd));
 
        if (!wl_tbm_client)
@@ -350,6 +416,7 @@ pui_create(Ecore_Wl2_Window *win)
                goto err;
        }
 
+       PUI_MAGIC_SET(handle, PUI_MAGIC_PUI_H);
        return handle;
 
 err:
@@ -363,8 +430,11 @@ pui_destroy(pui_h handle)
 {
        pui_ani_h ani_h = NULL;
 
-       if (!handle)
+       if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
+       {
+               PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
                return;
+       }
 
        EINA_LIST_FREE(handle->ani_handles, ani_h)
        {
@@ -382,6 +452,7 @@ pui_destroy(pui_h handle)
                handle->wl_tbm_client = NULL;
        }
 
+       PUI_MAGIC_SET(handle, PUI_MAGIC_NONE);
        free(handle);
 }
 
@@ -400,6 +471,11 @@ _pui_load_backend_module(void)
 
        pui_backend_module_data *backend_module_data = NULL;
 
+       if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
+       {
+               PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
+               return;
+       }
 
        module_info = dlopen(DEFAULT_LIB, RTLD_LAZY);
 
@@ -465,9 +541,9 @@ err:
 static void
 _pui_unload_backend_module(void)
 {
-       if (!pui_module)
+       if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
        {
-               pui_err("Invalid pui module !\n");
+               PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
                return;
        }
 
@@ -487,7 +563,13 @@ _pui_load_backend_collect_animations(void)
 {
        pui_int_error ret;
 
-       if (!pui_module || !pui_module->backend_module_data) {
+       if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
+       {
+               PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
+               return;
+       }
+
+       if (!pui_module->backend_module_data) {
                pui_err("pui module data is not loaded\n");
                return;
        }
@@ -575,6 +657,8 @@ pui_init(void)
                goto error;
        }
 
+       PUI_MAGIC_SET(pui_module, PUI_MAGIC_PUI_M);
+
        ecore_wl2_init();
 
        _pui_event_init();
@@ -597,9 +681,9 @@ pui_shutdown(void)
                return 0;
        }
 
-       if (!pui_module)
+       if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
        {
-               pui_err("Invalid pui module data !\n");
+               PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
                return _pui_init_count;
        }
 
@@ -612,6 +696,7 @@ pui_shutdown(void)
 
        ecore_wl2_shutdown();
 
+       PUI_MAGIC_SET(pui_module, PUI_MAGIC_NONE);
        free(pui_module);
 
        return _pui_init_count;
index 325274e..40b0a3e 100644 (file)
@@ -78,9 +78,9 @@ pui_ani_get_buffer(pui_ani_h ani_h)
        pui_h handle = NULL;
        pui_ani_control_buffer *buffer = NULL;
 
-       if (!ani_h)
+       if (!PUI_MAGIC_CHECK(ani_h, PUI_MAGIC_ANI_H))
        {
-               pui_err("Invalid pui ani handle !\n");
+               PUI_MAGIC_FAIL(ani_h, PUI_MAGIC_ANI_H, __FUNCTION__);
                return NULL;
        }
 
@@ -96,7 +96,20 @@ pui_ani_set_buffer(pui_ani_h ani_h, pui_ani_control_buffer *buffer)
        pui_error e = PUI_ERROR_NONE;
        pui_h handle = NULL;
 
+       if (!PUI_MAGIC_CHECK(ani_h, PUI_MAGIC_ANI_H))
+       {
+               PUI_MAGIC_FAIL(ani_h, PUI_MAGIC_ANI_H, __FUNCTION__);
+               return PUI_ERROR_INVALID_HANDLE;
+       }
+
        handle = ani_h->pui_handle;
+
+       if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
+       {
+               PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
+               return PUI_ERROR_INVALID_HANDLE;
+       }
+
        e = pui_display_set_buffer(handle, buffer);
 
        return _pui_ani_error_to_int_error(e);
@@ -128,9 +141,9 @@ _pui_ani_frame_cb(void *data)
 
        pui_ani_t *ani = (pui_ani_t *)data;
 
-       if (!ani)
+       if (!PUI_MAGIC_CHECK(ani, PUI_MAGIC_ANI_T))
        {
-               pui_err("Invalid pui ani !\n");
+               PUI_MAGIC_FAIL(ani, PUI_MAGIC_ANI_T, __FUNCTION__);
                return ECORE_CALLBACK_CANCEL;
        }
 
@@ -183,9 +196,9 @@ pui_ani_add_frame_cb(pui_ani_t *ani, pui_bool (*frame_cb)(void *data, int serial
 {
        Ecore_Timer *timer = NULL;
 
-       if (!ani)
+       if (!PUI_MAGIC_CHECK(ani, PUI_MAGIC_ANI_T))
        {
-               pui_err("Invalid put ani !\n");
+               PUI_MAGIC_FAIL(ani, PUI_MAGIC_ANI_T, __FUNCTION__);
                return 0;
        }
 
@@ -222,9 +235,9 @@ pui_ani_add_frame_cb(pui_ani_t *ani, pui_bool (*frame_cb)(void *data, int serial
 void
 pui_ani_remove_frame_cb(pui_ani_t *ani)
 {
-       if (!ani)
+       if (!PUI_MAGIC_CHECK(ani, PUI_MAGIC_ANI_T))
        {
-               pui_err("Invalid put ani !\n");
+               PUI_MAGIC_FAIL(ani, PUI_MAGIC_ANI_T, __FUNCTION__);
                return;
        }
 
@@ -245,8 +258,17 @@ pui_ani_remove_frame_cb(pui_ani_t *ani)
 pui_id
 pui_ani_get_id(pui_ani_h ani_h)
 {
-       if (!ani_h || !ani_h->ani)
+       if (!PUI_MAGIC_CHECK(ani_h, PUI_MAGIC_ANI_H))
+       {
+               PUI_MAGIC_FAIL(ani_h, PUI_MAGIC_ANI_H, __FUNCTION__);
                return NULL;
+       }
+
+       if (!PUI_MAGIC_CHECK(ani_h->ani, PUI_MAGIC_ANI_T))
+       {
+               PUI_MAGIC_FAIL(ani_h->ani, PUI_MAGIC_ANI_T, __FUNCTION__);
+               return NULL;
+       }
 
        return ani_h->ani->id;
 }
@@ -254,8 +276,17 @@ pui_ani_get_id(pui_ani_h ani_h)
 pui_ani_cmd
 pui_ani_get_cmd(pui_ani_h ani_h)
 {
-       if (!ani_h || !ani_h->ani)
+       if (!PUI_MAGIC_CHECK(ani_h, PUI_MAGIC_ANI_H))
+       {
+               PUI_MAGIC_FAIL(ani_h, PUI_MAGIC_ANI_H, __FUNCTION__);
+               return PUI_ANI_CMD_NONE;
+       }
+
+       if (!PUI_MAGIC_CHECK(ani_h->ani, PUI_MAGIC_ANI_T))
+       {
+               PUI_MAGIC_FAIL(ani_h->ani, PUI_MAGIC_ANI_T, __FUNCTION__);
                return PUI_ANI_CMD_NONE;
+       }
 
        return ani_h->ani->cmd;
 }
@@ -263,8 +294,17 @@ pui_ani_get_cmd(pui_ani_h ani_h)
 int
 pui_ani_get_repeat(pui_ani_h ani_h)
 {
-       if (!ani_h || !ani_h->ani)
+       if (!PUI_MAGIC_CHECK(ani_h, PUI_MAGIC_ANI_H))
+       {
+               PUI_MAGIC_FAIL(ani_h, PUI_MAGIC_ANI_H, __FUNCTION__);
                return 0;
+       }
+
+       if (!PUI_MAGIC_CHECK(ani_h->ani, PUI_MAGIC_ANI_T))
+       {
+               PUI_MAGIC_FAIL(ani_h->ani, PUI_MAGIC_ANI_T, __FUNCTION__);
+               return 0;
+       }
 
        return ani_h->ani->repeat;
 }
@@ -272,8 +312,11 @@ pui_ani_get_repeat(pui_ani_h ani_h)
 pui_backend_ani_data *
 pui_ani_get_ani_data(pui_ani_t *ani)
 {
-       if (!ani)
+       if (!PUI_MAGIC_CHECK(ani, PUI_MAGIC_ANI_T))
+       {
+               PUI_MAGIC_FAIL(ani, PUI_MAGIC_ANI_T, __FUNCTION__);
                return NULL;
+       }
 
        return ani->ani_data;
 }
@@ -285,9 +328,9 @@ pui_ani_status_update(pui_ani_t *ani, pui_ani_status status)
        pui_ani_h ani_h;
        PUI_Event_Animation_Status *e = NULL;
 
-       if (!ani)
+       if (!PUI_MAGIC_CHECK(ani, PUI_MAGIC_ANI_T))
        {
-               pui_err("Invalid pui ani !\n");
+               PUI_MAGIC_FAIL(ani, PUI_MAGIC_ANI_T, __FUNCTION__);
                return;
        }
 
@@ -347,9 +390,9 @@ pui_ani_status_get(pui_ani_t *ani)
 {
        pui_ani_status status = PUI_ANI_STATUS_UNKNOWN;
 
-       if (!ani)
+       if (!PUI_MAGIC_CHECK(ani, PUI_MAGIC_ANI_T))
        {
-               pui_err("Invalid pui ani !\n");
+               PUI_MAGIC_FAIL(ani, PUI_MAGIC_ANI_T, __FUNCTION__);
                return status;
        }
 
@@ -364,8 +407,11 @@ _pui_ani_control_with_force(pui_ani_h ani_h, pui_ani_cmd cmd, int repeat, pui_bo
        pui_h handle = NULL;
        pui_backend_ani_func *ani_func = NULL;
 
-       if (!ani_h)
+       if (!PUI_MAGIC_CHECK(ani_h, PUI_MAGIC_ANI_H))
+       {
+               PUI_MAGIC_FAIL(ani_h, PUI_MAGIC_ANI_H, __FUNCTION__);
                return PUI_ERROR_INVALID_ANI_HANDLE;
+       }
 
        if (cmd < PUI_ANI_CMD_START || cmd >= PUI_ANI_CMD_LAST)
        {
@@ -382,9 +428,21 @@ _pui_ani_control_with_force(pui_ani_h ani_h, pui_ani_cmd cmd, int repeat, pui_bo
        handle = ani_h->pui_handle;
        ani = ani_h->ani;
 
-       if (!ani || !ani->ani_data)
+       if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
        {
-               pui_err("Invalid ani or ani_data !\n");
+               PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
+               return PUI_ERROR_INTERNAL;
+       }
+
+       if (!PUI_MAGIC_CHECK(ani, PUI_MAGIC_ANI_T))
+       {
+               PUI_MAGIC_FAIL(ani, PUI_MAGIC_ANI_T, __FUNCTION__);
+               return PUI_ERROR_INTERNAL;
+       }
+
+       if (!ani->ani_data)
+       {
+               pui_err("Invalid ani_data !\n");
                return PUI_ERROR_INTERNAL;
        }
 
@@ -484,6 +542,24 @@ _cb_visibility_change(void *data, int type EINA_UNUSED, void *event)
        Ecore_Wl2_Event_Window_Visibility_Change *ev;
        PUI_Event_Animation_Status *e = NULL;
 
+       if (!PUI_MAGIC_CHECK(ani_h, PUI_MAGIC_ANI_H))
+       {
+               PUI_MAGIC_FAIL(ani_h, PUI_MAGIC_ANI_H, __FUNCTION__);
+               return ECORE_CALLBACK_PASS_ON;
+       }
+
+       if (!PUI_MAGIC_CHECK(ani, PUI_MAGIC_ANI_T))
+       {
+               PUI_MAGIC_FAIL(ani, PUI_MAGIC_ANI_T, __FUNCTION__);
+               return ECORE_CALLBACK_PASS_ON;
+       }
+
+       if (!PUI_MAGIC_CHECK(ph, PUI_MAGIC_PUI_H))
+       {
+               PUI_MAGIC_FAIL(ph, PUI_MAGIC_PUI_H, __FUNCTION__);
+               return ECORE_CALLBACK_PASS_ON;
+       }
+
        ev = event;
 
        /* check if this is needed */
@@ -530,9 +606,9 @@ _pui_ani_event_handlers_init(pui_ani_h ani_h)
 {
        Ecore_Event_Handler *h = NULL;
 
-       if (!ani_h)
+       if (!PUI_MAGIC_CHECK(ani_h, PUI_MAGIC_ANI_H))
        {
-               pui_err("Invalid handle !\n");
+               PUI_MAGIC_FAIL(ani_h, PUI_MAGIC_ANI_H, __FUNCTION__);
                return;
        }
 
@@ -547,9 +623,9 @@ _pui_ani_event_handlers_init(pui_ani_h ani_h)
 static void
 _pui_ani_event_handlers_shutdown(pui_ani_h ani_h)
 {
-       if (!ani_h)
+       if (!PUI_MAGIC_CHECK(ani_h, PUI_MAGIC_ANI_H))
        {
-               pui_err("Invalid handle !\n");
+               PUI_MAGIC_FAIL(ani_h, PUI_MAGIC_ANI_H, __FUNCTION__);
                return;
        }
 
@@ -570,9 +646,15 @@ pui_ani_create(pui_h handle, pui_id id)
        pui_ani_t *ani = NULL;
        pui_backend_ani_data *ani_data = NULL;
 
-       if (!handle || !handle->backend_module_data)
+       if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
        {
-               pui_err("Invalid pui handle or backend module data !\n");
+               PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
+               return NULL;
+       }
+
+       if (!handle->backend_module_data)
+       {
+               pui_err("Invalid backend module data !\n");
                return NULL;
        }
 
@@ -596,6 +678,8 @@ pui_ani_create(pui_h handle, pui_id id)
        ani_h->pui_handle = handle;
        ani_h->ecore_event_hdls = NULL;
 
+       PUI_MAGIC_SET(ani_h, PUI_MAGIC_ANI_H);
+
        _pui_ani_event_handlers_init(ani_h);
 
        ani = (pui_ani_t *)calloc(1, sizeof(pui_ani_t));
@@ -617,6 +701,8 @@ pui_ani_create(pui_h handle, pui_id id)
 
        handle->ani_handles = eina_list_append(handle->ani_handles, ani_h);
 
+       PUI_MAGIC_SET(ani, PUI_MAGIC_ANI_T);
+
        return ani_h;
 
 err:
@@ -626,7 +712,10 @@ err:
        }
 
        if (ani_h)
+       {
+               PUI_MAGIC_SET(ani_h, PUI_MAGIC_NONE);
                free(ani_h);
+       }
 
        return NULL;
 }
@@ -638,12 +727,27 @@ pui_ani_destroy(pui_ani_h ani_h)
        pui_ani_t *ani = NULL;
        pui_backend_module_data *backend_module_data = NULL;
 
-       if (!ani_h || !ani_h->pui_handle)
+       if (!PUI_MAGIC_CHECK(ani_h, PUI_MAGIC_ANI_H))
+       {
+               PUI_MAGIC_FAIL(ani_h, PUI_MAGIC_ANI_H, __FUNCTION__);
                return;
+       }
 
        handle = ani_h->pui_handle;
        ani = ani_h->ani;
 
+       if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
+       {
+               PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
+               return;
+       }
+
+       if (!PUI_MAGIC_CHECK(ani, PUI_MAGIC_ANI_T))
+       {
+               PUI_MAGIC_FAIL(ani, PUI_MAGIC_ANI_T, __FUNCTION__);
+               return;
+       }
+
        /* stop the animation being played already if any */
        if (ani->status == PUI_ANI_STATUS_STARTED || ani->status == PUI_ANI_STATUS_RUNNING)
                pui_ani_control(ani_h, PUI_ANI_CMD_STOP, 0);
@@ -658,6 +762,7 @@ pui_ani_destroy(pui_ani_h ani_h)
                ani->frame_cb_timer = NULL;
        }
 
+       PUI_MAGIC_SET(ani_h->ani, PUI_MAGIC_NONE);
        free(ani_h->ani);
 
        _pui_ani_event_handlers_shutdown(ani_h);
@@ -670,6 +775,8 @@ pui_ani_destroy(pui_ani_h ani_h)
 
        handle->ani_handles = eina_list_remove(handle->ani_handles, ani_h);
 
+       PUI_MAGIC_SET(ani_h, PUI_MAGIC_NONE);
+
        free(ani_h->id);
        free(ani_h);
 }
index e49449e..371daf4 100644 (file)
@@ -31,6 +31,12 @@ pui_backend_ani_get_buffer(pui_ani_t *ani)
 {
        pui_ani_control_buffer *buffer = NULL;
 
+       if (!PUI_MAGIC_CHECK(ani, PUI_MAGIC_ANI_T))
+       {
+               PUI_MAGIC_FAIL(ani, PUI_MAGIC_ANI_T, __FUNCTION__);
+               return NULL;
+       }
+
        buffer = pui_ani_get_buffer(ani->ani_h);
 
        if (!buffer)
@@ -44,6 +50,12 @@ pui_backend_ani_set_buffer(pui_ani_t *ani, pui_ani_control_buffer *buffer)
 {
        pui_int_error err = PUI_INT_ERROR_NONE;
 
+       if (!PUI_MAGIC_CHECK(ani, PUI_MAGIC_ANI_T))
+       {
+               PUI_MAGIC_FAIL(ani, PUI_MAGIC_ANI_T, __FUNCTION__);
+               return PUI_INT_ERROR_INVALID_BUFFER;
+       }
+
        if (!buffer)
                return PUI_INT_ERROR_INVALID_BUFFER;
 
@@ -57,6 +69,12 @@ pui_backend_ani_update(pui_ani_t *ani)
 {
        pui_int_error err = PUI_INT_ERROR_NONE;
 
+       if (!PUI_MAGIC_CHECK(ani, PUI_MAGIC_ANI_T))
+       {
+               PUI_MAGIC_FAIL(ani, PUI_MAGIC_ANI_T, __FUNCTION__);
+               return PUI_INT_ERROR_INVALID_HANDLE;
+       }
+
        err = pui_ani_update(ani->ani_h);
 
        return err;
index 06be182..39c6af7 100644 (file)
 #define PATH_MAX 4096
 #endif
 
+#define PUI_MAGIC_NONE         0xfedc4321
+#define PUI_MAGIC_PUI_M        0xDE9BBFAE
+#define PUI_MAGIC_PUI_H        0xDE89C0AD
+#define PUI_MAGIC_ANI_H        0xDE77C1AC
+#define PUI_MAGIC_ANI_T        0xDE65C2AB
+
+typedef unsigned int PUI_Magic;
+#define PUI_MAGIC      PUI_Magic __magic
+
+#define PUI_MAGIC_SET(p, m)            (p)->__magic = (m)
+#define PUI_MAGIC_CHECK(p, m)  ((p) && ((p)->__magic == (m)))
+#define PUI_MAGIC_FAIL(p, m, fn)       _pui_magic_fail((p), (p) ? (p)->__magic : 0, (m), (fn));
+
 struct _pui_ani
 {
+       PUI_MAGIC;
+
        pui_h pui_handle;
        pui_ani_t *ani;
 
@@ -52,8 +67,9 @@ struct _pui_ani
 
 struct _pui_ani_t
 {
-       pui_ani_h ani_h;
+       PUI_MAGIC;
 
+       pui_ani_h ani_h;
        pui_id id;
        pui_ani_cmd cmd;
        int repeat;
@@ -73,6 +89,8 @@ struct _pui_ani_t
 
 struct _pui
 {
+       PUI_MAGIC;
+
        Ecore_Wl2_Window *win;
        Ecore_Wl2_Display *ewd;
        int visibility;
@@ -93,6 +111,8 @@ struct _pui
 
 struct _pui_module_data
 {
+       PUI_MAGIC;
+
        void *module_info;
        pui_backend_module *backend_module_info;
        pui_backend_module_data *backend_module_data;
@@ -102,6 +122,9 @@ struct _pui_module_data
 extern "C" {
 #endif
 
+void
+_pui_magic_fail(const void *p, PUI_Magic m, PUI_Magic req_m, const char *fname);
+
 pui_ani_control_buffer *
 pui_ani_get_buffer(pui_ani_h ani_h);