Skip to content

Function pointers with lots of parameters are not capped at 22 #382

@keynmol

Description

@keynmol

https://sn-bindgen-web.indoorvivants.com/binding/4974b0bb-4a5a-4b0d-9597-86b9774f2fd0

typedef void (FunctionWithLotsOfParameters)(int a,
    int b, int c, int d, int e, int f, int g, int h,
    int i, int j, int k, int l, int m, int n, int o, int p, int q, int r, int s, int t,
    int u, int v, int w, int x, int y, int z);
package my_bindings

import _root_.scala.scalanative.unsafe.*
import _root_.scala.scalanative.unsigned.*
import _root_.scala.scalanative.libc.*
import _root_.scala.scalanative.*

object aliases:
   import _root_.my_bindings.aliases.*
   type FunctionWithLotsOfParameters = CFuncPtr26[CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, Unit]
   object FunctionWithLotsOfParameters:
      given _tag: Tag[FunctionWithLotsOfParameters] = Tag.materializeCFuncPtr26[CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, Unit]
      inline def apply(inline o: CFuncPtr26[CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, Unit]): FunctionWithLotsOfParameters = o
      extension (v: FunctionWithLotsOfParameters)
         inline def value: CFuncPtr26[CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, CInt, Unit] = v

object types:
      export _root_.my_bindings.aliases.*

object all:
   export _root_.my_bindings.aliases.FunctionWithLotsOfParameters

This of course is not possible (CFuncPtr22 is the maximum)

The issue here is that at this point I don't know how to even represent this in Scala.

One idea is

  1. A hidden struct with same number of parameters
  2. The function type is itself an opaque pointer Ptr[Byte] (e.g. opaque type FunctionWithLotsOfParameters = Ptr[Byte]
  3. A apply(...) extension on FunctionWithLotsOfParameters which takes all the parameters, packs them into a stack allocated struct, then invokes
  4. a glue C function that unpacks the struct into individual parameters, and invokes the original FunctionWithLotsOfParameters

The overhead on this puppy is going to be severe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions