This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Inline S_procself_val() into S_set_caret_x().
authorNicholas Clark <nick@ccl4.org>
Tue, 13 Sep 2011 19:31:34 +0000 (21:31 +0200)
committerNicholas Clark <nick@ccl4.org>
Wed, 14 Sep 2011 09:25:57 +0000 (11:25 +0200)
Possibly this should have been done as part of commit 3aa90d208c3bbfc1,
which broke S_set_caret_X() out from S_init_postdump_symbols().
[S_procself_val() was not inlined into S_init_postdump_symbols() because
Nick Ing-Simmons thought it unwise to hold on to MAXPATHLEN bytes of stack
longer than necessary.]

perl.c

diff --git a/perl.c b/perl.c
index 39c555c..32d47dd 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -1389,41 +1389,6 @@ Perl_call_atexit(pTHX_ ATEXIT_t fn, void *ptr)
     ++PL_exitlistlen;
 }
 
-#ifdef HAS_PROCSELFEXE
-/* This is a function so that we don't hold on to MAXPATHLEN
-   bytes of stack longer than necessary
- */
-STATIC void
-S_procself_val(pTHX_ SV *sv, const char *arg0)
-{
-    char buf[MAXPATHLEN];
-    int len = readlink(PROCSELFEXE_PATH, buf, sizeof(buf) - 1);
-
-    /* On Playstation2 Linux V1.0 (kernel 2.2.1) readlink(/proc/self/exe)
-       includes a spurious NUL which will cause $^X to fail in system
-       or backticks (this will prevent extensions from being built and
-       many tests from working). readlink is not meant to add a NUL.
-       Normal readlink works fine.
-     */
-    if (len > 0 && buf[len-1] == '\0') {
-      len--;
-    }
-
-    /* FreeBSD's implementation is acknowledged to be imperfect, sometimes
-       returning the text "unknown" from the readlink rather than the path
-       to the executable (or returning an error from the readlink).  Any valid
-       path has a '/' in it somewhere, so use that to validate the result.
-       See http://www.freebsd.org/cgi/query-pr.cgi?pr=35703
-    */
-    if (len > 0 && memchr(buf, '/', len)) {
-       sv_setpvn(sv,buf,len);
-    }
-    else {
-       sv_setpv(sv,arg0);
-    }
-}
-#endif /* HAS_PROCSELFEXE */
-
 STATIC void
 S_set_caret_X(pTHX) {
     dVAR;
@@ -1431,7 +1396,31 @@ S_set_caret_X(pTHX) {
     if (tmpgv) {
        SV *const caret_x = GvSV(tmpgv);
 #ifdef HAS_PROCSELFEXE
-       S_procself_val(aTHX_ caret_x, PL_origargv[0]);
+       char buf[MAXPATHLEN];
+       int len = readlink(PROCSELFEXE_PATH, buf, sizeof(buf) - 1);
+
+       /* On Playstation2 Linux V1.0 (kernel 2.2.1) readlink(/proc/self/exe)
+          includes a spurious NUL which will cause $^X to fail in system
+          or backticks (this will prevent extensions from being built and
+          many tests from working). readlink is not meant to add a NUL.
+          Normal readlink works fine.
+       */
+       if (len > 0 && buf[len-1] == '\0') {
+           len--;
+       }
+
+       /* FreeBSD's implementation is acknowledged to be imperfect, sometimes
+          returning the text "unknown" from the readlink rather than the path
+          to the executable (or returning an error from the readlink). Any
+          valid path has a '/' in it somewhere, so use that to validate the
+          result. See http://www.freebsd.org/cgi/query-pr.cgi?pr=35703
+       */
+       if (len > 0 && memchr(buf, '/', len)) {
+           sv_setpvn(caret_x, buf, len);
+       }
+       else {
+           sv_setpv(caret_x, PL_origargv[0]);
+       }
 #else
 #ifdef OS2
        sv_setpv(caret_x, os2_execname(aTHX));