Commit f0e1e2df authored by Garrett Regier's avatar Garrett Regier

Use new GObject private API

parent 001fa770
......@@ -85,12 +85,13 @@ dnl ================================================================
PKG_PROG_PKG_CONFIG
GLIB_REQUIRED=2.36.0
GOBJECT_REQUIRED=2.38.0
GIO_REQUIRED=2.32.0
INTROSPECTION_REQUIRED=1.39.0
PKG_CHECK_MODULES(PEAS, [
glib-2.0 >= $GLIB_REQUIRED
gobject-2.0 >= $GLIB_REQUIRED
gobject-2.0 >= $GOBJECT_REQUIRED
gmodule-2.0 >= $GLIB_REQUIRED
gio-2.0 >= $GIO_REQUIRED
gobject-introspection-1.0 >= $INTROSPECTION_REQUIRED
......
......@@ -32,10 +32,10 @@ enum {
PLUGIN_INFO_NAME_COLUMN = 0
};
struct _PeasGtkDisablePluginsDialogPrivate {
typedef struct {
PeasPluginInfo *plugin_info;
GList *dep_plugins;
};
} PeasGtkDisablePluginsDialogPrivate;
/* Properties */
enum {
......@@ -47,9 +47,12 @@ enum {
static GParamSpec *properties[N_PROPERTIES] = { NULL };
G_DEFINE_TYPE (PeasGtkDisablePluginsDialog,
peas_gtk_disable_plugins_dialog,
GTK_TYPE_MESSAGE_DIALOG)
G_DEFINE_TYPE_WITH_PRIVATE (PeasGtkDisablePluginsDialog,
peas_gtk_disable_plugins_dialog,
GTK_TYPE_MESSAGE_DIALOG)
#define GET_PRIV(o) \
(peas_gtk_disable_plugins_dialog_get_instance_private (o))
static gint
model_name_sort_func (GtkListStore *store,
......@@ -79,6 +82,7 @@ model_name_sort_func (GtkListStore *store,
static void
build_multiple_dependant_plugins (PeasGtkDisablePluginsDialog *dialog)
{
PeasGtkDisablePluginsDialogPrivate *priv = GET_PRIV (dialog);
gchar *message;
GtkWidget *message_area;
GtkWidget *sw;
......@@ -96,7 +100,7 @@ build_multiple_dependant_plugins (PeasGtkDisablePluginsDialog *dialog)
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
_("The following plugins depend on '%s' and will also be disabled:"),
peas_plugin_info_get_name (dialog->priv->plugin_info));
peas_plugin_info_get_name (priv->plugin_info));
message_area = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog));
......@@ -117,7 +121,7 @@ build_multiple_dependant_plugins (PeasGtkDisablePluginsDialog *dialog)
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
GTK_SORT_ASCENDING);
for (dep_plugin = dialog->priv->dep_plugins; dep_plugin != NULL;
for (dep_plugin = priv->dep_plugins; dep_plugin != NULL;
dep_plugin = dep_plugin->next)
{
PeasPluginInfo *plugin = (PeasPluginInfo *) dep_plugin->data;
......@@ -150,6 +154,7 @@ build_multiple_dependant_plugins (PeasGtkDisablePluginsDialog *dialog)
static void
build_single_dependant_plugin (PeasGtkDisablePluginsDialog *dialog)
{
PeasGtkDisablePluginsDialogPrivate *priv = GET_PRIV (dialog);
gchar *message;
message = g_strconcat ("<span weight=\"bold\" size=\"larger\">",
......@@ -162,19 +167,15 @@ build_single_dependant_plugin (PeasGtkDisablePluginsDialog *dialog)
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
_("The '%s' plugin depends on the '%s' plugin.\n"
"If you disable '%s', '%s' will also be disabled."),
peas_plugin_info_get_name (dialog->priv->plugin_info),
peas_plugin_info_get_name (dialog->priv->dep_plugins->data),
peas_plugin_info_get_name (dialog->priv->plugin_info),
peas_plugin_info_get_name (dialog->priv->dep_plugins->data));
peas_plugin_info_get_name (priv->plugin_info),
peas_plugin_info_get_name (priv->dep_plugins->data),
peas_plugin_info_get_name (priv->plugin_info),
peas_plugin_info_get_name (priv->dep_plugins->data));
}
static void
peas_gtk_disable_plugins_dialog_init (PeasGtkDisablePluginsDialog *dialog)
{
dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
PEAS_GTK_TYPE_DISABLE_PLUGINS_DIALOG,
PeasGtkDisablePluginsDialogPrivate);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
gtk_dialog_add_button (GTK_DIALOG (dialog),
......@@ -190,14 +191,15 @@ peas_gtk_disable_plugins_dialog_set_property (GObject *object,
GParamSpec *pspec)
{
PeasGtkDisablePluginsDialog *dialog = PEAS_GTK_DISABLE_PLUGINS_DIALOG (object);
PeasGtkDisablePluginsDialogPrivate *priv = GET_PRIV (dialog);
switch (prop_id)
{
case PROP_PLUGIN_INFO:
dialog->priv->plugin_info = g_value_get_pointer (value);
priv->plugin_info = g_value_get_pointer (value);
break;
case PROP_DEPENDANT_PLUGINS:
dialog->priv->dep_plugins = g_value_get_pointer (value);
priv->dep_plugins = g_value_get_pointer (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -212,14 +214,15 @@ peas_gtk_disable_plugins_dialog_get_property (GObject *object,
GParamSpec *pspec)
{
PeasGtkDisablePluginsDialog *dialog = PEAS_GTK_DISABLE_PLUGINS_DIALOG (object);
PeasGtkDisablePluginsDialogPrivate *priv = GET_PRIV (dialog);
switch (prop_id)
{
case PROP_PLUGIN_INFO:
g_value_set_pointer (value, dialog->priv->plugin_info);
g_value_set_pointer (value, priv->plugin_info);
break;
case PROP_DEPENDANT_PLUGINS:
g_value_set_pointer (value, dialog->priv->dep_plugins);
g_value_set_pointer (value, priv->dep_plugins);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -231,8 +234,9 @@ static void
peas_gtk_disable_plugins_dialog_constructed (GObject *object)
{
PeasGtkDisablePluginsDialog *dialog = PEAS_GTK_DISABLE_PLUGINS_DIALOG (object);
PeasGtkDisablePluginsDialogPrivate *priv = GET_PRIV (dialog);
if (dialog->priv->dep_plugins->next == NULL)
if (priv->dep_plugins->next == NULL)
build_single_dependant_plugin (dialog);
else
build_multiple_dependant_plugins (dialog);
......@@ -244,8 +248,9 @@ static void
peas_gtk_disable_plugins_dialog_finalize (GObject *object)
{
PeasGtkDisablePluginsDialog *dialog = PEAS_GTK_DISABLE_PLUGINS_DIALOG (object);
PeasGtkDisablePluginsDialogPrivate *priv = GET_PRIV (dialog);
g_list_free (dialog->priv->dep_plugins);
g_list_free (priv->dep_plugins);
G_OBJECT_CLASS (peas_gtk_disable_plugins_dialog_parent_class)->finalize (object);
}
......@@ -277,7 +282,6 @@ peas_gtk_disable_plugins_dialog_class_init (PeasGtkDisablePluginsDialogClass *kl
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
g_type_class_add_private (object_class, sizeof (PeasGtkDisablePluginsDialogPrivate));
}
/*
......
......@@ -39,13 +39,9 @@ G_BEGIN_DECLS
typedef struct _PeasGtkDisablePluginsDialog PeasGtkDisablePluginsDialog;
typedef struct _PeasGtkDisablePluginsDialogClass PeasGtkDisablePluginsDialogClass;
typedef struct _PeasGtkDisablePluginsDialogPrivate PeasGtkDisablePluginsDialogPrivate;
struct _PeasGtkDisablePluginsDialog {
GtkMessageDialog parent;
/*< private > */
PeasGtkDisablePluginsDialogPrivate *priv;
};
struct _PeasGtkDisablePluginsDialogClass {
......
......@@ -46,9 +46,9 @@ static const GType ColumnTypes[] = {
G_STATIC_ASSERT (G_N_ELEMENTS (ColumnTypes) == PEAS_GTK_PLUGIN_MANAGER_STORE_N_COLUMNS);
struct _PeasGtkPluginManagerStorePrivate {
typedef struct {
PeasEngine *engine;
};
} PeasGtkPluginManagerStorePrivate;
/* Properties */
enum {
......@@ -59,7 +59,12 @@ enum {
static GParamSpec *properties[N_PROPERTIES] = { NULL };
G_DEFINE_TYPE (PeasGtkPluginManagerStore, peas_gtk_plugin_manager_store, GTK_TYPE_LIST_STORE)
G_DEFINE_TYPE_WITH_PRIVATE (PeasGtkPluginManagerStore,
peas_gtk_plugin_manager_store,
GTK_TYPE_LIST_STORE)
#define GET_PRIV(o) \
(peas_gtk_plugin_manager_store_get_instance_private (o))
static void
update_plugin (PeasGtkPluginManagerStore *store,
......@@ -197,10 +202,6 @@ model_name_sort_func (PeasGtkPluginManagerStore *store,
static void
peas_gtk_plugin_manager_store_init (PeasGtkPluginManagerStore *store)
{
store->priv = G_TYPE_INSTANCE_GET_PRIVATE (store,
PEAS_GTK_TYPE_PLUGIN_MANAGER_STORE,
PeasGtkPluginManagerStorePrivate);
gtk_list_store_set_column_types (GTK_LIST_STORE (store),
PEAS_GTK_PLUGIN_MANAGER_STORE_N_COLUMNS,
(GType *) ColumnTypes);
......@@ -221,11 +222,12 @@ peas_gtk_plugin_manager_store_set_property (GObject *object,
GParamSpec *pspec)
{
PeasGtkPluginManagerStore *store = PEAS_GTK_PLUGIN_MANAGER_STORE (object);
PeasGtkPluginManagerStorePrivate *priv = GET_PRIV (store);
switch (prop_id)
{
case PROP_ENGINE:
store->priv->engine = g_value_get_object (value);
priv->engine = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -240,11 +242,12 @@ peas_gtk_plugin_manager_store_get_property (GObject *object,
GParamSpec *pspec)
{
PeasGtkPluginManagerStore *store = PEAS_GTK_PLUGIN_MANAGER_STORE (object);
PeasGtkPluginManagerStorePrivate *priv = GET_PRIV (store);
switch (prop_id)
{
case PROP_ENGINE:
g_value_set_object (value, store->priv->engine);
g_value_set_object (value, priv->engine);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -256,18 +259,19 @@ static void
peas_gtk_plugin_manager_store_constructed (GObject *object)
{
PeasGtkPluginManagerStore *store = PEAS_GTK_PLUGIN_MANAGER_STORE (object);
PeasGtkPluginManagerStorePrivate *priv = GET_PRIV (store);
if (store->priv->engine == NULL)
store->priv->engine = peas_engine_get_default ();
if (priv->engine == NULL)
priv->engine = peas_engine_get_default ();
g_object_ref (store->priv->engine);
g_object_ref (priv->engine);
g_signal_connect_object (store->priv->engine,
g_signal_connect_object (priv->engine,
"load-plugin",
G_CALLBACK (plugin_loaded_toggled_cb),
store,
G_CONNECT_AFTER);
g_signal_connect_object (store->priv->engine,
g_signal_connect_object (priv->engine,
"unload-plugin",
G_CALLBACK (plugin_loaded_toggled_cb),
store,
......@@ -282,8 +286,9 @@ static void
peas_gtk_plugin_manager_store_dispose (GObject *object)
{
PeasGtkPluginManagerStore *store = PEAS_GTK_PLUGIN_MANAGER_STORE (object);
PeasGtkPluginManagerStorePrivate *priv = GET_PRIV (store);
g_clear_object (&store->priv->engine);
g_clear_object (&priv->engine);
G_OBJECT_CLASS (peas_gtk_plugin_manager_store_parent_class)->dispose (object);
}
......@@ -313,7 +318,6 @@ peas_gtk_plugin_manager_store_class_init (PeasGtkPluginManagerStoreClass *klass)
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
g_type_class_add_private (object_class, sizeof (PeasGtkPluginManagerStorePrivate));
}
/*
......@@ -345,6 +349,7 @@ peas_gtk_plugin_manager_store_new (PeasEngine *engine)
void
peas_gtk_plugin_manager_store_reload (PeasGtkPluginManagerStore *store)
{
PeasGtkPluginManagerStorePrivate *priv = GET_PRIV (store);
GtkListStore *list_store;
const GList *plugins;
GtkTreeIter iter;
......@@ -355,7 +360,7 @@ peas_gtk_plugin_manager_store_reload (PeasGtkPluginManagerStore *store)
gtk_list_store_clear (list_store);
plugins = peas_engine_get_plugin_list (store->priv->engine);
plugins = peas_engine_get_plugin_list (priv->engine);
while (plugins != NULL)
{
......@@ -386,6 +391,7 @@ peas_gtk_plugin_manager_store_set_enabled (PeasGtkPluginManagerStore *store,
GtkTreeIter *iter,
gboolean enabled)
{
PeasGtkPluginManagerStorePrivate *priv = GET_PRIV (store);
PeasPluginInfo *info;
g_return_if_fail (PEAS_GTK_IS_PLUGIN_MANAGER_STORE (store));
......@@ -397,11 +403,11 @@ peas_gtk_plugin_manager_store_set_enabled (PeasGtkPluginManagerStore *store,
if (enabled)
{
peas_engine_load_plugin (store->priv->engine, info);
peas_engine_load_plugin (priv->engine, info);
}
else
{
peas_engine_unload_plugin (store->priv->engine, info);
peas_engine_unload_plugin (priv->engine, info);
}
/* Don't need to manually update the plugin as
......
......@@ -55,13 +55,9 @@ typedef enum {
typedef struct _PeasGtkPluginManagerStore PeasGtkPluginManagerStore;
typedef struct _PeasGtkPluginManagerStoreClass PeasGtkPluginManagerStoreClass;
typedef struct _PeasGtkPluginManagerStorePrivate PeasGtkPluginManagerStorePrivate;
struct _PeasGtkPluginManagerStore {
GtkListStore parent;
/*< private > */
PeasGtkPluginManagerStorePrivate *priv;
};
struct _PeasGtkPluginManagerStoreClass {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -42,8 +42,6 @@
* the same purpose.
**/
G_DEFINE_ABSTRACT_TYPE (PeasExtensionBase, peas_extension_base, G_TYPE_OBJECT)
struct _PeasExtensionBasePrivate {
PeasPluginInfo *info;
};
......@@ -58,6 +56,13 @@ enum {
static GParamSpec *properties[N_PROPERTIES] = { NULL };
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (PeasExtensionBase,
peas_extension_base,
G_TYPE_OBJECT)
#define GET_PRIV(o) \
(peas_extension_base_get_instance_private (o))
static void
peas_extension_base_get_property (GObject *object,
guint prop_id,
......@@ -87,11 +92,12 @@ peas_extension_base_set_property (GObject *object,
GParamSpec *pspec)
{
PeasExtensionBase *extbase = PEAS_EXTENSION_BASE (object);
PeasExtensionBasePrivate *priv = GET_PRIV (extbase);
switch (prop_id)
{
case PROP_PLUGIN_INFO:
extbase->priv->info = g_value_get_boxed (value);
priv->info = g_value_get_boxed (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -102,9 +108,6 @@ peas_extension_base_set_property (GObject *object,
static void
peas_extension_base_init (PeasExtensionBase *extbase)
{
extbase->priv = G_TYPE_INSTANCE_GET_PRIVATE (extbase,
PEAS_TYPE_EXTENSION_BASE,
PeasExtensionBasePrivate);
}
static void
......@@ -134,7 +137,6 @@ peas_extension_base_class_init (PeasExtensionBaseClass *klass)
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
g_type_class_add_private (klass, sizeof (PeasExtensionBasePrivate));
}
/**
......@@ -149,9 +151,11 @@ peas_extension_base_class_init (PeasExtensionBaseClass *klass)
PeasPluginInfo *
peas_extension_base_get_plugin_info (PeasExtensionBase *extbase)
{
PeasExtensionBasePrivate *priv = GET_PRIV (extbase);
g_return_val_if_fail (PEAS_IS_EXTENSION_BASE (extbase), NULL);
return extbase->priv->info;
return priv->info;
}
/**
......@@ -167,7 +171,9 @@ peas_extension_base_get_plugin_info (PeasExtensionBase *extbase)
gchar *
peas_extension_base_get_data_dir (PeasExtensionBase *extbase)
{
PeasExtensionBasePrivate *priv = GET_PRIV (extbase);
g_return_val_if_fail (PEAS_IS_EXTENSION_BASE (extbase), NULL);
return g_strdup (peas_plugin_info_get_data_dir (extbase->priv->info));
return g_strdup (peas_plugin_info_get_data_dir (priv->info));
}
This diff is collapsed.
This diff is collapsed.
......@@ -31,13 +31,18 @@
#include "peas-object-module.h"
#include "peas-plugin-info-priv.h"
struct _PeasPluginLoaderCPrivate {
typedef struct {
GMutex lock;
GHashTable *loaded_plugins;
};
} PeasPluginLoaderCPrivate;
G_DEFINE_TYPE (PeasPluginLoaderC, peas_plugin_loader_c, PEAS_TYPE_PLUGIN_LOADER)
G_DEFINE_TYPE_WITH_PRIVATE (PeasPluginLoaderC,
peas_plugin_loader_c,
PEAS_TYPE_PLUGIN_LOADER)
#define GET_PRIV(o) \
(peas_plugin_loader_c_get_instance_private (o))
static
G_DEFINE_QUARK (peas-extension-type, extension_type)
......@@ -47,10 +52,11 @@ peas_plugin_loader_c_load (PeasPluginLoader *loader,
PeasPluginInfo *info)
{
PeasPluginLoaderC *cloader = PEAS_PLUGIN_LOADER_C (loader);
PeasPluginLoaderCPrivate *priv = GET_PRIV (cloader);
g_mutex_lock (&cloader->priv->lock);
g_mutex_lock (&priv->lock);
if (!g_hash_table_lookup_extended (cloader->priv->loaded_plugins,
if (!g_hash_table_lookup_extended (priv->loaded_plugins,
info->filename,
NULL, (gpointer *) &info->loader_data))
{
......@@ -70,11 +76,11 @@ peas_plugin_loader_c_load (PeasPluginLoader *loader,
if (!g_type_module_use (G_TYPE_MODULE (info->loader_data)))
g_clear_object (&info->loader_data);
g_hash_table_insert (cloader->priv->loaded_plugins,
g_hash_table_insert (priv->loaded_plugins,
g_strdup (info->filename), info->loader_data);
}
g_mutex_unlock (&cloader->priv->lock);
g_mutex_unlock (&priv->lock);
return info->loader_data != NULL;
}
......@@ -147,29 +153,26 @@ peas_plugin_loader_c_create_extension (PeasPluginLoader *loader,
}
static void
peas_plugin_loader_c_init (PeasPluginLoaderC *loader)
peas_plugin_loader_c_init (PeasPluginLoaderC *cloader)
{
loader->priv = G_TYPE_INSTANCE_GET_PRIVATE (loader,
PEAS_TYPE_PLUGIN_LOADER_C,
PeasPluginLoaderCPrivate);
PeasPluginLoaderCPrivate *priv = GET_PRIV (cloader);
g_mutex_init (&loader->priv->lock);
g_mutex_init (&priv->lock);
/* loaded_plugins maps PeasPluginInfo:filename to a PeasObjectModule */
loader->priv->loaded_plugins = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
NULL);
priv->loaded_plugins = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
}
static void
peas_plugin_loader_c_finalize (GObject *object)
{
PeasPluginLoaderC *cloader = PEAS_PLUGIN_LOADER_C (object);
PeasPluginLoaderCPrivate *priv = GET_PRIV (cloader);
g_mutex_clear (&cloader->priv->lock);
g_mutex_clear (&priv->lock);
g_hash_table_destroy (cloader->priv->loaded_plugins);
g_hash_table_destroy (priv->loaded_plugins);
G_OBJECT_CLASS (peas_plugin_loader_c_parent_class)->finalize (object);
}
......@@ -186,8 +189,6 @@ peas_plugin_loader_c_class_init (PeasPluginLoaderCClass *klass)
loader_class->unload = peas_plugin_loader_c_unload;
loader_class->provides_extension = peas_plugin_loader_c_provides_extension;
loader_class->create_extension = peas_plugin_loader_c_create_extension;
g_type_class_add_private (object_class, sizeof (PeasPluginLoaderCPrivate));
}
/**
......
......@@ -35,12 +35,9 @@ G_BEGIN_DECLS
typedef struct _PeasPluginLoaderC PeasPluginLoaderC;
typedef struct _PeasPluginLoaderCClass PeasPluginLoaderCClass;
typedef struct _PeasPluginLoaderCPrivate PeasPluginLoaderCPrivate;
struct _PeasPluginLoaderC {
PeasPluginLoader parent;
PeasPluginLoaderCPrivate *priv;
};
struct _PeasPluginLoaderCClass {
......
......@@ -38,15 +38,20 @@
typedef void (* LgiLockFunc) (gpointer lgi_lock);
struct _PeasPluginLoaderLuaPrivate {
typedef struct {
lua_State *L;
gpointer lgi_lock;
LgiLockFunc lgi_enter_func;
LgiLockFunc lgi_leave_func;
};
} PeasPluginLoaderLuaPrivate;
G_DEFINE_TYPE (PeasPluginLoaderLua, peas_plugin_loader_lua, PEAS_TYPE_PLUGIN_LOADER)
G_DEFINE_TYPE_WITH_PRIVATE (PeasPluginLoaderLua,
peas_plugin_loader_lua,
PEAS_TYPE_PLUGIN_LOADER)
#define GET_PRIV(o) \
(peas_plugin_loader_lua_get_instance_private (o))
static
G_DEFINE_QUARK (peas-extension-type, extension_type)
......@@ -224,12 +229,13 @@ peas_plugin_loader_lua_provides_extension (PeasPluginLoader *loader,
GType exten_type)
{
PeasPluginLoaderLua *lua_loader = PEAS_PLUGIN_LOADER_LUA (loader);
lua_State *L = lua_loader->priv->L;
PeasPluginLoaderLuaPrivate *priv = GET_PRIV (lua_loader);
lua_State *L = priv->L;
GType extension_type;
lua_loader->priv->lgi_enter_func (lua_loader->priv->lgi_lock);
priv->lgi_enter_func (priv->lgi_lock);
extension_type = _lua_find_extension_type (L, info, exten_type);
lua_loader->priv->lgi_leave_func (lua_loader->priv->lgi_lock);
priv->lgi_leave_func (priv->lgi_lock);
return extension_type != G_TYPE_INVALID;
}
......@@ -242,11 +248,12 @@ peas_plugin_loader_lua_create_extension (PeasPluginLoader *loader,
GParameter *parameters)
{
PeasPluginLoaderLua *lua_loader = PEAS_PLUGIN_LOADER_LUA (loader);
lua_State *L = lua_loader->priv->L;
PeasPluginLoaderLuaPrivate *priv = GET_PRIV (lua_loader);
lua_State *L = priv->L;
GType the_type;
GObject *object = NULL;
lua_loader->priv->lgi_enter_func (lua_loader->priv->lgi_lock);
priv->lgi_enter_func (priv->lgi_lock);
the_type = _lua_find_extension_type (L, info, exten_type);
if (the_type == G_TYPE_INVALID)
......@@ -294,7 +301,7 @@ peas_plugin_loader_lua_create_extension (PeasPluginLoader *loader,
out:
lua_loader->priv->lgi_leave_func (lua_loader->priv->lgi_lock);
priv->lgi_leave_func (priv->lgi_lock);
return object;
}
......@@ -303,10 +310,11 @@ peas_plugin_loader_lua_load (PeasPluginLoader *loader,
PeasPluginInfo *info)
{
PeasPluginLoaderLua *lua_loader = PEAS_PLUGIN_LOADER_LUA (loader);
lua_State *L = lua_loader->priv->L;
PeasPluginLoaderLuaPrivate *priv = GET_PRIV (lua_loader);
lua_State *L = priv->L;
gboolean success;
lua_loader->priv->lgi_enter_func (lua_loader->priv->lgi_lock);
priv->lgi_enter_func (priv->lgi_lock);
luaL_checkstack (L, 2, "");
......@@ -351,7 +359,7 @@ peas_plugin_loader_lua_load (PeasPluginLoader *loader,
/* Pop the module's table */
lua_pop (L, 1);
lua_loader->priv->lgi_leave_func (lua_loader->priv->lgi_lock);
priv->lgi_leave_func (priv->lgi_lock);
return success;
}
......@@ -366,10 +374,11 @@ static void
peas_plugin_loader_lua_garbage_collect (PeasPluginLoader *loader)
{
PeasPluginLoaderLua *lua_loader = PEAS_PLUGIN_LOADER_LUA (loader);
PeasPluginLoaderLuaPrivate *priv = GET_PRIV (lua_loader);
lua_loader->priv->lgi_enter_func (lua_loader->priv->lgi_lock);
lua_gc (lua_loader->priv->L, LUA_GCCOLLECT, 0);
lua_loader->priv->lgi_leave_func (lua_loader->priv->lgi_lock);
priv->lgi_enter_func (priv->lgi_lock);
lua_gc (priv->L, LUA_GCCOLLECT, 0);
priv->lgi_leave_func (priv->lgi_lock);
}
static int
......@@ -383,6 +392,7 @@ static gboolean
peas_plugin_loader_lua_initialize (PeasPluginLoader *loader)
{
PeasPluginLoaderLua *lua_loader = PEAS_PLUGIN_LOADER_LUA (loader);
PeasPluginLoaderLuaPrivate *priv = GET_PRIV (lua_loader);
lua_State *L;
L = luaL_newstate ();
......@@ -406,20 +416,20 @@ peas_plugin_loader_lua_initialize (PeasPluginLoader *loader)
}
lua_getfield (L, -1, "lock");
lua_loader->priv->lgi_lock = lua_touserdata (L, -1);
priv->lgi_lock = lua_touserdata (L, -1);
lua_pop (L, 1);
lua_getfield (L, -1, "enter");
lua_loader->priv->lgi_enter_func = lua_touserdata (L, -1);
priv->lgi_enter_func = lua_touserdata (L, -1);
lua_pop (L, 1);
lua_getfield (L, -1, "leave");
lua_loader->priv->lgi_leave_func = lua_touserdata (L, -1);
priv->lgi_leave_func = lua_touserdata (L, -1);
lua_pop (L, 1);
if (lua_loader->priv->lgi_lock == NULL ||
lua_loader->priv->lgi_enter_func == NULL ||
lua_loader->priv->lgi_leave_func == NULL)
if (priv->lgi_lock == NULL ||
priv->lgi_enter_func == NULL ||
priv->lgi_leave_func == NULL)
{
g_warning ("Failed to find 'lgi.lock', 'lgi.enter' and 'lgi.leave'");
lua_close (L);
......@@ -437,9 +447,9 @@ peas_plugin_loader_lua_initialize (PeasPluginLoader *loader)
/* Initially the lock is taken by LGI,
* release as we are not running Lua code
*/
lua_loader->priv->lgi_leave_func (lua_loader->priv->lgi_lock);
priv->lgi_leave_func (priv->lgi_lock);
lua_loader->priv->L = L;
priv->L = L;
return TRUE;
}
......@@ -452,22 +462,20 @@ peas_plugin_loader_lua_is_global (PeasPluginLoader *loader)
static void
peas_plugin_loader_lua_init (PeasPluginLoaderLua *lua_loader)
{
lua_loader->priv = G_TYPE_INSTANCE_GET_PRIVATE (lua_loader,
PEAS_TYPE_PLUGIN_LOADER_LUA,
PeasPluginLoaderLuaPrivate);
}
static void
peas_plugin_loader_lua_finalize (GObject *object)
{
PeasPluginLoaderLua *lua_loader = PEAS_PLUGIN_LOADER_LUA (object);
PeasPluginLoaderLuaPrivate *priv = GET_PRIV (lua_loader);
/* Must take the lock as Lua code will run on lua_close
* and another thread might be running Lua code already
*/
lua_loader->priv->lgi_enter_func (lua_loader->priv->lgi_lock);
priv->lgi_enter_func (priv->lgi_lock);
g_clear_pointer (&lua_loader->priv->L, (GDestroyNotify) lua_close);
g_clear_pointer (&priv->L, (GDestroyNotify) lua_close);
G_OBJECT_CLASS (peas_plugin_loader_lua_parent_class)->finalize (object);
}
......@@ -487,6 +495,4 @@ peas_plugin_loader_lua_class_init (PeasPluginLoaderLuaClass *klass)
loader_class->create_extension = peas_plugin_loader_lua_create_extension;
loader_class->provides_extension = peas_plugin_loader_lua_provides_extension;
loader_class->garbage_collect = peas_plugin_loader_lua_garbage_collect;
g_type_class_add_private (object_class, sizeof (PeasPluginLoaderLuaPrivate));
}
......@@ -37,12 +37,9 @@ G_BEGIN_DECLS
typedef struct _PeasPluginLoaderLua PeasPluginLoaderLua;
typedef struct _PeasPluginLoaderLuaClass PeasPluginLoaderLuaClass;
typedef struct _PeasPluginLoaderLuaPrivate PeasPluginLoaderLuaPrivate;
struct _PeasPluginLoaderLua {
PeasPluginLoader parent;
PeasPluginLoaderLuaPrivate *priv;
};
struct _PeasPluginLoaderLuaClass {
......
......@@ -41,7 +41,7 @@ typedef int Py_ssize_t;
#define PY_SSIZE_T_MIN INT_MIN
#endif
struct _PeasPluginLoaderPythonPrivate {
typedef struct {