Skip to content
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

Statically linking this extension in C code cause seg fault #6

Open
shah opened this issue Oct 17, 2023 · 1 comment
Open

Statically linking this extension in C code cause seg fault #6

shah opened this issue Oct 17, 2023 · 1 comment

Comments

@shah
Copy link

shah commented Oct 17, 2023

This is a great extension @asg017! I'm trying to compile and statically link this extension in my own C code.

I used your make static-release and got the .a file and then tried to compile it with this C function and it builds my binary but when I try to call udi_sqlite_init_extensions as part of the SQLite execution I get a segfault. Is there anything special I need to do on the Rust code side?

#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1

#include "sqlite-ulid/dist/release/sqlite-ulid.h"

int udi_sqlite_init_extensions(sqlite3 *db, char **pzErrMsg,
                               const sqlite3_api_routines *pApi) {
  (void)pzErrMsg;
  SQLITE_EXTENSION_INIT2(pApi);

  // Initialize all static-linked extension here (e.g., ULID)
  int rc = sqlite3_ulid_init(db, pzErrMsg, pApi);
  if (rc != SQLITE_OK) {
     return rc;
  }

  return SQLITE_OK;
}
@asg017
Copy link
Owner

asg017 commented Oct 17, 2023

There's a bug in the current implementation of sqlite-loadable-rs, where calling sqlite3_ulid_init() by hand will cause a segfault. Instead, you can use sqlite3_auto_extension which should work, but means every database will pre-load sqlite-ulid functions.

Though I did find a fix for that bug, so in the next version of sqlite-ulid, your code should work. But you'll need to do the auto_extension workaround for now!

Example: https://github.com/asg017/sqlite-ulid/blob/main/examples/c/demo.c

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

2 participants