summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1999-02-08 13:23:16 +0000
committerGurusamy Sarathy <gsar@cpan.org>1999-02-08 13:23:16 +0000
commitf25172013443eb112285f24a09b83900edb8a738 (patch)
tree678f9789da4edbccaa4836270985332e36f7f449
parent651b9576cc8d7812bbcba060854ec8a56f698aae (diff)
downloadperl-f25172013443eb112285f24a09b83900edb8a738.tar.gz
make safesysmalloc() etc., always available; safemalloc() et al are
now macros that point to the right malloc; fix various places in sources that need to always use safesysmalloc() et al p4raw-id: //depot/perl@2834
-rw-r--r--embed.h16
-rw-r--r--global.sym8
-rw-r--r--iperlsys.h6
-rw-r--r--mg.c15
-rw-r--r--objXSUB.h16
-rw-r--r--perl.h9
-rw-r--r--perl_exp.SH20
-rw-r--r--proto.h10
-rw-r--r--util.c62
-rw-r--r--vms/gen_shrfls.pl3
-rw-r--r--win32/makedef.pl7
11 files changed, 79 insertions, 93 deletions
diff --git a/embed.h b/embed.h
index 78c28e2970..6fc73ca1b8 100644
--- a/embed.h
+++ b/embed.h
@@ -788,10 +788,10 @@
#define rxres_free Perl_rxres_free
#define rxres_restore Perl_rxres_restore
#define rxres_save Perl_rxres_save
-#define safecalloc Perl_safecalloc
-#define safefree Perl_safefree
-#define safemalloc Perl_safemalloc
-#define saferealloc Perl_saferealloc
+#define safesyscalloc Perl_safesyscalloc
+#define safesysfree Perl_safesysfree
+#define safesysmalloc Perl_safesysmalloc
+#define safesysrealloc Perl_safesysrealloc
#define safexcalloc Perl_safexcalloc
#define safexfree Perl_safexfree
#define safexmalloc Perl_safexmalloc
@@ -1947,10 +1947,10 @@
#define rxres_free CPerlObj::Perl_rxres_free
#define rxres_restore CPerlObj::Perl_rxres_restore
#define rxres_save CPerlObj::Perl_rxres_save
-#define safecalloc CPerlObj::Perl_safecalloc
-#define safefree CPerlObj::Perl_safefree
-#define safemalloc CPerlObj::Perl_safemalloc
-#define saferealloc CPerlObj::Perl_saferealloc
+#define safesyscalloc CPerlObj::Perl_safesyscalloc
+#define safesysfree CPerlObj::Perl_safesysfree
+#define safesysmalloc CPerlObj::Perl_safesysmalloc
+#define safesysrealloc CPerlObj::Perl_safesysrealloc
#define safexcalloc CPerlObj::Perl_safexcalloc
#define safexfree CPerlObj::Perl_safexfree
#define safexmalloc CPerlObj::Perl_safexmalloc
diff --git a/global.sym b/global.sym
index 0c6eece211..7295be6a9f 100644
--- a/global.sym
+++ b/global.sym
@@ -435,10 +435,10 @@ runops_standard
rxres_free
rxres_restore
rxres_save
-safecalloc
-safefree
-safemalloc
-saferealloc
+safesyscalloc
+safesysfree
+safesysmalloc
+safesysrealloc
safexcalloc
safexfree
safexmalloc
diff --git a/iperlsys.h b/iperlsys.h
index 97f30e33b4..cfdc39f9de 100644
--- a/iperlsys.h
+++ b/iperlsys.h
@@ -610,15 +610,9 @@ 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 */
diff --git a/mg.c b/mg.c
index 9547da88d2..bab5298acb 100644
--- a/mg.c
+++ b/mg.c
@@ -880,7 +880,7 @@ magic_clear_all_env(SV *sv, MAGIC *mg)
#if defined(VMS)
die("Can't make list assignment to %%ENV on this system");
#else
-#ifdef WIN32
+# ifdef WIN32
char *envv = GetEnvironmentStrings();
char *cur = envv;
STRLEN len;
@@ -896,18 +896,21 @@ magic_clear_all_env(SV *sv, MAGIC *mg)
cur += len+1;
}
FreeEnvironmentStrings(envv);
-#else
+# else
+# ifndef PERL_USE_SAFE_PUTENV
I32 i;
if (environ == PL_origenviron)
- New(901, environ, 1, char*);
+ environ = (char**)safesysmalloc(sizeof(char*));
else
for (i = 0; environ[i]; i++)
- Safefree(environ[i]);
+ safesysfree(environ[i]);
+# endif /* PERL_USE_SAFE_PUTENV */
+
environ[0] = Nullch;
-#endif
-#endif
+# endif /* WIN32 */
+#endif /* VMS */
return 0;
}
diff --git a/objXSUB.h b/objXSUB.h
index 71aa21108a..0c4efd5456 100644
--- a/objXSUB.h
+++ b/objXSUB.h
@@ -2705,14 +2705,14 @@
#define rxres_restore pPerl->Perl_rxres_restore
#undef rxres_save
#define rxres_save pPerl->Perl_rxres_save
-#undef safecalloc
-#define safecalloc pPerl->Perl_safecalloc
-#undef safefree
-#define safefree pPerl->Perl_safefree
-#undef safemalloc
-#define safemalloc pPerl->Perl_safemalloc
-#undef saferealloc
-#define saferealloc pPerl->Perl_saferealloc
+#undef safesyscalloc
+#define safesyscalloc pPerl->Perl_safesyscalloc
+#undef safesysfree
+#define safesysfree pPerl->Perl_safesysfree
+#undef safesysmalloc
+#define safesysmalloc pPerl->Perl_safesysmalloc
+#undef safesysrealloc
+#define safesysrealloc pPerl->Perl_safesysrealloc
#undef safexcalloc
#define safexcalloc pPerl->Perl_safexcalloc
#undef safexfree
diff --git a/perl.h b/perl.h
index 206f6be56e..783f9042af 100644
--- a/perl.h
+++ b/perl.h
@@ -400,14 +400,15 @@ Malloc_t Perl_realloc _((Malloc_t where, MEM_SIZE nbytes));
* that causes clashes with case-insensitive linkers */
Free_t Perl_mfree _((Malloc_t where));
-# undef safemalloc
-# undef safecalloc
-# undef saferealloc
-# undef safefree
# define safemalloc Perl_malloc
# define safecalloc Perl_calloc
# define saferealloc Perl_realloc
# define safefree Perl_mfree
+#else /* MYMALLOC */
+# define safemalloc safesysmalloc
+# define safecalloc safesyscalloc
+# define saferealloc safesysrealloc
+# define safefree safesysfree
#endif /* MYMALLOC */
#if defined(STANDARD_C) && defined(I_STDDEF)
diff --git a/perl_exp.SH b/perl_exp.SH
index 51c3ab2584..6bf0d7c941 100644
--- a/perl_exp.SH
+++ b/perl_exp.SH
@@ -100,29 +100,11 @@ perl_call_sv
perl_eval_pv
perl_eval_sv
perl_require_pv
-END
-
-case "$ccflags" in
-*-DHIDEMYMALLOC*)
- cat >>perl.exp <<END
-Mymalloc
-Mycalloc
-Myremalloc
-Myfree
-END
- ;;
-esac
-
-case "$ccflags" in
-*-DEMBEDMYMALLOC*)
- cat >>perl.exp <<END
Perl_malloc
Perl_calloc
Perl_realloc
-Perl_free
+Perl_mfree
END
- ;;
-esac
# The shebang line nicely sorts as the first one.
sort -o perl.exp -u perl.exp
diff --git a/proto.h b/proto.h
index 93517d2e70..f91e80bc5b 100644
--- a/proto.h
+++ b/proto.h
@@ -677,12 +677,10 @@ VIRTUAL int yylex _((PERL_YYLEX_PARAM_DECL));
VIRTUAL int yyparse _((void));
VIRTUAL int yywarn _((char* s));
-#ifndef MYMALLOC
-VIRTUAL Malloc_t safemalloc _((MEM_SIZE nbytes));
-VIRTUAL Malloc_t safecalloc _((MEM_SIZE elements, MEM_SIZE size));
-VIRTUAL Malloc_t saferealloc _((Malloc_t where, MEM_SIZE nbytes));
-VIRTUAL Free_t safefree _((Malloc_t where));
-#endif
+VIRTUAL Malloc_t safesysmalloc _((MEM_SIZE nbytes));
+VIRTUAL Malloc_t safesyscalloc _((MEM_SIZE elements, MEM_SIZE size));
+VIRTUAL Malloc_t safesysrealloc _((Malloc_t where, MEM_SIZE nbytes));
+VIRTUAL Free_t safesysfree _((Malloc_t where));
#ifdef LEAKTEST
VIRTUAL Malloc_t safexmalloc _((I32 x, MEM_SIZE size));
diff --git a/util.c b/util.c
index 77dd842f42..8dd7d00931 100644
--- a/util.c
+++ b/util.c
@@ -62,9 +62,7 @@ long lastxycount[MAXXCOUNT][MAXYCOUNT];
#endif
-#ifndef MYMALLOC
-
-/* paranoid version of malloc */
+/* paranoid version of system's malloc() */
/* NOTE: Do not call the next three routines directly. Use the macros
* in handy.h, so that we can easily redefine everything to do tracking of
@@ -73,7 +71,7 @@ long lastxycount[MAXXCOUNT][MAXYCOUNT];
*/
Malloc_t
-safemalloc(MEM_SIZE size)
+safesysmalloc(MEM_SIZE size)
{
Malloc_t ptr;
#ifdef HAS_64K_LIMIT
@@ -104,10 +102,10 @@ safemalloc(MEM_SIZE size)
/*NOTREACHED*/
}
-/* paranoid version of realloc */
+/* paranoid version of system's realloc() */
Malloc_t
-saferealloc(Malloc_t where,MEM_SIZE size)
+safesysrealloc(Malloc_t where,MEM_SIZE size)
{
Malloc_t ptr;
#if !defined(STANDARD_C) && !defined(HAS_REALLOC_PROTOTYPE)
@@ -122,12 +120,12 @@ saferealloc(Malloc_t where,MEM_SIZE size)
}
#endif /* HAS_64K_LIMIT */
if (!size) {
- safefree(where);
+ safesysfree(where);
return NULL;
}
if (!where)
- return safemalloc(size);
+ return safesysmalloc(size);
#ifdef DEBUGGING
if ((long)size < 0)
croak("panic: realloc");
@@ -158,10 +156,10 @@ saferealloc(Malloc_t where,MEM_SIZE size)
/*NOTREACHED*/
}
-/* safe version of free */
+/* safe version of system's free() */
Free_t
-safefree(Malloc_t where)
+safesysfree(Malloc_t where)
{
#if !(defined(I286) || defined(atarist))
DEBUG_m( PerlIO_printf(Perl_debug_log, "0x%x: (%05d) free\n",(char *) where,PL_an++));
@@ -174,10 +172,10 @@ safefree(Malloc_t where)
}
}
-/* safe version of calloc */
+/* safe version of system's calloc() */
Malloc_t
-safecalloc(MEM_SIZE count, MEM_SIZE size)
+safesyscalloc(MEM_SIZE count, MEM_SIZE size)
{
Malloc_t ptr;
@@ -213,8 +211,6 @@ safecalloc(MEM_SIZE count, MEM_SIZE size)
/*NOTREACHED*/
}
-#endif /* !MYMALLOC */
-
#ifdef LEAKTEST
struct mem_test_strut {
@@ -1504,6 +1500,8 @@ warner(U32 err, const char* pat,...)
void
my_setenv(char *nam, char *val)
{
+#ifndef PERL_USE_SAFE_PUTENV
+ /* most putenv()s leak, so we manipulate environ directly */
register I32 i=setenv_getix(nam); /* where does it go? */
if (environ == PL_origenviron) { /* need we copy environment? */
@@ -1513,14 +1511,16 @@ my_setenv(char *nam, char *val)
/*SUPPRESS 530*/
for (max = i; environ[max]; max++) ;
- New(901,tmpenv, max+2, char*);
- for (j=0; j<max; j++) /* copy environment */
- tmpenv[j] = savepv(environ[j]);
+ tmpenv = (char**)safesysmalloc((max+2) * sizeof(char*));
+ for (j=0; j<max; j++) { /* copy environment */
+ tmpenv[j] = (char*)safesysmalloc((strlen(environ[j])+1)*sizeof(char));
+ strcpy(tmpenv[j], environ[j]);
+ }
tmpenv[max] = Nullch;
environ = tmpenv; /* tell exec where it is now */
}
if (!val) {
- Safefree(environ[i]);
+ safesysfree(environ[i]);
while (environ[i]) {
environ[i] = environ[i+1];
i++;
@@ -1528,12 +1528,13 @@ my_setenv(char *nam, char *val)
return;
}
if (!environ[i]) { /* does not exist yet */
- Renew(environ, i+2, char*); /* just expand it a bit */
+ environ = (char**)safesysrealloc(environ, (i+2) * sizeof(char*));
environ[i+1] = Nullch; /* make sure it's null terminated */
}
else
- Safefree(environ[i]);
- New(904, environ[i], strlen(nam) + strlen(val) + 2, char);
+ safesysfree(environ[i]);
+ environ[i] = (char*)safesysmalloc((strlen(nam)+strlen(val)+2) * sizeof(char));
+
#ifndef MSDOS
(void)sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
#else
@@ -1545,6 +1546,19 @@ my_setenv(char *nam, char *val)
strcpy(environ[i],nam); strupr(environ[i]);
(void)sprintf(environ[i] + strlen(nam),"=%s",val);
#endif /* MSDOS */
+
+#else /* PERL_USE_SAFE_PUTENV */
+ char *new_env;
+
+ new_env = (char*)safesysmalloc((strlen(nam) + strlen(val) + 2) * sizeof(char));
+#ifndef MSDOS
+ (void)sprintf(new_env,"%s=%s",nam,val);/* all that work just for this */
+#else
+ strcpy(new_env,nam); strupr(new_env);
+ (void)sprintf(new_env + strlen(nam),"=%s",val);
+#endif
+ (void)putenv(new_env);
+#endif /* PERL_USE_SAFE_PUTENV */
}
#else /* if WIN32 */
@@ -1582,13 +1596,13 @@ my_setenv(char *nam,char *val)
}
else
vallen = strlen(val);
- New(904, envstr, namlen + vallen + 3, char);
+ envstr = (char*)safesysmalloc((namlen + vallen + 3) * sizeof(char));
(void)sprintf(envstr,"%s=%s",nam,val);
(void)PerlEnv_putenv(envstr);
if (oldstr)
- Safefree(oldstr);
+ safesysfree(oldstr);
#ifdef _MSC_VER
- Safefree(envstr); /* MSVCRT leaks without this */
+ safesysfree(envstr); /* MSVCRT leaks without this */
#endif
#else /* !USE_WIN32_RTL_ENV */
diff --git a/vms/gen_shrfls.pl b/vms/gen_shrfls.pl
index f6906c51c9..8e89348ae4 100644
--- a/vms/gen_shrfls.pl
+++ b/vms/gen_shrfls.pl
@@ -73,7 +73,6 @@ if ($docc) {
open CONFIG, "< $config";
while(<CONFIG>) {
$debugging_enabled++ if /define\s+DEBUGGING/;
- $hide_mymalloc++ if /define\s+EMBEDMYMALLOC/;
$use_mymalloc++ if /define\s+MYMALLOC/;
}
@@ -203,7 +202,7 @@ if ($use_mymalloc) {
$fcns{'Perl_malloc'}++;
$fcns{'Perl_calloc'}++;
$fcns{'Perl_realloc'}++;
- $fcns{'Perl_myfree'}++;
+ $fcns{'Perl_mfree'}++;
}
$used_expectation_enum = $used_opcode_enum = 0; # avoid warnings
diff --git a/win32/makedef.pl b/win32/makedef.pl
index 4e60302bcc..0d9069b9fd 100644
--- a/win32/makedef.pl
+++ b/win32/makedef.pl
@@ -181,14 +181,9 @@ PL_opsave
if ($define{'MYMALLOC'})
{
- skip_symbols [qw(
- Perl_safefree
- Perl_safemalloc
- Perl_saferealloc
- Perl_safecalloc)];
emit_symbols [qw(
Perl_malloc
- Perl_free
+ Perl_mfree
Perl_realloc
Perl_calloc)];
}