summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2023-05-16 12:28:37 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-05-16 21:32:20 -0400
commit2972fd66f91cb51426a1df86b8166a067015e231 (patch)
tree1cd193c2b3454ef884da5af55c20073f934c217a
parent3d23060c6f088e786b95865b9ac1ca84e97c1e6d (diff)
downloadhaskell-2972fd66f91cb51426a1df86b8166a067015e231.tar.gz
JS: fix getpid (fix #23399)
-rw-r--r--libraries/base/System/Posix/Internals.hs2
-rw-r--r--libraries/base/tests/System/T23399.hs9
-rw-r--r--libraries/base/tests/System/T23399.stdout1
-rw-r--r--libraries/base/tests/System/all.T1
4 files changed, 12 insertions, 1 deletions
diff --git a/libraries/base/System/Posix/Internals.hs b/libraries/base/System/Posix/Internals.hs
index 244e46f496..bd3d4db8ca 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 10ddd7754f..b56d239b26 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), req_process],
compile_and_run, [''])
test('Timeout001', js_broken(22261), compile_and_run, [''])
test('T16466', normal, compile_and_run, [''])
+test('T23399', normal, compile_and_run, [''])