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

Buggy smartmatch on tied array #13335

Open
p5pRT opened this issue Oct 6, 2013 · 6 comments
Open

Buggy smartmatch on tied array #13335

p5pRT opened this issue Oct 6, 2013 · 6 comments
Labels
Closable? We might be able to close this ticket, but we need to check with the reporter type-core

Comments

@p5pRT
Copy link

p5pRT commented Oct 6, 2013

Migrated from rt.perl.org#120122 (status was 'open')

Searchable as RT120122$

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 2013

From @sanko

This is a bug report for perl from sanko@​cpan.org,
generated with the help of perlbug 1.39 running under perl 5.16.3.


More tie() tinkering... I've found that the now experimental smartmatch
operator does not work well with tied arrays. Simple example​:

  use Tie​::Array;
  tie my @​array_t, 'Tie​::StdArray';
  @​array_t = qw[aaa bbb ccc ddd eee];
  print "tied smatch​: " . (/a/ ~~ @​array_t) . "\n";
  print "tied grep​: " . (grep {/a/} @​array_t) . "\n";

Smartmatch correctly calls the FETCHSIZE method but the magic is ignored
when it's time to get the individual elements. FETCH is never called and
undefined values are matched instead. FWIW, matching against tied hashes
seems to work as it should.

Original discussion on PerlMonks​: http​://perlmonks.org/?node_id=1057045



Flags​:
  category=core
  severity=low


Site configuration information for perl 5.16.3​:

Configured by strawberry-perl at Tue Mar 12 13​:56​:09 2013.

Summary of my perl5 (revision 5 version 16 subversion 3) configuration​:

  Platform​:
  osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
  uname='Win32 strawberry-perl 5.16.3.1 #1 Tue Mar 12 13​:55​:20 2013 i386'
  config_args='undef'
  hint=recommended, useposix=true, d_sigaction=undef
  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='gcc', ccflags =' -s -O2 -DWIN32 -DPERL_TEXTMODE_SCRIPTS
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing
-mms-bitfields',
  optimize='-s -O2',
  cppflags='-DWIN32'
  ccversion='', gccversion='4.6.3', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long
long', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='g++', ldflags ='-s -L"C​:\strawberry\perl\lib\CORE"
-L"C​:\strawberry\c\lib"'
  libpth=C​:\strawberry\c\lib C​:\strawberry\c\i686-w64-mingw32\lib
  libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32
-lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
  perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool
-lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid
-lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
  libc=, so=dll, useshrplib=true, libperl=libperl516.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags='-mdll -s
-L"C​:\strawberry\perl\lib\CORE" -L"C​:\strawberry\c\lib"'

Locally applied patches​:


@​INC for perl 5.16.3​:
  C​:/strawberry/perl/site/lib/MSWin32-x86-multi-thread
  C​:/strawberry/perl/site/lib
  C​:/strawberry/perl/vendor/lib
  C​:/strawberry/perl/lib
  .


Environment for perl 5.16.3​:
  HOME=C​:\Users\Sanko
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=C​:\Windows\system32;C​:\Windows;C​:\Windows\System32\Wbem;C​:\Windows\System32\WindowsPowerShell\v1.0\;C​:\Windows\System32\WindowsPowerShell\v1.0\;C​:\Windows\System32\WindowsPowerShell\v1.0\;C​:\strawberry\c\bin;C​:\strawberry\perl\site\bin;C​:\strawberry\perl\bin;C​:\Ruby193\bin;C​:\Windows\system32;C​:\Windows;C​:\Windows\System32\Wbem;C​:\Windows\System32\WindowsPowerShell\v1.0\;C​:\Windows\System32\WindowsPowerShell\v1.0\;C​:\Windows\System32\WindowsPowerShell\v1.0\;C​:\Program
Files\Mercurial;C​:\strawberry\c\bin;C​:\strawberry\perl\site\bin;C​:\strawberry\perl\bin;C​:\Program
Files\Python32\Lib\site-packages\PyQt4;C​:\Program
Files\Prio;C​:\Program Files\git-cola\bin;C​:\Program
Files\Git\cmd;C​:\Program Files\Git\bin;;
  PERL_BADLANG (unset)
  PERL_CPANM_OPT=--mirror http​://cpan.cpantesters.org --verbose
--notest --force
  SHELL (unset)
--
Sanko Robinson
sanko@​cpan.org

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 2013

From @cpansprout

On Sun Oct 06 08​:50​:23 2013, sanko wrote​:

This is a bug report for perl from sanko@​cpan.org,
generated with the help of perlbug 1.39 running under perl 5.16.3.

-----------------------------------------------------------------
More tie() tinkering... I've found that the now experimental
smartmatch
operator does not work well with tied arrays. Simple example​:

use Tie​::Array;
tie my @​array\_t\, 'Tie​::StdArray';
@​array\_t = qw\[aaa bbb ccc ddd eee\];
print "tied smatch​:  " \. \(/a/ ~~ @​array\_t\) \. "\\n";
print "tied grep​:    " \. \(grep \{/a/\} @​array\_t\) \. "\\n";

Smartmatch correctly calls the FETCHSIZE method but the magic is
ignored
when it's time to get the individual elements. FETCH is never called
and
undefined values are matched instead. FWIW, matching against tied
hashes
seems to work as it should.

I probably broke that in v5.11.2-153-g69dc4b3. pp_match now assumes it
is preceded by a pp_regcomp (which is the case outside of smartmatch).
The solution is probably to have pp_ctl.c​:S_matcher_matches_sv call
get-magic itself.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 2013

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 2013

From @Leont

On Sun, Oct 6, 2013 at 5​:50 PM, Sanko Robinson <perlbug-followup@​perl.org>wrote​:

More tie() tinkering... I've found that the now experimental smartmatch
operator does not work well with tied arrays. Simple example​:

use Tie&#8203;::Array;
tie my @&#8203;array\_t\, 'Tie&#8203;::StdArray';
@&#8203;array\_t = qw\[aaa bbb ccc ddd eee\];
print "tied smatch&#8203;:  " \. \(/a/ ~~ @&#8203;array\_t\) \. "\\n";
print "tied grep&#8203;:    " \. \(grep \{/a/\} @&#8203;array\_t\) \. "\\n";

Smartmatch correctly calls the FETCHSIZE method but the magic is ignored
when it's time to get the individual elements. FETCH is never called and
undefined values are matched instead. FWIW, matching against tied hashes
seems to work as it should.

Original discussion on PerlMonks​: http​://perlmonks.org/?node_id=1057045

Smartmatch is generally quite sloppy with array magic. The only reason that
it works as expected for hashes is because no smartmatch looks at the
values of hashes. The issue is explained in
perlguts#Understanding-the-Magic-of-Tied-Hashes-and-Arrays, to summarize a
longer story you always want to call getmagic (or setmagic when that's
appropriate) on the values [ah]v_fetch returns to you. It's broken for all
matches involving array elements.

Leon

@toddr
Copy link
Member

toddr commented Feb 14, 2020

I think this ticket can be closed as: By design (for some versions of design)?

@toddr toddr added Closable? We might be able to close this ticket, but we need to check with the reporter and removed distro-mswin32 labels Feb 14, 2020
@Leont
Copy link
Contributor

Leont commented Feb 14, 2020

I think this ticket can be closed as: By design (for some versions of design)?

Not really. I can't think of any reason for this not to DWIM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closable? We might be able to close this ticket, but we need to check with the reporter type-core
Projects
None yet
Development

No branches or pull requests

4 participants