From 8d91b142fb58b95435a1850ac51b349c39fbabcf Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 20 Mar 2023 15:34:08 -0700 Subject: loaders/python: modernize GType definitions --- loaders/python/peas-plugin-loader-python.c | 47 +++++++++++++----------------- loaders/python/peas-plugin-loader-python.h | 24 ++------------- 2 files changed, 23 insertions(+), 48 deletions(-) diff --git a/loaders/python/peas-plugin-loader-python.c b/loaders/python/peas-plugin-loader-python.c index c51529f..b1c6099 100644 --- a/loaders/python/peas-plugin-loader-python.c +++ b/loaders/python/peas-plugin-loader-python.c @@ -34,21 +34,18 @@ #undef _POSIX_C_SOURCE #include -typedef struct { +struct _PeasPluginLoaderPython { + PeasPluginLoader parent_instance; + PyThreadState *py_thread_state; guint n_loaded_plugins; guint init_failed : 1; guint must_finalize_python : 1; -} PeasPluginLoaderPythonPrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (PeasPluginLoaderPython, - peas_plugin_loader_python, - PEAS_TYPE_PLUGIN_LOADER) +}; -#define GET_PRIV(o) \ - (peas_plugin_loader_python_get_instance_private (o)) +G_DEFINE_FINAL_TYPE (PeasPluginLoaderPython, peas_plugin_loader_python, PEAS_TYPE_PLUGIN_LOADER) static GQuark quark_extension_type = 0; @@ -162,7 +159,6 @@ peas_plugin_loader_python_load (PeasPluginLoader *loader, PeasPluginInfo *info) { PeasPluginLoaderPython *pyloader = PEAS_PLUGIN_LOADER_PYTHON (loader); - PeasPluginLoaderPythonPrivate *priv = GET_PRIV (pyloader); const gchar *module_dir, *module_name; PyObject *pymodule; PyGILState_STATE state = PyGILState_Ensure (); @@ -177,7 +173,7 @@ peas_plugin_loader_python_load (PeasPluginLoader *loader, if (pymodule != NULL) { info->loader_data = pymodule; - priv->n_loaded_plugins += 1; + pyloader->n_loaded_plugins += 1; } PyGILState_Release (state); @@ -189,13 +185,12 @@ peas_plugin_loader_python_unload (PeasPluginLoader *loader, PeasPluginInfo *info) { PeasPluginLoaderPython *pyloader = PEAS_PLUGIN_LOADER_PYTHON (loader); - PeasPluginLoaderPythonPrivate *priv = GET_PRIV (pyloader); PyGILState_STATE state = PyGILState_Ensure (); /* We have to use this as a hook as the * loader will not be finalized by applications */ - if (--priv->n_loaded_plugins == 0) + if (--pyloader->n_loaded_plugins == 0) peas_python_internal_call ("all_plugins_unloaded", NULL, NULL); Py_CLEAR (info->loader_data); @@ -216,7 +211,6 @@ static gboolean peas_plugin_loader_python_initialize (PeasPluginLoader *loader) { PeasPluginLoaderPython *pyloader = PEAS_PLUGIN_LOADER_PYTHON (loader); - PeasPluginLoaderPythonPrivate *priv = GET_PRIV (pyloader); PyGILState_STATE state = 0; long hexversion; @@ -232,7 +226,7 @@ peas_plugin_loader_python_initialize (PeasPluginLoader *loader) else { Py_InitializeEx (FALSE); - priv->must_finalize_python = TRUE; + pyloader->must_finalize_python = TRUE; } hexversion = PyLong_AsLong (PySys_GetObject ((char *) "hexversion")); @@ -266,20 +260,20 @@ peas_plugin_loader_python_initialize (PeasPluginLoader *loader) PyEval_InitThreads (); /* Only redirect warnings when python was not already initialized */ - if (!priv->must_finalize_python) + if (!pyloader->must_finalize_python) pyg_disable_warning_redirections (); /* Must be done last, finalize() depends on init_failed */ - if (!peas_python_internal_setup (!priv->must_finalize_python)) + if (!peas_python_internal_setup (!pyloader->must_finalize_python)) { /* Already warned */ goto python_init_error; } - if (!priv->must_finalize_python) + if (!pyloader->must_finalize_python) PyGILState_Release (state); else - priv->py_thread_state = PyEval_SaveThread (); + pyloader->py_thread_state = PyEval_SaveThread (); return TRUE; @@ -291,10 +285,10 @@ python_init_error: g_warning ("Please check the installation of all the Python " "related packages required by libpeas and try again"); - if (!priv->must_finalize_python) + if (!pyloader->must_finalize_python) PyGILState_Release (state); - priv->init_failed = TRUE; + pyloader->init_failed = TRUE; return FALSE; } @@ -307,27 +301,26 @@ static void peas_plugin_loader_python_finalize (GObject *object) { PeasPluginLoaderPython *pyloader = PEAS_PLUGIN_LOADER_PYTHON (object); - PeasPluginLoaderPythonPrivate *priv = GET_PRIV (pyloader); PyGILState_STATE state; if (!Py_IsInitialized ()) goto out; - g_warn_if_fail (priv->n_loaded_plugins == 0); + g_warn_if_fail (pyloader->n_loaded_plugins == 0); - if (!priv->init_failed) + if (!pyloader->init_failed) { state = PyGILState_Ensure (); peas_python_internal_shutdown (); PyGILState_Release (state); } - if (priv->py_thread_state) - PyEval_RestoreThread (priv->py_thread_state); + if (pyloader->py_thread_state) + PyEval_RestoreThread (pyloader->py_thread_state); - if (priv->must_finalize_python) + if (pyloader->must_finalize_python) { - if (!priv->init_failed) + if (!pyloader->init_failed) PyGILState_Ensure (); Py_Finalize (); diff --git a/loaders/python/peas-plugin-loader-python.h b/loaders/python/peas-plugin-loader-python.h index f634d59..d816260 100644 --- a/loaders/python/peas-plugin-loader-python.h +++ b/loaders/python/peas-plugin-loader-python.h @@ -29,28 +29,10 @@ G_BEGIN_DECLS -#define PEAS_TYPE_PLUGIN_LOADER_PYTHON (peas_plugin_loader_python_get_type ()) -#define PEAS_PLUGIN_LOADER_PYTHON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PEAS_TYPE_PLUGIN_LOADER_PYTHON, PeasPluginLoaderPython)) -#define PEAS_PLUGIN_LOADER_PYTHON_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PEAS_TYPE_PLUGIN_LOADER_PYTHON, PeasPluginLoaderPython const)) -#define PEAS_PLUGIN_LOADER_PYTHON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PEAS_TYPE_PLUGIN_LOADER_PYTHON, PeasPluginLoaderPythonClass)) -#define PEAS_IS_PLUGIN_LOADER_PYTHON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PEAS_TYPE_PLUGIN_LOADER_PYTHON)) -#define PEAS_IS_PLUGIN_LOADER_PYTHON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PEAS_TYPE_PLUGIN_LOADER_PYTHON)) -#define PEAS_PLUGIN_LOADER_PYTHON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PEAS_TYPE_PLUGIN_LOADER_PYTHON, PeasPluginLoaderPythonClass)) +#define PEAS_TYPE_PLUGIN_LOADER_PYTHON (peas_plugin_loader_python_get_type()) -typedef struct _PeasPluginLoaderPython PeasPluginLoaderPython; -typedef struct _PeasPluginLoaderPythonClass PeasPluginLoaderPythonClass; +G_DECLARE_FINAL_TYPE (PeasPluginLoaderPython, peas_plugin_loader_python, PEAS, PLUGIN_LOADER_PYTHON, PeasPluginLoader) -struct _PeasPluginLoaderPython { - PeasPluginLoader parent; -}; - -struct _PeasPluginLoaderPythonClass { - PeasPluginLoaderClass parent_class; -}; - -GType peas_plugin_loader_python_get_type (void) G_GNUC_CONST; - -/* All the loaders must implement this function */ -G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS -- cgit v1.2.1