From fb46c04ad6c9d43be5e2687cae678878d7520283 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Sun, 2 Oct 2005 02:50:52 +0000 Subject: [PATCH] Got it to compile under VC --- dtool/src/dtoolbase/ptmalloc2_smp.c | 355 ++++++++++++++-------------- 1 file changed, 173 insertions(+), 182 deletions(-) diff --git a/dtool/src/dtoolbase/ptmalloc2_smp.c b/dtool/src/dtoolbase/ptmalloc2_smp.c index 128ceef0e4..676eb6aadd 100644 --- a/dtool/src/dtoolbase/ptmalloc2_smp.c +++ b/dtool/src/dtoolbase/ptmalloc2_smp.c @@ -2,10 +2,10 @@ license as well as the LGPL, in spite of the comments below. See http://www.malloc.de . */ -#include "dtoolbase.h" - #if defined(USE_MEMORY_PTMALLOC2) && !defined(linux) #define USE_DL_PREFIX 1 +#define __STDC__ 1 +#define MREMAP_MAYMOVE 1 /* terrible hack--drose */ /* Malloc implementation for multiple threads without lock contention. Copyright (C) 1996,1997,1998,1999,2000,01,02 Free Software Foundation, Inc. @@ -238,14 +238,6 @@ probably don't want to touch unless you are extending or adapting malloc. */ -/* - WIN32 sets up defaults for MS environment and compilers. - Otherwise defaults are for unix. -*/ - -/* #define WIN32 */ - - /*************************** thread-m.h ******************************/ @@ -2248,7 +2240,7 @@ struct malloc_chunk { }; -/*typedef struct malloc_chunk* mchunkptr;*/ +typedef struct malloc_chunk* mchunkptr; /* malloc_chunk details: @@ -2868,7 +2860,7 @@ struct malloc_par { char* sbrk_base; }; -/*typedef struct malloc_state *mstate;*/ +typedef struct malloc_state *mstate; /* There are several instances of this struct ("arenas") in this malloc. If you are adapting this malloc in a way that does NOT use @@ -5320,9 +5312,6 @@ mremap_chunk(p, new_size) mchunkptr p; size_t new_size; /* Note the extra SIZE_SZ overhead as in mmap_chunk(). */ new_size = (new_size + offset + SIZE_SZ + page_mask) & ~page_mask; -#ifndef MREMAP_MAYMOVE -#define MREMAP_MAYMOVE 1 /* terrible hack--drose */ -#endif cp = (char *)mremap((char *)p - offset, size + offset, new_size, MREMAP_MAYMOVE); @@ -7828,205 +7817,208 @@ sbrk_exit: /* mmap for windows */ static void *mmap (void *ptr, long size, long prot, long type, long handle, long arg) { - static long g_pagesize; - static long g_regionsize; + static long g_pagesize; + static long g_regionsize; + DWORD alloc=MEM_RESERVE|MEM_TOP_DOWN; + DWORD ntprot=0; + long rounding=0; #ifdef TRACE - printf ("mmap %p %d %d %d\n", ptr, size, prot, type); + printf ("mmap %p %d %d %d\n", ptr, size, prot, type); #endif - /* Wait for spin lock */ - slwait (&g_sl); - /* First time initialization */ - if (! g_pagesize) - g_pagesize = getpagesize (); - if (! g_regionsize) - g_regionsize = getregionsize (); - /* Assert preconditions */ - assert ((unsigned) ptr % g_pagesize == 0); - assert (size % g_pagesize == 0); - /* Allocate this */ - DWORD alloc=MEM_RESERVE|MEM_TOP_DOWN, ntprot=0; - long rounding=0; - if(!(type & MAP_NORESERVE)) alloc|=MEM_COMMIT; - if((prot & (PROT_READ|PROT_WRITE))==(PROT_READ|PROT_WRITE)) ntprot|=PAGE_READWRITE; - else if(prot & PROT_READ) ntprot|=PAGE_READONLY; - else if(prot & PROT_WRITE) ntprot|=PAGE_READWRITE; - else - { - ntprot|=PAGE_NOACCESS; - if(size==HEAP_MAX_SIZE) - { - rounding=size; - size<<=1; + /* Wait for spin lock */ + slwait (&g_sl); + /* First time initialization */ + if (! g_pagesize) + g_pagesize = getpagesize (); + if (! g_regionsize) + g_regionsize = getregionsize (); + /* Assert preconditions */ + assert ((unsigned) ptr % g_pagesize == 0); + assert (size % g_pagesize == 0); + /* Allocate this */ + if(!(type & MAP_NORESERVE)) alloc|=MEM_COMMIT; + if((prot & (PROT_READ|PROT_WRITE))==(PROT_READ|PROT_WRITE)) ntprot|=PAGE_READWRITE; + else if(prot & PROT_READ) ntprot|=PAGE_READONLY; + else if(prot & PROT_WRITE) ntprot|=PAGE_READWRITE; + else + { + ntprot|=PAGE_NOACCESS; + if(size==HEAP_MAX_SIZE) + { + rounding=size; + size<<=1; #ifdef TRACE - printf("Rounding to multiple of %d\n", rounding); + printf("Rounding to multiple of %d\n", rounding); #endif - } - if(ptr) - { /* prot==PROT_NONE also appears to be a euphemism for free */ - MEMORY_BASIC_INFORMATION mbi; - DWORD read=0; - for(char *p=((char *)ptr)+read; read