From 82df074771372e6c7b259b693c28b85925ad5625 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sun, 27 Apr 2014 12:53:21 -0700 Subject: [PATCH] C++ Windows fixes. Particularly interesting is src/engine/Makefile.am: Having a mention of target_CFLAGS in an #if disables automatic use AM_CFLAGS even when the #if condition is false. --- src/engine/Makefile.am | 2 ++ src/engine/test/Makefile.am | 3 ++- src/libqof/qof/gnc-date.c | 9 ++++---- src/libqof/qof/guid.c | 4 ++-- src/libqof/qof/qof-win32.c | 18 ++++++++------- src/libqof/qof/qofmath128.c | 2 +- src/libqof/qof/test/test-gnc-date.c | 3 +-- src/libqof/qof/test/test-qofsession.c | 32 +-------------------------- src/test-core/Makefile.am | 3 ++- 9 files changed, 25 insertions(+), 51 deletions(-) diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am index dbe2afe932..2f8c5d6565 100644 --- a/src/engine/Makefile.am +++ b/src/engine/Makefile.am @@ -131,6 +131,8 @@ noinst_SCRIPTS = iso-currencies-to-c libgncmod_engine_la_LDFLAGS = -avoid-version if CLANG libgncmod_engine_la_CFLAGS = ${AM_CFLAGS} -Wno-invalid-source-encoding +else +libgncmod_engine_la_CFLAGS = ${AM_CFLAGS} endif libgncmod_engine_la_LIBADD = \ ../gnc-module/libgnc-module.la \ diff --git a/src/engine/test/Makefile.am b/src/engine/test/Makefile.am index 515a3a7984..ec7bed021d 100644 --- a/src/engine/test/Makefile.am +++ b/src/engine/test/Makefile.am @@ -126,7 +126,8 @@ test_engine_CFLAGS = \ ${DEFAULT_INCLUDES} \ -I${top_srcdir}/${MODULEPATH}/ \ -DTESTPROG=test_engine \ - ${GLIB_CFLAGS} + ${GLIB_CFLAGS} \ + ${AM_CFLAGS} noinst_LTLIBRARIES = \ libutest-Split.la \ diff --git a/src/libqof/qof/gnc-date.c b/src/libqof/qof/gnc-date.c index d60fd55ed2..e99a7e6802 100644 --- a/src/libqof/qof/gnc-date.c +++ b/src/libqof/qof/gnc-date.c @@ -119,7 +119,6 @@ gnc_g_time_zone_new_local (void) #else { TIME_ZONE_INFORMATION tzinfo; - gint64 dst = GetTimeZoneInformation (&tzinfo); gint bias = tzinfo.Bias + tzinfo.StandardBias; gint hours = -bias / 60; // 60 minutes per hour gint minutes = (bias < 0 ? -bias : bias) % 60; @@ -151,13 +150,13 @@ dst_systemtime_to_gdate (SYSTEMTIME stime, GDate *gdate, gint year) */ static const int gdate_sunday = 7; static const int week_length = 7; - + GDateMonth month = static_cast(stime.wMonth); g_date_clear (gdate, 1); - g_date_set_dmy (gdate, 1, stime.wMonth, year); + g_date_set_dmy (gdate, 1, month, year); wkday = g_date_get_weekday (gdate) % gdate_sunday; days = week_length * stime.wDay + stime.wDayOfWeek - wkday; - while (days > g_date_get_days_in_month (stime.wMonth, year)) + while (days > g_date_get_days_in_month (month, year)) days -= week_length; g_date_add_days (gdate, days); wkday = g_date_get_weekday (gdate) % gdate_sunday; @@ -179,7 +178,7 @@ win32_in_dst (GDateTime *date, TIME_ZONE_INFORMATION *tzinfo) return FALSE; g_date_time_get_ymd (date, &year, &month, &day); g_date_clear (&gdate, 1); - g_date_set_dmy (&gdate, day, month, year); + g_date_set_dmy (&gdate, day, static_cast(month), year); dst_systemtime_to_gdate (tzinfo->StandardDate, &std, year); dst_systemtime_to_gdate (tzinfo->DaylightDate, &dlt, year); /* In the southern hemisphere, where DST ends in spring and begins in fall, we look for the date being before std or after dlt; in the northern hemisphere we look for them to be between dlt and std. diff --git a/src/libqof/qof/guid.c b/src/libqof/qof/guid.c index cd955ae137..0e9438fc4b 100644 --- a/src/libqof/qof/guid.c +++ b/src/libqof/qof/guid.c @@ -676,10 +676,10 @@ guid_to_string(const GncGUID * guid) static GStaticPrivate guid_buffer_key = G_STATIC_PRIVATE_INIT; gchar *string; - string = g_static_private_get (&guid_buffer_key); + string = static_cast(g_static_private_get (&guid_buffer_key)); if (string == NULL) { - string = malloc(GUID_ENCODING_LENGTH + 1); + string = static_cast(malloc(GUID_ENCODING_LENGTH + 1)); g_static_private_set (&guid_buffer_key, string, g_free); } #else diff --git a/src/libqof/qof/qof-win32.c b/src/libqof/qof/qof-win32.c index b76e11a1e7..8ff0ce1658 100644 --- a/src/libqof/qof/qof-win32.c +++ b/src/libqof/qof/qof-win32.c @@ -44,11 +44,12 @@ G_LOCK_DEFINE_STATIC(picture_to_format); gchar * qof_time_format_from_utf8(const gchar *utf8_format) { - gunichar2 *utf16_format; - gchar *retval; + wchar_t* utf16_format; + gchar* retval; gsize count; - utf16_format = g_utf8_to_utf16(utf8_format, -1, NULL, NULL, NULL); + utf16_format = reinterpret_cast(g_utf8_to_utf16(utf8_format, -1, + NULL, NULL, NULL)); if (!utf16_format) return NULL; @@ -58,7 +59,7 @@ qof_time_format_from_utf8(const gchar *utf8_format) return NULL; /* malloc and convert */ - retval = g_malloc((count + 1) * sizeof(gchar)); + retval = static_cast(g_malloc((count + 1) * sizeof(gchar))); count = wcstombs(retval, utf16_format, count + 1); g_free(utf16_format); if (count <= 0) @@ -83,8 +84,9 @@ qof_formatted_time_to_utf8(const gchar *locale_string) return NULL; /* malloc and convert */ - utf16_string = g_malloc((count + 1) * sizeof(gunichar2)); - count = mbstowcs(utf16_string, locale_string, count + 1); + utf16_string = static_cast(g_malloc((count + 1) * sizeof(gunichar2))); + count = mbstowcs(reinterpret_cast(utf16_string), + locale_string, count + 1); if (count <= 0) { g_free(utf16_string); @@ -125,8 +127,8 @@ qof_win32_get_time_format(QofWin32Picture picture) G_LOCK(picture_to_format); if (!picture_to_format) picture_to_format = g_hash_table_new_full(g_str_hash, g_str_equal, - NULL, g_free); - format = g_hash_table_lookup(picture_to_format, locale_string); + NULL, g_free); + format = static_cast(g_hash_table_lookup(picture_to_format, locale_string)); if (!format) { format = translate_win32_picture(locale_string); diff --git a/src/libqof/qof/qofmath128.c b/src/libqof/qof/qofmath128.c index 91eef575f2..daedc4ff5d 100644 --- a/src/libqof/qof/qofmath128.c +++ b/src/libqof/qof/qofmath128.c @@ -197,7 +197,7 @@ div128 (qofint128 n, gint64 d) remainder <<= 1; if (sbit) remainder |= 1; quotient = shiftleft128 (quotient); - if (remainder >= static_cast(d)) + if (remainder >= static_cast(d)) { remainder -= d; quotient.lo |= 1; diff --git a/src/libqof/qof/test/test-gnc-date.c b/src/libqof/qof/test/test-gnc-date.c index 9447e4306f..83b17a5143 100644 --- a/src/libqof/qof/test/test-gnc-date.c +++ b/src/libqof/qof/test/test-gnc-date.c @@ -995,7 +995,7 @@ qof_print_date_buff (char * buff, size_t len, time64 t)// C: 3 in 1 Local: 2:0: static void test_qof_print_date_buff (void) { - gchar buff[MAX_DATE_LENGTH], t_buff[MAX_DATE_LENGTH]; + gchar buff[MAX_DATE_LENGTH]; gchar *locale = g_strdup (setlocale (LC_TIME, NULL)); GDateTime *gd1 = gncdt.new_local (1974, 11, 23, 12, 0, 0.0); GDateTime *gd2 = gncdt.new_local (1961, 2, 2, 12, 0, 0.0); @@ -1276,7 +1276,6 @@ static void test_qof_print_date (void) { gchar *locale = g_strdup (setlocale (LC_TIME, NULL)); - gchar *buff; GDateTime *gd1 = gncdt.new_local (1974, 11, 23, 12, 0, 0.0); GDateTime *gd2 = gncdt.new_local (1961, 2, 2, 12, 0, 0.0); GDateTime *gd3 = gncdt.new_local (2045, 6, 16, 12, 0, 0.0); diff --git a/src/libqof/qof/test/test-qofsession.c b/src/libqof/qof/test/test-qofsession.c index 780424c8db..9f4ee521a9 100644 --- a/src/libqof/qof/test/test-qofsession.c +++ b/src/libqof/qof/test/test-qofsession.c @@ -446,42 +446,12 @@ mock_sync (QofBackend *be, QofBook *book) session_save_struct.sync_called = TRUE; } -static void -mock_session_begin_for_save (QofBackend *be, QofSession *session, const char *book_id, - gboolean ignore_lock, gboolean create, gboolean force) -{ - g_assert (be); - g_assert (be == session_save_struct.be); - g_assert (session); - g_assert (session == session_save_struct.session); - g_assert (book_id); - g_assert_cmpstr (book_id, == , session_save_struct.book_id); - g_assert (ignore_lock); - g_assert (create); - g_assert (force); - session_save_struct.session_begin_called = TRUE; -} - -static QofBackend* -mock_backend_new_for_save (void) -{ - QofBackend *be = NULL; - - be = g_new0 (QofBackend, 1); - g_assert (be); - be->session_begin = mock_session_begin_for_save; - be->sync = mock_sync; - session_save_struct.be = be; - session_save_struct.backend_new_called = TRUE; - return be; -} - static void test_qof_session_save (Fixture *fixture, gconstpointer pData) { QofBook *book = NULL; QofBackend *be = NULL; - QofBackendProvider *prov = NULL, *reg_prov = NULL; + QofBackendProvider *prov = NULL; g_test_message ("Test when backend not set"); g_assert (fixture->session->backend == NULL); diff --git a/src/test-core/Makefile.am b/src/test-core/Makefile.am index 8ed78a4fdf..6a46fef788 100644 --- a/src/test-core/Makefile.am +++ b/src/test-core/Makefile.am @@ -52,7 +52,8 @@ libtest_core_guile_la_LIBADD = \ libtest_core_guile_la_CFLAGS = \ ${libtest_core_la_CPPFLAGS} \ - ${GUILE_CFLAGS} + ${GUILE_CFLAGS} \ + ${AM_CFLAGS} libtest_core_guile_la_LDFLAGS = \ -rpath ${exec-prefix}/lib