Hacking on Perl feature.h help

--0000000000007f46280570564a2a
Content-Type: text/plain; charset="UTF-8"

Hey P5P folks,

I'm hacking on the Perl source to get to know it a little better, and I'm
trying to implement a feature that allows require to return false and not
die with "did not return a true value".

I added the feature flag, added a private op to leaveeval. In this commit:

https://github.com/dnmfarrell/perl5/commit/9e47a7970d408bd5ba83627657a6debf2f280257

I updated op.c to set the private flag if the feature was enabled.

My problem is, after compiling perl the feature flag is always false, even
though I do "use feature 'require_false';". I added the feature in this
commit:

https://github.com/dnmfarrell/perl5/commit/66f43943f438f5bc7970dab0b7940e46c84909f5

I've compared my code to the signatures feature, and I can't see what I'm
missing. Could anybody help me please?

Thanks in advance

David

--0000000000007f46280570564a2a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hey P5P folks,<div><br></div><div>I&#39;m hacking on the P=
erl source to get to know it a little better, and I&#39;m trying to impleme=
nt a feature that allows require to return false and not die with &quot;did=
 not return a true value&quot;.</div><div><br></div><div>I added the featur=
e flag, added a private op to leaveeval. In this commit:</div><div><br></di=
v><div><a href=3D"https://github.com/dnmfarrell/perl5/commit/9e47a7970d408b=
d5ba83627657a6debf2f280257">https://github.com/dnmfarrell/perl5/commit/9e47=
a7970d408bd5ba83627657a6debf2f280257</a></div><div><br></div><div>I updated=
 op.c to set the private flag if the feature was enabled.</div><div><br></d=
iv><div>My problem is, after compiling perl the feature flag is always fals=
e, even though I do &quot;use feature &#39;require_false&#39;;&quot;. I add=
ed the feature in this commit:</div><div><br></div><div><a href=3D"https://=
github.com/dnmfarrell/perl5/commit/66f43943f438f5bc7970dab0b7940e46c84909f5=
">https://github.com/dnmfarrell/perl5/commit/66f43943f438f5bc7970dab0b7940e=
46c84909f5</a><br></div><div><br></div><div>I&#39;ve compared my code to th=
e signatures feature, and I can&#39;t see what I&#39;m missing. Could anybo=
dy help me please?</div><div><br></div><div>Thanks in advance</div><div><br=
></div><div>David</div></div>

--0000000000007f46280570564a2a--
0
davidnmfarrell
7/6/2018 3:26:42 PM
perl.perl5.porters 47436 articles. 0 followers. Follow

3 Replies
52 Views

Similar Articles

[PageSpeed] 24

Bumping David's email here. If any hacker has a bit of spare time to
help an up-and-coming hacker.

On 07/06/2018 06:26 PM, David Farrell wrote:
> Hey P5P folks,
>
> I'm hacking on the Perl source to get to know it a little better, and
> I'm trying to implement a feature that allows require to return false
> and not die with "did not return a true value".
>
> I added the feature flag, added a private op to leaveeval. In this commit:
>
> https://github.com/dnmfarrell/perl5/commit/9e47a7970d408bd5ba83627657a6debf2f280257
>
> I updated op.c to set the private flag if the feature was enabled.
>
> My problem is, after compiling perl the feature flag is always false,
> even though I do "use feature 'require_false';". I added the feature
> in this commit:
>
> https://github.com/dnmfarrell/perl5/commit/66f43943f438f5bc7970dab0b7940e46c84909f5
>
> I've compared my code to the signatures feature, and I can't see what
> I'm missing. Could anybody help me please?
>
> Thanks in advance
>
> David
0
xsawyerx
8/25/2018 9:01:05 AM
On Fri, Jul 06, 2018 at 11:26:42AM -0400, David Farrell wrote:
> Hey P5P folks,
> 
> I'm hacking on the Perl source to get to know it a little better, and I'm
> trying to implement a feature that allows require to return false and not
> die with "did not return a true value".
> 
> I added the feature flag, added a private op to leaveeval. In this commit:
> 
> https://github.com/dnmfarrell/perl5/commit/9e47a7970d408bd5ba83627657a6debf2f280257
> 
> I updated op.c to set the private flag if the feature was enabled.
> 
> My problem is, after compiling perl the feature flag is always false, even
> though I do "use feature 'require_false';". I added the feature in this
> commit:
> 
> https://github.com/dnmfarrell/perl5/commit/66f43943f438f5bc7970dab0b7940e46c84909f5
> 
> I've compared my code to the signatures feature, and I can't see what I'm
> missing. Could anybody help me please?

