diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2023-05-16 12:28:37 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2023-05-17 11:43:28 -0400 |
commit | 5292bdf87f1a6e5a48375beb3cdea6785a2fecbd (patch) | |
tree | 27522f3a7c6d3c1144cfd19b3eb0738e76761aff | |
parent | 1fdbbd8d81b3b5e80e8997d279764f62cdcc3c26 (diff) | |
download | haskell-5292bdf87f1a6e5a48375beb3cdea6785a2fecbd.tar.gz |
JS: fix getpid (fix #23399)
(cherry picked from commit 2972fd66f91cb51426a1df86b8166a067015e231)
-rw-r--r-- | libraries/base/System/Posix/Internals.hs | 2 | ||||
-rw-r--r-- | libraries/base/tests/System/T23399.hs | 9 | ||||
-rw-r--r-- | libraries/base/tests/System/T23399.stdout | 1 | ||||
-rw-r--r-- | libraries/base/tests/System/all.T | 1 |
4 files changed, 12 insertions, 1 deletions
diff --git a/libraries/base/System/Posix/Internals.hs b/libraries/base/System/Posix/Internals.hs index 89fa80672f..e4b45532b6 100644 --- a/libraries/base/System/Posix/Internals.hs +++ b/libraries/base/System/Posix/Internals.hs @@ -499,7 +499,7 @@ foreign import javascript interruptible "(($1,$2_1,$2_2,$c) => { return h$base_f c_ftruncate :: CInt -> FileOffset -> IO CInt foreign import javascript interruptible "(($1_1,$1_2,$c) => { return h$base_unlink($1_1,$1_2,$c); })" c_unlink :: CString -> IO CInt -foreign import javascript unsafe "(() => { return h$base_getpid; })" +foreign import javascript unsafe "h$base_getpid" c_getpid :: IO CPid -- foreign import ccall unsafe "HsBase.h fork" -- c_fork :: IO CPid diff --git a/libraries/base/tests/System/T23399.hs b/libraries/base/tests/System/T23399.hs new file mode 100644 index 0000000000..4232c94d16 --- /dev/null +++ b/libraries/base/tests/System/T23399.hs @@ -0,0 +1,9 @@ +module Main where + +import System.Posix.Internals + +main = do + r <- c_getpid + -- #23399: JS backend wasn't returning a valid JS number as a CPid hence + -- "read" would fail because the string was "0\0" (not a number, NUL byte) + print ((read (show r) :: Int) /= -1) diff --git a/libraries/base/tests/System/T23399.stdout b/libraries/base/tests/System/T23399.stdout new file mode 100644 index 0000000000..0ca95142bb --- /dev/null +++ b/libraries/base/tests/System/T23399.stdout @@ -0,0 +1 @@ +True diff --git a/libraries/base/tests/System/all.T b/libraries/base/tests/System/all.T index ad3b046b25..15834c1b7b 100644 --- a/libraries/base/tests/System/all.T +++ b/libraries/base/tests/System/all.T @@ -8,3 +8,4 @@ test('system001', [js_broken(22349), when(opsys("mingw32"), skip)], \ compile_and_run, ['']) test('Timeout001', js_broken(22261), compile_and_run, ['']) test('T16466', normal, compile_and_run, ['']) +test('T23399', normal, compile_and_run, ['']) |