From 8bff8eda656fb7056fbe182a72708ef301792d4b Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 25 Jul 2023 11:11:03 -0700 Subject: [PATCH 1/2] Cleanup usage of unsafeCoerce --- CHANGELOG.md | 1 + src/Node/ChildProcess.purs | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19a77b4..e169ef9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ New features: Other improvements: - Fix regression: add `ref`/`unref` APIs that were dropped in `v10.0.0` (#50 by @JordanMartinez) +- Wrap `Unsafe` API via `ChildProcess` in safer way (#53 by @JordanMartinez) ## [v10.0.0](https://github.com/purescript-node/purescript-node-child-process/releases/tag/v10.0.0) - 2023-07-20 diff --git a/src/Node/ChildProcess.purs b/src/Node/ChildProcess.purs index 211d47a..9989ab7 100644 --- a/src/Node/ChildProcess.purs +++ b/src/Node/ChildProcess.purs @@ -157,10 +157,10 @@ stderr = toUnsafeChildProcess >>> UnsafeCP.unsafeStderr >>> unsafeFromNull -- | the process has spawned. Note that if the process has already -- | exited, another process may have taken the same ID, so be careful! pid :: ChildProcess -> Effect (Maybe Pid) -pid = unsafeCoerce SafeCP.pid +pid cp = SafeCP.pid $ toUnsafeChildProcess cp pidExists :: ChildProcess -> Effect Boolean -pidExists = unsafeCoerce SafeCP.pidExists +pidExists cp = SafeCP.pidExists $ toUnsafeChildProcess cp -- | Indicates whether it is still possible to send and receive -- | messages from the child process. @@ -168,17 +168,17 @@ connected :: ChildProcess -> Effect Boolean connected = unsafeCoerce SafeCP.connected exitCode :: ChildProcess -> Effect (Maybe Int) -exitCode = unsafeCoerce SafeCP.exitCode +exitCode cp = SafeCP.exitCode $ toUnsafeChildProcess cp -- | Closes the IPC channel between parent and child. disconnect :: ChildProcess -> Effect Unit -disconnect = unsafeCoerce SafeCP.disconnect +disconnect cp = SafeCP.disconnect $ toUnsafeChildProcess cp kill :: ChildProcess -> Effect Boolean -kill = unsafeCoerce SafeCP.kill +kill cp = SafeCP.kill $ toUnsafeChildProcess cp kill' :: KillSignal -> ChildProcess -> Effect Boolean -kill' = unsafeCoerce SafeCP.kill' +kill' sig cp = SafeCP.kill' sig $ toUnsafeChildProcess cp -- | Send a signal to a child process. In the same way as the -- | [unix kill(2) system call](https://linux.die.net/man/2/kill), @@ -189,25 +189,25 @@ kill' = unsafeCoerce SafeCP.kill' -- | The child process might emit an `"error"` event if the signal -- | could not be delivered. killSignal :: Signal -> ChildProcess -> Effect Boolean -killSignal = unsafeCoerce SafeCP.killSignal +killSignal sig cp = SafeCP.killSignal sig $ toUnsafeChildProcess cp killed :: ChildProcess -> Effect Boolean -killed = unsafeCoerce SafeCP.killed +killed cp = SafeCP.killed $ toUnsafeChildProcess cp ref :: ChildProcess -> Effect Unit -ref = unsafeCoerce SafeCP.ref +ref cp = SafeCP.ref $ toUnsafeChildProcess cp unref :: ChildProcess -> Effect Unit -unref = unsafeCoerce SafeCP.unref +unref cp = SafeCP.unref $ toUnsafeChildProcess cp signalCode :: ChildProcess -> Effect (Maybe String) -signalCode = unsafeCoerce SafeCP.signalCode +signalCode cp = SafeCP.signalCode $ toUnsafeChildProcess cp spawnArgs :: ChildProcess -> Array String -spawnArgs = unsafeCoerce SafeCP.spawnArgs +spawnArgs cp = SafeCP.spawnArgs $ toUnsafeChildProcess cp spawnFile :: ChildProcess -> String -spawnFile = unsafeCoerce SafeCP.spawnFile +spawnFile cp = SafeCP.spawnFile $ toUnsafeChildProcess cp -- | Note: `exitStatus` combines the `status` and `signal` fields -- | from the value normally returned by `spawnSync` into one value From a7bab119834e7beb7e9c7592e04242a1deade634 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 25 Jul 2023 11:19:18 -0700 Subject: [PATCH 2/2] Fix PR numbers --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e169ef9..9e4579a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,11 +24,11 @@ Breaking changes: New features: - Added `fromKillSignal` (#51 by @JordanMartinez) -- Added `pidExists` (#52 by @JordanMartinez) +- Added `pidExists` (#53 by @JordanMartinez) Other improvements: - Fix regression: add `ref`/`unref` APIs that were dropped in `v10.0.0` (#50 by @JordanMartinez) -- Wrap `Unsafe` API via `ChildProcess` in safer way (#53 by @JordanMartinez) +- Wrap `Unsafe` API via `ChildProcess` in safer way (#54 by @JordanMartinez) ## [v10.0.0](https://github.com/purescript-node/purescript-node-child-process/releases/tag/v10.0.0) - 2023-07-20