[libgda] Provider's plugin system simplified
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Provider's plugin system simplified
- Date: Mon, 22 Apr 2019 18:57:27 +0000 (UTC)
commit 1abc55e82fe08091e467f95dd39a079efa9c6031
Author: Daniel Espinosa <esodan gmail com>
Date: Mon Apr 22 13:05:25 2019 -0500
Provider's plugin system simplified
Avoids memory leaks and remove some unnecesary API
libgda/gda-config.c | 12 ++--
libgda/gda-server-provider-extra.h | 6 +-
libgda/gda-server-provider.c | 43 -------------
libgda/sqlite/gda-sqlite-provider.c | 57 ++++++-----------
providers/mysql/gda-mysql-provider.c | 41 ++++---------
providers/mysql/libmain.c | 8 +--
providers/postgres/libmain.c | 16 +----
.../skel-implementation/capi/gda-capi-provider.c | 71 ++++++----------------
providers/skel-implementation/models/libmain.c | 10 +--
providers/sqlite/libmain.c | 8 +--
10 files changed, 61 insertions(+), 211 deletions(-)
---
diff --git a/libgda/gda-config.c b/libgda/gda-config.c
index 36cf3d27c..ecbdbb3cf 100644
--- a/libgda/gda-config.c
+++ b/libgda/gda-config.c
@@ -1696,18 +1696,16 @@ gda_config_get_provider (const gchar *provider_name, GError **error)
return NULL;
}
- void (*plugin_init) (const gchar *);
+ void (*plugin_init) (void);
if (g_module_symbol (ip->handle, "plugin_init", (gpointer *) &plugin_init)) {
- gchar *dirname = g_path_get_dirname (info->location);
- plugin_init (dirname);
- g_free (dirname);
+ plugin_init ();
}
}
g_module_symbol (ip->handle, "plugin_create_provider", (gpointer) &plugin_create_provider);
- if (plugin_create_provider)
- ip->instance = plugin_create_provider ();
- else {
+ if (plugin_create_provider) {
+ ip->instance = plugin_create_provider ();
+ } else {
g_module_symbol (ip->handle, "plugin_create_sub_provider", (gpointer)
&plugin_create_sub_provider);
if (plugin_create_sub_provider)
ip->instance = plugin_create_sub_provider (provider_name);
diff --git a/libgda/gda-server-provider-extra.h b/libgda/gda-server-provider-extra.h
index 904db5097..2dc66ea24 100644
--- a/libgda/gda-server-provider-extra.h
+++ b/libgda/gda-server-provider-extra.h
@@ -70,9 +70,8 @@ typedef struct {
GType g_type;
gchar *dbms_type;
} GdaServerProviderHandlerInfo;
-
-GdaDataHandler *gda_server_provider_handler_find (GdaServerProvider *prov, GdaConnection *cnc,
- GType g_type, const gchar *dbms_type);
+GdaDataHandler *gda_server_provider_handler_find (GdaServerProvider *prov, GdaConnection *cnc,
+ GType g_type, const gchar *dbms_type);
void gda_server_provider_handler_declare (GdaServerProvider *prov, GdaDataHandler *dh,
GdaConnection *cnc,
GType g_type, const gchar *dbms_type);
@@ -81,7 +80,6 @@ void _gda_server_provider_handlers_clear_for_cnc (GdaServerProvider *
/*
* misc
*/
-gchar *gda_server_provider_find_file (GdaServerProvider *prov, const gchar *inst_dir,
const gchar *filename);
gchar *gda_server_provider_load_resource_contents (const gchar *prov_name, const gchar *resource);
G_END_DECLS
diff --git a/libgda/gda-server-provider.c b/libgda/gda-server-provider.c
index 3f42d71f8..a1ef3f0f7 100644
--- a/libgda/gda-server-provider.c
+++ b/libgda/gda-server-provider.c
@@ -4263,49 +4263,6 @@ _gda_server_provider_handlers_clear_for_cnc (GdaServerProvider *prov, GdaConnect
g_hash_table_foreach_remove (priv->data_handlers, (GHRFunc) handlers_clear_for_cnc_fh, cnc);
}
-/**
- * gda_server_provider_find_file:
- * @prov: a #GdaServerProvider
- * @inst_dir: directory where @prov is installed
- * @filename: name of the file to find
- *
- * Finds the location of a @filename. This function should only be used by database provider's
- * implementations
- *
- * Returns: (transfer full): the complete path to @filename, or %NULL if not found
- */
-gchar *
-gda_server_provider_find_file (GdaServerProvider *prov, const gchar *inst_dir, const gchar *filename)
-{
- gchar *file = NULL;
- const gchar *dirname;
-
- g_return_val_if_fail (GDA_IS_SERVER_PROVIDER (prov), NULL);
- dirname = g_object_get_data (G_OBJECT (prov), "GDA_PROVIDER_DIR");
- if (dirname)
- file = g_build_filename (dirname, filename, NULL);
-
- if (!file ||
- (file && !g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) {
- g_free (file);
- file = g_build_filename (inst_dir, filename, NULL);
- if (! g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
- g_free (file);
- file = NULL;
- if (dirname) {
- /* look in the parent dir, to handle the case where the lib is in a .libs dir
*/
- file = g_build_filename (dirname, "..", filename, NULL);
- if (! g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
- g_free (file);
- file = NULL;
- }
- }
- }
- }
-
- return file;
-}
-
/**
* gda_server_provider_load_resource_contents:
* @prov_name: the provider's name
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index 3dae4199e..208185591 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -1566,51 +1566,28 @@ static gchar *
gda_sqlite_provider_render_operation (GdaServerProvider *provider, GdaConnection *cnc,
GdaServerOperation *op, GError **error)
{
- gchar *sql = NULL;
- gchar *file;
- gchar *str;
- gchar *dir;
-
- /* test @op's validity */
- file = g_strdup_printf (PNAME "_specs_%s.xml",
- gda_server_operation_op_type_to_string (gda_server_operation_get_op_type
(op)));
- str = g_utf8_strdown (file, -1);
- g_free (file);
-
- dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
- file = gda_server_provider_find_file (provider, dir, str);
- g_free (dir);
+ gchar *sql = NULL;
+ gchar *str;
+ str = g_strdup_printf ("/spec/" PNAME "/" PNAME "_specs_%s.raw.xml",
+ gda_server_operation_op_type_to_string (gda_server_operation_get_op_type (op)));
+ gchar *res = g_utf8_strdown (str, -1);
g_free (str);
- if (! file) {
- str = g_strdup_printf ("/spec/" PNAME "/" PNAME "_specs_%s.raw.xml",
- gda_server_operation_op_type_to_string (gda_server_operation_get_op_type
(op)));
- gchar *res = g_utf8_strdown (str, -1);
- g_free (str);
- GBytes *contents;
- contents = g_resources_lookup_data (res,
- G_RESOURCE_LOOKUP_FLAGS_NONE,
- error);
- if (contents == NULL) {
- g_assert (*error != NULL);
+ GBytes *contents;
+ contents = g_resources_lookup_data (res,
+ G_RESOURCE_LOOKUP_FLAGS_NONE,
+ error);
+ if (contents == NULL) {
+ g_assert (*error != NULL);
#ifdef GDA_DEBUG
- g_print ("Error at getting specs '%s': %s\n", res, (*error)->message);
+ g_print ("Error at getting specs '%s': %s\n", res, (*error)->message);
#endif
- g_free (str);
- g_free (res);
- return NULL;
- }
+ g_free (str);
g_free (res);
- /* else: TO_IMPLEMENT */
- g_bytes_unref (contents);
- }
- else {
- if (!gda_server_operation_is_valid (op, file, error)) {
- g_assert (*error != NULL);
- g_free (file);
- return NULL;
- }
- g_free (file);
+ return NULL;
}
+ g_free (res);
+ /* else: TO_IMPLEMENT */
+ g_bytes_unref (contents);
/* actual rendering */
switch (gda_server_operation_get_op_type (op)) {
diff --git a/providers/mysql/gda-mysql-provider.c b/providers/mysql/gda-mysql-provider.c
index b49bd2ded..0990929ee 100644
--- a/providers/mysql/gda-mysql-provider.c
+++ b/providers/mysql/gda-mysql-provider.c
@@ -819,9 +819,9 @@ gda_mysql_provider_render_operation (GdaServerProvider *provider,
GdaServerOperation *op,
GError **error)
{
- gchar *sql = NULL;
- gchar *file;
- gchar *str;
+ gchar *sql = NULL;
+ gchar *file;
+ gchar *str;
gchar *dir;
if (cnc) {
@@ -830,33 +830,16 @@ gda_mysql_provider_render_operation (GdaServerProvider *provider,
}
/* test @op's validity */
- file = g_utf8_strdown (gda_server_operation_op_type_to_string (gda_server_operation_get_op_type
(op)), -1);
- str = g_strdup_printf ("mysql_specs_%s", file);
- g_free (file);
-
- gchar *tmp;
- tmp = g_strdup_printf ("%s.xml", str);
- dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
- file = gda_server_provider_find_file (provider, dir, tmp);
- g_free (dir);
- g_free (tmp);
-
- if (file) {
- g_free (str);
- if (!gda_server_operation_is_valid (op, file, error)) {
- g_free (file);
- return NULL;
- }
+ file = g_utf8_strdown (gda_server_operation_op_type_to_string (gda_server_operation_get_op_type (op)), -1);
+ str = g_strdup_printf ("mysql_specs_%s", file);
+ g_free (file);
+
+ file = g_strdup_printf ("/spec/mysql/%s.raw.xml", str);
+ g_free (str);
+ if (!gda_server_operation_is_valid_from_resource (op, file, error)) {
+ g_free (file);
+ return NULL;
}
- else {
- file = g_strdup_printf ("/spec/mysql/%s.raw.xml", str);
- g_free (str);
- if (!gda_server_operation_is_valid_from_resource (op, file, error)) {
- g_free (file);
- return NULL;
- }
- }
- g_free (file);
/* actual rendering */
switch (gda_server_operation_get_op_type (op)) {
diff --git a/providers/mysql/libmain.c b/providers/mysql/libmain.c
index c6842004e..0b015322b 100644
--- a/providers/mysql/libmain.c
+++ b/providers/mysql/libmain.c
@@ -30,7 +30,6 @@
#include "gda-mysql.h"
#include "gda-mysql-provider.h"
-static gchar *module_path = NULL;
const gchar *plugin_get_name (void);
const gchar *plugin_get_description (void);
gchar *plugin_get_dsn_spec (void);
@@ -49,8 +48,6 @@ g_module_check_init (G_GNUC_UNUSED GModule *module)
void
g_module_unload (G_GNUC_UNUSED GModule *module)
{
- g_free (module_path);
- module_path = NULL;
}
/*
@@ -59,8 +56,6 @@ g_module_unload (G_GNUC_UNUSED GModule *module)
void
plugin_init (const gchar *real_path)
{
- if (real_path)
- module_path = g_strdup (real_path);
}
const gchar *
@@ -87,6 +82,5 @@ plugin_create_provider (void)
GdaServerProvider *prov;
prov = (GdaServerProvider*) g_object_new (GDA_TYPE_MYSQL_PROVIDER, NULL);
- g_object_set_data ((GObject *) prov, "GDA_PROVIDER_DIR", module_path);
- return prov;
+ return prov;
}
diff --git a/providers/postgres/libmain.c b/providers/postgres/libmain.c
index 66168a22c..6615d892f 100644
--- a/providers/postgres/libmain.c
+++ b/providers/postgres/libmain.c
@@ -29,7 +29,6 @@
#include "gda-postgres.h"
#include "gda-postgres-provider.h"
-static gchar *module_path = NULL;
const gchar *plugin_get_name (void);
const gchar *plugin_get_description (void);
gchar *plugin_get_dsn_spec (void);
@@ -48,8 +47,6 @@ g_module_check_init (G_GNUC_UNUSED GModule *module)
void
g_module_unload (G_GNUC_UNUSED GModule *module)
{
- g_free (module_path);
- module_path = NULL;
}
/*
@@ -58,16 +55,6 @@ g_module_unload (G_GNUC_UNUSED GModule *module)
void
plugin_init (const gchar *real_path)
{
- /* This is never freed, but that is OK. It is only called once. */
- /* But it would be nice to have some cleanup function just to shut valgrind up. murrayc. */
- if (real_path) {
- if(module_path) {
- g_free (module_path);
- module_path = NULL;
- }
-
- module_path = g_strdup (real_path);
- }
}
const gchar *
@@ -94,6 +81,5 @@ plugin_create_provider (void)
GdaServerProvider *prov;
prov = (GdaServerProvider*) g_object_new (GDA_TYPE_POSTGRES_PROVIDER, NULL);
- g_object_set_data ((GObject *) prov, "GDA_PROVIDER_DIR", module_path);
- return prov;
+ return prov;
}
diff --git a/providers/skel-implementation/capi/gda-capi-provider.c
b/providers/skel-implementation/capi/gda-capi-provider.c
index 597b7bdd9..dd8170b43 100644
--- a/providers/skel-implementation/capi/gda-capi-provider.c
+++ b/providers/skel-implementation/capi/gda-capi-provider.c
@@ -509,41 +509,26 @@ gda_capi_provider_create_operation (GdaServerProvider *provider, GdaConnection *
GdaServerOperationType type, G_GNUC_UNUSED GdaSet *options,
GError **error)
{
- gchar *file;
- GdaServerOperation *op;
- gchar *str;
+ gchar *file;
+ GdaServerOperation *op;
+ gchar *str;
gchar *dir;
if (cnc) {
g_return_val_if_fail (GDA_IS_CONNECTION (cnc), FALSE);
g_return_val_if_fail (gda_connection_get_provider (cnc) == provider, FALSE);
}
+ file = g_utf8_strdown (gda_server_operation_op_type_to_string (type), -1);
+ str = g_strdup_printf ("capi_specs_%s", file);
+ g_free (file);
- file = g_utf8_strdown (gda_server_operation_op_type_to_string (type), -1);
- str = g_strdup_printf ("capi_specs_%s", file);
- g_free (file);
-
- gchar *tmp;
- tmp = g_strdup_printf ("%s.xml", str);
- dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
- file = gda_server_provider_find_file (provider, dir, tmp);
- g_free (dir);
- g_free (tmp);
-
- if (file) {
- g_free (str);
- op = gda_server_operation_new (type, file);
- g_free (file);
- }
- else {
- file = g_strdup_printf ("/spec/capi/%s.raw.xml", str);
- g_free (str);
- op = GDA_SERVER_OPERATION (g_object_new (GDA_TYPE_SERVER_OPERATION, "op-type", type,
- "spec-resource", file, NULL));
- g_free (file);
- }
+ file = g_strdup_printf ("/spec/capi/%s.raw.xml", str);
+ g_free (str);
+ op = GDA_SERVER_OPERATION (g_object_new (GDA_TYPE_SERVER_OPERATION, "op-type", type,
+ "spec-resource", file, NULL));
+ g_free (file);
- return op;
+ return op;
}
/*
@@ -564,32 +549,16 @@ gda_capi_provider_render_operation (GdaServerProvider *provider, GdaConnection *
}
/* test @op's validity */
- file = g_utf8_strdown (gda_server_operation_op_type_to_string (gda_server_operation_get_op_type
(op)), -1);
- str = g_strdup_printf ("capi_specs_%s", file);
- g_free (file);
+ file = g_utf8_strdown (gda_server_operation_op_type_to_string (gda_server_operation_get_op_type (op)), -1);
+ str = g_strdup_printf ("capi_specs_%s", file);
+ g_free (file);
- gchar *tmp;
- tmp = g_strdup_printf ("%s.xml", str);
- dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
- file = gda_server_provider_find_file (provider, dir, tmp);
- g_free (dir);
- g_free (tmp);
-
- if (file) {
- g_free (str);
- if (!gda_server_operation_is_valid (op, file, error)) {
- g_free (file);
- return NULL;
- }
+ file = g_strdup_printf ("/spec/mysql/%s.raw.xml", str);
+ g_free (str);
+ if (!gda_server_operation_is_valid_from_resource (op, file, error)) {
+ g_free (file);
+ return NULL;
}
- else {
- file = g_strdup_printf ("/spec/mysql/%s.raw.xml", str);
- g_free (str);
- if (!gda_server_operation_is_valid_from_resource (op, file, error)) {
- g_free (file);
- return NULL;
- }
- }
g_free (file);
/* actual rendering */
diff --git a/providers/skel-implementation/models/libmain.c b/providers/skel-implementation/models/libmain.c
index 49684c6f9..f6c887d15 100644
--- a/providers/skel-implementation/models/libmain.c
+++ b/providers/skel-implementation/models/libmain.c
@@ -28,7 +28,6 @@
#include "gda-models.h"
#include "gda-models-provider.h"
-static gchar *module_path = NULL;
const gchar *plugin_get_name (void);
const gchar *plugin_get_description (void);
gchar *plugin_get_dsn_spec (void);
@@ -47,8 +46,6 @@ g_module_check_init (G_GNUC_UNUSED GModule *module)
void
g_module_unload (G_GNUC_UNUSED GModule *module)
{
- g_free (module_path);
- module_path = NULL;
}
/*
@@ -57,8 +54,6 @@ g_module_unload (G_GNUC_UNUSED GModule *module)
void
plugin_init (const gchar *real_path)
{
- if (real_path)
- module_path = g_strdup (real_path);
}
const gchar *
@@ -95,7 +90,6 @@ plugin_create_provider (void)
{
GdaServerProvider *prov;
- prov = (GdaServerProvider *) g_object_new (GDA_TYPE_MODELS_PROVIDER, NULL);
- g_object_set_data ((GObject *) prov, "GDA_PROVIDER_DIR", module_path);
- return prov;
+ prov = (GdaServerProvider *) g_object_new (GDA_TYPE_MODELS_PROVIDER, NULL);
+ return prov;
}
diff --git a/providers/sqlite/libmain.c b/providers/sqlite/libmain.c
index 991c629cc..1b042cbe5 100644
--- a/providers/sqlite/libmain.c
+++ b/providers/sqlite/libmain.c
@@ -30,7 +30,6 @@
#include <libgda/gda-server-provider-extra.h>
#include <libgda/binreloc/gda-binreloc.h>
-static gchar *module_path = NULL;
const gchar *plugin_get_name (void);
const gchar *plugin_get_description (void);
gchar *plugin_get_dsn_spec (void);
@@ -49,8 +48,6 @@ g_module_check_init (G_GNUC_UNUSED GModule *module)
void
g_module_unload (G_GNUC_UNUSED GModule *module)
{
- g_free (module_path);
- module_path = NULL;
}
/*
@@ -59,8 +56,6 @@ g_module_unload (G_GNUC_UNUSED GModule *module)
void
plugin_init (const gchar *real_path)
{
- if (real_path)
- module_path = g_strdup (real_path);
}
const gchar *
@@ -98,6 +93,5 @@ plugin_create_provider (void)
GdaServerProvider *prov;
prov = (GdaServerProvider*) g_object_new (GDA_TYPE_SQLITE_PROVIDER, NULL);
- g_object_set_data ((GObject *) prov, "GDA_PROVIDER_DIR", module_path);
- return prov;
+ return prov;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]