diff --git a/src/backup.cc b/src/backup.cc index 50adba6a..5835a7e5 100644 --- a/src/backup.cc +++ b/src/backup.cc @@ -178,12 +178,7 @@ void Backup::Work_BeginInitialize(Database::Baton* baton) { assert(baton->db->open); baton->db->pending++; auto env = baton->db->Env(); - int UNUSED(status) = napi_create_async_work( - env, NULL, Napi::String::New(env, "sqlite3.Backup.Initialize"), - Work_Initialize, Work_AfterInitialize, baton, &baton->request - ); - assert(status == 0); - napi_queue_async_work(env, baton->request); + CREATE_WORK("sqlite3.Backup.Initialize", Work_Initialize, Work_AfterInitialize); } void Backup::Work_Initialize(napi_env e, void* data) { diff --git a/src/database.cc b/src/database.cc index 77d8f707..7f89c10c 100644 --- a/src/database.cc +++ b/src/database.cc @@ -152,12 +152,7 @@ Database::Database(const Napi::CallbackInfo& info) : Napi::ObjectWrap( void Database::Work_BeginOpen(Baton* baton) { auto env = baton->db->Env(); - int UNUSED(status) = napi_create_async_work( - env, NULL, Napi::String::New(env, "sqlite3.Database.Open"), - Work_Open, Work_AfterOpen, baton, &baton->request - ); - assert(status == 0); - napi_queue_async_work(env, baton->request); + CREATE_WORK("sqlite3.Database.Open", Work_Open, Work_AfterOpen); } void Database::Work_Open(napi_env e, void* data) { @@ -245,13 +240,7 @@ void Database::Work_BeginClose(Baton* baton) { baton->db->closing = true; auto env = baton->db->Env(); - - int UNUSED(status) = napi_create_async_work( - env, NULL, Napi::String::New(env, "sqlite3.Database.Close"), - Work_Close, Work_AfterClose, baton, &baton->request - ); - assert(status == 0); - napi_queue_async_work(env, baton->request); + CREATE_WORK("sqlite3.Database.Close", Work_Close, Work_AfterClose); } void Database::Work_Close(napi_env e, void* data) { @@ -585,13 +574,9 @@ void Database::Work_BeginExec(Baton* baton) { assert(baton->db->_handle); assert(baton->db->pending == 0); baton->db->pending++; + auto env = baton->db->Env(); - int UNUSED(status) = napi_create_async_work( - env, NULL, Napi::String::New(env, "sqlite3.Database.Exec"), - Work_Exec, Work_AfterExec, baton, &baton->request - ); - assert(status == 0); - napi_queue_async_work(env, baton->request); + CREATE_WORK("sqlite3.Database.Exec", Work_Exec, Work_AfterExec); } void Database::Work_Exec(napi_env e, void* data) { @@ -694,13 +679,9 @@ void Database::Work_BeginLoadExtension(Baton* baton) { assert(baton->db->_handle); assert(baton->db->pending == 0); baton->db->pending++; + auto env = baton->db->Env(); - int UNUSED(status) = napi_create_async_work( - env, NULL, Napi::String::New(env, "sqlite3.Database.LoadExtension"), - Work_LoadExtension, Work_AfterLoadExtension, baton, &baton->request - ); - assert(status == 0); - napi_queue_async_work(env, baton->request); + CREATE_WORK("sqlite3.Database.LoadExtension", Work_LoadExtension, Work_AfterLoadExtension); } void Database::Work_LoadExtension(napi_env e, void* data) { diff --git a/src/macros.h b/src/macros.h index 8e4139d4..3bcde83c 100644 --- a/src/macros.h +++ b/src/macros.h @@ -23,13 +23,6 @@ inline bool OtherIsInt(Napi::Number source) { } } -#ifdef UNUSED -#elif defined(__GNUC__) -# define UNUSED(x) UNUSED_ ## x __attribute__((unused)) -#else -# define UNUSED(x) x -#endif - #define IS_FUNCTION(cb) \ !cb.IsUndefined() && cb.IsFunction() @@ -144,6 +137,19 @@ inline bool OtherIsInt(Napi::Number source) { static void Work_##name(napi_env env, void* data); \ static void Work_After##name(napi_env env, napi_status status, void* data); +#ifdef DEBUG + #define ASSERT_STATUS() assert(status == 0); +#else + #define ASSERT_STATUS() (void)status; +#endif + +#define CREATE_WORK(name, workerFn, afterFn) \ + int status = napi_create_async_work(env, NULL, Napi::String::New(env, name),\ + workerFn, afterFn, baton, &baton->request); \ + \ + ASSERT_STATUS(); \ + napi_queue_async_work(env, baton->request); + #define STATEMENT_BEGIN(type) \ assert(baton); \ assert(baton->stmt); \ @@ -153,12 +159,7 @@ inline bool OtherIsInt(Napi::Number source) { baton->stmt->locked = true; \ baton->stmt->db->pending++; \ auto env = baton->stmt->Env(); \ - int UNUSED(status) = napi_create_async_work( \ - env, NULL, Napi::String::New(env, "sqlite3.Statement."#type), \ - Work_##type, Work_After##type, baton, &baton->request \ - ); \ - assert(status == 0); \ - napi_queue_async_work(env, baton->request); + CREATE_WORK("sqlite3.Statement."#type, Work_##type, Work_After##type); #define STATEMENT_INIT(type) \ type* baton = static_cast(data); \ @@ -189,12 +190,7 @@ inline bool OtherIsInt(Napi::Number source) { baton->backup->locked = true; \ baton->backup->db->pending++; \ auto env = baton->backup->Env(); \ - int UNUSED(status) = napi_create_async_work( \ - env, NULL, Napi::String::New(env, "sqlite3.Backup."#type), \ - Work_##type, Work_After##type, baton, &baton->request \ - ); \ - assert(status == 0); \ - napi_queue_async_work(env, baton->request); + CREATE_WORK("sqlite3.Backup."#type, Work_##type, Work_After##type); #define BACKUP_INIT(type) \ type* baton = static_cast(data); \ diff --git a/src/statement.cc b/src/statement.cc index 2d6daa41..b39f0c83 100644 --- a/src/statement.cc +++ b/src/statement.cc @@ -121,13 +121,9 @@ Statement::Statement(const Napi::CallbackInfo& info) : Napi::ObjectWrapdb->open); baton->db->pending++; + auto env = baton->db->Env(); - int UNUSED(status) = napi_create_async_work( - env, NULL, Napi::String::New(env, "sqlite3.Statement.Prepare"), - Work_Prepare, Work_AfterPrepare, baton, &baton->request - ); - assert(status == 0); - napi_queue_async_work(env, baton->request); + CREATE_WORK("sqlite3.Statement.Prepare", Work_Prepare, Work_AfterPrepare); } void Statement::Work_Prepare(napi_env e, void* data) {