Quickier thread-specific data on OS/2
[p5sagit/p5-mst-13.2.git] / malloc.c
index e8fe41e..d543b9b 100644 (file)
--- a/malloc.c
+++ b/malloc.c
  * This is designed for use in a program that uses vast quantities of memory,
  * but bombs when it runs out.
  * 
- * Modifications Copyright Ilya Zakharevich 1996-98.
+ * Modifications Copyright Ilya Zakharevich 1996-99.
  * 
  * Still very quick, but much more thrifty.  (Std config is 10% slower
  * than it was, and takes 67% of old heap size for typical usage.)
@@ -827,7 +827,7 @@ botch(char *diag, char *s)
 #endif
 
 Malloc_t
-malloc(register size_t nbytes)
+Perl_malloc(register size_t nbytes)
 {
        register union overhead *p;
        register int bucket;
@@ -1330,7 +1330,7 @@ morecore(register int bucket)
 }
 
 Free_t
-free(void *mp)
+Perl_mfree(void *mp)
 {   
        register MEM_SIZE size;
        register union overhead *ovp;
@@ -1412,7 +1412,7 @@ free(void *mp)
 #define reall_srchlen  4       /* 4 should be plenty, -1 =>'s whole list */
 
 Malloc_t
-realloc(void *mp, size_t nbytes)
+Perl_realloc(void *mp, size_t nbytes)
 {   
        register MEM_SIZE onb;
        union overhead *ovp;
@@ -1431,7 +1431,7 @@ realloc(void *mp, size_t nbytes)
 
        BARK_64K_LIMIT("Reallocation",nbytes,size);
        if (!cp)
-               return malloc(nbytes);
+               return Perl_malloc(nbytes);
 
        MALLOC_LOCK;
        ovp = (union overhead *)((caddr_t)cp 
@@ -1568,12 +1568,12 @@ realloc(void *mp, size_t nbytes)
                              "0x%lx: (%05lu) realloc %ld bytes the hard way\n",
                              (unsigned long)cp,(unsigned long)(PL_an++),
                              (long)size));
-           if ((res = (char*)malloc(nbytes)) == NULL)
+           if ((res = (char*)Perl_malloc(nbytes)) == NULL)
                return (NULL);
            if (cp != res)                      /* common optimization */
                Copy(cp, res, (MEM_SIZE)(nbytes<onb?nbytes:onb), char);
            if (was_alloced)
-               free(cp);
+               Perl_mfree(cp);
        }
        return ((Malloc_t)res);
 }
@@ -1601,10 +1601,10 @@ findbucket(union overhead *freep, int srchlen)
 }
 
 Malloc_t
-calloc(register size_t elements, register size_t size)
+Perl_calloc(register size_t elements, register size_t size)
 {
     long sz = elements * size;
-    Malloc_t p = malloc(sz);
+    Malloc_t p = Perl_malloc(sz);
 
     if (p) {
        memset((void*)p, 0, sz);
@@ -1727,7 +1727,7 @@ dump_mstats(char *s)
 
 #ifdef USE_PERL_SBRK
 
-#   if defined(__MACHTEN_PPC__) || defined(__NeXT__)
+#   if defined(__MACHTEN_PPC__) || defined(NeXT) || defined(__NeXT__)
 #      define PERL_SBRK_VIA_MALLOC
 /*
  * MachTen's malloc() returns a buffer aligned on a two-byte boundary.
@@ -1743,14 +1743,6 @@ dump_mstats(char *s)
 #   endif
 
 #   ifdef PERL_SBRK_VIA_MALLOC
-#      if defined(HIDEMYMALLOC) || defined(EMBEDMYMALLOC)
-#         undef malloc         /* Expose names that  */
-#         undef calloc         /* HIDEMYMALLOC hides */
-#         undef realloc
-#         undef free
-#      else
-#         include "Error: -DPERL_SBRK_VIA_MALLOC needs -D(HIDE|EMBED)MYMALLOC"
-#      endif
 
 /* it may seem schizophrenic to use perl's malloc and let it call system */
 /* malloc, the reason for that is only the 3.2 version of the OS that had */
@@ -1801,7 +1793,7 @@ Perl_sbrk(int size)
 #  endif
       got = (IV)SYSTEM_ALLOC(size);
 #  if NEEDED_ALIGNMENT > SYSTEM_ALLOC_ALIGNMENT
-      got = (got + NEEDED_ALIGNMENT - 1) & (NEEDED_ALIGNMENT - 1);
+      got = (got + NEEDED_ALIGNMENT - 1) & ~(NEEDED_ALIGNMENT - 1);
 #  endif
       if (small) {
        /* Chunk is small, register the rest for future allocs. */