r18972 - gnucash/trunk/src - Code cleanup in binreloc: Remove unused init_lib function. Add possibility to set the looked-up exe path from somewhere else.
Christian Stimming
cstim at code.gnucash.org
Sat Mar 27 18:08:17 EDT 2010
Author: cstim
Date: 2010-03-27 18:08:17 -0400 (Sat, 27 Mar 2010)
New Revision: 18972
Trac: http://svn.gnucash.org/trac/changeset/18972
Modified:
gnucash/trunk/src/core-utils/binreloc.c
gnucash/trunk/src/core-utils/binreloc.h
gnucash/trunk/src/gnc/main.cpp
Log:
Code cleanup in binreloc: Remove unused init_lib function. Add possibility to set the looked-up exe path from somewhere else.
Remove symbol mangling because r18940 already added the gnc_* prefix,
hence the symbol names are unique to gnucash anyway.
Modified: gnucash/trunk/src/core-utils/binreloc.c
===================================================================
--- gnucash/trunk/src/core-utils/binreloc.c 2010-03-27 21:02:18 UTC (rev 18971)
+++ gnucash/trunk/src/core-utils/binreloc.c 2010-03-27 22:08:17 UTC (rev 18972)
@@ -227,129 +227,23 @@
}
-/** @internal
- * Find the canonical filename of the executable which owns symbol.
- * Returns a filename which must be freed, or NULL on error.
- */
-static char *
-_br_find_exe_for_symbol (const void *symbol, Gnc_GbrInitError *error)
-{
-#ifndef ENABLE_BINRELOC
- if (error)
- *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 = GNC_GBR_INIT_ERROR_DISABLED;
- return (char *) NULL;
-#else
-#define SIZE PATH_MAX + 100
- FILE *f;
- size_t address_string_len;
- char *address_string, line[SIZE], *found;
- if (symbol == NULL)
- return (char *) NULL;
+static gchar *exe = NULL;
- f = fopen ("/proc/self/maps", "r");
- if (f == NULL)
- return (char *) NULL;
+static void set_gerror (GError **error, Gnc_GbrInitError errcode);
- address_string_len = 4;
- address_string = (char *) g_try_malloc (address_string_len);
- found = (char *) NULL;
- while (!feof (f))
- {
- char *start_addr, *end_addr, *end_addr_end, *file;
- void *start_addr_p, *end_addr_p;
- size_t len;
+void gnc_gbr_set_exe (const gchar* default_exe)
+{
+ if (exe != NULL)
+ g_free(exe);
+ exe = NULL;
- if (fgets (line, SIZE, f) == NULL)
- break;
-
- /* Sanity check. */
- if (strstr (line, " r-xp ") == NULL || strchr (line, '/') == NULL)
- continue;
-
- /* Parse line. */
- start_addr = line;
- end_addr = strchr (line, '-');
- file = strchr (line, '/');
-
- /* More sanity check. */
- if (!(file > end_addr && end_addr != NULL && end_addr[0] == '-'))
- continue;
-
- end_addr[0] = '\0';
- end_addr++;
- end_addr_end = strchr (end_addr, ' ');
- if (end_addr_end == NULL)
- continue;
-
- end_addr_end[0] = '\0';
- len = strlen (file);
- if (len == 0)
- continue;
- if (file[len - 1] == '\n')
- file[len - 1] = '\0';
-
- /* Get rid of "(deleted)" from the filename. */
- len = strlen (file);
- if (len > 10 && strcmp (file + len - 10, " (deleted)") == 0)
- file[len - 10] = '\0';
-
- /* I don't know whether this can happen but better safe than sorry. */
- len = strlen (start_addr);
- if (len != strlen (end_addr))
- continue;
-
-
- /* Transform the addresses into a string in the form of 0xdeadbeef,
- * then transform that into a pointer. */
- if (address_string_len < len + 3)
- {
- address_string_len = len + 3;
- address_string = (char *) g_try_realloc (address_string, address_string_len);
- }
-
- memcpy (address_string, "0x", 2);
- memcpy (address_string + 2, start_addr, len);
- address_string[2 + len] = '\0';
- sscanf (address_string, "%p", &start_addr_p);
-
- memcpy (address_string, "0x", 2);
- memcpy (address_string + 2, end_addr, len);
- address_string[2 + len] = '\0';
- sscanf (address_string, "%p", &end_addr_p);
-
-
- if (symbol >= start_addr_p && symbol < end_addr_p)
- {
- found = file;
- break;
- }
- }
-
- g_free (address_string);
- fclose (f);
-
- if (found == NULL)
- return (char *) NULL;
- else
- return g_strdup (found);
-#endif /* G_OS_WIN32 */
-#endif /* ENABLE_BINRELOC */
+ if (default_exe != NULL)
+ exe = g_strdup(default_exe);
}
-static gchar *exe = NULL;
-
-static void set_gerror (GError **error, Gnc_GbrInitError errcode);
-
-
/** Initialize the BinReloc library (for applications).
*
* This function must be called before using any other BinReloc functions.
@@ -384,34 +278,6 @@
}
-/** Initialize the BinReloc library (for libraries).
- *
- * This function must be called before using any other BinReloc functions.
- * It attempts to locate the calling library's canonical filename.
- *
- * @note The BinReloc source code MUST be included in your library, or this
- * function won't work correctly.
- *
- * @returns TRUE on success, FALSE if a filename cannot be found.
- */
-gboolean
-gnc_gbr_init_lib (GError **error)
-{
- Gnc_GbrInitError errcode = 0;
-
- exe = _br_find_exe_for_symbol ((const void *) "", &errcode);
- if (exe != NULL)
- /* Success! */
- return TRUE;
- else
- {
- /* Failed :-( */
- set_gerror (error, errcode);
- return exe != NULL;
- }
-}
-
-
static void
set_gerror (GError **error, Gnc_GbrInitError errcode)
{
Modified: gnucash/trunk/src/core-utils/binreloc.h
===================================================================
--- gnucash/trunk/src/core-utils/binreloc.h 2010-03-27 21:02:18 UTC (rev 18971)
+++ gnucash/trunk/src/core-utils/binreloc.h 2010-03-27 22:08:17 UTC (rev 18972)
@@ -18,7 +18,7 @@
G_BEGIN_DECLS
-/** These error codes can be returned by br_init(), br_init_lib(), gnc_gbr_init() or gnc_gbr_init_lib(). */
+/** These error codes can be returned by gnc_gbr_init(). */
typedef enum
{
/** Cannot allocate memory. */
@@ -38,22 +38,7 @@
} Gnc_GbrInitError;
-#ifndef BINRELOC_RUNNING_DOXYGEN
-/* Mangle symbol names to avoid symbol collisions with other ELF objects. */
-#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 gnc_gbr_init (GError **error);
-gboolean gnc_gbr_init_lib (GError **error);
gchar *gnc_gbr_find_exe (const gchar *default_exe);
gchar *gnc_gbr_find_exe_dir (const gchar *default_dir);
@@ -65,7 +50,13 @@
gchar *gnc_gbr_find_libexec_dir (const gchar *default_libexec_dir);
gchar *gnc_gbr_find_etc_dir (const gchar *default_etc_dir);
+/** Sets the executable path to the given value. This is useful if the
+ * binreloc lookup code will not be used, but instead the executable
+ * location is obtained from somewhere else (e.g. qt) but the gnucash
+ * code should nevertheless use this path internally. */
+void gnc_gbr_set_exe (const gchar* default_exe);
+
G_END_DECLS
#endif /* __BINRELOC_H__ */
Modified: gnucash/trunk/src/gnc/main.cpp
===================================================================
--- gnucash/trunk/src/gnc/main.cpp 2010-03-27 21:02:18 UTC (rev 18971)
+++ gnucash/trunk/src/gnc/main.cpp 2010-03-27 22:08:17 UTC (rev 18972)
@@ -148,19 +148,11 @@
#endif
g_thread_init(NULL);
-#ifdef ENABLE_BINRELOC
- {
- GError *binreloc_error = NULL;
- if (!gnc_gbr_init(&binreloc_error))
- {
- g_print("main: Error on gnc_gbr_init: %s\n", binreloc_error->message);
- g_error_free(binreloc_error);
- }
- }
-#else
- //g_message("main: binreloc relocation support was disabled at configure time.\n");
-#endif
+ QApplication app(argc, argv);
+ // Binreloc is initialized by the Qt exe path lookup.
+ gnc_gbr_set_exe(QCoreApplication::applicationFilePath().toUtf8());
+
#ifdef HAVE_GETTEXT
{
gchar *localedir = gnc_path_get_localedir();
@@ -194,7 +186,6 @@
int r;
{
// From here on the new C++ code
- QApplication app(argc, argv);
gnc::MainWindow mainWin;
mainWin.show();
More information about the gnucash-changes
mailing list