From 801060c7a53066acb7996d4e7384e8ac7d5af052 Mon Sep 17 00:00:00 2001 From: "Bradley C. Kuszmaul" Date: Tue, 4 Sep 2007 21:01:41 +0000 Subject: [PATCH] Create sample_offsets git-svn-id: file:///svn/tokudb@240 c7de825b-a66e-492c-adef-691d508d4ae1 --- buildheader/sample_offsets.c | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 buildheader/sample_offsets.c diff --git a/buildheader/sample_offsets.c b/buildheader/sample_offsets.c new file mode 100644 index 00000000000..516b9ad25e1 --- /dev/null +++ b/buildheader/sample_offsets.c @@ -0,0 +1,76 @@ +/* Make a db.h that will be link-time compatible with Sleepycat's Berkeley DB. */ + +#include +#include +#include + + +DB db_dummy; + +#define DECL_LIMIT 100 +#define FIELD_LIMIT 100 +struct fieldinfo { + char decl[DECL_LIMIT]; + unsigned int off; + unsigned int size; +} db_fields[FIELD_LIMIT]; +int db_field_counter=0; + + +int compare_fields (const void *av, const void *bv) { + const struct fieldinfo *a = av; + const struct fieldinfo *b = bv; + if (a->off < b->off) return -1; + if (a->off > b->off) return 1; + return 0; +} + +#define DB_STRUCT_SETUP(name, fstring) ({ snprintf(db_fields[db_field_counter].decl, DECL_LIMIT, fstring, #name); \ + db_fields[db_field_counter].off = offsetof(DB, name); \ + db_fields[db_field_counter].size = sizeof(db_dummy.name); \ + db_field_counter++; }) + +void sample_offsets (void) { + int i; + unsigned int current_offset=0; + int dummy_counter=0; + int did_toku_internal=0; + /* Do these in alphabetical order. */ + DB_STRUCT_SETUP(app_private, "void *%s"); + DB_STRUCT_SETUP(close, "int (*%s) (DB*, u_int32_t)"); + DB_STRUCT_SETUP(cursor, "int (*%s) (DB *, DB_TXN *, DBC **, u_int32_t)"); + DB_STRUCT_SETUP(del, "int (*%s) (DB *, DB_TXN *, DBT *, u_int32_t)"); + DB_STRUCT_SETUP(get, "int (*%s) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)"); + DB_STRUCT_SETUP(key_range, "int (*%s) (DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t)"); + DB_STRUCT_SETUP(open, "int (*%s) (DB *, DB_TXN *, const char *, const char *, DBTYPE, u_int32_t, int)"); + DB_STRUCT_SETUP(put, "int (*%s) (DB *, DB_TXN *, DBT *, DBT *, u_int32_t)"); + DB_STRUCT_SETUP(remove, "int (*%s) (DB *, const char *, const char *, u_int32_t)"); + DB_STRUCT_SETUP(rename, "int (*%s) (DB *, const char *, const char *, const char *, u_int32_t)"); + DB_STRUCT_SETUP(set_bt_compare, "int (*%s) (DB *, int (*)(DB *, const DBT *, const DBT *))"); + DB_STRUCT_SETUP(set_flags, "int (*%s) (DB *, u_int32_t)"); + DB_STRUCT_SETUP(stat, "int (*%s) (DB *, void *, u_int32_t)"); + qsort(db_fields, db_field_counter, sizeof(db_fields[0]), compare_fields); + printf("struct __toku_db {\n"); + for (i=0; icurrent_offset) { + printf(" struct __tokudb_internal *i;\n"); + current_offset+=sizeof(void*); + did_toku_internal=1; + } + if (this_offset>current_offset) { + printf(" char dummy%d[%d];\n", dummy_counter++, this_offset-current_offset); + current_offset=this_offset; + } + if (this_offset