Clang.jl icon indicating copy to clipboard operation
Clang.jl copied to clipboard

Feature request: add a codegen option to create function wrappers for c structures of function ptrs

Open IanET opened this issue 1 month ago • 0 comments

Several c libraries like ONNX, primarily use structs of function pointers which then get translated to Ptr{Cvoid} eg

struct OrtCustomOp
    version::UInt32
    CreateKernel::Ptr{Cvoid}
    GetName::Ptr{Cvoid}
    GetExecutionProviderType::Ptr{Cvoid}
    GetInputType::Ptr{Cvoid}
    GetInputTypeCount::Ptr{Cvoid}
   etc
end

It would be great if wrappers could be automatically created for the function ptr fields to make them easier to call eg

CreateKernel(ort_custom_op::OrtCustomOp, session_OrtCustomOpoptions, kernel_info, kernel) = @ccall $(ort_custom_op.CreateKernel)(session_options::Ptr{OrtSessionOptions}, kernel_info::Ptr{OrtKernelInfo}, kernel::Ptr{Ptr{OrtKernel}})::OrtStatusPtr
GetName(ort_custom_op::OrtCustomOp, op) = @ccall $(ort_custom_op.GetName)(op::Ptr{OrtCustomOp} )::Cwstring
GetExecutionProviderType(ort_custom_op::OrtCustomOp, op) = @ccall $(ort_custom_op.GetExecutionProviderType)(op::Ptr{OrtCustomOp})::Cwstring
etc

IanET avatar Nov 27 '25 21:11 IanET