# \#ffi

**URL:** https://racket.discourse.group/tag/ffi/35.md

[Latest](https://racket.discourse.group/latest.md) · [Categories](https://racket.discourse.group/categories.md) · [Tags](https://racket.discourse.group/tags.md)

---

## [How does \_array/list work?](https://racket.discourse.group/t/how-does-array-list-work/4078)

<div class="topic-metadata">

**Author:** [@MickeyKnox](https://racket.discourse.group/u/MickeyKnox)\
**Replies:** 7\
**Last updated:** [January 15, 2026, 10:40pm UTC](https://racket.discourse.group/t/how-does-array-list-work/4078 "2026-01-15T22:40:11Z")

</div>

I have a list that I want to convert into a C array. \_array/list looks promising, as "the Racket representation is a list". But how exactly can I convert my list into a C array?

---

## [Allocating a pointer to an array of C structs using C FFI](https://racket.discourse.group/t/allocating-a-pointer-to-an-array-of-c-structs-using-c-ffi/3615)

<div class="topic-metadata">

**Author:** [@jjsimpso](https://racket.discourse.group/u/jjsimpso)\
**Replies:** 0\
**Last updated:** [March 10, 2025, 3:09pm UTC](https://racket.discourse.group/t/allocating-a-pointer-to-an-array-of-c-structs-using-c-ffi/3615 "2025-03-10T15:09:12Z")

</div>

I'd like suggestions for improving the following function: (define-cstruct \_Slice (\[start \_intptr\] \[end \_intptr\] \[stride \_intptr\])) ;; provide the number of dimensions and a list of triples(start end stride) ;;…

---

## [FFI: 'file' size of a non-file file descriptor](https://racket.discourse.group/t/ffi-file-size-of-a-non-file-file-descriptor/3341)

<div class="topic-metadata">

**Author:** [@Laurent.O](https://racket.discourse.group/u/Laurent.O)\
**Replies:** 8\
**Last updated:** [November 29, 2024, 5:31pm UTC](https://racket.discourse.group/t/ffi-file-size-of-a-non-file-file-descriptor/3341 "2024-11-29T17:31:44Z")

</div>

I'm currently playing with shared memory spaces via the FFI, looking into shm\_open and mmap. After obtaining a file descriptor fd corresponding to an existing such space, I want to find out the underlying 'file' size. H…

---

## [Cpointer -\> flvector?](https://racket.discourse.group/t/cpointer-flvector/3348)

<div class="topic-metadata">

**Author:** [@Laurent.O](https://racket.discourse.group/u/Laurent.O)\
**Replies:** 5\
**Last updated:** [November 23, 2024, 7:59am UTC](https://racket.discourse.group/t/cpointer-flvector/3348 "2024-11-23T07:59:12Z")

</div>

Once I have a pointer to a memory block from the ffi (allocated in a shared memory space), is there a way to turn it into a standard racket flvector? I see there's a flvector-\>cpointer, but not the converse.

---

## [Collect safe foreign procedure in another OS thread](https://racket.discourse.group/t/collect-safe-foreign-procedure-in-another-os-thread/2889)

<div class="topic-metadata">

**Author:** [@amirouche](https://racket.discourse.group/u/amirouche)\
**Replies:** 3\
**Last updated:** [May 30, 2024, 6:39am UTC](https://racket.discourse.group/t/collect-safe-foreign-procedure-in-another-os-thread/2889 "2024-05-30T06:39:14Z")

</div>

I struggle to create a Racket wrapper for FoundationDB C client. The Chez code rely on foreign-procedure's \_\_collect\_safe is there an equivalent available in Racket?

---

## [Help with FFI errors (for #lang clingo integration)](https://racket.discourse.group/t/help-with-ffi-errors-for-lang-clingo-integration/2585)

<div class="topic-metadata">

**Author:** [@kiranandcode](https://racket.discourse.group/u/kiranandcode)\
**Replies:** 7\
**Last updated:** [December 10, 2023, 2:56pm UTC](https://racket.discourse.group/t/help-with-ffi-errors-for-lang-clingo-integration/2585 "2023-12-10T14:56:56Z")

</div>

Heya!! This is a long shot, but I figured I'd post here to see if anyone could possibly provide some advice on an FFI integration that I'm currently building and running into some really mind-bending errors. The reposit…

---

## [Racket Wasmtime Bindings](https://racket.discourse.group/t/racket-wasmtime-bindings/2541)

<div class="topic-metadata">

**Author:** [@slaymaker1907](https://racket.discourse.group/u/slaymaker1907)\
**Replies:** 0\
**Last updated:** [November 26, 2023, 8:30pm UTC](https://racket.discourse.group/t/racket-wasmtime-bindings/2541 "2023-11-26T20:30:57Z")

</div>

I've been working on some bindings for Wasmtime since I've found DrRacket to be a great IDE when working with WASM. This gist is still missing quite a bit of what Wasmtime can do, but I think it's definitely enough for d…

---

## [\`ffi-lib\` fails to load an existing library](https://racket.discourse.group/t/ffi-lib-fails-to-load-an-existing-library/2353)

<div class="topic-metadata">

**Author:** [@Antigen-11](https://racket.discourse.group/u/Antigen-11)\
**Replies:** 7\
**Last updated:** [October 1, 2023, 4:19pm UTC](https://racket.discourse.group/t/ffi-lib-fails-to-load-an-existing-library/2353 "2023-10-01T16:19:40Z")

</div>

Hello, everyone! I create an application and use The Racket Foreign Interface to load foreign libraries. Here's part of the project after compiling c codes. ./gsl-fork/build/lib/ ├── libgsl.a ├── libgslcblas.a ├── lib…

---

## [Calling into a Chez Scheme library from Racket -- imported symbol rewritten in vm-eval?](https://racket.discourse.group/t/calling-into-a-chez-scheme-library-from-racket-imported-symbol-rewritten-in-vm-eval/2257)

<div class="topic-metadata">

**Author:** [@awwx](https://racket.discourse.group/u/awwx)\
**Replies:** 9\
**Last updated:** [September 1, 2023, 2:15am UTC](https://racket.discourse.group/t/calling-into-a-chez-scheme-library-from-racket-imported-symbol-rewritten-in-vm-eval/2257 "2023-09-01T02:15:31Z")

</div>

I have a Chez Scheme library "foo.ss" that I'd like to call from Racket: (library (foo) (export bar) (import (rnrs)) (define (bar) "hello")) From Chez Scheme: $ chezscheme Chez Scheme Version 9.5.4 Copyright…

---

## [Identifiers in \`\_fun\`](https://racket.discourse.group/t/identifiers-in-fun/1769)

<div class="topic-metadata">

**Author:** [@Antigen-11](https://racket.discourse.group/u/Antigen-11)\
**Replies:** 2\
**Last updated:** [March 9, 2023, 6:56pm UTC](https://racket.discourse.group/t/identifiers-in-fun/1769 "2023-03-09T18:56:58Z")

</div>

I typed this in the repl and an error was raised: \> (require ffi/unsafe) \> (\_fun (f) :: ((\_array/list \_int (length f)) = f) -\> \_int) f: undefined; cannot reference an identifier before its definition in module: top-l…

---

## [FFI wrapper for a callback with variable number of arguments](https://racket.discourse.group/t/ffi-wrapper-for-a-callback-with-variable-number-of-arguments/1416)

<div class="topic-metadata">

**Author:** [@wluker](https://racket.discourse.group/u/wluker)\
**Replies:** 2\
**Last updated:** [October 31, 2022, 2:11pm UTC](https://racket.discourse.group/t/ffi-wrapper-for-a-callback-with-variable-number-of-arguments/1416 "2022-10-31T14:11:08Z")

</div>

In the GEOS C library a variadic printf like function is required as a callback for error reporting and I am unsure how to wrap that with racket's FFI. There is a racket ffi example of how to wrap printf where the types…

---

## [FFI: Converting from \_pointer to byte string](https://racket.discourse.group/t/ffi-converting-from-pointer-to-byte-string/1349)

<div class="topic-metadata">

**Author:** [@jA\_cOp](https://racket.discourse.group/u/jA_cOp)\
**Replies:** 8\
**Last updated:** [October 6, 2022, 12:59pm UTC](https://racket.discourse.group/t/ffi-converting-from-pointer-to-byte-string/1349 "2022-10-06T12:59:23Z")

</div>

I have a C struct like so: (define-cstruct \_foo (\[data \_pointer\] \[len \_int32\])) I then get an instance of this struct as an output parameter of a C function. data points to a non-null-terminated array of bytes, of leng…

---

## [FFI cannot find symbol in shared library despite nm utility saying otherwise](https://racket.discourse.group/t/ffi-cannot-find-symbol-in-shared-library-despite-nm-utility-saying-otherwise/1098)

<div class="topic-metadata">

**Author:** [@kurinoku](https://racket.discourse.group/u/kurinoku)\
**Replies:** 2\
**Last updated:** [June 27, 2022, 3:16pm UTC](https://racket.discourse.group/t/ffi-cannot-find-symbol-in-shared-library-despite-nm-utility-saying-otherwise/1098 "2022-06-27T15:16:39Z")

</div>

I'm trying to create a dynamic library out of sxiv since I need to have a programmatically controllable image viewer, I don't really have much experience with shared libraries so it might be an error outside of Racket, b…

---

## [Using \`'nonatomic\` foreign memory](https://racket.discourse.group/t/using-nonatomic-foreign-memory/787)

<div class="topic-metadata">

**Author:** [@LiberalArtist](https://racket.discourse.group/u/LiberalArtist)\
**Replies:** 4\
**Last updated:** [March 11, 2022, 7:53pm UTC](https://racket.discourse.group/t/using-nonatomic-foreign-memory/787 "2022-03-11T19:53:15Z")

</div>

Consider this C type definition: typedef struct git\_strarray { char \*\*strings; size\_t count; } git\_strarray; This called to mind the support added in https://github.com/racket/racket/commit/87196e0144226b44fd4c00fcca…

---

## [FFI define-cstruct recursive dependencies on types](https://racket.discourse.group/t/ffi-define-cstruct-recursive-dependencies-on-types/353)

<div class="topic-metadata">

**Author:** [@simonls](https://racket.discourse.group/u/simonls)\
**Replies:** 4\
**Last updated:** [February 17, 2022, 10:24pm UTC](https://racket.discourse.group/t/ffi-define-cstruct-recursive-dependencies-on-types/353 "2022-02-17T22:24:48Z")

</div>

I am trying to use define-cstruct 1.4 C Structs to define many cstructs some of those have pointers to other cstructs. My actual code is quite big, but I think it boils down to being able to define mutually recursive cst…

---

## [How to safely cast a \_pointer to \_bytes?](https://racket.discourse.group/t/how-to-safely-cast-a-pointer-to-bytes/364)

<div class="topic-metadata">

**Author:** [@kurinoku](https://racket.discourse.group/u/kurinoku)\
**Replies:** 6\
**Last updated:** [December 6, 2021, 7:26pm UTC](https://racket.discourse.group/t/how-to-safely-cast-a-pointer-to-bytes/364 "2021-12-06T19:26:07Z")

</div>

I'm using racket/draw/unsafe/cairo and a custom ffi for MagickWand C API. I have this definition, you can see the last parameter is \_bytes. (define-mwand MagickExportImagePixels (\_fun \_MagickWand-pointer \_size \_size \_s…
