Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

[Win32] Weird behavioural change between 5.38.0 and 5.40.0

by syphilis (Archbishop)
on Aug 03, 2024 at 14:07 UTC ( [id://11160849]=perlquestion: print w/replies, xml ) Need Help??

syphilis has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Strawberry Perl's (portable PDL edition) portableshell.bat contains the following one-liner:
perl -MConfig -MPDL -e "printf("""Perl executable: %%s\nPerl version + : %%vd / $Config{archname}\nPDL version : %%s\n\n""", $^X, $^V, $ +PDL::VERSION)";
The behaviour of that one-liner changes between perl-5.38.0 and perl-5.40.0. (See https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/200.

Here's a reduced demo of the issue.
On perl-5.38.0, on my Windows 11 box, I get:
D:\>perl -le "print $];printf(""" wtf""")"; 5.038000 wtf D:\>perl -le "print $];printf("""wtf""")"; 5.038000 wtf
On perl-5.40.0, on the same Windows box, running the same 2 one-liners,I get:
D:\>perl -le "print $];printf(""" wtf""")"; Can't find string terminator '"' anywhere before EOF at -e line 1. D:\>perl -le "print $];printf("""wtf""")"; 5.040000 wtf
Why does that error occur ?

If I change the triplets of double-quotes to pairs of double-quotes, the behavioural differences take another turn.
With perl-5.38.0:
D:\>perl -le "print $];printf("" wtf"")"; Can't find string terminator '"' anywhere before EOF at -e line 1. D:\>perl -le "print $];printf(""wtf"")"; Can't find string terminator '"' anywhere before EOF at -e line 1.
And with perl-5.40.0:
D:\>perl -le "print $];printf("" wtf"")"; 5.040000 wtf D:\>perl -le "print $];printf(""wtf"")"; 5.040000 wtf
Is there some perl bugginess going on here ? ... or am I merely looking at changes in undefined (or implementation defined) behaviour ?

I must confess that I don't know what to expect with all of those multiple double quotes.
Insights are most welcome.

Cheers,
Rob

Replies are listed 'Best First'.
Re: [Win32] Weird behavioural change between 5.38.0 and 5.40.0
by ikegami (Patriarch) on Aug 03, 2024 at 17:40 UTC

    In Windows, it's up to each program to parse their command line. It's not up to the shell. So it's up to Perl to parse the command line.[1]

    But it's not Perl itself that parses the command line; it hands this off to the underlying C library.

    So I suspect a difference in the C library used.

    As a solution, you could escape the quote using a backslash (\"). I must admit that """ as an escape for " is very unexpected to me.


    1. Yes, this is bonkers.

      In Windows, it's up to each program to parse their command line. It's not up to the shell. So it's up to Perl to parse the command line.

      Yes, this is bonkers.

      Unfortunately, that's the idiotic price for perfects backwards compatibility. MS-DOS has done it this way, so Windows does it this way, too. And i rather suspect, MS-DOS did it this way, because the command line interpreter for Microsoft Basic (which was the "shell" of many 8 bit computers) did this for the "run" command - just push the rest of the command line on the stack (or just leave it in the input buffer, as it were) and have the newly started program figure it out.

      "8-Bit Show And Tell" on Youtube has you covered there: https://www.youtube.com/watch?v=HC2--B9ZhUA

      As a solution, you could escape the quote using a backslash (\").

      Thanks - that seems to work fine.

      I must admit that """ as an escape for " is very unexpected to me.


      Me, too.
      In fact, it was so unexpected that I didn't even consider the possibility of that being its purpose.
      Upon reflection, however, I think I've been told about that before ... and then forgotten ....
      I reckon I'll be able to remember it now ... for at least a fortnight.

      UPDATE: For anyone who is wondering, it's the white space between the 2 triplets of double-quotes that's tripping things up on perl-5.40.0:
      C:\>perl -we "printf("""Version:%s\n""", $]);" Version:5.040000 C:\>perl -we "printf("""Version: %s\n""", $]);" Can't find string terminator '"' anywhere before EOF at -e line 1
      Cheers,
      Rob

      So I suspect a difference in the C library used.

      It's my understanding from the comments here that SP 5.40.0.1 switched from using a compiler that uses MSVCRT to one using to UCRT (such as Visual Studio 2022 and mingw-w64 ports of gcc-13.2.0).

      Added solution.

Re: [Win32] Weird behavioural change between 5.38.0 and 5.40.0
by sectokia (Pilgrim) on Aug 05, 2024 at 00:52 UTC
    I would suggest to create a C program that calls buildargv and see what its output is. It looks like there are a lot of changes to how argc/argv are generated by different gcc versions.
      It looks like there are a lot of changes to how argc/argv are generated by different gcc versions.

      I also have perls 5.36.0, 5.38.0 and 5.40.0 built using MS Visual Studio 2022.
      All of those perls suffer the very same issue:
      D:\comp-2022-vs>perl -le "printf(""" wtf""");" Can't find string terminator '"' anywhere before EOF at -e line 1. D:\comp-2022-vs>perl -le "printf("""wtf""");" wtf
      So I think it's probably a case of the mingw C runtime having only recently "caught up to" (and synced with) something that has been present in Microsoft's C runtime for quite a while.

      The fact that it's something that MS toolchains do, pretty much legitimizes the change in behaviour.
      Maybe someone will alert MS to the change, and they might do something to revert it.
      But it's something that's only going to be noticed when using """ ... and who does that, anyway ?

      Cheers,
      Rob

        So I think it's probably a case of the mingw C runtime having only recently "caught up to" (and synced with) something that has been present in Microsoft's C runtime for quite a while.

        I think they changed compiler and in the process changed from one MS runtime (MSVCRT) to a new one MS runtime (UCRT). See my other comment.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11160849]
Approved by johngg
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-10-04 00:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (42 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.