qulogic/gplugin

Use g_set_error* more.
feature/new-glib-stuff
2019-01-25, Elliott Sales de Andrade
3e9310ee57d7
Parents 5502aeffdc42
Children a0edf0043321
Use g_set_error* more.
--- a/gplugin/gplugin-loader.c Thu Jan 24 23:45:54 2019 -0500
+++ b/gplugin/gplugin-loader.c Fri Jan 25 00:50:20 2019 -0500
@@ -103,9 +103,9 @@
if(klass && klass->load)
ret = klass->load(loader, plugin, error);
- if(!ret && error && *error == NULL) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- "Failed to load plugin : unknown");
+ if (!ret) {
+ g_set_error(error, GPLUGIN_DOMAIN, 0,
+ "Failed to load plugin : unknown");
}
return ret;
@@ -138,9 +138,9 @@
if(klass && klass->unload)
ret = klass->unload(loader, plugin, error);
- if(!ret && error && *error == NULL) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- "Failed to unload plugin : unknown");
+ if (!ret) {
+ g_set_error(error, GPLUGIN_DOMAIN, 0,
+ "Failed to unload plugin : unknown");
}
return ret;
--- a/gplugin/gplugin-manager.c Thu Jan 24 23:45:54 2019 -0500
+++ b/gplugin/gplugin-manager.c Fri Jan 25 00:50:20 2019 -0500
@@ -775,11 +775,9 @@
/* now try to get the plugin info from the plugin */
info = gplugin_plugin_get_info(plugin);
if(info == NULL) {
- if(error) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- _("Plugin %s did not return value plugin info"),
- gplugin_plugin_get_filename(plugin));
- }
+ g_set_error(error, GPLUGIN_DOMAIN, 0,
+ _("Plugin %s did not return value plugin info"),
+ gplugin_plugin_get_filename(plugin));
gplugin_plugin_set_state(plugin, GPLUGIN_PLUGIN_STATE_LOAD_FAILED);
@@ -798,12 +796,10 @@
loader = gplugin_plugin_get_loader(plugin);
if(!GPLUGIN_IS_LOADER(loader)) {
- if(error) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- _("The loader for %s is not a loader. This "
- "should not happened!"),
- gplugin_plugin_get_filename(plugin));
- }
+ g_set_error(error, GPLUGIN_DOMAIN, 0,
+ _("The loader for %s is not a loader. This "
+ "should not happened!"),
+ gplugin_plugin_get_filename(plugin));
gplugin_plugin_set_state(plugin, GPLUGIN_PLUGIN_STATE_LOAD_FAILED);
@@ -844,10 +840,8 @@
loader = gplugin_plugin_get_loader(plugin);
if(!GPLUGIN_IS_LOADER(loader)) {
- if(error) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- _("Plugin loader is not a loader"));
- }
+ g_set_error(error, GPLUGIN_DOMAIN, 0,
+ _("Plugin loader is not a loader"));
return FALSE;
}
--- a/gplugin/gplugin-native-loader.c Thu Jan 24 23:45:54 2019 -0500
+++ b/gplugin/gplugin-native-loader.c Fri Jan 25 00:50:20 2019 -0500
@@ -59,11 +59,8 @@
g_return_val_if_fail(module != NULL, NULL);
if(!g_module_symbol(module, name, &symbol)) {
- if(error) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- _("symbol %s was not found"), name);
-
- }
+ g_set_error(error, GPLUGIN_DOMAIN, 0,
+ _("symbol %s was not found"), name);
return NULL;
}
@@ -149,11 +146,9 @@
if(module)
g_module_close(module);
- if(error && !*error) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- _("the query function did not return a "
- "GPluginPluginInfo instance"));
- }
+ g_set_error_literal(error, GPLUGIN_DOMAIN, 0,
+ _("the query function did not return a "
+ "GPluginPluginInfo instance"));
return NULL;
}
@@ -168,11 +163,9 @@
if(!GPLUGIN_IS_PLUGIN_INFO(info)) {
g_module_close(module);
- if(error && !*error) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- _("the query function did not return a "
- "GPluginPluginInfo instance"));
- }
+ g_set_error_literal(error, GPLUGIN_DOMAIN, 0,
+ _("the query function did not return a "
+ "GPluginPluginInfo instance"));
return NULL;
}
@@ -215,10 +208,8 @@
g_object_unref(G_OBJECT(info));
if(!GPLUGIN_IS_NATIVE_PLUGIN(plugin)) {
- if(error) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- _("failed to create plugin instance"));
- }
+ g_set_error_literal(error, GPLUGIN_DOMAIN, 0,
+ _("failed to create plugin instance"));
return NULL;
}
@@ -238,8 +229,7 @@
/* get and call the function */
g_object_get(G_OBJECT(plugin), "load-func", &func, NULL);
if(!func(GPLUGIN_NATIVE_PLUGIN(plugin), error)) {
- if(error && *error == NULL)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, _("unknown failure"));
+ g_set_error_literal(error, GPLUGIN_DOMAIN, 0, _("unknown failure"));
return FALSE;
}
@@ -271,8 +261,7 @@
/* now call the function */
if(!func(GPLUGIN_NATIVE_PLUGIN(plugin), error)) {
- if(error && *error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, _("unknown failure"));
+ g_set_error_literal(error, GPLUGIN_DOMAIN, 0, _("unknown failure"));
return FALSE;
}
--- a/gplugin/gplugin-version.c Thu Jan 24 23:45:54 2019 -0500
+++ b/gplugin/gplugin-version.c Fri Jan 25 00:50:20 2019 -0500
@@ -76,10 +76,8 @@
matches = g_regex_match(regex, v, 0, &info);
if(!matches) {
- if(error) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- _("%s does not match the version regex"), v);
- }
+ g_set_error(error, GPLUGIN_DOMAIN, 0,
+ _("%s does not match the version regex"), v);
return FALSE;
}
--- a/gplugin/tests/bad-plugins/query-error.c Thu Jan 24 23:45:54 2019 -0500
+++ b/gplugin/tests/bad-plugins/query-error.c Fri Jan 25 00:50:20 2019 -0500
@@ -20,8 +20,7 @@
G_MODULE_EXPORT GPluginPluginInfo *
gplugin_query(GPLUGIN_UNUSED GError **error) {
- if(error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "expected error");
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "expected error");
return NULL;
}
--- a/gplugin/tests/dynamic-type/dynamic-type-user.c Thu Jan 24 23:45:54 2019 -0500
+++ b/gplugin/tests/dynamic-type/dynamic-type-user.c Fri Jan 25 00:50:20 2019 -0500
@@ -42,8 +42,8 @@
test_object = g_object_new(DYNAMIC_TYPE_TEST, NULL);
if (test_object == NULL) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- "could not create an instance of DynamicTest");
+ g_set_error(error, GPLUGIN_DOMAIN, 0,
+ "could not create an instance of DynamicTest");
return FALSE;
}
@@ -55,8 +55,8 @@
g_object_unref(test_object);
if (DYNAMIC_IS_TEST(test_object)) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- "test_object is still valid");
+ g_set_error(error, GPLUGIN_DOMAIN, 0,
+ "test_object is still valid");
return FALSE;
}
--- a/gplugin/tests/load-on-query-fail/load-on-query-fail.c Thu Jan 24 23:45:54 2019 -0500
+++ b/gplugin/tests/load-on-query-fail/load-on-query-fail.c Fri Jan 25 00:50:20 2019 -0500
@@ -32,7 +32,7 @@
gplugin_load(GPLUGIN_UNUSED GPluginNativePlugin *plugin, GError **error) {
static int count = 1;
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "called %d times", count++);
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "called %d times", count++);
return FALSE;
}
--- a/gplugin/tests/plugins/load-failed.c Thu Jan 24 23:45:54 2019 -0500
+++ b/gplugin/tests/plugins/load-failed.c Fri Jan 25 00:50:20 2019 -0500
@@ -29,8 +29,7 @@
G_MODULE_EXPORT gboolean
gplugin_load(GPLUGIN_UNUSED GPluginNativePlugin *plugin, GError **error) {
- if(error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "expected error");
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "expected error");
return FALSE;
}
--- a/gplugin/tests/plugins/unload-failed.c Thu Jan 24 23:45:54 2019 -0500
+++ b/gplugin/tests/plugins/unload-failed.c Fri Jan 25 00:50:20 2019 -0500
@@ -36,8 +36,7 @@
G_MODULE_EXPORT gboolean
gplugin_unload(GPLUGIN_UNUSED GPluginNativePlugin *plugin, GError **error) {
- if(error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "expected error");
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "expected error");
return FALSE;
}
--- a/lua/gplugin-lua-loader.c Thu Jan 24 23:45:54 2019 -0500
+++ b/lua/gplugin-lua-loader.c Fri Jan 25 00:50:20 2019 -0500
@@ -39,8 +39,7 @@
msg = lua_tostring(L, -1);
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- "%s", (msg) ? msg : "Unknown");
+ g_set_error_literal(error, GPLUGIN_DOMAIN, 0, (msg) ? msg : "Unknown");
}
static gboolean
@@ -112,8 +111,7 @@
}
if(!lua_istable(L, -1)) {
- if(error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "moonscript returned an unexpected value");
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "moonscript returned an unexpected value");
return NULL;
}
@@ -143,8 +141,7 @@
lua_getglobal(L, "gplugin_query");
if(lua_isnil(L, -1)) {
- if(error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "no gplugin_query function found");
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "no gplugin_query function found");
return NULL;
}
--- a/python/gplugin-python-loader.c Thu Jan 24 23:45:54 2019 -0500
+++ b/python/gplugin-python-loader.c Fri Jan 25 00:50:20 2019 -0500
@@ -203,10 +203,8 @@
Py_DECREF(result);
if(!ret) {
- if(error) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- _("Failed to load plugin"));
- }
+ g_set_error_literal(error, GPLUGIN_DOMAIN, 0,
+ _("Failed to load plugin"));
}
return ret;
@@ -239,10 +237,8 @@
Py_DECREF(result);
if(!ret) {
- if(error) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- _("Failed to unload plugin"));
- }
+ g_set_error_literal(error, GPLUGIN_DOMAIN, 0,
+ _("Failed to unload plugin"));
}
return ret;
--- a/tcc/gplugin-tcc-loader.c Thu Jan 24 23:45:54 2019 -0500
+++ b/tcc/gplugin-tcc-loader.c Fri Jan 25 00:50:20 2019 -0500
@@ -58,8 +58,7 @@
tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
if(tcc_add_file(s, filename) == -1) {
- if(error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "couldn't load file %s", filename);
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "couldn't load file %s", filename);
tcc_delete(s);
@@ -68,8 +67,7 @@
/* copy code into memory */
if((memsize = tcc_relocate(s, NULL)) < 0) {
- if(error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "couldn't work out how much memory is needed");
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "couldn't work out how much memory is needed");
tcc_delete(s);
return NULL;
@@ -77,8 +75,7 @@
memneeded = g_malloc0(memsize);
if(tcc_relocate(s, memneeded) < 0) {
- if(error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "could not relocate plugin into memory");
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "could not relocate plugin into memory");
tcc_delete(s);
g_free(memneeded);
@@ -87,8 +84,7 @@
gplugin_query = (GPluginTccPluginQueryFunc) tcc_get_symbol(s, "gplugin_query");
if (gplugin_query == NULL) {
- if(error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "no gplugin_query function found");
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "no gplugin_query function found");
tcc_delete(s);
g_free(memneeded);
@@ -123,8 +119,7 @@
gplugin_load = (GPluginTccPluginLoadFunc) tcc_get_symbol(s, "gplugin_load");
if (gplugin_load == NULL) {
- if(error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "no gplugin_load function found");
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "no gplugin_load function found");
return FALSE;
}
@@ -142,8 +137,7 @@
gplugin_unload = (GPluginTccPluginUnloadFunc) tcc_get_symbol(s, "gplugin_unload");
if (gplugin_unload == NULL) {
- if(error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "no gplugin_unload function found");
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "no gplugin_unload function found");
return FALSE;
}
--- a/tcc/tests/plugins/load-failed.c Thu Jan 24 23:45:54 2019 -0500
+++ b/tcc/tests/plugins/load-failed.c Fri Jan 25 00:50:20 2019 -0500
@@ -28,8 +28,7 @@
G_MODULE_EXPORT gboolean
gplugin_load(GPLUGIN_UNUSED GPluginNativePlugin *plugin, GError **error) {
- if(error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "expected error");
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "expected error");
return FALSE;
}
--- a/tcc/tests/plugins/unload-failed.c Thu Jan 24 23:45:54 2019 -0500
+++ b/tcc/tests/plugins/unload-failed.c Fri Jan 25 00:50:20 2019 -0500
@@ -35,8 +35,7 @@
G_MODULE_EXPORT gboolean
gplugin_unload(GPLUGIN_UNUSED GPluginNativePlugin *plugin, GError **error) {
- if(error)
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "expected error");
+ g_set_error(error, GPLUGIN_DOMAIN, 0, "expected error");
return FALSE;
}