[libpeas] Validate function arguments



commit c86b3c8d8581018c1f659e9a73c52d3636858fae
Author: Garrett Regier <alias301 gmail com>
Date:   Fri Feb 11 02:36:12 2011 -0800

    Validate function arguments

 libpeas/peas-engine.c        |   26 ++++++++++++++++++++++----
 libpeas/peas-extension-set.c |   12 ++++++++++++
 libpeas/peas-extension.c     |    3 +++
 libpeas/peas-object-module.c |   16 ++++++++++++++++
 4 files changed, 53 insertions(+), 4 deletions(-)
---
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index 962fd84..5ee843a 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -327,6 +327,8 @@ loader_garbage_collect (const gchar *id,
 void
 peas_engine_garbage_collect (PeasEngine *engine)
 {
+  g_return_if_fail (PEAS_IS_ENGINE (engine));
+
   g_hash_table_foreach (loaders,
                         (GHFunc) loader_garbage_collect,
                         NULL);
@@ -702,6 +704,7 @@ peas_engine_enable_loader (PeasEngine  *engine,
   LoaderInfo *loader_info;
 
   g_return_if_fail (PEAS_IS_ENGINE (engine));
+  g_return_if_fail (loader_id != NULL);
 
   loader_info = (LoaderInfo *) g_hash_table_lookup (loaders,
                                                     loader_id);
@@ -723,6 +726,8 @@ peas_engine_enable_loader (PeasEngine  *engine,
 const GList *
 peas_engine_get_plugin_list (PeasEngine *engine)
 {
+  g_return_val_if_fail (PEAS_IS_ENGINE (engine), NULL);
+
   return engine->priv->plugin_list;
 }
 
@@ -745,9 +750,14 @@ PeasPluginInfo *
 peas_engine_get_plugin_info (PeasEngine  *engine,
                              const gchar *plugin_name)
 {
-  GList *l = g_list_find_custom (engine->priv->plugin_list,
-                                 plugin_name,
-                                 (GCompareFunc) compare_plugin_info_and_name);
+  GList *l;
+
+  g_return_val_if_fail (PEAS_IS_ENGINE (engine), NULL);
+  g_return_val_if_fail (plugin_name != NULL, NULL);
+
+  l = g_list_find_custom (engine->priv->plugin_list,
+                          plugin_name,
+                          (GCompareFunc) compare_plugin_info_and_name);
 
   return l == NULL ? NULL : (PeasPluginInfo *) l->data;
 }
@@ -854,6 +864,7 @@ gboolean
 peas_engine_load_plugin (PeasEngine     *engine,
                          PeasPluginInfo *info)
 {
+  g_return_val_if_fail (PEAS_IS_ENGINE (engine), FALSE);
   g_return_val_if_fail (info != NULL, FALSE);
 
   if (!peas_plugin_info_is_available (info, NULL))
@@ -921,6 +932,7 @@ gboolean
 peas_engine_unload_plugin (PeasEngine     *engine,
                            PeasPluginInfo *info)
 {
+  g_return_val_if_fail (PEAS_IS_ENGINE (engine), FALSE);
   g_return_val_if_fail (info != NULL, FALSE);
 
   if (!peas_plugin_info_is_loaded (info))
@@ -1095,9 +1107,13 @@ peas_engine_create_extension (PeasEngine     *engine,
 gchar **
 peas_engine_get_loaded_plugins (PeasEngine *engine)
 {
-  GArray *array = g_array_new (TRUE, FALSE, sizeof (gchar *));
+  GArray *array;
   GList *pl;
 
+  g_return_val_if_fail (PEAS_IS_ENGINE (engine), NULL);
+
+  array = g_array_new (TRUE, FALSE, sizeof (gchar *));
+
   for (pl = engine->priv->plugin_list; pl; pl = pl->next)
     {
       PeasPluginInfo *info = (PeasPluginInfo *) pl->data;
@@ -1146,6 +1162,8 @@ peas_engine_set_loaded_plugins (PeasEngine   *engine,
 {
   GList *pl;
 
+  g_return_if_fail (PEAS_IS_ENGINE (engine));
+
   for (pl = engine->priv->plugin_list; pl; pl = pl->next)
     {
       PeasPluginInfo *info = (PeasPluginInfo *) pl->data;
diff --git a/libpeas/peas-extension-set.c b/libpeas/peas-extension-set.c
index 62f86c8..5e3580f 100644
--- a/libpeas/peas-extension-set.c
+++ b/libpeas/peas-extension-set.c
@@ -481,6 +481,9 @@ peas_extension_set_call (PeasExtensionSet *set,
   va_list args;
   gboolean result;
 
+  g_return_val_if_fail (PEAS_IS_EXTENSION_SET (set), FALSE);
+  g_return_val_if_fail (method_name != NULL, FALSE);
+
   va_start (args, method_name);
   result = peas_extension_set_call_valist (set, method_name, args);
   va_end (args);
@@ -577,6 +580,9 @@ peas_extension_set_newv (PeasEngine *engine,
 {
   PeasParameterArray construct_properties = { n_parameters, parameters };
 
+  g_return_val_if_fail (PEAS_IS_ENGINE (engine), NULL);
+  g_return_val_if_fail (G_TYPE_IS_INTERFACE (exten_type), NULL);
+
   return PEAS_EXTENSION_SET (g_object_new (PEAS_TYPE_EXTENSION_SET,
                                            "engine", engine,
                                            "extension-type", exten_type,
@@ -609,6 +615,9 @@ peas_extension_set_new_valist (PeasEngine  *engine,
   guint n_parameters;
   PeasExtensionSet *set;
 
+  g_return_val_if_fail (PEAS_IS_ENGINE (engine), NULL);
+  g_return_val_if_fail (G_TYPE_IS_INTERFACE (exten_type), NULL);
+
   type_struct = _g_type_struct_ref (exten_type);
 
   if (!_valist_to_parameter_list (exten_type, type_struct, first_property,
@@ -659,6 +668,9 @@ peas_extension_set_new (PeasEngine  *engine,
   va_list var_args;
   PeasExtensionSet *set;
 
+  g_return_val_if_fail (PEAS_IS_ENGINE (engine), NULL);
+  g_return_val_if_fail (G_TYPE_IS_INTERFACE (exten_type), NULL);
+
   va_start (var_args, first_property);
   set = peas_extension_set_new_valist (engine, exten_type, first_property, var_args);
   va_end (var_args);
diff --git a/libpeas/peas-extension.c b/libpeas/peas-extension.c
index 9024199..0a434d1 100644
--- a/libpeas/peas-extension.c
+++ b/libpeas/peas-extension.c
@@ -201,6 +201,9 @@ peas_extension_call (PeasExtension *exten,
   va_list args;
   gboolean result;
 
+  g_return_val_if_fail (PEAS_IS_EXTENSION (exten), FALSE);
+  g_return_val_if_fail (method_name != NULL, FALSE);
+
   va_start (args, method_name);
   result = peas_extension_call_valist (exten, method_name, args);
   va_end (args);
diff --git a/libpeas/peas-object-module.c b/libpeas/peas-object-module.c
index 2fde033..2589998 100644
--- a/libpeas/peas-object-module.c
+++ b/libpeas/peas-object-module.c
@@ -30,6 +30,7 @@
 #include <string.h>
 
 #include "peas-object-module.h"
+#include "peas-plugin-loader.h"
 
 /**
  * SECTION:peas-object-module
@@ -389,6 +390,13 @@ peas_object_module_register_extension_factory (PeasObjectModule *module,
                                                GDestroyNotify    destroy_func)
 {
   InterfaceImplementation impl = { iface_type, factory_func, user_data, destroy_func };
+
+  g_return_if_fail (PEAS_IS_OBJECT_MODULE (module));
+  g_return_if_fail (factory_func != NULL);
+
+  if (iface_type != PEAS_TYPE_PLUGIN_LOADER)
+    g_return_if_fail (G_TYPE_IS_INTERFACE (iface_type));
+
   g_array_append_val (module->priv->implementations, impl);
 
   g_debug ("Registered extension for type '%s'", g_type_name (iface_type));
@@ -437,6 +445,14 @@ peas_object_module_register_extension_type (PeasObjectModule *module,
                                             GType             iface_type,
                                             GType             extension_type)
 {
+  g_return_if_fail (PEAS_IS_OBJECT_MODULE (module));
+
+  if (iface_type != PEAS_TYPE_PLUGIN_LOADER)
+    {
+      g_return_if_fail (G_TYPE_IS_INTERFACE (iface_type));
+      g_return_if_fail (g_type_is_a (extension_type, iface_type));
+    }
+
   peas_object_module_register_extension_factory (module,
                                                  iface_type,
                                                  create_gobject_from_type,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]