Revision: 28508
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28508
Author:   gsrb3d
Date:     2010-04-29 19:34:40 +0200 (Thu, 29 Apr 2010)

Log Message:
-----------
Make Blender malloc wrapper be 64 bit ready.

Modified Paths:
--------------
    trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
    trunk/blender/intern/guardedalloc/intern/mallocn.c

Modified: trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
===================================================================
--- trunk/blender/intern/guardedalloc/MEM_guardedalloc.h        2010-04-29 
17:07:17 UTC (rev 28507)
+++ trunk/blender/intern/guardedalloc/MEM_guardedalloc.h        2010-04-29 
17:34:40 UTC (rev 28508)
@@ -89,18 +89,18 @@
          * 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, unsigned int len);
+       void *MEM_reallocN(void *vmemh, size_t len);
 
        /**
         * Allocate a block of memory of size len, with tag name str. The
         * memory is cleared. The name must be static, because only a
         * pointer to it is stored ! */
-       void *MEM_callocN(unsigned int len, const char * str);
+       void *MEM_callocN(size_t len, const char * str);
        
        /** Allocate a block of memory of size len, with tag name str. The
                * name must be a static, because only a pointer to it is stored 
!
                * */
-       void *MEM_mallocN(unsigned int len, const char * str);
+       void *MEM_mallocN(size_t len, const char * str);
        
        /** Same as callocN, clears memory and uses mmap (disk cached) if 
supported.
                Can be free'd with MEM_freeN as usual.

Modified: trunk/blender/intern/guardedalloc/intern/mallocn.c
===================================================================
--- trunk/blender/intern/guardedalloc/intern/mallocn.c  2010-04-29 17:07:17 UTC 
(rev 28507)
+++ trunk/blender/intern/guardedalloc/intern/mallocn.c  2010-04-29 17:34:40 UTC 
(rev 28508)
@@ -36,13 +36,20 @@
 #include <stdlib.h>
 #include <string.h>    /* memcpy */
 #include <stdarg.h>
+#include <sys/types.h>
+/* Blame Microsoft for LLP64 and no inttypes.h, quick workaround needed: */
+#if defined(WIN64)
+#define SIZET_FORMAT "%I64u"
+#define SIZET_ARG(a) ((unsigned long long)(a))
+#else
+#define SIZET_FORMAT "%lu"
+#define SIZET_ARG(a) ((unsigned long)(a))
+#endif
 
 /* mmap exception */
 #if defined(WIN32)
-#include <sys/types.h>
 #include "mmap_win.h"
 #else
-#include <sys/types.h>
 #include <sys/mman.h>
 #endif
 
@@ -82,7 +89,7 @@
        /* note: keep this struct aligned (e.g., irix/gcc) - Hos */
 typedef struct MemHead {
        int tag1;
-       unsigned int len;
+       size_t len;
        struct MemHead *next,*prev;
        const char * name;
        const char * nextname;
@@ -245,7 +252,7 @@
        return newp;
 }
 
-void *MEM_reallocN(void *vmemh, unsigned int len)
+void *MEM_reallocN(void *vmemh, size_t len)
 {
        void *newp= NULL;
        
@@ -267,7 +274,7 @@
        return newp;
 }
 
-static void make_memhead_header(MemHead *memh, unsigned int len, const char 
*str)
+static void make_memhead_header(MemHead *memh, size_t len, const char *str)
 {
        MemTail *memt;
        
@@ -288,7 +295,7 @@
        mem_in_use += len;
 }
 
-void *MEM_mallocN(unsigned int len, const char *str)
+void *MEM_mallocN(size_t len, const char *str)
 {
        MemHead *memh;
 
@@ -312,11 +319,11 @@
                return (++memh);
        }
        mem_unlock_thread();
-       print_error("Malloc returns nill: len=%d in %s, total %u\n",len, str, 
mem_in_use);
+       print_error("Malloc returns null: len=" SIZET_FORMAT " in %s, total 
%u\n", SIZET_ARG(len), str, mem_in_use);
        return NULL;
 }
 
-void *MEM_callocN(unsigned int len, const char *str)
+void *MEM_callocN(size_t len, const char *str)
 {
        MemHead *memh;
 
@@ -337,12 +344,12 @@
                return (++memh);
        }
        mem_unlock_thread();
-       print_error("Calloc returns nill: len=%d in %s, total %u\n",len, str, 
mem_in_use);
+       print_error("Calloc returns null: len=" SIZET_FORMAT " in %s, total 
%u\n", SIZET_ARG(len), str, mem_in_use);
        return 0;
 }
 
 /* note; mmap returns zero'd memory */
-void *MEM_mapallocN(unsigned int len, const char *str)
+void *MEM_mapallocN(size_t len, const char *str)
 {
        MemHead *memh;
 
@@ -380,7 +387,7 @@
        }
        else {
                mem_unlock_thread();
-               print_error("Mapalloc returns nill, fallback to regular malloc: 
len=%d in %s, total %u\n",len, str, mmap_in_use);
+               print_error("Mapalloc returns null, fallback to regular malloc: 
len=" SIZET_FORMAT " in %s, total %u\n", SIZET_ARG(len), str, mmap_in_use);
                return MEM_callocN(len, str);
        }
 }
@@ -492,12 +499,12 @@
        }
        while(membl) {
                if (pydict) {
-                       fprintf(stderr, "{'len':%i, 'name':'''%s''', 
'pointer':'%p'},\\\n", membl->len, membl->name, membl+1);
+                       fprintf(stderr, "{'len':" SIZET_FORMAT ", 
'name':'''%s''', 'pointer':'%p'},\\\n", SIZET_ARG(membl->len), membl->name, 
membl+1);
                } else {
 #ifdef DEBUG_MEMCOUNTER
-                       print_error("%s len: %d %p, count: 
%d\n",membl->name,membl->len, membl+1, membl->_count);
+                       print_error("%s len: " SIZET_FORMAT " %p, count: %d\n", 
membl->name, SIZET_ARG(membl->len), membl+1, membl->_count);
 #else
-                       print_error("%s len: %d %p\n",membl->name,membl->len, 
membl+1);
+                       print_error("%s len: " SIZET_FORMAT " %p\n", 
membl->name, SIZET_ARG(membl->len), membl+1);
 #endif
                }
                if(membl->next)


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

Reply via email to