summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorDaniel Dragan <bulk88@hotmail.com>2012-11-12 06:19:10 -0800
committerFather Chrysostomos <sprout@cpan.org>2012-11-12 08:32:50 -0800
commit4cbe3a7d4e9196aab2ca064651827e69cfa50f74 (patch)
tree11adea255a75691aac2e61ba2162d24ca40f9a59 /util.c
parent0e578cb525681b03d8893587039eba95f1e2e0ab (diff)
downloadperl-4cbe3a7d4e9196aab2ca064651827e69cfa50f74.tar.gz
clean up the users of PL_no_mem
This commit eliminates a couple strlen()s of a literal. "Out of memory!\n" and PL_no_mem did not string pool on Visual C, so PL_no_mem was given a length. This commit removes S_write_no_mem and replaces it with nonstatic. Perl_croak_no_mem was made nocontext to save instructions in it's callers. NORETURN_FUNCTION_END caused a syntax error on Visual C C++ mode and therefore was removed.
Diffstat (limited to 'util.c')
-rw-r--r--util.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/util.c b/util.c
index b7403e89c6..5132c24b84 100644
--- a/util.c
+++ b/util.c
@@ -59,17 +59,6 @@ int putenv(char *);
* XXX This advice seems to be widely ignored :-( --AD August 1996.
*/
-static char *
-S_write_no_mem(pTHX)
-{
- dVAR;
- /* Can't use PerlIO to write as it allocates memory */
- PerlLIO_write(PerlIO_fileno(Perl_error_log),
- PL_no_mem, strlen(PL_no_mem));
- my_exit(1);
- NORETURN_FUNCTION_END;
-}
-
#if defined (DEBUGGING) || defined(PERL_IMPLICIT_SYS) || defined (PERL_TRACK_MEMPOOL)
# define ALWAYS_NEED_THX
#endif
@@ -131,7 +120,7 @@ Perl_safesysmalloc(MEM_SIZE size)
if (PL_nomemok)
return NULL;
else {
- return write_no_mem();
+ croak_no_mem();
}
}
/*NOTREACHED*/
@@ -234,7 +223,7 @@ Perl_safesysrealloc(Malloc_t where,MEM_SIZE size)
if (PL_nomemok)
return NULL;
else {
- return write_no_mem();
+ croak_no_mem();
}
}
/*NOTREACHED*/
@@ -368,7 +357,7 @@ Perl_safesyscalloc(MEM_SIZE count, MEM_SIZE size)
#endif
if (PL_nomemok)
return NULL;
- return write_no_mem();
+ croak_no_mem();
}
}
@@ -1013,7 +1002,7 @@ Perl_savesharedpv(pTHX_ const char *pv)
pvlen = strlen(pv)+1;
newaddr = (char*)PerlMemShared_malloc(pvlen);
if (!newaddr) {
- return write_no_mem();
+ croak_no_mem();
}
return (char*)memcpy(newaddr, pv, pvlen);
}
@@ -1035,7 +1024,7 @@ Perl_savesharedpvn(pTHX_ const char *const pv, const STRLEN len)
/* PERL_ARGS_ASSERT_SAVESHAREDPVN; */
if (!newaddr) {
- return write_no_mem();
+ croak_no_mem();
}
newaddr[len] = '\0';
return (char*)memcpy(newaddr, pv, len);
@@ -1630,6 +1619,20 @@ Perl_croak_no_modify()
Perl_croak_nocontext( "%s", PL_no_modify);
}
+/* does not return, used in util.c perlio.c and win32.c
+ This is typically called when malloc returns NULL.
+*/
+void
+Perl_croak_no_mem()
+{
+ dTHX;
+ dVAR;
+ /* Can't use PerlIO to write as it allocates memory */
+ PerlLIO_write(PerlIO_fileno(Perl_error_log),
+ PL_no_mem, sizeof(PL_no_mem)-1);
+ my_exit(1);
+}
+
/*
=for apidoc Am|void|warn_sv|SV *baseex