]> gitweb.factorcode.org Git - factor.git/commitdiff
alien.data: adding stream-read-c-ptr
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 2 Dec 2023 23:32:36 +0000 (15:32 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 2 Dec 2023 23:32:36 +0000 (15:32 -0800)
basis/alien/data/data.factor
basis/io/backend/unix/unix.factor

index 3676317a24603935d319cb7134315a88bd515a5d..ce03044b7c80956892ce7a326e51f3c7508d9e96 100644 (file)
@@ -3,8 +3,8 @@
 USING: accessors alien alien.arrays alien.c-types alien.strings
 arrays byte-arrays combinators combinators.short-circuit
 cpu.architecture generalizations io io.streams.memory kernel
-libc math parser sequences stack-checker.dependencies summary
-words ;
+libc math namespaces parser sequences stack-checker.dependencies
+summary words ;
 IN: alien.data
 
 : <ref> ( value c-type -- c-ptr )
@@ -14,6 +14,12 @@ IN: alien.data
 : deref ( c-ptr c-type -- value )
     [ 0 ] dip alien-value ; inline
 
+: stream-read-c-ptr ( c-ptr stream -- value )
+    over [ heap-size ] [ stream-read ] [ deref ] tri* ; inline
+
+: read-c-ptr ( c-ptr -- value )
+    input-stream get stream-read-c-ptr ; inline
+
 : little-endian? ( -- ? ) 1 int <ref> char deref 1 = ; foldable
 
 GENERIC: c-array-constructor ( c-type -- word ) foldable
index f58e2d942119f945546af85a780bf1df76bb7671..6b304ef49683b72e8ff925762a7fc3c9568ee7e2 100644 (file)
@@ -141,7 +141,7 @@ M: stdin dispose*
 
 : wait-for-stdin ( stdin -- size )
     [ control>> CHAR: X over io:stream-write1 io:stream-flush ]
-    [ size>> ssize_t heap-size swap io:stream-read ssize_t deref ]
+    [ size>> ssize_t swap stream-read-c-ptr ]
     bi ;
 
 :: refill-stdin ( buffer stdin size -- )