On Sun, May 23, 2021 at 7:57 PM Matthew Flatt <[email protected]> wrote:
> At Sun, 23 May 2021 14:57:42 +0000, Sage Gerard wrote: > > Is there a cross-VM way to pass an arbitrary input port to the C > > runtime (e.g. via open-input-bytes), such that the C runtime can read > > bytes on its own? > > No, not unless you know that the port's implementation is sufficiently > constrained. In general, reading from a port can involve thread > switches and synchronization, and those are not allowed in callbacks > from foreign libraries. > Off hand, I think some some version of "sanitizing" an arbitrary port for use from C is used by: - `racket/system` (here <https://github.com/racket/racket/blob/448b77a6629c68659e1360fbe9f9e1ecea078f9c/racket/collects/racket/system.rkt#L98-L114> and here <https://github.com/racket/racket/blob/448b77a6629c68659e1360fbe9f9e1ecea078f9c/racket/collects/racket/system.rkt#L173-L193>), where the implementation comes from `racket/private/streams`; - `racket/draw`, for the various parts of Cairo that can read from or write to ports, in `racket/draw/unsafe/callback` (and maybe something similar in `racket/draw/private/write-bytes`?); and - `readline`, which uses callbacks rather than creating file-stream ports. Would it make sense to expose some part of this functionality as a new primitive? (I'm not familiar with all of the constraints in these use-cases: maybe they're different enough that the answer is "no".) -Philip -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/010001799bd5ab46-d39f83a5-bb2d-49e5-8ce2-3315307742ac-000000%40email.amazonses.com.

