Revision: 58887
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58887
Author:   campbellbarton
Date:     2013-08-04 03:00:04 +0000 (Sun, 04 Aug 2013)
Log Message:
-----------
avoid using MEM_reallocN_id directly, add utility macro for freeing.

Modified Paths:
--------------
    trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
    trunk/blender/intern/guardedalloc/intern/mallocn.c
    trunk/blender/source/blender/blenkernel/intern/fmodifier.c
    trunk/blender/source/blender/blenlib/intern/buffer.c

Modified: trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
===================================================================
--- trunk/blender/intern/guardedalloc/MEM_guardedalloc.h        2013-08-04 
00:01:41 UTC (rev 58886)
+++ trunk/blender/intern/guardedalloc/MEM_guardedalloc.h        2013-08-04 
03:00:04 UTC (rev 58887)
@@ -102,25 +102,12 @@
 #endif
        ;
 
-       void *MEM_reallocN_id(void *vmemh, size_t len, const char *str)
-#if MEM_GNU_ATTRIBUTES
-       __attribute__((warn_unused_result))
-       __attribute__((alloc_size(2)))
-#endif
-       ;
-       void *MEM_recallocN_id(void *vmemh, size_t len, const char *str)
-#if MEM_GNU_ATTRIBUTES
-       __attribute__((warn_unused_result))
-       __attribute__((alloc_size(2)))
-#endif
-       ;
-
        /**
         * Reallocates a block of memory, and returns pointer to the newly
         * allocated block, the old one is freed. this is not as optimized
         * as a system realloc but just makes a new allocation and copies
         * over from existing memory. */
-       void *MEM_reallocN(void *vmemh, size_t len)
+       void *MEM_reallocN_id(void *vmemh, size_t len, const char *str)
 #if MEM_GNU_ATTRIBUTES
        __attribute__((warn_unused_result))
        __attribute__((alloc_size(2)))
@@ -130,13 +117,16 @@
        /**
         * A variant of realloc which zeros new bytes
         */
-       void *MEM_recallocN(void *vmemh, size_t len)
+       void *MEM_recallocN_id(void *vmemh, size_t len, const char *str)
 #if MEM_GNU_ATTRIBUTES
        __attribute__((warn_unused_result))
        __attribute__((alloc_size(2)))
 #endif
        ;
 
+#define MEM_reallocN(vmemh, len) MEM_reallocN_id(vmemh, len, __func__)
+#define MEM_recallocN(vmemh, len) MEM_recallocN_id(vmemh, len, __func__)
+
        /**
         * Allocate a block of memory of size len, with tag name str. The
         * memory is cleared. The name must be static, because only a
@@ -223,6 +213,8 @@
 #endif
        ;
 
+#define MEM_SAFE_FREE(v) if (v) { MEM_freeN(v); v = NULL; } (void)0
+
 #ifndef NDEBUG
 const char *MEM_name_ptr(void *vmemh);
 #endif

Modified: trunk/blender/intern/guardedalloc/intern/mallocn.c
===================================================================
--- trunk/blender/intern/guardedalloc/intern/mallocn.c  2013-08-04 00:01:41 UTC 
(rev 58886)
+++ trunk/blender/intern/guardedalloc/intern/mallocn.c  2013-08-04 03:00:04 UTC 
(rev 58887)
@@ -434,17 +434,6 @@
        return newp;
 }
 
-
-void *MEM_reallocN(void *vmemh, size_t len)
-{
-       return MEM_reallocN_id(vmemh, len, __func__);
-}
-void *MEM_recallocN(void *vmemh, size_t len)
-{
-       return MEM_recallocN_id(vmemh, len, __func__);
-}
-
-
 #ifdef DEBUG_BACKTRACE
 #  if defined(__linux__) || defined(__APPLE__)
 static void make_memhead_backtrace(MemHead *memh)

Modified: trunk/blender/source/blender/blenkernel/intern/fmodifier.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fmodifier.c  2013-08-04 
00:01:41 UTC (rev 58886)
+++ trunk/blender/source/blender/blenkernel/intern/fmodifier.c  2013-08-04 
03:00:04 UTC (rev 58887)
@@ -144,9 +144,8 @@
                        const int arraysize_new = data->poly_order + 1;
                        /* arraysize needs to be order+1, so resize if not */
                        if (data->arraysize != arraysize_new) {
-                               data->coefficients = 
MEM_recallocN_id(data->coefficients,
-                                                                     
sizeof(float) * arraysize_new,
-                                                                     
"FMod_Generator_Coefs");
+                               data->coefficients = 
MEM_recallocN(data->coefficients,
+                                                                  
sizeof(float) * arraysize_new);
                                data->arraysize = arraysize_new;
                        }
                        break;
@@ -156,9 +155,8 @@
                        const int arraysize_new = data->poly_order * 2;
                        /* arraysize needs to be (2 * order), so resize if not 
*/
                        if (data->arraysize != arraysize_new) {
-                               data->coefficients = 
MEM_recallocN_id(data->coefficients,
-                                                                     
sizeof(float) * arraysize_new,
-                                                                     
"FMod_Generator_Coefs");
+                               data->coefficients = 
MEM_recallocN(data->coefficients,
+                                                                  
sizeof(float) * arraysize_new);
                                data->arraysize = arraysize_new;
                        }
                        break;

Modified: trunk/blender/source/blender/blenlib/intern/buffer.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/buffer.c        2013-08-04 
00:01:41 UTC (rev 58886)
+++ trunk/blender/source/blender/blenlib/intern/buffer.c        2013-08-04 
03:00:04 UTC (rev 58887)
@@ -34,9 +34,12 @@
 
 static void *buffer_realloc(BLI_Buffer *buffer, int len)
 {
-       return ((buffer->flag & BLI_BUFFER_USE_CALLOC) ?
-               MEM_recallocN : MEM_reallocN)
-               (buffer->data, (buffer->elem_size * len));
+       if (buffer->flag & BLI_BUFFER_USE_CALLOC) {
+               return MEM_recallocN(buffer->data, buffer->elem_size * len);
+       }
+       else {
+               return MEM_reallocN(buffer->data, buffer->elem_size * len);
+       }
 }
 
 void BLI_buffer_resize(BLI_Buffer *buffer, int new_count)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to