Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillermo S. Romero <gsr.b3d@infernal-iceberg.com>2010-04-29 21:34:40 +0400
committerGuillermo S. Romero <gsr.b3d@infernal-iceberg.com>2010-04-29 21:34:40 +0400
commit1fc7ea774f628c61af633415fefd6c5bd7058c87 (patch)
tree3052e7bf7c4f5ac903dda9ab8934bc420b87d739 /intern/guardedalloc
parentf63de81223620e0a61202fff024ce5f3ea0170ab (diff)
Make Blender malloc wrapper be 64 bit ready.
Diffstat (limited to 'intern/guardedalloc')
-rw-r--r--intern/guardedalloc/MEM_guardedalloc.h6
-rw-r--r--intern/guardedalloc/intern/mallocn.c35
2 files changed, 24 insertions, 17 deletions
diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h
index 45c2e048df9..1d8f42a2707 100644
--- a/intern/guardedalloc/MEM_guardedalloc.h
+++ b/intern/guardedalloc/MEM_guardedalloc.h
@@ -89,18 +89,18 @@ extern "C" {
* 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.
diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c
index 624687735dc..2e7faf8aac1 100644
--- a/intern/guardedalloc/intern/mallocn.c
+++ b/intern/guardedalloc/intern/mallocn.c
@@ -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 @@ typedef struct localListBase
/* 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 @@ void *MEM_dupallocN(void *vmemh)
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 @@ void *MEM_reallocN(void *vmemh, unsigned int len)
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 @@ static void make_memhead_header(MemHead *memh, unsigned int len, const char *str
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 @@ void *MEM_mallocN(unsigned int len, const char *str)
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 @@ void *MEM_callocN(unsigned int len, const char *str)
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 @@ void *MEM_mapallocN(unsigned int len, const char *str)
}
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 @@ static void MEM_printmemlist_internal( int pydict )
}
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)