Skip to content

Conversation

YarinHeffes
Copy link
Contributor

This is an option for gaining access to values that are mutated by foreign function calls.

The advantage of this solution is ease-of-use with (multiple-value-bind ... ... ...) and (declare (ignore ...)).
The consequence is unnecessary calls to cffi:mem-ref.

There are three alternatives.

  1. Use a typecase that allows the use to pass either a value or a pointer to a value. The advantage here is that we don't have unnecessary calls to cffi:mem-ref. The consequences are that the user has to manage the memory allocation and that we use typecase.

  2. Force the user to manage the memory allocation for all pointer variables. The advantage here is that we don't use typecase. The consequences are extra work for the user and unnecessary loss of type-checking.

  3. Give up access to mutated pointers, keep everything as-is.

Let me know your thoughts, @stylewarning @kchanqvq

@kchanqvq
Copy link

kchanqvq commented Jun 19, 2025

I like this solution. The cost of cffi:mem-ref is negligible when type is know at compile time (inlined and compiled to 0~1 instructions). The overhead induced by multiple value return is probably comparable to cffi:mem-ref.

The only nit I think of is... mild inconvenience! That's lots of value to destruct. Maybe we can specify what (n-th) value to return in functions.txt? That require a bit more changes, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants