Change 12043 by ams@ams-lustre on 2001/09/17 05:44:50
Subject: Re: [BUG?] chdir(undef) == chdir() probably a bug
From: Michael G Schwern <[EMAIL PROTECTED]>
Date: Mon, 17 Sep 2001 07:49:04 +0200
Message-Id: <20010917074904.V1588@blackrider>
(Applied with tweaks to chdir.t and pp_sys.c hunks.)
Affected files ...
... //depot/perl/MANIFEST#556 edit
... //depot/perl/pp_sys.c#255 edit
... //depot/perl/t/op/chdir.t#1 add
Differences ...
==== //depot/perl/MANIFEST#556 (text) ====
Index: perl/MANIFEST
--- perl/MANIFEST.~1~ Mon Sep 17 00:00:05 2001
+++ perl/MANIFEST Mon Sep 17 00:00:05 2001
@@ -2038,6 +2038,7 @@
t/op/bless.t See if bless works
t/op/bop.t See if bitops work
t/op/chars.t See if character escapes work
+t/op/chdir.t See if chdir works
t/op/chop.t See if chop works
t/op/closure.t See if closures work
t/op/cmp.t See if the various string and numeric compare work
==== //depot/perl/pp_sys.c#255 (text) ====
Index: perl/pp_sys.c
--- perl/pp_sys.c.~1~ Mon Sep 17 00:00:05 2001
+++ perl/pp_sys.c Mon Sep 17 00:00:05 2001
@@ -3375,27 +3375,22 @@
SV **svp;
STRLEN n_a;
- if (MAXARG < 1)
- tmps = Nullch;
+ if (MAXARG < 1) {
+ if (((svp = hv_fetch(GvHVn(PL_envgv), "HOME", 4, FALSE))
+ || (svp = hv_fetch(GvHVn(PL_envgv), "LOGDIR", 6, FALSE))
+#ifdef VMS
+ || (svp = hv_fetch(GvHVn(PL_envgv), "SYS$LOGIN", 9, FALSE))
+#endif
+ ) && SvPOK(*svp))
+ {
+ tmps = SvPV(*svp, n_a);
+ }
+ else
+ tmps = Nullch;
+ }
else
tmps = POPpx;
- if (!tmps || !*tmps) {
- svp = hv_fetch(GvHVn(PL_envgv), "HOME", 4, FALSE);
- if (svp)
- tmps = SvPV(*svp, n_a);
- }
- if (!tmps || !*tmps) {
- svp = hv_fetch(GvHVn(PL_envgv), "LOGDIR", 6, FALSE);
- if (svp)
- tmps = SvPV(*svp, n_a);
- }
-#ifdef VMS
- if (!tmps || !*tmps) {
- svp = hv_fetch(GvHVn(PL_envgv), "SYS$LOGIN", 9, FALSE);
- if (svp)
- tmps = SvPV(*svp, n_a);
- }
-#endif
+
TAINT_PROPER("chdir");
PUSHi( PerlDir_chdir(tmps) >= 0 );
#ifdef VMS
==== //depot/perl/t/op/chdir.t#1 (text) ====
Index: perl/t/op/chdir.t
--- perl/t/op/chdir.t.~1~ Mon Sep 17 00:00:05 2001
+++ perl/t/op/chdir.t Mon Sep 17 00:00:05 2001
@@ -0,0 +1,68 @@
+BEGIN {
+ # We're not going to chdir() into 't' because we don't know if
+ # chdir() works! Instead, we'll hedge our bets and put both
+ # possibilities into @INC.
+ @INC = ('lib', '../lib');
+}
+
+
+# Might be a little early in the testing process to start using these,
+# but I can't think of a way to write this test without them.
+use Cwd qw(abs_path cwd);
+use File::Spec::Functions qw(:DEFAULT splitdir);
+
+use Test::More tests => 24;
+
+my $cwd = abs_path;
+
+# Let's get to a known position
+SKIP: {
+ skip("Already in t/", 2) if (splitdir(abs_path))[-1] eq 't';
+
+ ok( chdir('t'), 'chdir("t")');
+ is( abs_path, catdir($cwd, 't'), ' abs_path() agrees' );
+}
+
+$cwd = abs_path;
+
+# The environment variables chdir() pays attention to.
+my @magic_envs = qw(HOME LOGDIR SYS$LOGIN);
+
+foreach my $key (@magic_envs) {
+ # We're going to be using undefs a lot here.
+ no warnings 'uninitialized';
+
+ delete @ENV{@magic_envs};
+ local $ENV{$key} = catdir $cwd, 'op';
+
+ if( $key eq 'SYS$LOGIN' && $^O ne 'VMS' ) {
+ # Make sure $ENV{'SYS$LOGIN'} is only honored on VMS.
+ ok( !chdir(), "chdir() w/\$ENV{$key} set" );
+ is( abs_path, $cwd, ' abs_path() agrees' );
+ }
+ else {
+ ok( chdir(), "chdir() w/\$ENV{$key} set" );
+ is( abs_path, $ENV{$key}, ' abs_path() agrees' );
+ chdir($cwd);
+ is( abs_path, $cwd, ' and back again' );
+ }
+
+ # Bug had chdir(undef) being the same as chdir()
+ ok( !chdir(undef), "chdir(undef) w/\$ENV{$key} set" );
+ is( abs_path, $cwd, ' abs_path() agrees' );
+
+ # Ditto chdir('').
+ ok( !chdir(''), "chdir('') w/\$ENV{$key} set" );
+ is( abs_path, $cwd, ' abs_path() agrees' );
+}
+
+{
+ # We're going to be using undefs a lot here.
+ no warnings 'uninitialized';
+
+ # Unset all the environment variables chdir() pay attention to.
+ local @ENV{@magic_envs} = (undef) x @magic_envs;
+
+ ok( !chdir(), 'chdir() w/o any ENV set' );
+ is( abs_path, $cwd, ' abs_path() agrees' );
+}
End of Patch.