From 3f316a4c208765a38b34e19704450cf0f34adef7 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 11 Mar 2009 22:22:35 +0100 Subject: [PATCH] Fix compilation for mingw. Two sources files failed to compile on GCC mingw (Minimalist GNU for Windows). For oid_db.c the problem was that GCC reported 'initializer element is not constant'. And the fix is to use initialize (use) at run-time. For timing.c the problem that HAVE_SYS_TIME_H and WIN32 was both defined - and the code was not prepared for that. --- src/oid_db.c | 14 ++++++++------ src/timing.c | 10 ++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/oid_db.c b/src/oid_db.c index 27f5be5..ea72462 100644 --- a/src/oid_db.c +++ b/src/oid_db.c @@ -27,7 +27,7 @@ struct yaz_oid_db { }; struct yaz_oid_db standard_db_l = { - yaz_oid_standard_entries, 0, 0 + 0, 0, 0 }; yaz_oid_db_t standard_db = &standard_db_l; @@ -36,6 +36,8 @@ yaz_oid_db_t yaz_oid_std(void) return standard_db; } +#define get_entries(db) (db->xmalloced==0 ? yaz_oid_standard_entries : db->entries) + const Odr_oid *yaz_string_to_oid(yaz_oid_db_t oid_db, oid_class oclass, const char *name) { @@ -44,13 +46,13 @@ const Odr_oid *yaz_string_to_oid(yaz_oid_db_t oid_db, struct yaz_oid_entry *e; if (oclass != CLASS_GENERAL) { - for (e = oid_db->entries; e->name; e++) + for (e = get_entries(oid_db); e->name; e++) { if (!yaz_matchstr(e->name, name) && oclass == e->oclass) return e->oid; } } - for (e = oid_db->entries; e->name; e++) + for (e = get_entries(oid_db); e->name; e++) { if (!yaz_matchstr(e->name, name)) return e->oid; @@ -81,7 +83,7 @@ const char *yaz_oid_to_string(yaz_oid_db_t oid_db, return 0; for (; oid_db; oid_db = oid_db->next) { - struct yaz_oid_entry *e = oid_db->entries; + struct yaz_oid_entry *e = get_entries(oid_db); for (; e->name; e++) { if (!oid_oidcmp(e->oid, oid)) @@ -97,7 +99,7 @@ const char *yaz_oid_to_string(yaz_oid_db_t oid_db, const char *yaz_oid_to_string_buf(const Odr_oid *oid, oid_class *oclass, char *buf) { - const char *p = yaz_oid_to_string(standard_db, oid, oclass); + const char *p = yaz_oid_to_string(yaz_oid_std(), oid, oclass); if (p) return p; if (oclass) @@ -192,7 +194,7 @@ void yaz_oid_trav(yaz_oid_db_t oid_db, { for (; oid_db; oid_db = oid_db->next) { - struct yaz_oid_entry *e = oid_db->entries; + struct yaz_oid_entry *e = get_entries(oid_db); for (; e->name; e++) func(e->oid, e->oclass, e->name, client_data); diff --git a/src/timing.c b/src/timing.c index eafe4ab..7a0b0b1 100644 --- a/src/timing.c +++ b/src/timing.c @@ -34,12 +34,13 @@ struct yaz_timing { #endif #if HAVE_SYS_TIME_H struct timeval start_time, end_time; -#endif +#else #ifdef WIN32 LONGLONG start_time, end_time; LONGLONG start_time_sys, start_time_user; LONGLONG end_time_sys, end_time_user; #endif +#endif double real_sec, user_sec, sys_sec; }; @@ -91,7 +92,7 @@ void yaz_timing_start(yaz_timing_t t) #if HAVE_SYS_TIME_H gettimeofday(&t->start_time, 0); t->real_sec = 0.0; -#endif +#else #ifdef WIN32 t->real_sec = 0.0; t->user_sec = 0.0; @@ -99,6 +100,7 @@ void yaz_timing_start(yaz_timing_t t) get_date_as_largeinteger(&t->start_time); get_process_time(&t->start_time_user, &t->start_time_sys); #endif +#endif } void yaz_timing_stop(yaz_timing_t t) @@ -113,8 +115,7 @@ void yaz_timing_stop(yaz_timing_t t) gettimeofday(&t->end_time, 0); t->real_sec = ((t->end_time.tv_sec - t->start_time.tv_sec) * 1000000.0 + t->end_time.tv_usec - t->start_time.tv_usec) / 1000000; - -#endif +#else #ifdef WIN32 get_date_as_largeinteger(&t->end_time); t->real_sec = (t->end_time - t->start_time) / 10000000.0; @@ -123,6 +124,7 @@ void yaz_timing_stop(yaz_timing_t t) t->user_sec = (t->end_time_user - t->start_time_user) / 10000000.0; t->sys_sec = (t->end_time_sys - t->start_time_sys) / 10000000.0; #endif +#endif } double yaz_timing_get_real(yaz_timing_t t) -- 1.7.10.4