#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
#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
rxres_free
rxres_restore
rxres_save
-safecalloc
-safefree
-safemalloc
-saferealloc
+safesyscalloc
+safesysfree
+safesysmalloc
+safesysrealloc
safexcalloc
safexfree
safexmalloc
#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 */
#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;
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;
}
#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
* 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)
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
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));
#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
*/
Malloc_t
-safemalloc(MEM_SIZE size)
+safesysmalloc(MEM_SIZE size)
{
Malloc_t ptr;
#ifdef HAS_64K_LIMIT
/*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)
}
#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");
/*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++));
}
}
-/* 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;
/*NOTREACHED*/
}
-#endif /* !MYMALLOC */
-
#ifdef LEAKTEST
struct mem_test_strut {
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? */
/*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++;
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
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 */
}
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 */
open CONFIG, "< $config";
while(<CONFIG>) {
$debugging_enabled++ if /define\s+DEBUGGING/;
- $hide_mymalloc++ if /define\s+EMBEDMYMALLOC/;
$use_mymalloc++ if /define\s+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
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)];
}