Skip to content

Wrong sqlite3_set_auxdata signature? #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Spxg opened this issue Jan 13, 2025 · 9 comments
Closed

Wrong sqlite3_set_auxdata signature? #92

Spxg opened this issue Jan 13, 2025 · 9 comments

Comments

@Spxg
Copy link

Spxg commented Jan 13, 2025

Wrong sqlite3_set_auxdata signature, should it be "v(p)"?

https://github.com/sqlite/sqlite/blob/f1747f93e0f8df7984b595b91649c7789217fe59/ext/wasm/api/sqlite3-api-glue.c-pp.js#L235

@tomayac
Copy link
Collaborator

tomayac commented Jan 13, 2025

Adding @sgbeal to take a look.

@sgbeal
Copy link
Collaborator

sgbeal commented Feb 3, 2025

v(p) and v(*) are the same thing. * is just a descriptive alias for p.

@sgbeal sgbeal closed this as completed Feb 3, 2025
@Spxg
Copy link
Author

Spxg commented Feb 3, 2025

v(p) and v(*) are the same thing. * is just a descriptive alias for p.

I remember that an exception was thrown when calling it, saying that the signature was wrong

@Spxg
Copy link
Author

Spxg commented Feb 3, 2025

Image

@sgbeal
Copy link
Collaborator

sgbeal commented Feb 3, 2025

Oh, indeed - that signature does need to be a p, as that one needs to be in the lower-level format. The release bundles for 3.49 are in the process of being bundled right this minute, so i can't get this fix in to 3.49 but will patch it as soon as that release goes out later today. Bummer :/.

@tomayac please wait until that patch before doing the npm build. i'll notify via this ticket when that's done.

@sgbeal
Copy link
Collaborator

sgbeal commented Feb 3, 2025

Correction: Richard let me slip that one in last-minute, so it will be in 3.49.

@sgbeal
Copy link
Collaborator

sgbeal commented Feb 3, 2025

BTW: in hindsight, i should have taken this opportunity to remove automatic JS-to-WASM function conversions for this particular case because it's waaaay too easy to leak huge amounts of memory via function conversions this way.

The newly-added test in the bottom-most diff of:

https://sqlite.org/src/info/d693c2dddbd10a2e

demonstrates how to avoid that leak and the rest of that checkin adds some new commentary about it.

You are apparently the only person to attempt use that API's automatic function conversions (teaching me yet another important lesson about proactively adding tests), so it would have been feasible to remove that capability, since it never worked. Passing a WASM function pointer (as the above-linked test does) has always worked and avoids the memory leak potential.

@sgbeal
Copy link
Collaborator

sgbeal commented Feb 3, 2025

Woot! Richard also let me slip this last-minute change in: sqlite3_set_auxdata() no longer supports automatic function conversion for destructors. It never worked before today, but fixing it was ill-conceived, as it's not currently possible for us to automate the cleanup of those conversions and they can leak a function instance on every call to a UDF. WASM function pointers can (still) be used in this context, though, and the test app demonstrates how to create them (and clean them up) for this purpose.

BTW: i'm only just now noticing that this was opened 3 weeks ago and i missed it at the time. My apologies for the delayed response.

@Spxg
Copy link
Author

Spxg commented Feb 4, 2025

it's not currently possible for us to automate the cleanup of those conversions and they can leak a function instance on every call to a UDF.

I agree with you, there is no good stage to release pAuxDtor.

I wrapped the sqlite-wasm capi to make it a "standard" capi for Rust: https://github.com/Spxg/sqlite-wasm-rs/blob/bc5285fe6d2f3a4e5eb946f5d0500fa26714f5ab/sqlite-wasm-rs/src/c.rs#L2013C1-L2026C2.
As you can see, I also have a leaked pAuxDtor function.

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

No branches or pull requests

3 participants