@nxtedition/rocksdb 10.0.12 → 10.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/binding.cc
CHANGED
|
@@ -76,15 +76,6 @@ struct Database final {
|
|
|
76
76
|
return db2->Close();
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
void Ref() { refs_++; }
|
|
80
|
-
|
|
81
|
-
void Unref() {
|
|
82
|
-
if (--refs_ == 0) {
|
|
83
|
-
Close();
|
|
84
|
-
delete this;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
79
|
void Attach(Closable* closable) {
|
|
89
80
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
90
81
|
|
|
@@ -105,7 +96,6 @@ struct Database final {
|
|
|
105
96
|
private:
|
|
106
97
|
mutable std::mutex mutex_;
|
|
107
98
|
std::set<Closable*> closables_;
|
|
108
|
-
std::atomic<int> refs_ = 0;
|
|
109
99
|
};
|
|
110
100
|
|
|
111
101
|
enum BatchOp { Empty, Put, Delete, Merge, Data };
|
|
@@ -492,7 +482,7 @@ static void env_cleanup_hook(void* data) {
|
|
|
492
482
|
// where it's our responsibility to clean up. Note also, the following code must
|
|
493
483
|
// be a safe noop if called before db_open() or after db_close().
|
|
494
484
|
if (database) {
|
|
495
|
-
database->
|
|
485
|
+
database->Close();
|
|
496
486
|
}
|
|
497
487
|
}
|
|
498
488
|
|
|
@@ -500,7 +490,7 @@ static void FinalizeDatabase(napi_env env, void* data, void* hint) {
|
|
|
500
490
|
auto database = reinterpret_cast<Database*>(data);
|
|
501
491
|
if (database) {
|
|
502
492
|
napi_remove_env_cleanup_hook(env, env_cleanup_hook, database);
|
|
503
|
-
database->
|
|
493
|
+
database->Close();
|
|
504
494
|
}
|
|
505
495
|
}
|
|
506
496
|
|
|
@@ -512,6 +502,8 @@ NAPI_METHOD(db_init) {
|
|
|
512
502
|
napi_valuetype type;
|
|
513
503
|
NAPI_STATUS_THROWS(napi_typeof(env, argv[0], &type));
|
|
514
504
|
|
|
505
|
+
napi_value result;
|
|
506
|
+
|
|
515
507
|
if (type == napi_string) {
|
|
516
508
|
std::string location;
|
|
517
509
|
size_t length = 0;
|
|
@@ -520,23 +512,21 @@ NAPI_METHOD(db_init) {
|
|
|
520
512
|
NAPI_STATUS_THROWS(napi_get_value_string_utf8(env, argv[0], &location[0], length + 1, &length));
|
|
521
513
|
|
|
522
514
|
database = new Database(location);
|
|
515
|
+
napi_add_env_cleanup_hook(env, env_cleanup_hook, database);
|
|
516
|
+
NAPI_STATUS_THROWS(napi_create_external(env, database, FinalizeDatabase, nullptr, &result));
|
|
523
517
|
} else if (type == napi_bigint) {
|
|
524
518
|
int64_t value;
|
|
525
519
|
bool lossless;
|
|
526
520
|
NAPI_STATUS_THROWS(napi_get_value_bigint_int64(env, argv[0], &value, &lossless));
|
|
527
521
|
|
|
528
522
|
database = reinterpret_cast<Database*>(value);
|
|
523
|
+
NAPI_STATUS_THROWS(napi_create_external(env, database, nullptr, nullptr, &result));
|
|
524
|
+
|
|
525
|
+
// We should have an env_cleanup_hook for closing iterators...
|
|
529
526
|
} else {
|
|
530
527
|
NAPI_STATUS_THROWS(napi_invalid_arg);
|
|
531
528
|
}
|
|
532
529
|
|
|
533
|
-
napi_add_env_cleanup_hook(env, env_cleanup_hook, database);
|
|
534
|
-
|
|
535
|
-
napi_value result;
|
|
536
|
-
NAPI_STATUS_THROWS(napi_create_external(env, database, FinalizeDatabase, nullptr, &result));
|
|
537
|
-
|
|
538
|
-
database->Ref();
|
|
539
|
-
|
|
540
530
|
return result;
|
|
541
531
|
}
|
|
542
532
|
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|