diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-08-26 09:49:37 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-08-26 09:49:37 -0700 |
commit | 0163043af7a8e96adfa1b5b3e4055cc161e03216 (patch) | |
tree | adc45f57db6fb16365ea6aebabef612342e763c1 /t | |
parent | fdd313f408816da86d118db4dd449f129d676885 (diff) | |
download | perl-0163043af7a8e96adfa1b5b3e4055cc161e03216.tar.gz |
&CORE::gmtime() and &CORE::localtime()
This commit allows &CORE::gmtime and &CORE::localtime to be called
through references and via ampersand syntax. pp_gmtime is modified
to take into account the nulls pushed on to the stack in pp_coreargs,
which happens because pp_coreargs has no other way to tell pp_gmtime
how many arguments it’s actually getting.
I was going to say ‘see commit f6a1686942 for more details’, but found
out, to my horror, that most of the commit message was cut off. I
don’t know which commit-munging part of git is responsible, but I’ve
had similar problems with git am and git commit --amend. But, then,
this could have been sloppy copy and paste. Anyway, here is the
missing part:
Usually, an op that has optional arguments has the number of arguments
indicated with flags on the op itself:
$ ./perl -Ilib -MO=Concise -e 'binmode 1'
6 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v:{ ->3
5 <@> binmode vK/1 ->6
- <0> ex-pushmark s ->3
4 <1> rv2gv sK*/1 ->5
3 <$> gv(*1) s ->4
-e syntax OK
$ ./perl -Ilib -MO=Concise -e 'binmode 1,2'
7 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v:{ ->3
6 <@> binmode vK/2 ->7
- <0> ex-pushmark s ->3
4 <1> rv2gv sK*/1 ->5
3 <$> gv(*1) s ->4
5 <$> const(IV 2) s ->6
-e syntax OK
Notice the /1 vs /2 on the binmode op.
With a CORE sub, we have a single op for both cases. So, what this
commit does is set the number of arguments to the maximum, push nulls
on to the stack in pp_coreargs (actually, it was already set up to
do it, so there is no change there), and have the pp_ functions for
each op that has optional arguments do a null check after popping
the stack.
pp_binmode already does a null check, but other pp_ functions will
need to be modified. Since each one is different, those will come in
separate commits.
This is what &CORE::binmode’s op tree looks like:
$ ./perl -Ilib -MO=Concise,CORE::binmode -e 'BEGIN{\&CORE::binmode}'
CORE::binmode:
3 <1> leavesub[1 ref] K/REFC,1 ->(end)
2 <@> binmode sK/2 ->3
- <0> ex-pushmark s ->1
1 <$> coreargs(IV 212) s ->2
-e syntax OK
Diffstat (limited to 't')
-rw-r--r-- | t/op/coresubs.t | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/t/op/coresubs.t b/t/op/coresubs.t index 3339f4f410..fcae6b8bb9 100644 --- a/t/op/coresubs.t +++ b/t/op/coresubs.t @@ -370,6 +370,10 @@ test_proto "get$_" for qw ' pwent pwnam pwuid servbyname servbyport servent sockname sockopt '; +test_proto 'gmtime'; +&CORE::gmtime; +pass '&gmtime without args does not crash'; ++$tests; + test_proto 'hex', ff=>255; test_proto 'int', 1.5=>1; test_proto 'ioctl'; @@ -390,6 +394,11 @@ test_proto 'lcfirst', 'AA', 'aA'; test_proto 'length', 'aaa', 3; test_proto 'link'; test_proto 'listen'; + +test_proto 'localtime'; +&CORE::localtime; +pass '&localtime without args does not crash'; ++$tests; + test_proto 'log'; test_proto "msg$_" for qw( ctl get rcv snd ); |