[ create a new paste ] login | about

Link: http://codepad.org/KCeSzRr6    [ raw code | output | fork ]

C, pasted on Apr 2:
#include <stdlib.h>
#include <stdio.h>
#include <lmdb.h>
// [01:00:55 eldil!11 py-lmdb] gcc -g -I lib -o break break.c lib/mdb.c lib/midl.c

#define KEYS 0xffff

static void must(int rc)
{
    if(rc) {
        fprintf(stderr, "errk, %s\n", mdb_strerror(rc));
        abort();
    }
}

int main(int argc, char **argv)
{
    char keybuf[8];
    int i;

    MDB_env *env;
    must(mdb_env_create(&env));
    system("rm -rf /tmp/crashdb*");
    must(mdb_env_set_mapsize(env, 1048576 * 1024));
    must(mdb_env_open(env, "/tmp/crashdb", MDB_NOSUBDIR, 0777));

    MDB_txn *txn;
    must(mdb_txn_begin(env, NULL, 0, &txn));

    MDB_dbi dbi;
    must(mdb_dbi_open(txn, NULL, 0, &dbi));

    MDB_val k = {5, keybuf};
    for(i = 0; i <= KEYS; i++) {
        sprintf(keybuf, "%05d", i);
        // MDB_APPEND is not necessary to trigger issue.
        must(mdb_put(txn, dbi, &k, &k, MDB_APPEND));
    }

    printf("inserted %d keys\n", i);

    MDB_cursor *cur;
    must(mdb_cursor_open(txn, dbi, &cur));
    must(mdb_cursor_get(cur, &k, &k, MDB_LAST));

    for(i = KEYS; i >= 0; i--) {
        sprintf(keybuf, "%05d", i);
        must(mdb_cursor_get(cur, &k, &k, MDB_GET_CURRENT));
        must(strncmp(keybuf, k.mv_data, k.mv_size));
        must(mdb_cursor_get(cur, &k, &k, MDB_PREV));
    }
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Line 17: error: lmdb.h: No such file or directory
In function 'main':
Line 22: error: 'MDB_env' undeclared (first use in this function)
Line 22: error: (Each undeclared identifier is reported only once
Line 22: error: for each function it appears in.)
Line 22: error: 'env' undeclared (first use in this function)
Line 26: error: 'MDB_NOSUBDIR' undeclared (first use in this function)
Line 28: error: 'MDB_txn' undeclared (first use in this function)
Line 28: error: 'txn' undeclared (first use in this function)
Line 31: error: 'MDB_dbi' undeclared (first use in this function)
Line 31: error: expected ';' before 'dbi'
Line 32: error: 'dbi' undeclared (first use in this function)
Line 34: error: 'MDB_val' undeclared (first use in this function)
Line 34: error: expected ';' before 'k'
Line 38: error: 'k' undeclared (first use in this function)
Line 38: error: 'MDB_APPEND' undeclared (first use in this function)
Line 43: error: 'MDB_cursor' undeclared (first use in this function)
Line 43: error: 'cur' undeclared (first use in this function)
Line 45: error: 'MDB_LAST' undeclared (first use in this function)
Line 49: error: 'MDB_GET_CURRENT' undeclared (first use in this function)
Line 51: error: 'MDB_PREV' undeclared (first use in this function)


Create a new paste based on this one


Comments: