<commit_before>#include <db.h>
#include <sys/stat.h>
#include "test.h"

static DB_ENV *env;
static DB *db;
DB_TXN *txn;

void setup (void) {
    system("rm -rf " ENVDIR);
    int r;
    r=mkdir(ENVDIR, 0777);       CKERR(r);

    r=db_env_create(&env, 0); CKERR(r);
    env->set_errfile(env, stderr);
    r=env->open(env, ENVDIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_CREATE|DB_PRIVATE, 0777); CKERR(r);
    r=db_create(&db, env, 0); CKERR(r);

    r=env->txn_begin(env, 0, &txn, 0); assert(r==0);
    r=db->open(db, txn, "foo.db", 0, DB_BTREE, DB_CREATE, 0777); CKERR(r);
    r=txn->commit(txn, 0);    assert(r==0);
}

void doit (void) {
    DBT key,data;
    int r;
    r=env->txn_begin(env, 0, &txn, 0); assert(r==0);
    r=db->put(db, txn, dbt_init(&key, "a", 2), dbt_init(&data, "a", 2), DB_YESOVERWRITE);
    r=db->put(db, txn, dbt_init(&key, "b", 2), dbt_init(&data, "b", 2), DB_YESOVERWRITE);
    r=db->put(db, txn, dbt_init(&key, "c", 2), dbt_init(&data, "c", 2), DB_YESOVERWRITE);
    r=txn->commit(txn, 0);    assert(r==0);
    
    r=env->txn_begin(env, 0, &txn, 0); assert(r==0);
    r=db->del(db, txn, dbt_init(&key, "b", 2),  0); assert(r==0);
    r=txn->commit(txn, 0);    assert(r==0);

    r=env->txn_begin(env, 0, &txn, 0); assert(r==0);    
    DBC *dbc;
    r = db->cursor(db, txn, &dbc, 0);                           assert(r==0);
    memset(&key,  0, sizeof(key));
    memset(&data, 0, sizeof(data));
    r = dbc->c_get(dbc, &key, &data, DB_FIRST);                 assert(r==0);
    assert(strcmp(key.data, "a")==0);
    assert(strcmp(data.data, "a")==0);
    r = dbc->c_get(dbc, &key, &data, DB_NEXT);                  assert(r==0);
    assert(strcmp(key.data, "c")==0);
    assert(strcmp(data.data, "c")==0);
    r = dbc->c_close(dbc);                                      assert(r==0);
    r=txn->commit(txn, 0);    assert(r==0);
}

int main (int argc, const char *argv[]) {
    parse_args(argc, argv);

    setup();
    doit();

    return 0;
}<commit_msg>Finish cleanup.  Addresses #855, #856.<commit_after>#include <db.h>
#include <sys/stat.h>
#include "test.h"

static DB_ENV *env;
static DB *db;
DB_TXN *txn;

void setup (void) {
    system("rm -rf " ENVDIR);
    int r;
    r=mkdir(ENVDIR, 0777);       CKERR(r);

    r=db_env_create(&env, 0); CKERR(r);
    env->set_errfile(env, stderr);
    r=env->open(env, ENVDIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_CREATE|DB_PRIVATE, 0777); CKERR(r);
    r=db_create(&db, env, 0); CKERR(r);

    r=env->txn_begin(env, 0, &txn, 0); assert(r==0);
    r=db->open(db, txn, "foo.db", 0, DB_BTREE, DB_CREATE, 0777); CKERR(r);
    r=txn->commit(txn, 0);    assert(r==0);
}

void shutdown (void) {
    int r;
    r= db->close(db, 0); CKERR(r);
    r= env->close(env, 0); CKERR(r);
}

void doit (void) {
    DBT key,data;
    int r;
    r=env->txn_begin(env, 0, &txn, 0); assert(r==0);
    r=db->put(db, txn, dbt_init(&key, "a", 2), dbt_init(&data, "a", 2), DB_YESOVERWRITE);
    r=db->put(db, txn, dbt_init(&key, "b", 2), dbt_init(&data, "b", 2), DB_YESOVERWRITE);
    r=db->put(db, txn, dbt_init(&key, "c", 2), dbt_init(&data, "c", 2), DB_YESOVERWRITE);
    r=txn->commit(txn, 0);    assert(r==0);
    
    r=env->txn_begin(env, 0, &txn, 0); assert(r==0);
    r=db->del(db, txn, dbt_init(&key, "b", 2),  0); assert(r==0);
    r=txn->commit(txn, 0);    assert(r==0);

    r=env->txn_begin(env, 0, &txn, 0); assert(r==0);    
    DBC *dbc;
    r = db->cursor(db, txn, &dbc, 0);                           assert(r==0);
    memset(&key,  0, sizeof(key));
    memset(&data, 0, sizeof(data));
    r = dbc->c_get(dbc, &key, &data, DB_FIRST);                 assert(r==0);
    assert(strcmp(key.data, "a")==0);
    assert(strcmp(data.data, "a")==0);
    r = dbc->c_get(dbc, &key, &data, DB_NEXT);                  assert(r==0);
    assert(strcmp(key.data, "c")==0);
    assert(strcmp(data.data, "c")==0);
    r = dbc->c_close(dbc);                                      assert(r==0);
    r=txn->commit(txn, 0);    assert(r==0);
}

int main (int argc, const char *argv[]) {
    parse_args(argc, argv);

    setup();
    doit();
    shutdown();

    return 0;
}
{'fraction_non_alphanumeric': 0.22396335583413693, 'fraction_numerical': 0.02892960462873674, 'mean_word_length': 3.0478048780487805, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '803356', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1825, 'n_words': 358}