fix(encode,errno): add iso-10646-1 alias and make local $! reset errno#616
Merged
fix(encode,errno): add iso-10646-1 alias and make local $! reset errno#616
local $! reset errno#616Conversation
Two related fixes uncovered while investigating `jcpan -t CSV::Processor`,
which cascades through Email::Extractor, Text::AutoCSV, and File::BOM.
1. Encode.java: register `iso-10646-1` / `ISO-10646-1` as aliases for
UCS-2 (UTF-16BE for the BMP), matching real Perl Encode's alias list.
File::BOM uses this alias when building its enc2bom table; without it,
`use File::BOM` died with "Unknown encoding: iso-10646-1" and the
whole module failed to load (which in turn broke Text::AutoCSV, etc.).
2. ErrnoVariable.dynamicSaveState: after pushing the saved errno/message,
reset the variable to the empty/no-error state so that `local $!;`
actually clears $! inside the dynamic scope, the way Perl does. The
parent `RuntimeScalar.dynamicSaveState` resets type/value to UNDEF,
but ErrnoVariable's `toString()`/`getInt()` read its private `errno`
and `message` fields, which were not being cleared. As a result,
`local $!;` was a no-op for the visible value of $!.
File::BOM relies on this in `_safe_read`:
local $!;
my $status = read($fh, my $out, $count);
die $! if !$status && $!;
With the bug, a stale $! from earlier in the program made every
end-of-file read look like an error, killing t/01..bom.t at test 41.
Test impact (./jperl):
- File::BOM t/01..bom.t: 41 → 85 passing tests (cutoff is now
POSIX::mkfifo, an unrelated unimplemented function).
- Text::AutoCSV: 7/48 → 535/560 passing tests (cascade unblocked).
- CSV::Processor itself loads and its Utils.t passes; the remaining
failure is the (already known) Email::Extractor → LWPx::TimedHTTP
chain, which depends on `fork`.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Adds a real implementation of POSIX::mkfifo backed by libc's mkfifo()
on Linux and macOS via the FFM interface. On Windows there is no POSIX
FIFO concept, so the function returns -1 with errno=ENOSYS.
- FFMPosixInterface: declare `int mkfifo(String path, int mode)`.
- FFMPosixLinux: bind libc's `mkfifo` (used on macOS too via the
inherited implementation). Resolution is guarded with `ifPresent`
so initialization stays robust on hypothetical libcs without it.
- FFMPosixWindows: stub that sets ENOSYS and returns -1.
- POSIX.java: register `_mkfifo` -> posix_mkfifo. Returns "0 but
true" on success and undef + sets $! on failure, matching real
Perl's POSIX::mkfifo contract.
- POSIX.pm: add `sub mkfifo { POSIX::_mkfifo(@_) }` wrapper next to
the other file-management wrappers (mkdir, rmdir, link, ...).
Smoke test:
$ ./jperl -MPOSIX -e '
my $p = "/tmp/x.$$";
POSIX::mkfifo($p, 0700) or die $!;
print "is_fifo=", (-p $p ? 1 : 0), "\n";
unlink $p;
my $r = POSIX::mkfifo("/no/such/dir/x", 0700);
print "fail=", (defined $r ? $r : "undef"), " errno=$!\n";
'
is_fifo=1
fail=undef errno=No such file or directory
This unblocks File::BOM's t/00..setup.t (which previously aborted with
"Undefined subroutine &POSIX::mkfifo"). The next blocker on that test
path is `fork`, which is a separate, already-known limitation.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
8b0c67f to
5d35b6c
Compare
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.
Summary
Investigation of
jcpan -t CSV::Processorrevealed two related PerlOnJava bugs that cascaded through the dependency chain (CSV::Processor → Text::AutoCSV → File::BOM). Both are fixed here in a single commit.1.
Encode.java: missingiso-10646-1aliasReal Perl's
Encodemodule definesiso-10646-1as an alias for UCS-2. PerlOnJava had aliases forUCS-2,UCS-2BE,UCS-2LEbut notiso-10646-1/ISO-10646-1.File::BOMreferences this alias when populating itsenc2bomtable, souse File::BOMdied at compile time withUnknown encoding: iso-10646-1. The cascading effect was that everything depending on File::BOM (Text::AutoCSV, etc.) also failed to load.2.
ErrnoVariable.dynamicSaveState:local $!was a no-oplocal $!;is supposed to clear$!to the empty/no-error state inside the dynamic scope (and restore the prior value on scope exit). The baseRuntimeScalar.dynamicSaveStateresetstype/valueto UNDEF, butErrnoVariableoverrides the readers (toString,getInt,getBoolean, ...) to return its privateerrno/messagefields, which were not being cleared duringlocal. Result:local $!;saved the old value but did not hide it, so any subsequent read still returned the stale errno.This breaks the very common idiom used by File::BOM's
_safe_read:A stale
$!from earlier in the program made every legitimate end-of-file read look like an error.Minimal repro (before fix):
After fix it prints
inside:(empty), matching system Perl.Test impact (running with
./jperl)File::BOMt/01..bom.tPOSIX::mkfifocutoffText::AutoCSV(entire suite)CSV::ProcessorUtils.tpassesTest plan
make(full unit-test suite) passes locallylocal $!smoke test matches system PerlFile::BOMt/01..bom.t reaches 85 passing tests (was 41)Text::AutoCSVregains 535/560 passing testsdynamicRestoreStatealready restores the savederrno/messagefrom the existing stacksRemaining issues (out of scope, separate tickets)
LWPx::TimedHTTPtest suite usesfork(unimplemented in PerlOnJava); theeval { fork }SKIP guard doesn't trigger correctly and tests hang/fail. BlocksEmail::Extractor, which in turn blocksCSV::Processorruntime tests.File::BOMt/02..perlio-via.t usesPerlIO::via, already documented as unimplemented indev/modules/perlio_via.md.File::BOM00..setup.t usesPOSIX::mkfifo, also unimplemented (would let the remaining 30 tests run if available).Email::Extractorhas an undeclaredMail::Addressdependency in its META — that's a CPAN module bug, not PerlOnJava.CSV::Processor::Utils.pmemits a"my" variable $path masks earlier declarationwarning — CPAN module's own code style.Generated with Devin