WishIHadThreeGuns
WishIHadThreeGuns

Reputation: 1479

Pass an UnsafeMutableRawPointer as a function parameter

When I try to pass an UnsafeMutableRawPointer as a function parameter I get the following error:

A C function pointer can only be formed from a reference to a 'func' or a literal closure

Specifically this is from the following code:

public func sqlite3_bind_text(_ oP: OpaquePointer!, _ first: Int32, _ second: UnsafePointer<Int8>!, _ third: Int32, _ ptrs: ((UnsafeMutableRawPointer?) -> Void)!) -> Int32 {
    SQLite3.sqlite3_bind_text(oP, first, second, third, ptrs)
}

I've looked at: How to use instance method as callback for function which takes only func or literal closure but can't see how I can apply that to my situation.

How can I pass the pointer through my function?

Upvotes: 1

Views: 283

Answers (1)

Martin R
Martin R

Reputation: 540065

SQLite is a pure C library, and SQLite3.sqlite3_bind_text() takes a pointer to a C function as the fifth parameter. Such a parameter is marked with @convention(c) and that must be replicated in your wrapper function:

public func sqlite3_bind_text(_ oP: OpaquePointer!, _ first: Int32,
                              _ second: UnsafePointer<Int8>!,
                              _ third: Int32,
                              _ ptrs: (@convention(c) (UnsafeMutableRawPointer?) -> Void)!) -> Int32 {
    SQLite3.sqlite3_bind_text(oP, first, second, third, ptrs)
}

Upvotes: 1

Related Questions