There are a number of potential solutions:
- Wrap all functions exposed to user space such that any exposed function returns the expected type. I.e.: functions that return functions will return closures, which are in turn wrapped to do the same. This would also apply to complex data structures.
- Ban functions from returning any non-primitive values (very limiting)
- Continue to return pointers and require user-space developers to use an abstraction API to interact with the values that are returned (a wrapper around the memory manager and heaps).
Note that this issue also presents itself to imported foreign functions (passing complex objects as arguments), though custom exposed methods are not currently available.