You should only be defining SQLITE_CORE if in fact the extension is part of the 
core -- that is compiled and included (statically linked) to the core sqlite3.c 
compilation unit.  In this case, the extension makes direct calls to the 
sqlite3 entry points and shares the same runtime as the sqlite3 core engine.

If the extension is *not* part of the same linkage unit as sqlite3.c, then it 
cannot access the sqlite3 core functions using direct linkage and must instead 
use a structure of function pointers (aka a class) for indirect access.

Having an extension be a part of the core but not telling it so is only 
deleterious to performance (linkage is via indirect function pointers rather 
than static linkage).

Telling an extension that it is part of the core when it is not will lead to 
memory access errors, either due to bad loadtime linkage or more likely to the 
fact that it is using a separate runtime heap and/or stack manager and neither 
the extension nor the actual sqlite3 core can manage each others' memory 
allocations.

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.


>-----Original Message-----
>From: sqlite-users [mailto:sqlite-users-
>boun...@mailinglists.sqlite.org] On Behalf Of Lifepillar
>Sent: Monday, 4 December, 2017 12:45
>To: sqlite-users@mailinglists.sqlite.org
>Subject: [sqlite] Cannot initialize statically linked extension
>
>Hello,
>I need some help to figure out a segfault. I have:
>
>- SQLite3 3.21.0 compiled as a static library;
>- a custom extension compiled as another static library,
>   passing -DSQLITE_CORE.
>- a simple main program linked to both libraries.
>
>My extension has the typical structure, nothing fancy.
>
>My main() function contains the following snippet:
>
>  int rc = sqlite3_open(":memory:", &db);
>   if (rc != SQLITE_OK) {
>     sqlite3_close(db);
>     return rc;
>   }
>   char* zErrMsg;
>   //sqlite3_myextension_init(db, &zErrMsg, 0);
>
>This works fine: I can use SQLite functions without problems.
>But, if I un-comment the line that invokes the entry point of
>my extension (the last line of the snippet above), the program
>crashes with a bad memory access error.
>
>Btw, if I build my extension as a dynamic library and load it
>in a SQLite shell, all is fine.
>
>Any idea what may be wrong?
>
>Thanks,
>Life.
>
>
>
>
>_______________________________________________
>sqlite-users mailing list
>sqlite-users@mailinglists.sqlite.org
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to