From 4f6e81cb751548787ca7078ea69ed393991ef4a5 Mon Sep 17 00:00:00 2001 From: ad hoc Date: Thu, 30 Nov 2023 11:15:56 +0100 Subject: [PATCH] fix review nits --- libsql-sqlite3/src/main.c | 27 ++++++++------------------- libsql-sqlite3/src/wal.c | 14 ++++++-------- libsql-sqlite3/src/wal.h | 2 +- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/libsql-sqlite3/src/main.c b/libsql-sqlite3/src/main.c index 86f287f991..472b6d8179 100644 --- a/libsql-sqlite3/src/main.c +++ b/libsql-sqlite3/src/main.c @@ -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); @@ -3639,10 +3638,8 @@ 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) */ @@ -3650,9 +3647,7 @@ int sqlite3_open_v2( 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 */ @@ -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 */ @@ -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( @@ -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); @@ -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; diff --git a/libsql-sqlite3/src/wal.c b/libsql-sqlite3/src/wal.c index 784a6437fb..fa0447b5dc 100644 --- a/libsql-sqlite3/src/wal.c +++ b/libsql-sqlite3/src/wal.c @@ -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; } /* @@ -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 }; /* @@ -4402,7 +4400,7 @@ void make_sqlite3_wal_manager_rc(RefCountedWalManager **out) { initialized = 1; } - *out = &manager; + return &manager; } typedef struct wal_impl wal_impl; diff --git a/libsql-sqlite3/src/wal.h b/libsql-sqlite3/src/wal.h index 3f175fcf43..f524a72e3d 100644 --- a/libsql-sqlite3/src/wal.h +++ b/libsql-sqlite3/src/wal.h @@ -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;