static JSBool rpmseq_Close(JSContext *cx, uintN argc, jsval *vp) { jsval *argv = JS_ARGV(cx , vp); JSObject *obj = JS_NewObjectForConstructor(cx , vp); if(!obj) { JS_ReportError(cx , "Failed to create 'this' object"); return JS_FALSE; } void * ptr = JS_GetInstancePrivate(cx, obj, &rpmseqClass, NULL); DB_SEQUENCE * seq = ptr; uint32_t _flags = 0; JSBool ok = JS_FALSE; _METHOD_DEBUG_ENTRY(_debug); if (seq == NULL) goto exit; JS_SET_RVAL(cx, vp, JSVAL_FALSE); if (!(ok = JS_ConvertArguments(cx, argc, argv, "/u", &_flags))) goto exit; { int ret = seq->close(seq, _flags); if (ret) fprintf(stderr, "DB_SEQUENCE->close: %s\n", db_strerror(ret)); else JS_SET_RVAL(cx, vp, JSVAL_TRUE); seq = ptr = NULL; (void) JS_SetPrivate(cx, obj, ptr); } ok = JS_TRUE; exit: return ok; }
DbSequence::~DbSequence() { DB_SEQUENCE *seq; seq = unwrap(this); if (seq != NULL) (void)seq->close(seq, 0); }
static void rpmseq_dtor(JSContext *cx, JSObject *obj) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmseqClass, NULL); DB_SEQUENCE * seq = ptr; _DTOR_DEBUG_ENTRY(_debug); if (seq) (void) seq->close(seq, 0); }
static int btreeSeqOpen( sqlite3_context *context, Btree *p, SEQ_COOKIE *cookie) { BtShared *pBt; DBT key; DB_SEQUENCE *seq; char seq_key[BT_MAX_SEQ_NAME]; int ret, seq_len; u_int32_t flags; pBt = p->pBt; if ((ret = btreeSeqGetCookie(context, p, cookie, 0)) != 0) return (ret); if (cookie->cache != 0) { if ((ret = db_sequence_create(&seq, pBt->metadb, 0)) != 0) return ret; seq->set_cachesize(seq, cookie->cache); flags = 0; #ifdef BDBSQL_SINGLE_THREAD flags |= DB_THREAD; #endif sqlite3_snprintf( BT_MAX_SEQ_NAME, seq_key, "%s_db", cookie->name); seq_len = (int)strlen(seq_key); memset(&key, 0, sizeof(key)); key.data = seq_key; key.size = key.ulen = seq_len; key.flags = DB_DBT_USERMEM; if ((ret = seq->open( seq, NULL, &key, flags)) != 0) { (void)seq->close(seq, 0); return ret; } cookie->handle = seq; } return (0); }
/* --- Object ctors/dtors */ static DB_SEQUENCE * rpmseq_init(JSContext *cx, JSObject *obj, DB * db, uint32_t flags) { DB_SEQUENCE * seq = NULL; int ret = db_sequence_create(&seq, db, flags); if (ret || seq == NULL || !JS_SetPrivate(cx, obj, (void *)seq)) { if (db) db->err(db, ret, "db_sequence_create"); else fprintf(stderr, "db_sequence_create: %s\n", db_strerror(ret)); if (seq) ret = seq->close(seq, 0); seq = NULL; } if (_debug) fprintf(stderr, "<== %s(%p,%p) seq %p\n", __FUNCTION__, cx, obj, seq); return seq; }