diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 1999-02-08 10:34:55 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-02-08 10:34:55 +0000 |
commit | 86058a2d0cb92466b4e8a316b21562a79c7559b9 (patch) | |
tree | 79fc2d8b5d8b0a111e3a74037359777afd1df976 | |
parent | a43a7b9b40bf89fadd8851b90ce97e573bb2509a (diff) | |
download | perl-86058a2d0cb92466b4e8a316b21562a79c7559b9.tar.gz |
make EMBEDMYMALLOC the default and provide PERL_POLLUTE_MALLOC to let
them ask for insanity (untested)
p4raw-id: //depot/perl@2832
-rw-r--r-- | INSTALL | 22 | ||||
-rw-r--r-- | Todo-5.005 | 1 | ||||
-rw-r--r-- | ext/SDBM_File/sdbm/sdbm.h | 28 | ||||
-rw-r--r-- | hints/machten.sh | 7 | ||||
-rw-r--r-- | hints/next_3.sh | 6 | ||||
-rw-r--r-- | hints/next_4.sh | 2 | ||||
-rw-r--r-- | hints/qnx.sh | 6 | ||||
-rw-r--r-- | iperlsys.h | 6 | ||||
-rw-r--r-- | malloc.c | 24 | ||||
-rw-r--r-- | perl.h | 46 | ||||
-rw-r--r-- | pod/perldelta.pod | 22 | ||||
-rw-r--r-- | pod/perlguts.pod | 7 | ||||
-rw-r--r-- | sv.c | 2 |
13 files changed, 90 insertions, 89 deletions
@@ -747,6 +747,11 @@ To build without perl's malloc, you can use the Configure command or you can answer 'n' at the appropriate interactive Configure prompt. +Note that Perl's malloc family of functions are called Perl_malloc(), +Perl_realloc(), Perl_calloc() and Perl_mfree(). The names do not clash +with the system versions of these functions. See -DPERL_POLLUTE_MALLOC +below if you want to do that for some reason. + =head2 Malloc Performance Flags If you are using Perl's malloc, you may add one or more of the following @@ -767,6 +772,18 @@ in Perl 5.004. Undefined by default. Defining it in addition to NO_FANCY_MALLOC returns malloc to the version used in Perl version 5.000. +=item -DPERL_POLLUTE_MALLOC + +Undefined by default. This is used to force Perl's malloc family of functions +to have the same names as the system versions. This is normally only required +when you have a need to replace the system versions of these functions. +This may be sometimes required when you have libraries that like to free() +data that may have been allocated by Perl_malloc() and vice versa. + +Note that enabling this option may sometimes lead to duplicate symbols from +the linker for malloc et al. In such cases, the system probably does not +allow its malloc functions to be fully replaced with custom versions. + =back =head2 Building a debugging perl @@ -1011,11 +1028,6 @@ The latter is especially useful if you see something like this at Perl startup. -=item malloc duplicates - -If you get duplicates upon linking for malloc et al, add -DEMBEDMYMALLOC -to your ccflags variable in config.sh. - =item varargs If you get varargs problems with gcc, be sure that gcc is installed diff --git a/Todo-5.005 b/Todo-5.005 index 58959fab77..a8831b1370 100644 --- a/Todo-5.005 +++ b/Todo-5.005 @@ -17,7 +17,6 @@ Compiler Namespace cleanup CPP-space: restrict what we export from headers - stop malloc()/free() pollution unless asked header-space: move into CORE/perl/ API-space: begin list of things that constitute public api diff --git a/ext/SDBM_File/sdbm/sdbm.h b/ext/SDBM_File/sdbm/sdbm.h index 84d5f75468..4921de7f8d 100644 --- a/ext/SDBM_File/sdbm/sdbm.h +++ b/ext/SDBM_File/sdbm/sdbm.h @@ -168,27 +168,19 @@ extern long sdbm_hash proto((char *, int)); /* This comes after <stdlib.h> so we don't try to change the standard * library prototypes; we'll use our own instead. */ -#if defined(MYMALLOC) && (defined(HIDEMYMALLOC) || defined(EMBEDMYMALLOC)) +#if defined(MYMALLOC) -# ifdef HIDEMYMALLOC -# define malloc Mymalloc -# define calloc Mycalloc -# define realloc Myremalloc -# define free Myfree -# endif -# ifdef EMBEDMYMALLOC -# define malloc Perl_malloc -# define calloc Perl_calloc -# define realloc Perl_realloc -# define free Perl_free -# endif +# define malloc Perl_malloc +# define calloc Perl_calloc +# define realloc Perl_realloc +# define free Perl_mfree - Malloc_t malloc proto((MEM_SIZE nbytes)); - Malloc_t calloc proto((MEM_SIZE elements, MEM_SIZE size)); - Malloc_t realloc proto((Malloc_t where, MEM_SIZE nbytes)); - Free_t free proto((Malloc_t where)); +Malloc_t Perl_malloc proto((MEM_SIZE nbytes)); +Malloc_t Perl_calloc proto((MEM_SIZE elements, MEM_SIZE size)); +Malloc_t Perl_realloc proto((Malloc_t where, MEM_SIZE nbytes)); +Free_t Perl_mfree proto((Malloc_t where)); -#endif /* MYMALLOC && (HIDEMYMALLOC || EMBEDMYMALLOC) */ +#endif /* MYMALLOC */ #ifdef I_STRING #include <string.h> diff --git a/hints/machten.sh b/hints/machten.sh index f283873699..767283792b 100644 --- a/hints/machten.sh +++ b/hints/machten.sh @@ -64,13 +64,6 @@ usemymalloc=${usemymalloc:-y} # Do not wrap the following long line malloc_cflags='ccflags="$ccflags -DPLAIN_MALLOC -DNO_FANCY_MALLOC -DUSE_PERL_SBRK"' -# Note that an empty malloc_cflags appears in config.sh if perl's -# malloc() is not used. his is harmless. -case "$usemymalloc" in -n) unset malloc_cflags;; -*) ccflags="$ccflags -DHIDEMYMALLOC" -esac - # When MachTen does a fork(), it immediately copies the whole of # the parent process' data space for the child. This can be # expensive. Using vfork() where appropriate avoids this cost. diff --git a/hints/next_3.sh b/hints/next_3.sh index 99adf50ffe..1a174b8d54 100644 --- a/hints/next_3.sh +++ b/hints/next_3.sh @@ -32,8 +32,8 @@ # than no perl at all. # # So, this hintsfile is using perl's malloc. If you want to turn -# perl's malloc off, you need to remove '-DUSE_PERL_SBRK' and -# '-DHIDEMYMALLOC' from the ccflags and set usemymalloc to 'n'. +# perl's malloc off, you need to remove '-DUSE_PERL_SBRK' +# from the ccflags and set usemymalloc to 'n'. # # 1997: # From perl5.003_22 the malloc bug has no impact any more. We can run @@ -42,7 +42,7 @@ # # use the following two lines to enable USE_PERL_SBRK. Try this if you # encounter intermittent core dumps: -#ccflags='-DUSE_NEXT_CTYPE -DUSE_PERL_SBRK -DHIDEMYMALLOC' +#ccflags='-DUSE_NEXT_CTYPE -DUSE_PERL_SBRK' #usemymalloc='y' # use the following two lines if you have perl5.003_22 or better and # do not encounter intermittent core dumps. diff --git a/hints/next_4.sh b/hints/next_4.sh index d1d0398dd9..8bc623a9e4 100644 --- a/hints/next_4.sh +++ b/hints/next_4.sh @@ -18,7 +18,7 @@ libc='/NextLibrary/Frameworks/System.framework/System' ldflags='-dynamic -prebind' lddlflags='-dynamic -bundle -undefined suppress' -ccflags='-dynamic -fno-common -DUSE_NEXT_CTYPE -DUSE_PERL_SBRK -DHIDEMYMALLOC' +ccflags='-dynamic -fno-common -DUSE_NEXT_CTYPE -DUSE_PERL_SBRK' cccdlflags='none' ld='cc' #optimize='-g -O' diff --git a/hints/qnx.sh b/hints/qnx.sh index b53a33d737..06d9010144 100644 --- a/hints/qnx.sh +++ b/hints/qnx.sh @@ -98,13 +98,9 @@ libc='/usr/lib/clib3r.lib' # constructs make a lot of noise, so I turn those warnings off. # A few still remain... # -# HIDEMYMALLOC is necessary if using mymalloc since it is very -# tricky (though not impossible) to totally replace the watcom -# malloc/free set. -# # unix.h is required as a general rule for unixy applications. #---------------------------------------------------------------- -ccflags='-DHIDEMYMALLOC -mf -w4 -Wc,-wcd=202 -Wc,-wcd=203 -Wc,-wcd=302 -Wc,-fi=unix.h' +ccflags='-mf -w4 -Wc,-wcd=202 -Wc,-wcd=203 -Wc,-wcd=302 -Wc,-fi=unix.h' #---------------------------------------------------------------- # ldflags: diff --git a/iperlsys.h b/iperlsys.h index cfdc39f9de..97f30e33b4 100644 --- a/iperlsys.h +++ b/iperlsys.h @@ -610,9 +610,15 @@ public: #else /* PERL_OBJECT */ +#ifdef MYMALLOC +#define PerlMem_malloc(size) Perl_malloc((size)) +#define PerlMem_realloc(buf, size) Perl_realloc((buf), (size)) +#define PerlMem_free(buf) Perl_mfree((buf)) +#else #define PerlMem_malloc(size) malloc((size)) #define PerlMem_realloc(buf, size) realloc((buf), (size)) #define PerlMem_free(buf) free((buf)) +#endif #endif /* PERL_OBJECT */ @@ -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); @@ -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 */ @@ -385,46 +385,30 @@ register struct op *Perl_op asm(stringify(OP_IN_REGISTER)); * library prototypes; we'll use our own in proto.h instead. */ #ifdef MYMALLOC - -# ifdef HIDEMYMALLOC -# define malloc Mymalloc -# define calloc Mycalloc -# define realloc Myrealloc -# define free Myfree -Malloc_t Mymalloc _((MEM_SIZE nbytes)); -Malloc_t Mycalloc _((MEM_SIZE elements, MEM_SIZE size)); -Malloc_t Myrealloc _((Malloc_t where, MEM_SIZE nbytes)); -Free_t Myfree _((Malloc_t where)); -# endif -# ifdef EMBEDMYMALLOC -# define malloc Perl_malloc -# define calloc Perl_calloc -# define realloc Perl_realloc -/* VMS' external symbols are case-insensitive, and there's already a */ -/* perl_free in perl.h */ -#ifdef VMS -# define free Perl_myfree -#else -# define free Perl_free -#endif +# ifdef PERL_POLLUTE_MALLOC +# define Perl_malloc malloc +# define Perl_calloc calloc +# define Perl_realloc realloc +# define Perl_mfree free +# else +# define EMBEDMYMALLOC /* for compatibility */ +# endif Malloc_t Perl_malloc _((MEM_SIZE nbytes)); Malloc_t Perl_calloc _((MEM_SIZE elements, MEM_SIZE size)); Malloc_t Perl_realloc _((Malloc_t where, MEM_SIZE nbytes)); -#ifdef VMS -Free_t Perl_myfree _((Malloc_t where)); -#else -Free_t Perl_free _((Malloc_t where)); -#endif +/* 'mfree' rather than 'free', since there is already a 'perl_free' + * that causes clashes with case-insensitive linkers */ +Free_t Perl_mfree _((Malloc_t where)); # endif # undef safemalloc # undef safecalloc # undef saferealloc # undef safefree -# define safemalloc malloc -# define safecalloc calloc -# define saferealloc realloc -# define safefree free +# define safemalloc Perl_malloc +# define safecalloc Perl_calloc +# define saferealloc Perl_realloc +# define safefree Perl_mfree #endif /* MYMALLOC */ diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 86781389b5..b2e197f47b 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -23,6 +23,28 @@ macros for extension source compatibility. As of release 5.006, these preprocessor definitions are not available by default. You need to explicitly compile perl with C<-DPERL_POLLUTE> in order to get these definitions. +=item C<PERL_POLLUTE_MALLOC> + +Enabling the use of Perl's malloc in release 5.005 and earlier caused +the namespace of system versions of the malloc family of functions to +be usurped by the Perl versions of these functions, since they used the +same names by default. + +Besides causing problems on platforms that do not allow these functions to +be cleanly replaced, this also meant that the system versions could not +be called in programs that used Perl's malloc. Previous versions of Perl +have allowed this behavior to be suppressed with the HIDEMYMALLOC and +EMBEDMYMALLOC preprocessor definitions. + +As of release 5.006, Perl's malloc family of functions have default names +distinct from the system versions. You need to explicitly compile perl with +C<-DPERL_POLLUTE_MALLOC> in order to get the older behavior. HIDEMYMALLOC +and EMBEDMYMALLOC have no effect, since the behavior they enabled is now +the default. + +Note that these functions do B<not> constitute Perl's memory allocation API. +See L<perlguts/"Memory Allocation"> for further information about that. + =item C<PL_na> and C<dTHR> Issues The C<PL_na> global is now thread local, so a C<dTHR> declaration is needed diff --git a/pod/perlguts.pod b/pod/perlguts.pod index 15ca4b776a..551e84c8df 100644 --- a/pod/perlguts.pod +++ b/pod/perlguts.pod @@ -1236,7 +1236,12 @@ consult L<perlcall>. =head2 Memory Allocation -It is suggested that you use the version of malloc that is distributed +All memory meant to be used with the Perl API functions should be manipulated +using the macros described in this section. The macros provide the necessary +transparency between differences in the actual malloc implementation that is +used within perl. + +It is suggested that you enable the version of malloc that is distributed with Perl. It keeps pools of various sizes of unallocated memory in order to satisfy allocation requests more quickly. However, on some platforms, it may cause spurious malloc or free errors. @@ -603,7 +603,7 @@ more_xpv(void) #ifdef PURIFY # define my_safemalloc(s) safemalloc(s) -# define my_safefree(s) free(s) +# define my_safefree(s) safefree(s) #else STATIC void* my_safemalloc(MEM_SIZE size) |