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 /pp_sys.c | |
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 'pp_sys.c')
-rw-r--r-- | pp_sys.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -4479,7 +4479,7 @@ PP(pp_gmtime) {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - if (MAXARG < 1) { + if (MAXARG < 1 || (!TOPs && ((void)POPs, 1))) { time_t now; (void)time(&now); when = (Time64_T)now; |