You're testing the feature flag before the context is restored to the
calling code and since the test module doesn't do C< use feature
'require_false'; > the flag check fails.

If you move the feature check after the context is back in the calling
code your test passes:

diff --git a/pp_ctl.c b/pp_ctl.c
index 22f24108d1..3889570a9b 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1631,8 +1631,7 @@ S_pop_eval_context_maybe_croak(pTHX_ PERL_CONTEXT *cx, SV *errsv, int action)
     bool do_croak;
 
     CX_LEAVE_SCOPE(cx);
-    do_croak = action && (CxOLD_OP_TYPE(cx) == OP_REQUIRE) &&
-        (!FEATURE_REQUIRE_FALSE_IS_ENABLED || action == 2);
+    do_croak = action && (CxOLD_OP_TYPE(cx) == OP_REQUIRE);
 
     if (do_croak) {
         /* keep namesv alive after cx_popeval() */
@@ -1644,7 +1643,8 @@ S_pop_eval_context_maybe_croak(pTHX_ PERL_CONTEXT *cx, SV *errsv, int action)
     cx_popblock(cx);
     CX_POP(cx);
 
-    if (do_croak) {
+    if (do_croak  &&
+        (!FEATURE_REQUIRE_FALSE_IS_ENABLED || action == 2)) {
         const char *fmt;
         HV *inc_hv = GvHVn(PL_incgv);
         I32  klen  = SvUTF8(namesv) ? -(I32)SvCUR(namesv) : (I32)SvCUR(namesv);

I do wonder if the feature flag should be in set by the loaded module
instead of the loading code, so you could put code on CPAN that does:

  package Foo;
  use feature 'require_false';

  ...

and code without the use feature can then load it.

Tony
0
tony
8/26/2018 11:45:25 PM
On Mon, Aug 27, 2018 at 09:45:25AM +1000, Tony Cook wrote:
> You're testing the feature flag before the context is restored to the
> calling code and since the test module doesn't do C< use feature
> 'require_false'; > the flag check fails.
> 
> If you move the feature check after the context is back in the calling
> code your test passes:
> 
> diff --git a/pp_ctl.c b/pp_ctl.c
> index 22f24108d1..3889570a9b 100644
> --- a/pp_ctl.c
> +++ b/pp_ctl.c
> @@ -1631,8 +1631,7 @@ S_pop_eval_context_maybe_croak(pTHX_ PERL_CONTEXT *cx, SV *errsv, int action)
>      bool do_croak;
>  
>      CX_LEAVE_SCOPE(cx);
> -    do_croak = action && (CxOLD_OP_TYPE(cx) == OP_REQUIRE) &&
> -        (!FEATURE_REQUIRE_FALSE_IS_ENABLED || action == 2);
> +    do_croak = action && (CxOLD_OP_TYPE(cx) == OP_REQUIRE);
>  
>      if (do_croak) {
>          /* keep namesv alive after cx_popeval() */
> @@ -1644,7 +1643,8 @@ S_pop_eval_context_maybe_croak(pTHX_ PERL_CONTEXT *cx, SV *errsv, int action)
>      cx_popblock(cx);
>      CX_POP(cx);
>  
> -    if (do_croak) {
> +    if (do_croak  &&
> +        (!FEATURE_REQUIRE_FALSE_IS_ENABLED || action == 2)) {
>          const char *fmt;
>          HV *inc_hv = GvHVn(PL_incgv);
>          I32  klen  = SvUTF8(namesv) ? -(I32)SvCUR(namesv) : (I32)SvCUR(namesv);

Actually, that explanation isn't completely correct.

Moving the check does fix your test case, but adding C< use feature
'require_false'; > to bleah.pm doesn't allow the test to pass, so I
expect the context where it's set has already been popped, even before
pp_leaveeval is called.

Tony
0
tony
8/27/2018 12:06:34 AM
Reply: