From bab6eb90724cc83ae01e1f9eb671f215e17878ed Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sun, 21 Mar 2010 00:40:24 +0000 Subject: [PATCH] Fixup binreloc, which wasn't working correctly on OSX Most changes are to rename the functions named gbr_* to gnc_gbr_*, so that our modified binreloc (to provide mac bundle support) doesn't collide with binreloc implementations in other libraries. (The instant case was in libenchant.) Also moved the IGE_MAC_CFLAGS and IGE_MAC_LIBS lines from engine/Makefile.am to core-utils/Makefile.am. This was missed when binreloc was moved. And last, there was a minor error in the original OSX binreloc patch: At line 68, #elif MAC_INTEGRATION should be (and now is) #elif defined MAC_INTEGRATION. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18940 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/bin/gnucash-bin.c | 5 ++- src/core-utils/Makefile.am | 2 + src/core-utils/binreloc.c | 92 +++++++++++++++++++------------------- src/core-utils/binreloc.h | 58 ++++++++++++------------ src/core-utils/gnc-path.c | 14 +++--- src/engine/Makefile.am | 2 - src/gnc/main.cpp | 4 +- 7 files changed, 89 insertions(+), 88 deletions(-) diff --git a/src/bin/gnucash-bin.c b/src/bin/gnucash-bin.c index d04a519de7..1f8a7ab5f2 100644 --- a/src/bin/gnucash-bin.c +++ b/src/bin/gnucash-bin.c @@ -585,9 +585,10 @@ main(int argc, char ** argv) #ifdef ENABLE_BINRELOC { GError *binreloc_error = NULL; - if (!gbr_init(&binreloc_error)) + g_print("Checking for Binreloc\n"); + if (!gnc_gbr_init(&binreloc_error)) { - g_print("main: Error on gbr_init: %s\n", binreloc_error->message); + g_print("main: Error on gnc_gbr_init: %s\n", binreloc_error->message); g_error_free(binreloc_error); } } diff --git a/src/core-utils/Makefile.am b/src/core-utils/Makefile.am index 0e74cd5241..c043b80096 100644 --- a/src/core-utils/Makefile.am +++ b/src/core-utils/Makefile.am @@ -19,6 +19,7 @@ libgnc_core_utils_la_LIBADD = \ ${GUILE_LIBS} \ ${GLIB_LIBS} \ ${BINRELOC_LIBS} \ + ${IGE_MAC_LIBS} \ ${GCONF_LIBS} \ ${QOF_LIBS} @@ -44,6 +45,7 @@ AM_CPPFLAGS = \ ${GUILE_INCS} \ ${GLIB_CFLAGS} \ ${GCONF_CFLAGS} \ + ${IGE_MAC_CFLAGS} \ ${QOF_CFLAGS} \ -I${top_srcdir}/src/libqof/qof \ -I${top_srcdir}/src diff --git a/src/core-utils/binreloc.c b/src/core-utils/binreloc.c index 33f9ccd739..e0578e82f0 100644 --- a/src/core-utils/binreloc.c +++ b/src/core-utils/binreloc.c @@ -40,11 +40,11 @@ static IgeMacBundle *bundle = NULL; * not NULL, the error code will be stored there, if an error occured. */ static char * -_br_find_exe (GbrInitError *error) +_br_find_exe (Gnc_GbrInitError *error) { #ifndef ENABLE_BINRELOC if (error) - *error = GBR_INIT_ERROR_DISABLED; + *error = GNC_GBR_INIT_ERROR_DISABLED; return NULL; #else #ifdef G_OS_WIN32 @@ -65,20 +65,20 @@ _br_find_exe (GbrInitError *error) (char*)NULL); g_free (prefix); return result; -#elif MAC_INTEGRATION +#elif defined MAC_INTEGRATION gchar *prefix = NULL, *result = NULL; g_type_init(); bundle = ige_mac_bundle_new(); if (!bundle) { - *error = GBR_INIT_ERROR_MAC_NOT_BUNDLE; + *error = GNC_GBR_INIT_ERROR_MAC_NOT_BUNDLE; return NULL; } if (!ige_mac_bundle_get_is_app_bundle (bundle)) { g_object_unref(bundle); bundle = NULL; - *error = GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE; + *error = GNC_GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE; return NULL; } ige_mac_bundle_setup_environment(bundle); @@ -104,7 +104,7 @@ _br_find_exe (GbrInitError *error) { /* Cannot allocate memory. */ if (error) - *error = GBR_INIT_ERROR_NOMEM; + *error = GNC_GBR_INIT_ERROR_NOMEM; return NULL; } path2 = (char *) g_try_malloc (buf_size); @@ -112,7 +112,7 @@ _br_find_exe (GbrInitError *error) { /* Cannot allocate memory. */ if (error) - *error = GBR_INIT_ERROR_NOMEM; + *error = GNC_GBR_INIT_ERROR_NOMEM; g_free (path); return NULL; } @@ -167,7 +167,7 @@ _br_find_exe (GbrInitError *error) /* Cannot allocate memory. */ g_free (path); if (error) - *error = GBR_INIT_ERROR_NOMEM; + *error = GNC_GBR_INIT_ERROR_NOMEM; return NULL; } @@ -176,7 +176,7 @@ _br_find_exe (GbrInitError *error) { g_free (line); if (error) - *error = GBR_INIT_ERROR_OPEN_MAPS; + *error = GNC_GBR_INIT_ERROR_OPEN_MAPS; return NULL; } @@ -187,7 +187,7 @@ _br_find_exe (GbrInitError *error) fclose (f); g_free (line); if (error) - *error = GBR_INIT_ERROR_READ_MAPS; + *error = GNC_GBR_INIT_ERROR_READ_MAPS; return NULL; } @@ -199,7 +199,7 @@ _br_find_exe (GbrInitError *error) fclose (f); g_free (line); if (error) - *error = GBR_INIT_ERROR_INVALID_MAPS; + *error = GNC_GBR_INIT_ERROR_INVALID_MAPS; return NULL; } if (line[buf_size - 1] == 10) @@ -214,7 +214,7 @@ _br_find_exe (GbrInitError *error) fclose (f); g_free (line); if (error) - *error = GBR_INIT_ERROR_INVALID_MAPS; + *error = GNC_GBR_INIT_ERROR_INVALID_MAPS; return NULL; } @@ -232,17 +232,17 @@ _br_find_exe (GbrInitError *error) * Returns a filename which must be freed, or NULL on error. */ static char * -_br_find_exe_for_symbol (const void *symbol, GbrInitError *error) +_br_find_exe_for_symbol (const void *symbol, Gnc_GbrInitError *error) { #ifndef ENABLE_BINRELOC if (error) - *error = GBR_INIT_ERROR_DISABLED; + *error = GNC_GBR_INIT_ERROR_DISABLED; return (char *) NULL; #else #if defined G_OS_WIN32 g_warning ("_br_find_exe_for_symbol not implemented on win32."); if (error) - *error = GBR_INIT_ERROR_DISABLED; + *error = GNC_GBR_INIT_ERROR_DISABLED; return (char *) NULL; #else #define SIZE PATH_MAX + 100 @@ -347,7 +347,7 @@ _br_find_exe_for_symbol (const void *symbol, GbrInitError *error) static gchar *exe = NULL; -static void set_gerror (GError **error, GbrInitError errcode); +static void set_gerror (GError **error, Gnc_GbrInitError errcode); /** Initialize the BinReloc library (for applications). @@ -356,19 +356,19 @@ static void set_gerror (GError **error, GbrInitError errcode); * It attempts to locate the application's canonical filename. * * @note If you want to use BinReloc for a library, then you should call - * gbr_init_lib() instead. + * gnc_gbr_init_lib() instead. * * @param error If BinReloc failed to initialize, then the error report will * be stored in this variable. Set to NULL if you don't want an - * error report. See the #GbrInitError for a list of error + * error report. See the #Gnc_GbrInitError for a list of error * codes. * * @returns TRUE on success, FALSE if BinReloc failed to initialize. */ gboolean -gbr_init (GError **error) +gnc_gbr_init (GError **error) { - GbrInitError errcode = 0; + Gnc_GbrInitError errcode = 0; /* Locate the application's filename. */ exe = _br_find_exe (&errcode); @@ -395,9 +395,9 @@ gbr_init (GError **error) * @returns TRUE on success, FALSE if a filename cannot be found. */ gboolean -gbr_init_lib (GError **error) +gnc_gbr_init_lib (GError **error) { - GbrInitError errcode = 0; + Gnc_GbrInitError errcode = 0; exe = _br_find_exe_for_symbol ((const void *) "", &errcode); if (exe != NULL) @@ -413,7 +413,7 @@ gbr_init_lib (GError **error) static void -set_gerror (GError **error, GbrInitError errcode) +set_gerror (GError **error, Gnc_GbrInitError errcode) { gchar *error_message; @@ -422,25 +422,25 @@ set_gerror (GError **error, GbrInitError errcode) switch (errcode) { - case GBR_INIT_ERROR_NOMEM: + case GNC_GBR_INIT_ERROR_NOMEM: error_message = "Cannot allocate memory."; break; - case GBR_INIT_ERROR_OPEN_MAPS: + case GNC_GBR_INIT_ERROR_OPEN_MAPS: error_message = "Unable to open /proc/self/maps for reading."; break; - case GBR_INIT_ERROR_READ_MAPS: + case GNC_GBR_INIT_ERROR_READ_MAPS: error_message = "Unable to read from /proc/self/maps."; break; - case GBR_INIT_ERROR_INVALID_MAPS: + case GNC_GBR_INIT_ERROR_INVALID_MAPS: error_message = "The file format of /proc/self/maps is invalid."; break; - case GBR_INIT_ERROR_MAC_NOT_BUNDLE: + case GNC_GBR_INIT_ERROR_MAC_NOT_BUNDLE: error_message = "Binreloc did not find a bundle"; break; - case GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE: + case GNC_GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE: error_message = "Binreloc found that the bundle is not an app bundle"; break; - case GBR_INIT_ERROR_DISABLED: + case GNC_GBR_INIT_ERROR_DISABLED: error_message = "Binary relocation support is disabled."; break; default: @@ -462,7 +462,7 @@ set_gerror (GError **error, GbrInitError errcode) * is NULL, then NULL will be returned. */ gchar * -gbr_find_exe (const gchar *default_exe) +gnc_gbr_find_exe (const gchar *default_exe) { if (exe == NULL) { @@ -491,7 +491,7 @@ gbr_find_exe (const gchar *default_exe) * returned. */ gchar * -gbr_find_exe_dir (const gchar *default_dir) +gnc_gbr_find_exe_dir (const gchar *default_dir) { if (exe == NULL) { @@ -521,7 +521,7 @@ gbr_find_exe_dir (const gchar *default_dir) * returned. */ gchar * -gbr_find_prefix (const gchar *default_prefix) +gnc_gbr_find_prefix (const gchar *default_prefix) { gchar *dir1, *dir2; @@ -553,7 +553,7 @@ gbr_find_prefix (const gchar *default_prefix) dir2 = g_path_get_dirname (dir1); g_free (dir1); return dir2; -#endif //ENABLE_BINRELOC && MAC_INTEGRATION +#endif //ENABLE_BINRELOC && defined MAC_INTEGRATION } @@ -571,7 +571,7 @@ gbr_find_prefix (const gchar *default_prefix) * be returned. If default_bin_dir is NULL, then NULL will be returned. */ gchar * -gbr_find_bin_dir (const gchar *default_bin_dir) +gnc_gbr_find_bin_dir (const gchar *default_bin_dir) { gchar *prefix, *dir; #if defined ENABLE_BINRELOC && defined MAC_INTEGRATION @@ -589,7 +589,7 @@ gbr_find_bin_dir (const gchar *default_bin_dir) return dir; #else - prefix = gbr_find_prefix (NULL); + prefix = gnc_gbr_find_prefix (NULL); if (prefix == NULL) { /* BinReloc not initialized. */ @@ -620,11 +620,11 @@ gbr_find_bin_dir (const gchar *default_bin_dir) * be returned. If default_bin_dir is NULL, then NULL will be returned. */ gchar * -gbr_find_sbin_dir (const gchar *default_sbin_dir) +gnc_gbr_find_sbin_dir (const gchar *default_sbin_dir) { gchar *prefix, *dir; - prefix = gbr_find_prefix (NULL); + prefix = gnc_gbr_find_prefix (NULL); if (prefix == NULL) { /* BinReloc not initialized. */ @@ -655,11 +655,11 @@ gbr_find_sbin_dir (const gchar *default_sbin_dir) * returned. */ gchar * -gbr_find_data_dir (const gchar *default_data_dir) +gnc_gbr_find_data_dir (const gchar *default_data_dir) { gchar *prefix, *dir; - prefix = gbr_find_prefix (NULL); + prefix = gnc_gbr_find_prefix (NULL); if (prefix == NULL) { /* BinReloc not initialized. */ @@ -689,11 +689,11 @@ gbr_find_data_dir (const gchar *default_data_dir) * If default_lib_dir is NULL, then NULL will be returned. */ gchar * -gbr_find_lib_dir (const gchar *default_lib_dir) +gnc_gbr_find_lib_dir (const gchar *default_lib_dir) { gchar *prefix, *dir; - prefix = gbr_find_prefix (NULL); + prefix = gnc_gbr_find_prefix (NULL); if (prefix == NULL) { /* BinReloc not initialized. */ @@ -723,11 +723,11 @@ gbr_find_lib_dir (const gchar *default_lib_dir) * If default_libexec_dir is NULL, then NULL will be returned. */ gchar * -gbr_find_libexec_dir (const gchar *default_libexec_dir) +gnc_gbr_find_libexec_dir (const gchar *default_libexec_dir) { gchar *prefix, *dir; - prefix = gbr_find_prefix (NULL); + prefix = gnc_gbr_find_prefix (NULL); if (prefix == NULL) { /* BinReloc not initialized. */ @@ -757,11 +757,11 @@ gbr_find_libexec_dir (const gchar *default_libexec_dir) * If default_etc_dir is NULL, then NULL will be returned. */ gchar * -gbr_find_etc_dir (const gchar *default_etc_dir) +gnc_gbr_find_etc_dir (const gchar *default_etc_dir) { gchar *prefix, *dir; - prefix = gbr_find_prefix (NULL); + prefix = gnc_gbr_find_prefix (NULL); if (prefix == NULL) { /* BinReloc not initialized. */ diff --git a/src/core-utils/binreloc.h b/src/core-utils/binreloc.h index c6d04615a5..6b886e1e15 100644 --- a/src/core-utils/binreloc.h +++ b/src/core-utils/binreloc.h @@ -18,52 +18,52 @@ G_BEGIN_DECLS -/** These error codes can be returned by br_init(), br_init_lib(), gbr_init() or gbr_init_lib(). */ +/** These error codes can be returned by br_init(), br_init_lib(), gnc_gbr_init() or gnc_gbr_init_lib(). */ typedef enum { /** Cannot allocate memory. */ - GBR_INIT_ERROR_NOMEM, + GNC_GBR_INIT_ERROR_NOMEM, /** Unable to open /proc/self/maps; see errno for details. */ - GBR_INIT_ERROR_OPEN_MAPS, + GNC_GBR_INIT_ERROR_OPEN_MAPS, /** Unable to read from /proc/self/maps; see errno for details. */ - GBR_INIT_ERROR_READ_MAPS, + GNC_GBR_INIT_ERROR_READ_MAPS, /** The file format of /proc/self/maps is invalid; kernel bug? */ - GBR_INIT_ERROR_INVALID_MAPS, + GNC_GBR_INIT_ERROR_INVALID_MAPS, /** BinReloc determined that gnucash is not running from a bundle */ - GBR_INIT_ERROR_MAC_NOT_BUNDLE, + GNC_GBR_INIT_ERROR_MAC_NOT_BUNDLE, /** Binreloc determined that the bundle is not an app bundle */ - GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE, + GNC_GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE, /** BinReloc is disabled (the ENABLE_BINRELOC macro is not defined). */ - GBR_INIT_ERROR_DISABLED -} GbrInitError; + GNC_GBR_INIT_ERROR_DISABLED +} Gnc_GbrInitError; #ifndef BINRELOC_RUNNING_DOXYGEN /* Mangle symbol names to avoid symbol collisions with other ELF objects. */ -#define gbr_find_exe ffEt66859784967989_gbr_find_exe -#define gbr_find_exe_dir ffEt66859784967989_gbr_find_exe_dir -#define gbr_find_prefix ffEt66859784967989_gbr_find_prefix -#define gbr_find_bin_dir ffEt66859784967989_gbr_find_bin_dir -#define gbr_find_sbin_dir ffEt66859784967989_gbr_find_sbin_dir -#define gbr_find_data_dir ffEt66859784967989_gbr_find_data_dir -#define gbr_find_lib_dir ffEt66859784967989_gbr_find_lib_dir -#define gbr_find_libexec_dir ffEt66859784967989_gbr_find_libexec_dir -#define gbr_find_etc_dir ffEt66859784967989_gbr_find_etc_dir +#define gnc_gbr_find_exe ffEt66859784967989_gnc_gbr_find_exe +#define gnc_gbr_find_exe_dir ffEt66859784967989_gnc_gbr_find_exe_dir +#define gnc_gbr_find_prefix ffEt66859784967989_gnc_gbr_find_prefix +#define gnc_gbr_find_bin_dir ffEt66859784967989_gnc_gbr_find_bin_dir +#define gnc_gbr_find_sbin_dir ffEt66859784967989_gnc_gbr_find_sbin_dir +#define gnc_gbr_find_data_dir ffEt66859784967989_gnc_gbr_find_data_dir +#define gnc_gbr_find_lib_dir ffEt66859784967989_gnc_gbr_find_lib_dir +#define gnc_gbr_find_libexec_dir ffEt66859784967989_gnc_gbr_find_libexec_dir +#define gnc_gbr_find_etc_dir ffEt66859784967989_gnc_gbr_find_etc_dir #endif -gboolean gbr_init (GError **error); -gboolean gbr_init_lib (GError **error); +gboolean gnc_gbr_init (GError **error); +gboolean gnc_gbr_init_lib (GError **error); -gchar *gbr_find_exe (const gchar *default_exe); -gchar *gbr_find_exe_dir (const gchar *default_dir); -gchar *gbr_find_prefix (const gchar *default_prefix); -gchar *gbr_find_bin_dir (const gchar *default_bin_dir); -gchar *gbr_find_sbin_dir (const gchar *default_sbin_dir); -gchar *gbr_find_data_dir (const gchar *default_data_dir); -gchar *gbr_find_lib_dir (const gchar *default_lib_dir); -gchar *gbr_find_libexec_dir (const gchar *default_libexec_dir); -gchar *gbr_find_etc_dir (const gchar *default_etc_dir); +gchar *gnc_gbr_find_exe (const gchar *default_exe); +gchar *gnc_gbr_find_exe_dir (const gchar *default_dir); +gchar *gnc_gbr_find_prefix (const gchar *default_prefix); +gchar *gnc_gbr_find_bin_dir (const gchar *default_bin_dir); +gchar *gnc_gbr_find_sbin_dir (const gchar *default_sbin_dir); +gchar *gnc_gbr_find_data_dir (const gchar *default_data_dir); +gchar *gnc_gbr_find_lib_dir (const gchar *default_lib_dir); +gchar *gnc_gbr_find_libexec_dir (const gchar *default_libexec_dir); +gchar *gnc_gbr_find_etc_dir (const gchar *default_etc_dir); G_END_DECLS diff --git a/src/core-utils/gnc-path.c b/src/core-utils/gnc-path.c index baa042d215..80f0c10c4d 100644 --- a/src/core-utils/gnc-path.c +++ b/src/core-utils/gnc-path.c @@ -27,8 +27,8 @@ gchar *gnc_path_get_prefix() { - //printf("Returning prefix %s\n", gbr_find_prefix (PREFIX)); - return gbr_find_prefix (PREFIX); + //printf("Returning prefix %s\n", gnc_gbr_find_prefix (PREFIX)); + return gnc_gbr_find_prefix (PREFIX); } /** Returns the libdir path, usually @@ -37,8 +37,8 @@ gchar *gnc_path_get_prefix() * @returns A newly allocated string. */ gchar *gnc_path_get_libdir() { - //printf("Returning libdir %s\n", gbr_find_lib_dir (LIBDIR)); - return gbr_find_lib_dir (LIBDIR); + //printf("Returning libdir %s\n", gnc_gbr_find_lib_dir (LIBDIR)); + return gnc_gbr_find_lib_dir (LIBDIR); } /** Returns the datadir path, usually @@ -47,7 +47,7 @@ gchar *gnc_path_get_libdir() * @returns A newly allocated string. */ gchar *gnc_path_get_pkgdatadir() { - gchar *datadir = gbr_find_data_dir (DATADIR); + gchar *datadir = gnc_gbr_find_data_dir (DATADIR); gchar *result = g_build_filename (datadir, "gnucash", (char*)NULL); g_free (datadir); //printf("Returning pkgdatadir %s\n", result); @@ -60,7 +60,7 @@ gchar *gnc_path_get_pkgdatadir() * @returns A newly allocated string. */ gchar *gnc_path_get_pkgsysconfdir() { - gchar *sysconfdir = gbr_find_etc_dir (SYSCONFDIR); + gchar *sysconfdir = gnc_gbr_find_etc_dir (SYSCONFDIR); gchar *result = g_build_filename (sysconfdir, "gnucash", (char*)NULL); g_free (sysconfdir); //printf("Returning pkgsysconfdir %s\n", result); @@ -126,7 +126,7 @@ gchar *gnc_path_get_accountsdir() * @returns A newly allocated string. */ gchar *gnc_path_get_gconfdir(gboolean force_slashes) { - gchar *sysconfdir = gbr_find_etc_dir (SYSCONFDIR); + gchar *sysconfdir = gnc_gbr_find_etc_dir (SYSCONFDIR); gchar *separator = G_DIR_SEPARATOR_S; gchar *result; diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am index 50069d38a6..208f57ab61 100644 --- a/src/engine/Makefile.am +++ b/src/engine/Makefile.am @@ -10,7 +10,6 @@ AM_CPPFLAGS = \ -I${top_srcdir}/src/gnc-module \ -I${top_srcdir}/src/libqof/qof \ ${GLIB_CFLAGS} \ - ${IGE_MAC_CFLAGS} \ ${GUILE_INCS} libgncmod_engine_la_SOURCES = \ @@ -109,7 +108,6 @@ libgncmod_engine_la_LIBADD = \ ${GUILE_LIBS} \ ${REGEX_LIBS} \ ${GLIB_LIBS} \ - ${IGE_MAC_LIBS} \ ${top_builddir}/lib/libc/libc-missing.la gncmoddir = ${GNC_SHAREDIR}/guile-modules/gnucash diff --git a/src/gnc/main.cpp b/src/gnc/main.cpp index 84c57874ca..ed6fddca57 100644 --- a/src/gnc/main.cpp +++ b/src/gnc/main.cpp @@ -148,9 +148,9 @@ main(int argc, char ** argv) #ifdef ENABLE_BINRELOC { GError *binreloc_error = NULL; - if (!gbr_init(&binreloc_error)) + if (!gnc_gbr_init(&binreloc_error)) { - g_print("main: Error on gbr_init: %s\n", binreloc_error->message); + g_print("main: Error on gnc_gbr_init: %s\n", binreloc_error->message); g_error_free(binreloc_error); } }