Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tie $scalar can tie a handle #10609

Closed
p5pRT opened this issue Sep 5, 2010 · 10 comments
Closed

tie $scalar can tie a handle #10609

p5pRT opened this issue Sep 5, 2010 · 10 comments

Comments

@p5pRT
Copy link
Collaborator

@p5pRT p5pRT commented Sep 5, 2010

Migrated from rt.perl.org#77688 (status was 'resolved')

Searchable as RT77688$

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Sep 5, 2010

From @cpansprout

tie() does not distinguish between $scalar and *$scalar if $scalar happens to hold a glob.


Flags​:
  category=core
  severity=low


Site configuration information for perl 5.13.4​:

Configured by sprout at Sun Aug 29 17​:21​:22 PDT 2010.

Summary of my perl5 (revision 5 version 13 subversion 4 patch v5.13.4-30-g9b47cdd) configuration​:
  Snapshot of​: 9b47cdd
  Platform​:
  osname=darwin, osvers=10.4.0, archname=darwin-thread-multi-2level
  uname='darwin pint.local 10.4.0 darwin kernel version 10.4.0​: fri apr 23 18​:28​:53 pdt 2010; root​:xnu-1504.7.4~1release_i386 i386 '
  config_args='-de -Dusedevel -Duseithreads'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=define, usemultiplicity=define
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=undef, use64bitall=undef, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include',
  optimize='-O3',
  cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.2.1 (Apple Inc. build 5664)', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /usr/lib
  libs=-ldbm -ldl -lm -lutil -lc
  perllibs=-ldl -lm -lutil -lc
  libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector'

Locally applied patches​:
 


@​INC for perl 5.13.4​:
  /usr/local/lib/perl5/site_perl/5.13.4/darwin-thread-multi-2level
  /usr/local/lib/perl5/site_perl/5.13.4
  /usr/local/lib/perl5/5.13.4/darwin-thread-multi-2level
  /usr/local/lib/perl5/5.13.4
  /usr/local/lib/perl5/site_perl
  .


Environment for perl 5.13.4​:
  DYLD_LIBRARY_PATH (unset)
  HOME=/Users/sprout
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/bin​:/bin​:/usr/sbin​:/sbin​:/usr/local/bin​:/usr/X11/bin​:/usr/local/bin
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Sep 5, 2010

From @cpansprout

On Sep 5, 2010, at 1​:19 PM, Father Chrysostomos wrote​:

tie() does not distinguish between $scalar and *$scalar if $scalar happens to hold a glob.

Here is a patch for it. It won’t apply without the patches for #77362 and #77496 applied first.

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Sep 5, 2010

From @cpansprout

From​: Father Chrysostomos <sprout@​cpan.org>

