Last active
March 14, 2024 23:23
-
-
Save Skyb0rg007/512ef7bd289daa319219b826fb5f3fb1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#PSScriptInfo | |
.VERSION 1.0 | |
.GUID dadcf7db-a1ab-4360-b66b-25d5e7a1666a | |
.AUTHOR [email protected] | |
.COPYRIGHT Skye Soss 2024 | |
.LICENSEURI https://opensource.org/license/mit | |
#> | |
<# | |
.DESCRIPTION | |
Exhibiting unintended behavior in SML/NJ on Windows | |
#> | |
[CmdletBinding(PositionalBinding=$false)] | |
Param( | |
[ValidateScript({Test-Path -Path $_ -PathType Container})] | |
[string] $TempDir = $env:TEMP, | |
[ValidateScript({Get-Command $_})] | |
[string] $SMLCommand = "sml", | |
[boolean] $Cleanup = $true | |
) | |
try { | |
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 | |
$lambda = [char]::ConvertFromUtf32(0x03BB) | |
$filename = "foo$lambda.sml" | |
$filepath = Join-Path -Path $TempDir -ChildPath $filename | |
'val () = print "Hello from SML\n"' | Out-File -Encoding ascii -FilePath $filepath | |
$relfilepath = Resolve-Path -Relative $filepath | |
Write-Host -ForegroundColor red "Testing SML with unicode .sml file ($SMLCommand $relfilepath)" | |
& $SMLCommand $relfilepath | |
Write-Host -ForegroundColor red "Testing SML to open unicode file (TextIO.openIn $filepath)" | |
'hello' | Out-File -Encoding ascii -FilePath $filepath | |
$smlscript = Join-Path -Path $TempDir -ChildPath "test.sml" | |
@" | |
val tmp = "$($TempDir -replace '\\', '\\')"; | |
val self = tmp ^ "\\test.sml"; | |
val f = TextIO.openIn self; | |
val () = TextIO.print "Successfully opened self\n"; | |
val () = TextIO.closeIn f; | |
val filename = tmp ^ "\\foo" ^ UTF8.encode 0wx03BB ^ ".sml"; | |
val () = TextIO.print ("Attempting to open \"" ^ filename ^ "\"\n"); | |
val f = TextIO.openIn filename; | |
val () = TextIO.print "Success!\n"; | |
val () = TextIO.closeIn f; | |
OS.Process.exit OS.Process.success : unit; | |
"@ | Out-File -Encoding ascii -FilePath $smlscript | |
& $SMLCommand $smlscript | |
} finally { | |
if ($Cleanup) { | |
Remove-Item -Path $filepath | |
Remove-Item -Path $smlscript | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PS C:\Users\skyle\Desktop> powershell .\SML-Bug.ps1 -TempDir . | |
Testing SML with unicode .sml file (sml .\fooλ.sml) | |
C:\Users\skyle\Desktop>REM sml.bat | |
C:\Users\skyle\Desktop>REM | |
C:\Users\skyle\Desktop>REM Copyright 2020 The Fellowship of SML/NJ (http://www.smlnj.org) | |
C:\Users\skyle\Desktop>REM All rights reserved. | |
C:\Users\skyle\Desktop>REM | |
C:\Users\skyle\Desktop>REM The standard driver for SML/NJ under the new runtime system | |
C:\Users\skyle\Desktop>REM | |
Standard ML of New Jersey (32-bit) v110.99.4 [built: Tue Aug 01 11:26:46 2023] | |
C:\Program Files (x86)\SMLNJ\\bin\.run\run.x86-win32.exe: Fatal error -- Uncaught exception InvalidArc with 0 | |
raised at Basis/Implementation/OS/os-path-fn.sml:47.62-47.72 | |
Testing SML to open unicode file (TextIO.openIn .\fooλ.sml) | |
C:\Users\skyle\Desktop>REM sml.bat | |
C:\Users\skyle\Desktop>REM | |
C:\Users\skyle\Desktop>REM Copyright 2020 The Fellowship of SML/NJ (http://www.smlnj.org) | |
C:\Users\skyle\Desktop>REM All rights reserved. | |
C:\Users\skyle\Desktop>REM | |
C:\Users\skyle\Desktop>REM The standard driver for SML/NJ under the new runtime system | |
C:\Users\skyle\Desktop>REM | |
Standard ML of New Jersey (32-bit) v110.99.4 [built: Tue Aug 01 11:26:46 2023] | |
[opening .\test.sml] | |
val tmp = "." : string | |
val self = ".\\test.sml" : string | |
[autoloading] | |
[library $SMLNJ-BASIS/basis.cm is stable] | |
[library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable] | |
[autoloading done] | |
val f = - : TextIO.instream | |
Successfully opened self | |
[autoloading] | |
[library $SMLNJ-LIB/Util/smlnj-lib.cm is stable] | |
[autoloading done] | |
val filename = ".\\foo\206\187.sml" : string | |
Attempting to open ".\fooλ.sml" | |
uncaught exception Io [Io: openIn failed on ".\fooλ.sml", Win32TextPrimIO.openRd: failed] | |
raised at: Basis/Implementation/IO/text-io-fn.sml:792.25-792.71 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment