Skip to content

Commit 76e0b1c

Browse files
Cleanup usage of unsafeCoerce (#54)
* Cleanup usage of unsafeCoerce * Fix PR numbers
1 parent 320afb1 commit 76e0b1c

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ Breaking changes:
2424

2525
New features:
2626
- Added `fromKillSignal` (#51 by @JordanMartinez)
27-
- Added `pidExists` (#52 by @JordanMartinez)
27+
- Added `pidExists` (#53 by @JordanMartinez)
2828

2929
Other improvements:
3030
- Fix regression: add `ref`/`unref` APIs that were dropped in `v10.0.0` (#50 by @JordanMartinez)
31+
- Wrap `Unsafe` API via `ChildProcess` in safer way (#54 by @JordanMartinez)
3132

3233
## [v10.0.0](https://github.com/purescript-node/purescript-node-child-process/releases/tag/v10.0.0) - 2023-07-20
3334

src/Node/ChildProcess.purs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,28 +157,28 @@ stderr = toUnsafeChildProcess >>> UnsafeCP.unsafeStderr >>> unsafeFromNull
157157
-- | the process has spawned. Note that if the process has already
158158
-- | exited, another process may have taken the same ID, so be careful!
159159
pid :: ChildProcess -> Effect (Maybe Pid)
160-
pid = unsafeCoerce SafeCP.pid
160+
pid cp = SafeCP.pid $ toUnsafeChildProcess cp
161161

162162
pidExists :: ChildProcess -> Effect Boolean
163-
pidExists = unsafeCoerce SafeCP.pidExists
163+
pidExists cp = SafeCP.pidExists $ toUnsafeChildProcess cp
164164

165165
-- | Indicates whether it is still possible to send and receive
166166
-- | messages from the child process.
167167
connected :: ChildProcess -> Effect Boolean
168168
connected = unsafeCoerce SafeCP.connected
169169

170170
exitCode :: ChildProcess -> Effect (Maybe Int)
171-
exitCode = unsafeCoerce SafeCP.exitCode
171+
exitCode cp = SafeCP.exitCode $ toUnsafeChildProcess cp
172172

173173
-- | Closes the IPC channel between parent and child.
174174
disconnect :: ChildProcess -> Effect Unit
175-
disconnect = unsafeCoerce SafeCP.disconnect
175+
disconnect cp = SafeCP.disconnect $ toUnsafeChildProcess cp
176176

177177
kill :: ChildProcess -> Effect Boolean
178-
kill = unsafeCoerce SafeCP.kill
178+
kill cp = SafeCP.kill $ toUnsafeChildProcess cp
179179

180180
kill' :: KillSignal -> ChildProcess -> Effect Boolean
181-
kill' = unsafeCoerce SafeCP.kill'
181+
kill' sig cp = SafeCP.kill' sig $ toUnsafeChildProcess cp
182182

183183
-- | Send a signal to a child process. In the same way as the
184184
-- | [unix kill(2) system call](https://linux.die.net/man/2/kill),
@@ -189,25 +189,25 @@ kill' = unsafeCoerce SafeCP.kill'
189189
-- | The child process might emit an `"error"` event if the signal
190190
-- | could not be delivered.
191191
killSignal :: Signal -> ChildProcess -> Effect Boolean
192-
killSignal = unsafeCoerce SafeCP.killSignal
192+
killSignal sig cp = SafeCP.killSignal sig $ toUnsafeChildProcess cp
193193

194194
killed :: ChildProcess -> Effect Boolean
195-
killed = unsafeCoerce SafeCP.killed
195+
killed cp = SafeCP.killed $ toUnsafeChildProcess cp
196196

197197
ref :: ChildProcess -> Effect Unit
198-
ref = unsafeCoerce SafeCP.ref
198+
ref cp = SafeCP.ref $ toUnsafeChildProcess cp
199199

200200
unref :: ChildProcess -> Effect Unit
201-
unref = unsafeCoerce SafeCP.unref
201+
unref cp = SafeCP.unref $ toUnsafeChildProcess cp
202202

203203
signalCode :: ChildProcess -> Effect (Maybe String)
204-
signalCode = unsafeCoerce SafeCP.signalCode
204+
signalCode cp = SafeCP.signalCode $ toUnsafeChildProcess cp
205205

206206
spawnArgs :: ChildProcess -> Array String
207-
spawnArgs = unsafeCoerce SafeCP.spawnArgs
207+
spawnArgs cp = SafeCP.spawnArgs $ toUnsafeChildProcess cp
208208

209209
spawnFile :: ChildProcess -> String
210-
spawnFile = unsafeCoerce SafeCP.spawnFile
210+
spawnFile cp = SafeCP.spawnFile $ toUnsafeChildProcess cp
211211

212212
-- | Note: `exitStatus` combines the `status` and `signal` fields
213213
-- | from the value normally returned by `spawnSync` into one value

0 commit comments

Comments
 (0)