Skip to content

Commit

Permalink
alien.data: adding stream-read-c-ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Dec 2, 2023
1 parent 011e378 commit d2acccb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions basis/alien/data/data.factor
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion basis/io/backend/unix/unix.factor
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- )
Expand Down

0 comments on commit d2acccb

Please sign in to comment.