Skip to content

Conversation

@iabyn
Copy link
Contributor

@iabyn iabyn commented Apr 28, 2025

Deparsing of 'substr($lex, 0, N)' was broken in 5.41.8. The two commits in this PR fix it and update deparse-skips.txt to skip a couple of recently-added tests. I propose that this PR be merged now, in time for 5.42.0.

  • This set of changes does not require a perldelta entry.

iabyn added 2 commits April 28, 2025 14:04
v5.41.7-43-gcdbed2a40e introduced the OP_SUBSTR_LEFT op,
which is an optimised version of OP_SUBSTR for when the offset
is zero and the replacement string is missing or ''.

Unfortunately the deparsing for this OP missed out the closing
parenthesis when the replacement string wasn't present; i.e.:

    substr($lex, 0, 4);

deparsed as:

    substr($lex, 0, 4;

The fix is trivial.
Add a couple of recently-added test files to

    Porting/deparse-skips.txt

These two test files have

    use utf8;
    "some string with accented chars"

and the accented char gets deparsed wrongly at the moment.
So skip those test files under

    cd t; ./TEST -deparse
@jkeenan
Copy link
Contributor

jkeenan commented Apr 28, 2025

Quick review suggests (a) branch in p.r. passes newly furnished tests; (b) blead fails on same tests. Hence, +1 to merge. However, at this point in the dev cycle, additional eyeballs welcome.

@jkeenan
Copy link
Contributor

jkeenan commented Apr 28, 2025

@richardleach, my hunch is that one of your commits is of concern here. Please review.

Copy link
Contributor

@leonerd leonerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

my $val = 'substr(' . $self->deparse($op->first->sibling, $cx)
. ', 0, ' . $self->deparse($op->first->sibling->sibling->sibling, $cx)
. ( (($op->private & 7) == 3) ? '' : ", '')" );
. ( (($op->private & 7) == 3) ? ')' : ", '')" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could even pull the common tail out:

Suggested change
. ( (($op->private & 7) == 3) ? ')' : ", '')" );
. ( (($op->private & 7) == 3) ? '' : ", ''" )
. ')';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make the change as absolutely minimal as possible, which is why I didn't factor out the common ')'.

@jkeenan
Copy link
Contributor

jkeenan commented Apr 28, 2025

Inspection of git log --format=fuller -- lib/B/Deparse.pm suggested a likely breaking commit during the 5.41.7 development cycle.

commit cdbed2a40eb1292d5be2fd59c091cf78f6a4be69
Author:     Richard Leach <[email protected]>
AuthorDate: Tue Nov 19 23:02:37 2024 +0000
Commit:     Richard Leach <[email protected]>
CommitDate: Mon Jan 13 22:11:16 2025 +0000

I hacked up a copy of lib/B/Deparse.t which included @iabyn's additional tests. I built perl at cdbed2a^ and ran that test file through the harness. It PASSed, as expected (since the flaw had not yet been introduced.)

I then built perl at cdbed2a and ran the test file through the harness. It FAILed, as expected, the flaw having just been introduced.

I have built the branch represented in this p.r. on both Linux and FreeBSD and gotten PASSes; merging into blead now.

@jkeenan jkeenan merged commit 9f37e11 into blead Apr 28, 2025
68 checks passed
@iabyn iabyn deleted the davem/deparse branch April 29, 2025 06:17
@richardleach
Copy link
Contributor

@iabyn - Thanks for the fix
@jkeenan - Thanks for confirming & merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants