about summary refs log tree commit diff stats
path: root/src/loader/loaderhandle.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-12-13 21:30:33 +0100
committerbptato <nincsnevem662@gmail.com>2023-12-13 21:30:33 +0100
commit506fe6579bf43097a2a99e93604e654623a857b4 (patch)
tree3b6307573411ca29879ce9362bd89ef455477297 /src/loader/loaderhandle.nim
parent53bc47531543fe55997f4c6875fa03745a17e754 (diff)
downloadchawan-506fe6579bf43097a2a99e93604e654623a857b4.tar.gz
loaderhandle: fix ConversionDefect in getFd
We must save fd in the constructor, because the stream type may be
changed while loading.
Diffstat (limited to 'src/loader/loaderhandle.nim')
-rw-r--r--src/loader/loaderhandle.nim9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/loader/loaderhandle.nim b/src/loader/loaderhandle.nim
index 93367607..dda00a1b 100644
--- a/src/loader/loaderhandle.nim
+++ b/src/loader/loaderhandle.nim
@@ -17,13 +17,18 @@ type LoaderHandle* = ref object
   canredir: bool
   sostream: Stream # saved ostream when redirected
   sostream_suspend: Stream # saved ostream when suspended
+  fd: int
 
 # Create a new loader handle, with the output stream ostream.
 proc newLoaderHandle*(ostream: Stream, canredir: bool): LoaderHandle =
-  return LoaderHandle(ostream: ostream, canredir: canredir)
+  return LoaderHandle(
+    ostream: ostream,
+    canredir: canredir,
+    fd: int(SocketStream(ostream).source.getFd())
+  )
 
 proc getFd*(handle: LoaderHandle): int =
-  return int(SocketStream(handle.ostream).source.getFd())
+  return handle.fd
 
 proc addOutputStream*(handle: LoaderHandle, stream: Stream) =
   if likely(handle.sostream_suspend != nil):