Migrate to g_memdup2 (#288)

With fakeglib and older versions of GLib, fall back to g_memdup with
a #define inside mdbprivate.h.

Fixes #287
This commit is contained in:
Evan Miller 2021-04-05 09:04:29 -04:00 committed by GitHub
parent afd154f619
commit fe0175aa63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 19 additions and 16 deletions

View File

@ -215,8 +215,8 @@ if test "$enable_glib" = "yes"; then
GLIB_PACKAGE=glib-2.0 GLIB_PACKAGE=glib-2.0
PKG_CHECK_MODULES([GLIB], [$GLIB_PACKAGE], HAVE_GLIB=true, HAVE_GLIB=false) PKG_CHECK_MODULES([GLIB], [$GLIB_PACKAGE], HAVE_GLIB=true, HAVE_GLIB=false)
if test "x$HAVE_GLIB" = "xtrue"; then if test "x$HAVE_GLIB" = "xtrue"; then
MDBTOOLS_CFLAGS="$MDBTOOLS_CFLAGS -DHAVE_GLIB=1"
GLIB_CFLAGS="$GLIB_CFLAGS -DHAVE_GLIB=1" GLIB_CFLAGS="$GLIB_CFLAGS -DHAVE_GLIB=1"
AC_CHECK_LIB($GLIB_PACKAGE, g_memdup2, [GLIB_CFLAGS="$GLIB_CFLAGS -DHAVE_G_MEMDUP2=1"])
AC_SUBST(GLIB_PACKAGE) AC_SUBST(GLIB_PACKAGE)
else else
enable_glib=no enable_glib=no

View File

@ -24,9 +24,8 @@
* exported to calling programs. * exported to calling programs.
*/ */
#define _(String) (String) #ifndef HAVE_G_MEMDUP2
#define N_(String) String #define g_memdup2 g_memdup
#define textdomain(Domain) #endif
#define bindtextdomain(Package, Directory)
#endif #endif

View File

@ -19,6 +19,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <stddef.h> #include <stddef.h>
#include "mdbtools.h" #include "mdbtools.h"
#include "mdbprivate.h"
MdbFormatConstants MdbJet4Constants = { MdbFormatConstants MdbJet4Constants = {
.pg_size = 4096, .pg_size = 4096,
@ -360,14 +361,14 @@ MdbHandle *mdb_clone_handle(MdbHandle *mdb)
MdbCatalogEntry *entry, *data; MdbCatalogEntry *entry, *data;
unsigned int i; unsigned int i;
newmdb = (MdbHandle *) g_memdup(mdb, sizeof(MdbHandle)); newmdb = (MdbHandle *) g_memdup2(mdb, sizeof(MdbHandle));
memset(&newmdb->catalog, 0, sizeof(MdbHandle) - offsetof(MdbHandle, catalog)); memset(&newmdb->catalog, 0, sizeof(MdbHandle) - offsetof(MdbHandle, catalog));
newmdb->catalog = g_ptr_array_new(); newmdb->catalog = g_ptr_array_new();
for (i=0;i<mdb->num_catalog;i++) { for (i=0;i<mdb->num_catalog;i++) {
entry = g_ptr_array_index(mdb->catalog,i); entry = g_ptr_array_index(mdb->catalog,i);
data = g_memdup(entry,sizeof(MdbCatalogEntry)); data = g_memdup2(entry,sizeof(MdbCatalogEntry));
data->mdb = newmdb; data->mdb = newmdb;
data->props = NULL; data->props = NULL;
g_ptr_array_add(newmdb->catalog, data); g_ptr_array_add(newmdb->catalog, data);

View File

@ -17,6 +17,7 @@
*/ */
#include "mdbtools.h" #include "mdbtools.h"
#include "mdbprivate.h"
#ifdef HAVE_LIBMSWSTR #ifdef HAVE_LIBMSWSTR
#include <mswstr/mswstr.h> #include <mswstr/mswstr.h>
#endif #endif
@ -524,7 +525,7 @@ mdb_index_test_sargs(MdbHandle *mdb, MdbIndex *idx, char *buf, int len)
col->idx_sarg_cache = g_ptr_array_new(); col->idx_sarg_cache = g_ptr_array_new();
for (j=0;j<col->num_sargs;j++) { for (j=0;j<col->num_sargs;j++) {
sarg = g_ptr_array_index (col->sargs, j); sarg = g_ptr_array_index (col->sargs, j);
idx_sarg = g_memdup(sarg,sizeof(MdbSarg)); idx_sarg = g_memdup2(sarg,sizeof(MdbSarg));
//printf("calling mdb_index_cache_sarg\n"); //printf("calling mdb_index_cache_sarg\n");
mdb_index_cache_sarg(col, sarg, idx_sarg); mdb_index_cache_sarg(col, sarg, idx_sarg);
g_ptr_array_add(col->idx_sarg_cache, idx_sarg); g_ptr_array_add(col->idx_sarg_cache, idx_sarg);

View File

@ -29,6 +29,7 @@
#include <time.h> #include <time.h>
#include "mdbtools.h" #include "mdbtools.h"
#include "mdbprivate.h"
void void
mdb_sql_walk_tree(MdbSargNode *node, MdbSargTreeFunc func, gpointer data) mdb_sql_walk_tree(MdbSargNode *node, MdbSargTreeFunc func, gpointer data)
@ -338,7 +339,7 @@ MdbSarg *sarg;
if (!col->sargs) { if (!col->sargs) {
col->sargs = g_ptr_array_new(); col->sargs = g_ptr_array_new();
} }
sarg = g_memdup(in_sarg,sizeof(MdbSarg)); sarg = g_memdup2(in_sarg,sizeof(MdbSarg));
g_ptr_array_add(col->sargs, sarg); g_ptr_array_add(col->sargs, sarg);
col->num_sargs++; col->num_sargs++;

View File

@ -17,6 +17,7 @@
*/ */
#include "mdbtools.h" #include "mdbtools.h"
#include "mdbprivate.h"
static gint mdb_col_comparer(MdbColumn **a, MdbColumn **b) static gint mdb_col_comparer(MdbColumn **a, MdbColumn **b)
{ {
@ -91,7 +92,7 @@ MdbTableDef *mdb_read_table(MdbCatalogEntry *entry)
mdb_free_tabledef(table); mdb_free_tabledef(table);
return NULL; return NULL;
} }
table->usage_map = g_memdup((char*)buf + row_start, table->map_sz); table->usage_map = g_memdup2((char*)buf + row_start, table->map_sz);
if (mdb_get_option(MDB_DEBUG_USAGE)) if (mdb_get_option(MDB_DEBUG_USAGE))
mdb_buffer_dump(buf, row_start, table->map_sz); mdb_buffer_dump(buf, row_start, table->map_sz);
mdb_debug(MDB_DEBUG_USAGE,"usage map found on page %ld row %d start %d len %d", mdb_debug(MDB_DEBUG_USAGE,"usage map found on page %ld row %d start %d len %d",
@ -104,7 +105,7 @@ MdbTableDef *mdb_read_table(MdbCatalogEntry *entry)
mdb_free_tabledef(table); mdb_free_tabledef(table);
return NULL; return NULL;
} }
table->free_usage_map = g_memdup((char*)buf + row_start, table->freemap_sz); table->free_usage_map = g_memdup2((char*)buf + row_start, table->freemap_sz);
mdb_debug(MDB_DEBUG_USAGE,"free map found on page %ld row %d start %d len %d\n", mdb_debug(MDB_DEBUG_USAGE,"free map found on page %ld row %d start %d len %d\n",
pg_row >> 8, pg_row & 0xff, row_start, table->freemap_sz); pg_row >> 8, pg_row & 0xff, row_start, table->freemap_sz);
@ -207,7 +208,7 @@ read_pg_if_n(MdbHandle *mdb, void *buf, int *cur_pos, size_t len)
void mdb_append_column(GPtrArray *columns, MdbColumn *in_col) void mdb_append_column(GPtrArray *columns, MdbColumn *in_col)
{ {
g_ptr_array_add(columns, g_memdup(in_col,sizeof(MdbColumn))); g_ptr_array_add(columns, g_memdup2(in_col,sizeof(MdbColumn)));
} }
void mdb_free_columns(GPtrArray *columns) void mdb_free_columns(GPtrArray *columns)
{ {

View File

@ -17,6 +17,7 @@
*/ */
#include "mdbtools.h" #include "mdbtools.h"
#include "mdbprivate.h"
/* /*
* Temp table routines. These are currently used to generate mock results for * Temp table routines. These are currently used to generate mock results for
@ -73,7 +74,7 @@ mdb_temp_table_add_col(MdbTableDef *table, MdbColumn *col)
col->col_num = table->num_cols; col->col_num = table->num_cols;
if (!col->is_fixed) if (!col->is_fixed)
col->var_col_num = table->num_var_cols++; col->var_col_num = table->num_var_cols++;
g_ptr_array_add(table->columns, g_memdup(col, sizeof(MdbColumn))); g_ptr_array_add(table->columns, g_memdup2(col, sizeof(MdbColumn)));
table->num_cols++; table->num_cols++;
} }
/* /*

View File

@ -18,7 +18,6 @@
#include "mdbtools.h" #include "mdbtools.h"
#include "mdbver.h" #include "mdbver.h"
#include "mdbprivate.h"
int int
main(int argc, char **argv) main(int argc, char **argv)
@ -58,7 +57,7 @@ main(int argc, char **argv)
} }
if (!(mdb = mdb_open(argv[1], MDB_NOFLAGS))) { if (!(mdb = mdb_open(argv[1], MDB_NOFLAGS))) {
fprintf(stderr,_("Error: unable to open file %s\n"), argv[1]); fprintf(stderr,"Error: unable to open file %s\n", argv[1]);
exit(1); exit(1);
} }
switch(mdb->f->jet_version) { switch(mdb->f->jet_version) {
@ -84,7 +83,7 @@ main(int argc, char **argv)
printf("ACE17\n"); printf("ACE17\n");
break; break;
default: default:
printf(_("unknown database version\n")); printf("unknown database version\n");
break; break;
} }