Repository navigation
vm: map every Win32 and Winsock code through MRI's errmap - #982
Open
tannevaled wants to merge 1 commit into
Open
tannevaled wants to merge 1 commit into
tannevaled wants to merge 1 commit into
Conversation
On Windows a syscall.Errno is the Win32 code itself, and errnoClasses is keyed by the numbers Go gives the POSIX names, so every raiser that looked a failed call's number up directly picked an unrelated class, or none. ERROR_PATH_NOT_FOUND (3) is Go's syscall.ENOTDIR there, so a path through a missing directory read as Errno::ENOTDIR where MRI raises Errno::ENOENT (witnessed on #978's Windows runner, for the flush), and rmdir of a non-empty directory (ERROR_DIR_NOT_EMPTY) fell to Errno::ENOENT. MRI maps the code first, through errmap and rb_w32_map_errno (win32/win32.c:145-300, v4.0.9). errnoOfError now does the same, once, so sysFail, chdir, realpath, pwrite, the flush and the dial error all see MRI's class. errIsErrno falls back on the mapped class, so ERROR_DIR_NOT_EMPTY is ENOTEMPTY for rmdir, and the two direct errors.Is(err, syscall.EINVAL) checks (File.truncate, flock) go through it. The Winsock rows are ported in full (43, where posixErrno held 15), and posixErrno is gone. Eight of their classes have no number in rbgo on any target (ESHUTDOWN, ETOOMANYREFS, EHOSTDOWN, EPFNOSUPPORT, ESOCKTNOSUPPORT, EPROCLIM, EUSERS, EREMOTE); those keep the WSA code and raise SystemCallError, as before. TestWSARowsWithoutAClass pins that list. Everywhere but Windows mapHostErrno is the identity. Fixes #980 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
On Windows a
syscall.Errnois the Win32 code itself.errnoClassesis keyed by the numbers Go gives the POSIX names, so every raiser that looked a failed call's number up directly picked an unrelated class, or none. Go definessyscall.ENOTDIRasERROR_PATH_NOT_FOUND(3), so a path through a missing directory read asErrno::ENOTDIR.ERROR_DIR_NOT_EMPTYnever matchedENOTEMPTY, soDir.rmdiron a non-empty directory fell toErrno::ENOENT.MRI maps the code first, through
errmapandrb_w32_map_errno(win32/win32.c:145-300, v4.0.9). This PR does the same in one place:errnoOfErrorreturns the mapped number.sysFail,Dir.chdir,File.realpath,IO#pwrite, the flush and the connect error all see MRI's class.raiseFlushErrno longer maps on its own.errIsErrnocompares the mapped number.Dir.rmdir's ENOTEMPTY, and the two directerrors.Is(err, syscall.EINVAL)checks it now replaces (File.truncate,File#flock), see the Win32 codes.errmapare ported in full: 43, whereposixErrnoheld 15.posixErrnois removed.Everywhere but Windows,
mapHostErrnois the identity.What stays a divergence
ESHUTDOWN,ETOOMANYREFS,EHOSTDOWN,EPFNOSUPPORT,ESOCKTNOSUPPORT,EPROCLIM,EUSERSandEREMOTEhave no number in rbgo on any target (errnoUndefinedEverywhere). Those rows keep their WSA code and raiseSystemCallError, as before.TestWSARowsWithoutAClasspins the list, so defining one of the names moves it out.os.MkdirAll,os.ReadDir,filepath.EvalSymlinks) is the number 3, which is indistinguishable fromERROR_PATH_NOT_FOUND, and maps to ENOENT. No raiser takes its error from those three today. The comment onerrnoOfErrorsays so.Measured
rubydiffagainst MRI 4.0.7 (arm64-darwin25). A program coveringDir.chdirthrough a missing directory,Dir.rmdiron a non-empty one, andFile.truncatethrough a missing directory: the two engines agree. MRI printsErrno::ENOENT,Errno::ENOTEMPTY,Errno::ENOENT.TestAFailedCallRaisesMRIsClassOnEveryHostholds that program with MRI's output as its expected value. It runs on every lane. On darwin and Linux it passes with or without the mapping; the Windows lane is the oracle for this PR, since no local run covers Windows.TestMapHostErrnoIsRbW32MapErrno,TestWSARowsWithoutAClass,TestErrnoOfErrorMapsTheWin32Code) check the table againsterrmaprow by row, plus the classerrnoOfErroranderrIsErrnogive a wrapped Win32 error.go test ./internal/vm/ ./cmd/rbgo/ ./passed locally on darwin (internal/vm295 s).buildscan --vetpassed under all 19 CI configurations. AIX and Plan 9, which no lane builds, cross-build.Fixes #980
Refs #978 (merged; it ported the Win32 rows and applied them to the flush alone)
🤖 Generated with Claude Code