Update coding convention
authorSung-jae Park <nicesj.park@samsung.com>
Tue, 13 Aug 2013 01:18:43 +0000 (10:18 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Tue, 13 Aug 2013 01:18:43 +0000 (10:18 +0900)
Change-Id: I1f942bdc126090c661a029c1da21c80797deb332

packaging/libheap-monitor.spec
src/dlist.c
src/heap-monitor.c

index 2cc5993..d6227cf 100644 (file)
@@ -1,6 +1,6 @@
 Name: libheap-monitor
 Summary: Library for monitoring the heap usage
-Version: 0.0.14
+Version: 0.0.15
 Release: 1
 Group: HomeTF/Livebox
 License: Flora License
@@ -23,7 +23,12 @@ Monitoring the heap usage to manage them safely.(dev)
 %setup -q
 
 %build
-cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+%if 0%{?tizen_build_binary_release_type_eng}
+export CFLAGS="${CFLAGS} -DTIZEN_ENGINEER_MODE"
+export CXXFLAGS="${CXXFLAGS} -DTIZEN_ENGINEER_MODE"
+export FFLAGS="${FFLAGS} -DTIZEN_ENGINEER_MODE"
+%endif
+%cmake .
 CFLAGS+="${CFLAGS} -fvisibility=hidden -Wall -Werror -Winline -fno-builtin-malloc" make %{?jobs:-j%jobs}
 
 %install
index fa3082a..3ae571b 100644 (file)
@@ -45,8 +45,9 @@ struct dlist *dlist_append(struct dlist *list, void *data)
        struct dlist *item;
 
        item = malloc(sizeof(*item));
-       if (!item)
+       if (!item) {
                return NULL;
+       }
 
        item->next = NULL;
        item->data = data;
@@ -71,8 +72,9 @@ struct dlist *dlist_prepend(struct dlist *list, void *data)
        struct dlist *item;
 
        item = malloc(sizeof(*item));
-       if (!item)
+       if (!item) {
                return NULL;
+       }
 
        item->data = data;
 
@@ -80,8 +82,9 @@ struct dlist *dlist_prepend(struct dlist *list, void *data)
                item->prev = item;
                item->next = NULL;
        } else {
-               if (list->prev->next)
+               if (list->prev->next) {
                        list->prev->next = item;
+               }
 
                item->prev = list->prev;
                item->next = list;
@@ -95,16 +98,19 @@ struct dlist *dlist_prepend(struct dlist *list, void *data)
 
 struct dlist *dlist_remove(struct dlist *list, struct dlist *l)
 {
-       if (!list || !l)
+       if (!list || !l) {
                return NULL;
+       }
 
-       if (l == list)
+       if (l == list) {
                list = l->next;
-       else
+       } else {
                l->prev->next = l->next;
+       }
 
-       if (l->next)
+       if (l->next) {
                l->next->prev = l->prev;
+       }
        /*!
         * \note
         * If the removed entry 'l' has no next element, it is the last element.
@@ -113,8 +119,9 @@ struct dlist *dlist_remove(struct dlist *list, struct dlist *l)
         *
         * If we didn't care about this, the head element(list) can indicates the invalid element.
         */
-       else if (list)
+       else if (list) {
                list->prev = l->prev;
+       }
 
        free(l);
        return list;
@@ -126,8 +133,9 @@ struct dlist *dlist_find_data(struct dlist *list, void *data)
        void *_data;
 
        dlist_foreach(list, l, _data) {
-               if (data == _data)
+               if (data == _data) {
                        return l;
+               }
        }
 
        return NULL;
@@ -169,8 +177,9 @@ struct dlist *dlist_nth(struct dlist *l, int nth)
 
        i = 0;
        for (n = l; n; n = n->next) {
-               if (i == nth)
+               if (i == nth) {
                        return n;
+               }
                i++;
        }
 
index 9184f6e..054a76a 100644 (file)
@@ -171,8 +171,9 @@ static inline struct target *find_target_by_name(const char *name)
        struct target *target;
 
        dlist_foreach(s_info.target_list, l, target) {
-               if (!strcmp(target->name, name))
+               if (!strcmp(target->name, name)) {
                        return target;
+               }
        }
 
        return NULL;
@@ -184,8 +185,9 @@ static inline struct target *find_target_by_addr(unsigned long addr)
        struct target *target;
 
        dlist_foreach(s_info.target_list, l, target) {
-               if (target->begin <= addr && addr < target->end)
+               if (target->begin <= addr && addr < target->end) {
                        return target;
+               }
        }
 
        return NULL;
@@ -207,8 +209,9 @@ static struct target *find_target_info(void)
        register unsigned long *stack;
        register int i;
 
-       if (s_info.target_cnt <= 0)
+       if (s_info.target_cnt <= 0) {
                return NULL;
+       }
 
        stack = (unsigned long *)&ret;
 
@@ -224,8 +227,9 @@ static struct target *find_target_info(void)
                        base = 0;
                        boundary = 0;
                        if (!pthread_getattr_np(tid, &attr)) {
-                               if (!pthread_attr_getstack(&attr, (void *)&base, &size))
+                               if (!pthread_attr_getstack(&attr, (void *)&base, &size)) {
                                        boundary = base + size;
+                               }
                                pthread_attr_destroy(&attr);
                        }
                } else {
@@ -242,22 +246,26 @@ static struct target *find_target_info(void)
                        }
 
                        target = find_target_by_addr(*stack++);
-                       if (!target)
+                       if (!target) {
                                continue;
+                       }
 
-                       if (s_info.debugger)
+                       if (s_info.debugger) {
                                DbgPrint("Target[%s]: %d\n", target->name, target->usage);
+                       }
 
                        return target;
                }
        } else {
                for (i = 0; i < s_info.dump_depth; i++) {
                        target = find_target_by_addr(*(stack++));
-                       if (!target)
+                       if (!target) {
                                continue;
+                       }
 
-                       if (s_info.debugger)
+                       if (s_info.debugger) {
                                DbgPrint("[%d] Target[%s]: %d\n", i, target->name, target->usage);
+                       }
 
                        return target;
                }
@@ -278,18 +286,21 @@ static void mcheck_cb(enum mcheck_status status)
                break;
        case MCHECK_HEAD:
                target = find_target_info();
-               if (target)
+               if (target) {
                        ErrPrint("[HEAD] Inconsistency: %s\n", target->name);
+               }
                break;
        case MCHECK_TAIL:
                target = find_target_info();
-               if (target)
+               if (target) {
                        ErrPrint("[HEAD] Inconsistency: %s\n", target->name);
+               }
                break;
        case MCHECK_FREE:
                target = find_target_info();
-               if (target)
+               if (target) {
                        ErrPrint("[FREE] Inconsistency: %s\n", target->name);
+               }
                break;
        default:
                break;
@@ -301,8 +312,9 @@ static inline int MPROBE(void *ptr)
        enum mcheck_status status;
 
        status = mprobe(ptr);
-       if (status == MCHECK_DISABLED)
+       if (status == MCHECK_DISABLED) {
                return 1;
+       }
 
        if (status != MCHECK_OK) {
                mcheck_cb(status);
@@ -329,8 +341,9 @@ static void *heap_monitor_malloc(size_t size, const void *caller)
                SET_PAD(ptr, 0);
                SET_STATE(ptr, VALID);
 
-               if (chunk->info)
+               if (chunk->info) {
                        chunk->info->usage += size;
+               }
        }
 
        ESTIMATE_END();
@@ -343,8 +356,9 @@ static void heap_monitor_free(void *ptr, const void *caller)
 {
        struct chunk *chunk;
 
-       if (!ptr)
+       if (!ptr) {
                return;
+       }
 
        LOCK();
        unhook();
@@ -357,8 +371,9 @@ static void heap_monitor_free(void *ptr, const void *caller)
        }
 
        chunk = container_of((void *)(((char *)ptr) - PAD(ptr)), struct chunk, data);
-       if (chunk->info)
+       if (chunk->info) {
                chunk->info->usage -= chunk->size;
+       }
 
        if (MPROBE(chunk)) {
                SET_STATE(ptr, INVALID);
@@ -390,8 +405,9 @@ static void *heap_monitor_realloc(void *__ptr, size_t size, const void *caller)
        unhook();
        ESTIMATE_START();
        if (!__ptr) {
-               if (!size)
+               if (!size) {
                        goto out;
+               }
 
                /* Allocation */
                chunk = realloc(__ptr, size + sizeof(*chunk));
@@ -403,8 +419,9 @@ static void *heap_monitor_realloc(void *__ptr, size_t size, const void *caller)
                        SET_PAD(ptr, 0);
                        SET_STATE(ptr, VALID);
 
-                       if (chunk->info)
+                       if (chunk->info) {
                                chunk->info->usage += size;
+                       }
                }
        } else if (size == 0) {
                /* Free */
@@ -413,8 +430,9 @@ static void *heap_monitor_realloc(void *__ptr, size_t size, const void *caller)
                        ptr = realloc(__ptr, size);
                } else {
                        chunk = container_of((void *)(((char *)__ptr) - PAD(__ptr)), struct chunk, data);
-                       if (chunk->info)
+                       if (chunk->info) {
                                chunk->info->usage -= chunk->size;
+                       }
 
                        if (MPROBE(chunk)) {
                                SET_STATE(__ptr, INVALID);
@@ -481,8 +499,9 @@ static void *heap_monitor_realloc(void *__ptr, size_t size, const void *caller)
 
                                        new_chunk = ptr;
                                        new_chunk->info = find_target_info();
-                                       if (new_chunk->info)
+                                       if (new_chunk->info) {
                                                new_chunk->info->usage += size;
+                                       }
                                        new_chunk->size = size;
                                        ptr = new_chunk->data;
                                        SET_STATE(ptr, VALID);
@@ -510,8 +529,9 @@ static void *heap_monitor_memalign(size_t align, size_t __size, const void *call
        int pad;
        int size;
 
-       if (!__size)
+       if (!__size) {
                return NULL;
+       }
 
        LOCK();
        unhook();
@@ -520,12 +540,14 @@ static void *heap_monitor_memalign(size_t align, size_t __size, const void *call
        pad = align - (sizeof(*chunk) % align);
        size = sizeof(*chunk) + pad;
        chunk = memalign(align, size + __size);
-       if (!chunk)
+       if (!chunk) {
                goto out;
+       }
 
        chunk->info = find_target_info();
-       if (chunk->info)
+       if (chunk->info) {
                chunk->info->usage += __size;
+       }
 
        chunk->size = __size;
 
@@ -566,7 +588,7 @@ static void unhook(void)
    hook variables as volatile. Define it as empty for
    older glibc versions */
 #ifndef __MALLOC_HOOK_VOLATILE
-#define __MALLOC_HOOK_VOLATILE
+     #define __MALLOC_HOOK_VOLATILE
 #endif
 
 void (*__MALLOC_HOOK_VOLATILE __malloc_initialize_hook)(void) = heap_monitor_init;
@@ -579,17 +601,19 @@ static int iterator_cb(struct dl_phdr_info *info, size_t size, void *data)
 
        target = data;
 
-       if (strcmp(info->dlpi_name, target->name))
+       if (strcmp(info->dlpi_name, target->name)) {
                return 0;
+       }
 
        for (i = 0; i < info->dlpi_phnum; i++) {
                phdr = info->dlpi_phdr + i;
                if (phdr->p_type == PT_LOAD && (phdr->p_flags & PF_X)) {
                        target->begin = info->dlpi_addr + (unsigned long)phdr->p_vaddr;
                        target->end = target->begin + phdr->p_memsz;
-                       if (s_info.debugger)
+                       if (s_info.debugger) {
                                DbgPrint("Target: %s - [%s] 0x%lX - 0x%lX\n",
                                                        target->name, info->dlpi_name, target->begin, target->end);
+                       }
                        break;
                }
        }
@@ -633,8 +657,9 @@ API int heap_monitor_add_target(const char *name)
 
        ret = 0;
        target = find_target_by_name(name);
-       if (target)
+       if (target) {
                goto out;
+       }
 
        target = malloc(sizeof(*target));
        if (!target) {
@@ -691,15 +716,17 @@ API void heap_monitor_init(void)
        const char *var;
        pthread_attr_t attr;
 
-       if (s_info.initialized)
+       if (s_info.initialized) {
                return;
+       }
        
 #if defined(_ENABLE_MCHECK)
        s_info.m_check = mcheck(mcheck_cb);
-       if (s_info.m_check < 0)
+       if (s_info.m_check < 0) {
                ErrPrint("Failed to install mcheck[%d]\n", s_info.m_check);
-       else
+       } else {
                DbgPrint("mcheck installed: %d\n", s_info.m_check);
+       }
 #endif
 
        s_info._malloc = __malloc_hook;
@@ -708,18 +735,21 @@ API void heap_monitor_init(void)
        s_info._memalign = __memalign_hook;
 
        var = getenv("HEAP_MONITOR_DUMP_DEPTH");
-       if (var)
+       if (var) {
                s_info.dump_depth = atoi(var);
+       }
 
        var = getenv("HEAP_MONITOR_DEBUGGER");
-       if (var)
+       if (var) {
                s_info.debugger = atoi(var);
+       }
 
        s_info.main_tid = pthread_self();
        s_info.initialized = 1;
 
-       if (pthread_getattr_np(s_info.main_tid, &attr))
+       if (pthread_getattr_np(s_info.main_tid, &attr)) {
                return;
+       }
 
        if (pthread_attr_getstack(&attr, (void *)&s_info.stack_base, &s_info.stack_size)) {
                s_info.stack_base = 0;
@@ -734,16 +764,18 @@ API void heap_monitor_init(void)
 
 API void heap_monitor_start(void)
 {
-       if (!s_info.initialized)
+       if (!s_info.initialized) {
                return;
+       }
 
        hook();
 }
 
 API void heap_monitor_stop(void)
 {
-       if (!s_info.initialized)
+       if (!s_info.initialized) {
                return;
+       }
 
        unhook();
 }