mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 23:04:20 +01:00
356e2cb4c9
git-svn-id: file:///svn/tokudb@244 c7de825b-a66e-492c-adef-691d508d4ae1
86 lines
2.5 KiB
C
86 lines
2.5 KiB
C
/* Make a db.h that will be link-time compatible with Sleepycat's Berkeley DB. */
|
|
|
|
#include <db.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
|
|
|
|
void print_dbtype(void) {
|
|
/* DBTYPE is mentioned by db_open.html */
|
|
printf("typedef enum {\n");
|
|
printf(" DB_BTREE=%d\n", DB_BTREE);
|
|
printf("} DBTYPE;\n");
|
|
}
|
|
|
|
|
|
#define DECL_LIMIT 100
|
|
struct fieldinfo {
|
|
char decl[DECL_LIMIT];
|
|
unsigned int off;
|
|
unsigned int size;
|
|
};
|
|
|
|
#include "sample_offsets_32.h"
|
|
#include "sample_offsets_64.h"
|
|
|
|
void print_db_struct (void) {
|
|
unsigned int i;
|
|
unsigned int current_32 = 0;
|
|
unsigned int current_64 = 0;
|
|
int dummy_counter=0;
|
|
// int did_toku_internal=0;
|
|
printf("struct __toku_db {\n");
|
|
assert(sizeof(fields32)==sizeof(fields64));
|
|
for (i=0; i<sizeof(fields32)/sizeof(fields32[0]); i++) {
|
|
unsigned int this_32 = fields32[i].off;
|
|
unsigned int this_64 = fields64[i].off;
|
|
assert(strcmp(fields32[i].decl, fields64[i].decl)==0);
|
|
#if 0
|
|
if (!did_toku_internal && this_offset+sizeof(void*)>current_offset) {
|
|
printf(" struct __tokudb_internal *i;\n");
|
|
current_offset+=sizeof(void*);
|
|
did_toku_internal=1;
|
|
}
|
|
#endif
|
|
if (this_32 > current_32 || this_64 > current_64) {
|
|
unsigned int diff32 = this_32-current_32;
|
|
unsigned int diff64 = this_64-current_64;
|
|
assert(this_32 > current_32 && this_64 > current_64);
|
|
if (diff32!=diff64) {
|
|
unsigned int diff = diff64-diff32;
|
|
printf(" void* dummy%d[%d];\n", dummy_counter++, diff/4);
|
|
diff64-=diff*2;
|
|
diff32-=diff;
|
|
|
|
}
|
|
assert(diff32==diff64);
|
|
if (diff32>0) {
|
|
printf(" char dummy%d[%d];\n", dummy_counter++, diff32);
|
|
}
|
|
current_32 = this_32;
|
|
current_64 = this_64;
|
|
}
|
|
if (this_32<current_32 || this_64<current_64) {
|
|
printf("Whoops\n");
|
|
}
|
|
printf(" %s; /* 32-bit offset=%d size=%d, 64=bit offset=%d size=%d */\n", fields32[i].decl, fields32[i].off, fields32[i].size, fields64[i].off, fields64[i].size);
|
|
current_32 += fields32[i].size;
|
|
current_64 += fields64[i].size;
|
|
}
|
|
printf("};\n");
|
|
}
|
|
|
|
int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
|
|
printf("#ifndef _DB_H\n");
|
|
printf("#define _DB_H\n");
|
|
printf("/* This code generated by make_db_h. Copyright (c) 2007 Tokutek */\n");
|
|
printf("#if defined(__cplusplus)\nextern \"C\" {\n#endif\n");
|
|
printf("typedef struct __toku_db DB;\n");
|
|
print_dbtype();
|
|
print_db_struct();
|
|
printf("#if defined(__cplusplus)\n}\n#endif\n");
|
|
printf("#endif\n");
|
|
return 0;
|
|
}
|