Compiles with VC++ as a .dll. Set up to use static glib, libiconv, libintl for ease of use.

This commit is contained in:
Jimmytaker
2014-12-22 20:09:43 +01:00
parent aab7a561f1
commit cb65d4f3dd
9 changed files with 207 additions and 163 deletions

View File

@@ -35,7 +35,7 @@
static int is_init;
GHashTable *mdb_backends;
void _mdb_remove_backends();
static void _mdb_remove_backends();
/* Access data types */
static MdbBackendType mdb_access_types[] = {
@@ -342,13 +342,39 @@ mdb_init_backends())
fprintf(stderr, "mdb_init_backends() is DEPRECATED and does nothing. Stop calling it.\n");
}
#ifdef _MSC_VER
#define CCALL __cdecl
#pragma section(".CRT$XCU",read)
#define INITIALIZER(f) \
static void __cdecl f(void); \
__declspec(allocate(".CRT$XCU")) void (__cdecl*f##_)(void) = f; \
static void __cdecl f(void)
#elif defined(__GNUC__)
#define CCALL
#define INITIALIZER(f) void __attribute__((constructor)) f(void)
#endif
/**
* mdb_remove_backends
*
* Removes all entries from and destroys the mdb_backends hash.
*/
static void CCALL _mdb_remove_backends(void)
{
g_hash_table_foreach_remove(mdb_backends, mdb_drop_backend, NULL);
g_hash_table_destroy(mdb_backends);
}
/**
* _mdb_init_backends
*
* Initializes the mdb_backends hash and loads the builtin backends.
* Use mdb_remove_backends() to destroy this hash when done.
*/
MDB_CONSTRUCTOR(_mdb_init_backends)
INITIALIZER(_mdb_init_backends)
{
mdb_backends = g_hash_table_new(g_str_hash, g_str_equal);
@@ -440,17 +466,6 @@ mdb_remove_backends())
fprintf(stderr, "mdb_remove_backends() is DEPRECATED and does nothing. Stop calling it.\n");
}
/**
* mdb_remove_backends
*
* Removes all entries from and destroys the mdb_backends hash.
*/
void
_mdb_remove_backends()
{
g_hash_table_foreach_remove(mdb_backends, mdb_drop_backend, NULL);
g_hash_table_destroy(mdb_backends);
}
static gboolean mdb_drop_backend(gpointer key, gpointer value, gpointer data)
{
MdbBackend *backend = (MdbBackend *)value;
@@ -869,7 +884,6 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
mdb_free_tabledef (table);
}
void
mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *dbnamespace, guint32 export_options)
{

View File

@@ -473,7 +473,7 @@ size_t
mdb_ole_read_next(MdbHandle *mdb, MdbColumn *col, void *ole_ptr)
{
guint32 ole_len;
void *buf;
unsigned char *buf;
int row_start;
size_t len;
@@ -506,7 +506,7 @@ size_t
mdb_ole_read(MdbHandle *mdb, MdbColumn *col, void *ole_ptr, int chunk_size)
{
guint32 ole_len;
void *buf;
unsigned char *buf;
int row_start;
size_t len;
@@ -672,7 +672,7 @@ static char *mdb_memo_to_string(MdbHandle *mdb, int start, int size)
guint32 memo_len;
gint32 row_start, pg_row;
size_t len;
void *buf, *pg_buf = mdb->pg_buf;
char *buf, *pg_buf = (char*) mdb->pg_buf;
char *text = (char *) g_malloc(MDB_BIND_SIZE);
if (size<MDB_MEMO_OVERHEAD) {
@@ -896,7 +896,7 @@ int floor_log10(double f, int is_single)
}
#endif
char *mdb_col_to_string(MdbHandle *mdb, void *buf, int start, int datatype, int size)
char *mdb_col_to_string(MdbHandle *mdb, char *buf, int start, int datatype, int size)
{
char *text = NULL;
float tf;

View File

@@ -16,7 +16,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <inttypes.h>
#include "mdbtools.h"
#ifdef DMALLOC
@@ -369,7 +368,7 @@ static ssize_t _mdb_read_pg(MdbHandle *mdb, void *pg_buf, unsigned long pg)
fstat(mdb->f->fd, &status);
if (status.st_size < offset) {
fprintf(stderr,"offset %jd is beyond EOF\n",(intmax_t)offset);
fprintf(stderr,"offset %jd is beyond EOF\n",offset);
return 0;
}
if (mdb->stats && mdb->stats->collect)
@@ -420,7 +419,7 @@ unsigned char mdb_pg_get_byte(MdbHandle *mdb, int offset)
return mdb->pg_buf[offset];
}
int mdb_get_int16(void *buf, int offset)
int mdb_get_int16(unsigned char *buf, int offset)
{
guint16 l;
memcpy(&l, buf + offset, 2);
@@ -433,13 +432,13 @@ int mdb_pg_get_int16(MdbHandle *mdb, int offset)
return mdb_get_int16(mdb->pg_buf, offset);
}
long mdb_get_int32_msb(void *buf, int offset)
long mdb_get_int32_msb(unsigned char *buf, int offset)
{
gint32 l;
memcpy(&l, buf + offset, 4);
return (long)GINT32_FROM_BE(l);
}
long mdb_get_int32(void *buf, int offset)
long mdb_get_int32(unsigned char *buf, int offset)
{
gint32 l;
memcpy(&l, buf + offset, 4);
@@ -452,7 +451,7 @@ long mdb_pg_get_int32(MdbHandle *mdb, int offset)
return mdb_get_int32(mdb->pg_buf, offset);
}
float mdb_get_single(void *buf, int offset)
float mdb_get_single(unsigned char *buf, int offset)
{
union {guint32 g; float f;} f;
memcpy(&f, buf + offset, 4);
@@ -466,7 +465,7 @@ float mdb_pg_get_single(MdbHandle *mdb, int offset)
return mdb_get_single(mdb->pg_buf, offset);
}
double mdb_get_double(void *buf, int offset)
double mdb_get_double(unsigned char *buf, int offset)
{
union {guint64 g; double d;} d;
memcpy(&d, buf + offset, 8);

View File

@@ -29,3 +29,8 @@ mdb_exit())
{
fprintf(stderr, "mdb_exit() is DEPRECATED and does nothing. Stop calling it.\n");
}
/* glib - to allow static linking of glib in mdbtools */
void mdb_g_free (gpointer mem) { g_free(mem); }
gpointer mdb_g_malloc (gsize n_bytes) { return g_malloc(n_bytes); }
gpointer mdb_g_malloc0 (gsize n_bytes) { return g_malloc0(n_bytes); }

View File

@@ -47,7 +47,7 @@ char *mdb_money_to_string(MdbHandle *mdb, int start)
int neg=0;
unsigned char multiplier[MAX_NUMERIC_PRECISION], temp[MAX_NUMERIC_PRECISION];
unsigned char product[MAX_NUMERIC_PRECISION];
unsigned char bytes[num_bytes];
unsigned char bytes[8];
memset(multiplier,0,MAX_NUMERIC_PRECISION);
memset(product,0,MAX_NUMERIC_PRECISION);
@@ -85,7 +85,7 @@ char *mdb_numeric_to_string(MdbHandle *mdb, int start, int prec, int scale) {
int neg=0;
unsigned char multiplier[MAX_NUMERIC_PRECISION], temp[MAX_NUMERIC_PRECISION];
unsigned char product[MAX_NUMERIC_PRECISION];
unsigned char bytes[num_bytes];
unsigned char bytes[16];
memset(multiplier,0,MAX_NUMERIC_PRECISION);
memset(product,0,MAX_NUMERIC_PRECISION);

View File

@@ -162,7 +162,7 @@ mdb_dump_props(MdbProperties *props, FILE *outfile, int show_name) {
* and returns a GArray of MdbProps*
*/
GArray*
mdb_kkd_to_props(MdbHandle *mdb, void *buffer, size_t len) {
mdb_kkd_to_props(MdbHandle *mdb, char *buffer, size_t len) {
guint32 record_len;
guint16 record_type;
size_t pos;

View File

@@ -76,7 +76,7 @@ MdbTableDef *mdb_read_table(MdbCatalogEntry *entry)
MdbHandle *mdb = entry->mdb;
MdbFormatConstants *fmt = mdb->fmt;
int row_start, pg_row;
void *buf, *pg_buf = mdb->pg_buf;
unsigned char *buf, *pg_buf = mdb->pg_buf;
guint i;
mdb_read_pg(mdb, entry->table_pg);
@@ -166,7 +166,7 @@ read_pg_if_8(MdbHandle *mdb, int *cur_pos)
* are still advanced and the page cursor is still updated.
*/
void *
read_pg_if_n(MdbHandle *mdb, void *buf, int *cur_pos, size_t len)
read_pg_if_n(MdbHandle *mdb, unsigned char *buf, int *cur_pos, size_t len)
{
/* Advance to page which contains the first byte */
while (*cur_pos >= mdb->fmt->pg_size) {

View File

@@ -18,7 +18,6 @@
#include <time.h>
#include <math.h>
#include <inttypes.h>
#include "mdbtools.h"
#ifdef DMALLOC
@@ -30,7 +29,7 @@
static int mdb_add_row_to_leaf_pg(MdbTableDef *table, MdbIndex *idx, MdbIndexPage *ipg, MdbField *idx_fields, guint32 pgnum, guint16 rownum);
void
mdb_put_int16(void *buf, guint32 offset, guint32 value)
mdb_put_int16(unsigned char *buf, guint32 offset, guint32 value)
{
value = GINT32_TO_LE(value);
memcpy(buf + offset, &value, 2);
@@ -44,7 +43,7 @@ __attribute__((alias("mdb_put_int16")));
#endif
void
mdb_put_int32(void *buf, guint32 offset, guint32 value)
mdb_put_int32(unsigned char *buf, guint32 offset, guint32 value)
{
value = GINT32_TO_LE(value);
memcpy(buf + offset, &value, 4);
@@ -58,7 +57,7 @@ __attribute__((alias("mdb_put_int32")));
#endif
void
mdb_put_int32_msb(void *buf, guint32 offset, guint32 value)
mdb_put_int32_msb(unsigned char *buf, guint32 offset, guint32 value)
{
value = GINT32_TO_BE(value);
memcpy(buf + offset, &value, 4);
@@ -81,7 +80,7 @@ mdb_write_pg(MdbHandle *mdb, unsigned long pg)
fstat(mdb->f->fd, &status);
/* is page beyond current size + 1 ? */
if (status.st_size < offset + mdb->fmt->pg_size) {
fprintf(stderr,"offset %jd is beyond EOF\n",(intmax_t)offset);
fprintf(stderr,"offset %jd is beyond EOF\n",offset);
return 0;
}
lseek(mdb->f->fd, offset, SEEK_SET);
@@ -172,7 +171,7 @@ mdb_crack_row(MdbTableDef *table, int row_start, int row_end, MdbField *fields)
MdbColumn *col;
MdbCatalogEntry *entry = table->entry;
MdbHandle *mdb = entry->mdb;
void *pg_buf = mdb->pg_buf;
unsigned char *pg_buf = mdb->pg_buf;
unsigned int row_var_cols=0, row_cols;
unsigned char *nullmask;
unsigned int bitmask_sz;
@@ -594,7 +593,7 @@ mdb_insert_row(MdbTableDef *table, int num_fields, MdbField *fields)
guint16
mdb_add_row_to_pg(MdbTableDef *table, unsigned char *row_buffer, int new_row_size)
{
void *new_pg;
unsigned char *new_pg;
int num_rows, i, pos, row_start;
size_t row_size;
MdbCatalogEntry *entry = table->entry;
@@ -725,7 +724,7 @@ MdbCatalogEntry *entry = table->entry;
MdbHandle *mdb = entry->mdb;
int pg_size = mdb->fmt->pg_size;
int rco = mdb->fmt->row_count_offset;
void *new_pg;
unsigned char *new_pg;
guint16 num_rows;
int row_start;
size_t row_size;
@@ -793,7 +792,7 @@ mdb_copy_index_pg(MdbTableDef *table, MdbIndex *idx, MdbIndexPage *ipg)
MdbColumn *col;
guint32 pg_row;
guint16 row = 0;
void *new_pg;
unsigned char *new_pg;
unsigned char key_hash[256];
int keycol;