Changeset: e12a1d2c29fe for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/e12a1d2c29fe Modified Files: clients/mapilib/mapi.c clients/mapilib/msettings.c clients/mapilib/msettings.h clients/mapilib/msettings_internal.h Branch: odbc_loader Log Message:
Make sure the msettings inside a Mid always use the standard allocator diffs (109 lines): diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c --- a/clients/mapilib/mapi.c +++ b/clients/mapilib/mapi.c @@ -1794,10 +1794,16 @@ mapi_new(msettings *settings) } if (settings == NULL) { settings = msettings_create(); - if (settings == NULL) { - mapi_destroy(mid); - return NULL; - } + } else if (msettings_get_allocator(settings, NULL) != NULL) { + // it uses a custom allocator, reallocate using regular + msettings *old = settings; + settings = msettings_clone(old); + if (settings) + msettings_destroy(old); + } + if (settings == NULL) { + mapi_destroy(mid); + return NULL; } mid->settings = settings; mid->blk.buf[0] = 0; diff --git a/clients/mapilib/msettings.c b/clients/mapilib/msettings.c --- a/clients/mapilib/msettings.c +++ b/clients/mapilib/msettings.c @@ -185,21 +185,13 @@ const msettings msettings_default_values const msettings *msettings_default = &msettings_default_values; -static void* -default_alloc(void *state, void *old, size_t size) -{ - (void)state; - return realloc(old, size); -} - msettings *msettings_create_with(msettings_allocator alloc, void *allocator_state) { if (alloc == NULL) { - alloc = default_alloc; allocator_state = NULL; } - msettings *mp = alloc(allocator_state, NULL, sizeof(*mp)); + msettings *mp = realloc_with_fallback(alloc, allocator_state, NULL, sizeof(*mp)); if (!mp) return NULL; @@ -215,6 +207,16 @@ msettings *msettings_create(void) return msettings_create_with(NULL, NULL); } +msettings_allocator +msettings_get_allocator(const msettings *mp, void **put_alloc_state_here) +{ + if (mp->alloc == NULL) + return NULL; + if (put_alloc_state_here) + *put_alloc_state_here = mp->alloc_state; + return mp->alloc; +} + msettings *msettings_clone_with(msettings_allocator alloc, void *alloc_state, const msettings *orig) { bool free_unix_sock_name_buffer = false; diff --git a/clients/mapilib/msettings.h b/clients/mapilib/msettings.h --- a/clients/mapilib/msettings.h +++ b/clients/mapilib/msettings.h @@ -132,6 +132,7 @@ mapi_export msettings *msettings_create( mapi_export msettings *msettings_create_with(msettings_allocator alloc, void *alloc_state); mapi_export msettings *msettings_clone(const msettings *mp); mapi_export msettings *msettings_clone_with(msettings_allocator alloc, void *alloc_state, const msettings *mp); +mapi_export msettings_allocator msettings_get_allocator(const msettings *mp, void **put_alloc_state_here); mapi_export void msettings_reset(msettings *mp); mapi_export const msettings *msettings_default; diff --git a/clients/mapilib/msettings_internal.h b/clients/mapilib/msettings_internal.h --- a/clients/mapilib/msettings_internal.h +++ b/clients/mapilib/msettings_internal.h @@ -72,7 +72,7 @@ struct msettings { bool validated; const char* (*localizer)(const void *data, mparm parm); void *localizer_data; - void *(*alloc)(void *state, void *old, size_t size); + void *(*alloc)(void *state, void *old, size_t size); // NULL means regular realloc void *alloc_state; char error_message[256]; }; @@ -84,9 +84,17 @@ const char *format_error(msettings *mp, // wrappers around mp->allocator static inline void* +realloc_with_fallback(msettings_allocator alloc, void *alloc_state, void *old, size_t size) +{ + return alloc + ? alloc(alloc_state, old, size) + : realloc(old, size); +} + +static inline void* msettings_realloc(const msettings *mp, void *old, size_t size) { - return mp->alloc(mp->alloc_state, old, size); + return realloc_with_fallback(mp->alloc, mp->alloc_state, old, size); } static inline void* _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org