Hi all,
I've been trying to wrap SQLite's C API within a singleton class. I'm
using a Singleton so I can access a particular sqlite db across my
application, which consists of my main program and objects, and other
components/objects from dynamic libraries. Unfortunately I get some
weird behaviour with my class that I'm having trouble understanding.
When I use the class from the part of my program that sets up the
database connection, all is well. When I try to use it from the
dynamically loaded components, my program seg faults. If I setup the
database connection in a dynamic object, the sqlite api will start
working from that object as well (as well as keep working with the
main part of the program).
The singleton class implementation seems to be okay -- I can access
any other member / do any other class-related functions as expected
outside of using sqlite with any object. The singleton and sqlite are
compiled as a shared static lib and my main program and dynamic
libraries link to it. I've spent a bunch of time trying to figure out
what's going on, but I'm not really getting anywhere. I'd appreciate
any help / insight. tldr;
* When I access a singleton class w/sqlite api inside my normal
application (no dynamically loaded stuff), it works fine.
* When I access the singleton class from within dynamically loaded
components, it seg faults.
* Singleton works as expected outside of sqlite calls.
* I'm not using threads.
// Backtrace
0 ?? 0
1 sqlite3_mutex_enter sqlite3.c 16473 0xb2e7123c
2 sqlite3LockAndPrepare sqlite3.c 89625 0xb2ec75ea
3 sqlite3_prepare_v2 sqlite3.c 89702 0xb2ec77e2
4 PrisSql::RunTest prissql.cpp 44 0xb2eea5bd
5 PrisHome::Initialize prishome.cpp 6 0xb2e5acc5 <---
dynamically loaded object
....
// Segmentation Fault in sqlite.c
/*
** Obtain the mutex p. If some other thread already has the mutex, block
** until it can be obtained.
*/
SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex *p){
if( p ){
sqlite3GlobalConfig.mutex.xMutexEnter(p); //<---- line where seg
fault occurs
}
}
To avoid a wall of text, I've provided my (very small test) Singleton
class here:
(header) http://pastebin.com/PYGX399p
(source) http://pastebin.com/6bwJiXGr
I'd appreciate any advice!
Regards,
-Pris
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users