Merge branch 'maint'

* Morritz Lipp's libdbi-0.9.0 compatibility fix
* Morritz Lipp's realloc return value fix
* Re-enable save and enable loading of $GNC_DOT_DIR/accelerator-map on OSX
This commit is contained in:
John Ralls 2014-04-18 12:57:30 -07:00
commit cf78eecdfa
4 changed files with 85 additions and 8 deletions

View File

@ -67,6 +67,13 @@
#define GETPID() getpid()
#endif
#if LIBDBI_VERSION >= 900
#define HAVE_LIBDBI_R 1
static dbi_inst dbi_instance;
#else
#define HAVE_LIBDBI_R 0
#endif
/* For direct access to dbi data structs, sadly needed for datetime */
#include <dbi/dbi-dev.h>
@ -283,7 +290,13 @@ gnc_dbi_sqlite3_session_begin( QofBackend *qbe, QofSession *session,
{
dbi_conn_close( be->conn );
}
#if HAVE_LIBDBI_R
be->conn = dbi_conn_new_r( "sqlite3", dbi_instance );
#else
be->conn = dbi_conn_new( "sqlite3" );
#endif
if ( be->conn == NULL )
{
PERR( "Unable to create sqlite3 dbi connection\n" );
@ -808,7 +821,11 @@ gnc_dbi_mysql_session_begin( QofBackend* qbe, QofSession *session,
{
dbi_conn_close( be->conn );
}
#if HAVE_LIBDBI_R
be->conn = dbi_conn_new_r( "mysql", dbi_instance );
#else
be->conn = dbi_conn_new( "mysql" );
#endif
if ( be->conn == NULL )
{
PERR( "Unable to create mysql dbi connection\n" );
@ -893,7 +910,12 @@ gnc_dbi_mysql_session_begin( QofBackend* qbe, QofSession *session,
dbi_conn_close( be->conn );
// Try again to connect to the db
#if HAVE_LIBDBI_R
be->conn = dbi_conn_new_r( "mysql", dbi_instance );
#else
be->conn = dbi_conn_new( "mysql" );
#endif
if ( be->conn == NULL )
{
PERR( "Unable to create mysql dbi connection\n" );
@ -1144,7 +1166,13 @@ gnc_dbi_postgres_session_begin( QofBackend *qbe, QofSession *session,
{
dbi_conn_close( be->conn );
}
#if HAVE_LIBDBI_R
be->conn = dbi_conn_new_r( "pgsql", dbi_instance );
#else
be->conn = dbi_conn_new( "pgsql" );
#endif
if ( be->conn == NULL )
{
PERR( "Unable to create pgsql dbi connection\n" );
@ -1230,7 +1258,12 @@ gnc_dbi_postgres_session_begin( QofBackend *qbe, QofSession *session,
dbi_conn_close( be->conn );
// Try again to connect to the db
#if HAVE_LIBDBI_R
be->conn = dbi_conn_new_r( "pgsql", dbi_instance );
#else
be->conn = dbi_conn_new( "pgsql" );
#endif
if ( be->conn == NULL )
{
PERR( "Unable to create pgsql dbi connection\n" );
@ -1835,7 +1868,11 @@ gnc_module_init_backend_dbi(void)
}
/* dbi_initialize returns -1 in case of errors */
#if HAVE_LIBDBI_R
num_drivers = dbi_initialize_r( driver_dir, dbi_instance );
#else
num_drivers = dbi_initialize( driver_dir );
#endif
if ( num_drivers <= 0 )
{
PWARN( "No DBD drivers found\n" );
@ -1847,7 +1884,12 @@ gnc_module_init_backend_dbi(void)
do
{
#if HAVE_LIBDBI_R
driver = dbi_driver_list_r( driver, dbi_instance );
#else
driver = dbi_driver_list( driver );
#endif
if ( driver != NULL )
{
const gchar* name = dbi_driver_get_name( driver );
@ -1945,7 +1987,11 @@ qof_backend_module_finalize( void )
void
gnc_module_finalize_backend_dbi( void )
{
#if HAVE_LIBDBI_R
dbi_shutdown_r(dbi_instance);
#else
dbi_shutdown();
#endif
}
/* --------------------------------------------------------- */

View File

@ -34,6 +34,13 @@
#include <gnc-prefs.h>
#include <qofsession-p.h>
#if LIBDBI_VERSION >= 900
#define HAVE_LIBDBI_R 1
static dbi_inst dbi_instance;
#else
#define HAVE_LIBDBI_R 0
#endif
static const gchar* suitename = "/backend/dbi";
void test_suite_gnc_backend_dbi (void);
@ -230,9 +237,17 @@ destroy_database (gchar* url)
gnc_uri_get_components (url, &protocol, &host, &portnum,
&username, &password, &dbname);
if (g_strcmp0 (protocol, "postgres") == 0)
conn = dbi_conn_new (pgsql);
#if HAVE_LIBDBI_R
conn = dbi_conn_new_r( pgsql, dbi_instance );
#else
conn = dbi_conn_new( pgsql );
#endif
else
#if HAVE_LIBDBI_R
conn = dbi_conn_new_r (protocol, dbi_instance);
#else
conn = dbi_conn_new (protocol);
#endif
port = g_strdup_printf ("%d", portnum);
if (conn == NULL)
{
@ -581,7 +596,11 @@ test_suite_gnc_backend_dbi (void)
{
dbi_driver driver = NULL;
GList *drivers = NULL;
#if HAVE_LIBDBI_R
while ((driver = dbi_driver_list_r (driver, dbi_instance)))
#else
while ((driver = dbi_driver_list (driver)))
#endif
{
drivers = g_list_prepend (drivers,
(gchar*)dbi_driver_get_name (driver));

View File

@ -104,7 +104,7 @@ gnc_xml_be_get_file_lock (FileBackend *be)
{
struct stat statbuf;
#ifndef G_OS_WIN32
char *pathbuf = NULL, *path = NULL;
char *pathbuf = NULL, *path = NULL, *tmpbuf = NULL;
size_t pathbuf_size = 0;
#endif
int rc;
@ -158,13 +158,22 @@ gnc_xml_be_get_file_lock (FileBackend *be)
#ifndef G_OS_WIN32
pathbuf_size = strlen (be->lockfile) + 100;
pathbuf = (char *) malloc (pathbuf_size);
if (pathbuf == NULL) {
return FALSE;
}
strcpy (pathbuf, be->lockfile);
path = strrchr (pathbuf, '.');
while (snprintf (path, pathbuf_size - (path - pathbuf), ".%lx.%d.LNK", gethostid(), getpid())
>= pathbuf_size - (path - pathbuf))
{
pathbuf_size += 100;
pathbuf = (char *) realloc (pathbuf, pathbuf_size);
tmpbuf = (char *) realloc (pathbuf, pathbuf_size);
if (tmpbuf == NULL) {
free(pathbuf);
return FALSE;
} else {
pathbuf = tmpbuf;
}
}
rc = link (be->lockfile, pathbuf);

View File

@ -709,9 +709,14 @@ gnc_gui_init(void)
gnc_window_set_progressbar_window (GNC_WINDOW(main_window));
#ifdef MAC_INTEGRATION
data_dir = gnc_path_get_pkgdatadir();
map = g_build_filename(data_dir, "ui", "osx_accel_map", NULL);
g_free(data_dir);
map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME);
if (!g_file_test (map, G_FILE_TEST_EXISTS))
{
g_free (map);
data_dir = gnc_path_get_pkgdatadir();
map = g_build_filename(data_dir, "ui", "osx_accel_map", NULL);
g_free(data_dir);
}
#else
map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME);
#endif /* MAC_INTEGRATION */
@ -748,11 +753,9 @@ gnc_gui_shutdown (void)
if (gnome_is_running && !gnome_is_terminating)
{
gnome_is_terminating = TRUE;
#ifndef MAC_INTEGRATION
map = gnc_build_dotgnucash_path(ACCEL_MAP_NAME);
gtk_accel_map_save(map);
g_free(map);
#endif /* MAC_INTEGRATION */
gtk_main_quit();
}
}