[perl #77688] tie $scalar can tie a handle

Make tie() distinguish between $scalar and *$scalar when $scalar holds
a glob copy, by checking for an OP_RV2GV.

Inline Patch
diff -Nup blead-77362-glob2lv10.glob-assign-and-magick/op.c blead-77362-glob2lv11.tie/op.c
--- blead-77362-glob2lv10.glob-assign-and-magick/op.c	2010-08-27 23:17:55.000000000 -0700
+++ blead-77362-glob2lv11.tie/op.c	2010-09-04 14:34:25.000000000 -0700
@@ -7156,7 +7156,12 @@ Perl_ck_fun(pTHX_ OP *o)
 #endif
 	listkids(o);
 
-	if (type == OP_TIED && cLISTOPo->op_first->op_type == OP_RV2GV)
+	if ((type == OP_TIED && cLISTOPo->op_first->op_type == OP_RV2GV)
+	 || (
+	        type == OP_TIE
+	     && cLISTOPo->op_first->op_sibling->op_type == OP_RV2GV
+	    )
+	   )
 	    o->op_flags |= OPf_SPECIAL;
     }
     else if (PL_opargs[type] & OA_DEFGV) {
diff -Nup blead-77362-glob2lv10.glob-assign-and-magick/op.h blead-77362-glob2lv11.tie/op.h
--- blead-77362-glob2lv10.glob-assign-and-magick/op.h	2010-08-27 23:18:02.000000000 -0700
+++ blead-77362-glob2lv11.tie/op.h	2010-09-04 06:24:30.000000000 -0700
@@ -139,7 +139,7 @@ Deprecated.  Use C<GIMME_V> instead.
 				/*  On OP_ANONHASH and OP_ANONLIST, create a
 				    reference to the new anon hash or array */
 				/*  On OP_ENTER, store caller context */
-				/*  On OP_TIED, RHS is a handle */
+				/*  On OP_TIE(D), RHS is a handle */
 				/*  On OP_HELEM and OP_HSLICE, localization will be followed
 				    by assignment, so do not wipe the target if it is special
 				    (e.g. a glob or a magic SV) */
diff -Nup blead-77362-glob2lv10.glob-assign-and-magick/pp_sys.c blead-77362-glob2lv11.tie/pp_sys.c
--- blead-77362-glob2lv10.glob-assign-and-magick/pp_sys.c	2010-08-27 23:18:20.000000000 -0700
+++ blead-77362-glob2lv11.tie/pp_sys.c	2010-09-04 14:34:59.000000000 -0700
@@ -826,7 +826,8 @@ PP(pp_tie)
 	    break;
 	case SVt_PVGV:
 	case SVt_PVLV:
-	    if (isGV_with_GP(varsv)) {
+	    if (isGV_with_GP(varsv)
+	     && (!SvFAKE(varsv) || PL_op->op_flags & OPf_SPECIAL)) {
 		methname = "TIEHANDLE";
 		how = PERL_MAGIC_tiedscalar;
 		/* For tied filehandles, we apply tiedscalar magic to the IO
diff -rup blead-77362-glob2lv10.glob-assign-and-magick/t/op/tie.t blead-77362-glob2lv11.tie/t/op/tie.t
--- blead-77362-glob2lv10.glob-assign-and-magick/t/op/tie.t	2010-08-27 23:18:42.000000000 -0700
+++ blead-77362-glob2lv11.tie/t/op/tie.t	2010-09-04 06:09:29.000000000 -0700
@@ -953,3 +953,14 @@ print ref tied *$rin, "\n";
 EXPECT
 main
 f
+########
+
+# tie $glob_copy vs tie *$glob_copy
+sub TIESCALAR { print "TIESCALAR\n" }
+sub TIEHANDLE{ print "TIEHANDLE\n" }
+$f = *foo;
+tie *$f, "";
+tie $f, "";
+EXPECT
+TIEHANDLE
+TIESCALAR
@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Oct 25, 2010

From @cpansprout

On Sun Sep 05 13​:39​:43 2010, sprout wrote​:

On Sep 5, 2010, at 1​:19 PM, Father Chrysostomos wrote​:

tie() does not distinguish between $scalar and *$scalar if $scalar
happens to hold a glob.

Here is a patch for it. It won’t apply without the patches for #77362
and #77496 applied first.

Change 2acc331 allows a much simpler fix, which has been applied
as 9aa8b00.

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Oct 25, 2010

From [Unknown Contact. See original ticket]

On Sun Sep 05 13​:39​:43 2010, sprout wrote​:

On Sep 5, 2010, at 1​:19 PM, Father Chrysostomos wrote​:

tie() does not distinguish between $scalar and *$scalar if $scalar
happens to hold a glob.

Here is a patch for it. It won’t apply without the patches for #77362
and #77496 applied first.

Change 2acc331 allows a much simpler fix, which has been applied
as 9aa8b00.

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Oct 25, 2010

@cpansprout - Status changed from 'new' to 'resolved'

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Apr 20, 2011

@cpansprout - Status changed from 'resolved' to 'open'

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Apr 20, 2011

From @cpansprout

I’ve re-opened this, since the fix was reverted for 5.14. See #79528.

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Jun 11, 2011

From @cpansprout

On Wed Apr 20 14​:34​:14 2011, sprout wrote​:

I’ve re-opened this, since the fix was reverted for 5.14. See #79528.

And now the revert has been reverted as 8bb5f78.

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Jun 11, 2011

@cpansprout - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.