Skip to content

Commit

Permalink
fix review nits
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinPostma committed Nov 30, 2023
1 parent 092d564 commit 4f6e81c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
27 changes: 8 additions & 19 deletions libsql-sqlite3/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,6 @@ void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
sqlite3_free(db->lookaside.pStart);
}

/* Destroy the create wal */
destroy_wal_manager(db->wal_manager);

sqlite3_free(db);
Expand Down Expand Up @@ -3639,20 +3638,16 @@ int sqlite3_open(
const char *zFilename,
sqlite3 **ppDb
){
RefCountedWalManager *wal;
make_sqlite3_wal_manager_rc(&wal);
return openDatabase(zFilename, ppDb,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL, wal);
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL, make_sqlite3_wal_manager_rc());
}
int sqlite3_open_v2(
const char *filename, /* Database filename (UTF-8) */
sqlite3 **ppDb, /* OUT: SQLite db handle */
int flags, /* Flags */
const char *zVfs /* Name of VFS module to use */
){
RefCountedWalManager *wal;
make_sqlite3_wal_manager_rc(&wal);
return openDatabase(filename, ppDb, (unsigned int)flags, zVfs, wal);
return openDatabase(filename, ppDb, (unsigned int)flags, zVfs, make_sqlite3_wal_manager_rc());
}

/* deprecated, only works with zWal == NULL */
Expand All @@ -3663,10 +3658,8 @@ int libsql_open(
const char *zVfs, /* Name of VFS module to use, NULL for default */
const char *zWal /* Name of WAL module to use */
) {
assert( zWal == NULL );;
RefCountedWalManager *wal;
make_sqlite3_wal_manager_rc(&wal);
return openDatabase(filename, ppDb, (unsigned int)flags, zVfs, wal);
assert( zWal == NULL );
return openDatabase(filename, ppDb, (unsigned int)flags, zVfs, make_sqlite3_wal_manager_rc());
}

/* deprecated, only works with zWal == NULL */
Expand All @@ -3678,10 +3671,8 @@ int libsql_open_v2(
const char *zWal, /* Name of WAL module to use */
void* pWalMethodsData /* User data, passed to the libsql_wal struct*/
) {
assert( zWal == NULL );;
RefCountedWalManager *wal;
make_sqlite3_wal_manager_rc(&wal);
return openDatabase(filename, ppDb, (unsigned int)flags, zVfs, wal);
assert( zWal == NULL );
return openDatabase(filename, ppDb, (unsigned int)flags, zVfs, make_sqlite3_wal_manager_rc());
}

int libsql_open_v3(
Expand All @@ -3691,7 +3682,7 @@ int libsql_open_v3(
const char *zVfs, /* Name of VFS module to use, NULL for default */
libsql_wal_manager wal_manager /* wal_manager implemetation */
) {
RefCountedWalManager *wal_manager_rc ;
RefCountedWalManager *wal_manager_rc;
int rc = make_ref_counted_wal_manager(wal_manager, &wal_manager_rc);
if (rc) {
wal_manager.xDestroy(wal_manager.pData);
Expand Down Expand Up @@ -3725,10 +3716,8 @@ int sqlite3_open16(
sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC);
zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8);
if( zFilename8 ){
RefCountedWalManager *wal;
make_sqlite3_wal_manager_rc(&wal);
rc = openDatabase(zFilename8, ppDb,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL, wal);
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL, make_sqlite3_wal_manager_rc());
assert( *ppDb || rc==SQLITE_NOMEM );
if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
SCHEMA_ENC(*ppDb) = ENC(*ppDb) = SQLITE_UTF16NATIVE;
Expand Down
14 changes: 6 additions & 8 deletions libsql-sqlite3/src/wal.c
Original file line number Diff line number Diff line change
Expand Up @@ -4167,21 +4167,19 @@ static int libsqlMakeWalPathname(const char *main_db_path_name, char **out) {
int sqlite3LogExists(wal_manager_impl* self, sqlite3_vfs *vfs, const char *main_db_path_name, int *exists) {
char *zWal;
int rc = libsqlMakeWalPathname(main_db_path_name, &zWal);
if (rc != 0) return rc;
if (rc != SQLITE_OK) return rc;
rc = sqlite3OsAccess(vfs, zWal, SQLITE_ACCESS_EXISTS, exists);
sqlite3_free(zWal);
if (rc != 0) return rc;
return SQLITE_OK;
return rc;
}

int sqlite3LogDestroy(wal_manager_impl* self, sqlite3_vfs *vfs, const char *main_db_path_name) {
char *zWal;
int rc = libsqlMakeWalPathname(main_db_path_name, &zWal);
if (rc != 0) return rc;
if (rc != SQLITE_OK) return rc;
rc = sqlite3OsDelete(vfs, zWal, 0);
sqlite3_free(zWal);
if (rc != 0) return rc;
return SQLITE_OK;
return rc;
}

/*
Expand Down Expand Up @@ -4389,7 +4387,7 @@ const libsql_wal_manager sqlite3_wal_manager = {
.xDestroy =(void (*)(wal_manager_impl*))sqlite3DestroyWalManager,
};

void make_sqlite3_wal_manager_rc(RefCountedWalManager **out) {
RefCountedWalManager *make_sqlite3_wal_manager_rc() {
static int initialized = 0;
static RefCountedWalManager manager = { 0 };
/*
Expand All @@ -4402,7 +4400,7 @@ void make_sqlite3_wal_manager_rc(RefCountedWalManager **out) {
initialized = 1;
}

*out = &manager;
return &manager;
}

typedef struct wal_impl wal_impl;
Expand Down
2 changes: 1 addition & 1 deletion libsql-sqlite3/src/wal.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ int make_ref_counted_wal_manager(libsql_wal_manager wal_manager, RefCountedWalMa
void destroy_wal_manager(RefCountedWalManager *p);
RefCountedWalManager* clone_wal_manager(RefCountedWalManager *p);

void make_sqlite3_wal_manager_rc(RefCountedWalManager **out);
RefCountedWalManager *make_sqlite3_wal_manager_rc();

extern const libsql_wal_manager sqlite3_wal_manager;

Expand Down

0 comments on commit 4f6e81c

Please sign in to comment.