summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2024-05-20 15:15:25 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2024-05-20 15:15:25 (GMT)
commit6decc8c40dfaf7cb04156f1ab233cd856ed06b37 (patch)
tree7a326fc66d2465bdedc978146faef55e53531652
parent79662ede83b35ad9d91b942218cf09e856e48b4c (diff)
Improve the DECLARE_GTYPE() macro and use it everywhere.
-rw-r--r--src/analysis/content.h17
-rw-r--r--src/analysis/contents/encapsulated.h18
-rw-r--r--src/analysis/contents/file.h18
-rw-r--r--src/analysis/contents/memory.h18
-rw-r--r--src/analysis/contents/restricted.h18
-rw-r--r--src/glibext/helpers.h60
-rw-r--r--src/plugins/plugin.h18
7 files changed, 48 insertions, 119 deletions
diff --git a/src/analysis/content.h b/src/analysis/content.h
index ad50c02..ce6810f 100644
--- a/src/analysis/content.h
+++ b/src/analysis/content.h
@@ -32,26 +32,15 @@
//#include "cattribs.h" // FIXME
#include "../arch/vmpa.h"
#include "../common/leb128.h"
+#include "../glibext/helpers.h"
-#define G_TYPE_BIN_CONTENT g_binary_content_get_type()
-#define G_BIN_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_BIN_CONTENT, GBinContent))
-#define G_IS_BIN_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_BIN_CONTENT))
-#define G_BIN_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BIN_CONTENT, GBinContentClass))
-#define G_IS_BIN_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BIN_CONTENT))
-#define G_BIN_CONTENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BIN_CONTENT, GBinContentClass))
+#define G_TYPE_BIN_CONTENT (g_binary_content_get_type())
+DECLARE_GTYPE(GBinContent, g_binary_content, G, BIN_CONTENT);
-/* Accès à un contenu binaire quelconque (instance) */
-typedef struct _GBinContent GBinContent;
-/* Accès à un contenu binaire quelconque (classe) */
-typedef struct _GBinContentClass GBinContentClass;
-
-
-/* Détermine le type d'un contenu binaire à parcourir. */
-GType g_binary_content_get_type(void) G_GNUC_CONST;
#if 0 // FIXME
/* Associe un ensemble d'attributs au contenu binaire. */
void g_binary_content_set_attributes(GBinContent *, GContentAttributes *);
diff --git a/src/analysis/contents/encapsulated.h b/src/analysis/contents/encapsulated.h
index 9b74eac..bfd17e7 100644
--- a/src/analysis/contents/encapsulated.h
+++ b/src/analysis/contents/encapsulated.h
@@ -29,26 +29,14 @@
#include "../content.h"
+#include "../../glibext/helpers.h"
-#define G_TYPE_ENCAPS_CONTENT (g_encaps_content_get_type())
-#define G_ENCAPS_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_ENCAPS_CONTENT, GEncapsContent))
-#define G_IS_ENCAPS_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_ENCAPS_CONTENT))
-#define G_ENCAPS_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ENCAPS_CONTENT, GEncapsContentClass))
-#define G_IS_ENCAPS_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ENCAPS_CONTENT))
-#define G_ENCAPS_CONTENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ENCAPS_CONTENT, GEncapsContentClass))
+#define G_TYPE_ENCAPS_CONTENT (g_encaps_content_get_type())
+DECLARE_GTYPE(GEncapsContent, g_encaps_content, G, ENCAPS_CONTENT);
-/* Contenu de issu d'un contenu plus global (instance) */
-typedef struct _GEncapsContent GEncapsContent;
-
-/* Contenu de issu d'un contenu plus global (classe) */
-typedef struct _GEncapsContentClass GEncapsContentClass;
-
-
-/* Indique le type défini par la GLib pour les contenus encapsulés. */
-GType g_encaps_content_get_type(void);
/* Charge en mémoire un contenu binaire encapsulé. */
GBinContent *g_encaps_content_new(GBinContent *, const char *, GBinContent *);
diff --git a/src/analysis/contents/file.h b/src/analysis/contents/file.h
index 5039f81..c54d890 100644
--- a/src/analysis/contents/file.h
+++ b/src/analysis/contents/file.h
@@ -29,26 +29,14 @@
#include "../content.h"
+#include "../../glibext/helpers.h"
-#define G_TYPE_FILE_CONTENT (g_file_content_get_type())
-#define G_FILE_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_FILE_CONTENT, GFileContent))
-#define G_IS_FILE_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_FILE_CONTENT))
-#define G_FILE_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_FILE_CONTENT, GFileContentClass))
-#define G_IS_FILE_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_FILE_CONTENT))
-#define G_FILE_CONTENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_FILE_CONTENT, GFileContentClass))
+#define G_TYPE_FILE_CONTENT (g_file_content_get_type())
+DECLARE_GTYPE(GFileContent, g_file_content, G, FILE_CONTENT);
-/* Contenu de données binaires issues d'un fichier (instance) */
-typedef struct _GFileContent GFileContent;
-
-/* Contenu de données binaires issues d'un fichier (classe) */
-typedef struct _GFileContentClass GFileContentClass;
-
-
-/* Indique le type défini par la GLib pour les contenus de données. */
-GType g_file_content_get_type(void);
/* Charge en mémoire le contenu d'un fichier donné. */
GBinContent *g_file_content_new(const char *);
diff --git a/src/analysis/contents/memory.h b/src/analysis/contents/memory.h
index 1759e69..20e3d18 100644
--- a/src/analysis/contents/memory.h
+++ b/src/analysis/contents/memory.h
@@ -29,26 +29,14 @@
#include "../content.h"
+#include "../../glibext/helpers.h"
-#define G_TYPE_MEMORY_CONTENT (g_memory_content_get_type())
-#define G_MEMORY_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_MEMORY_CONTENT, GMemoryContent))
-#define G_IS_MEMORY_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_MEMORY_CONTENT))
-#define G_MEMORY_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_MEMORY_CONTENT, GMemoryContentClass))
-#define G_IS_MEMORY_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_MEMORY_CONTENT))
-#define G_MEMORY_CONTENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_MEMORY_CONTENT, GMemoryContentClass))
+#define G_TYPE_MEMORY_CONTENT (g_memory_content_get_type())
+DECLARE_GTYPE(GMemoryContent, g_memory_content, G, MEMORY_CONTENT);
-/* Contenu de données binaires résidant en mémoire (instance) */
-typedef struct _GMemoryContent GMemoryContent;
-
-/* Contenu de données binaires résidant en mémoire (classe) */
-typedef struct _GMemoryContentClass GMemoryContentClass;
-
-
-/* Indique le type défini par la GLib pour les contenus de données en mémoire. */
-GType g_memory_content_get_type(void);
/* Charge en mémoire le contenu de données brutes. */
GBinContent *g_memory_content_new(const bin_t *, phys_t);
diff --git a/src/analysis/contents/restricted.h b/src/analysis/contents/restricted.h
index 1cea390..3925233 100644
--- a/src/analysis/contents/restricted.h
+++ b/src/analysis/contents/restricted.h
@@ -29,26 +29,14 @@
#include "../content.h"
+#include "../../glibext/helpers.h"
-#define G_TYPE_RESTRICTED_CONTENT (g_restricted_content_get_type())
-#define G_RESTRICTED_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_RESTRICTED_CONTENT, GRestrictedContent))
-#define G_IS_RESTRICTED_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_RESTRICTED_CONTENT))
-#define G_RESTRICTED_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_RESTRICTED_CONTENT, GRestrictedContentClass))
-#define G_IS_RESTRICTED_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_RESTRICTED_CONTENT))
-#define G_RESTRICTED_CONTENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_RESTRICTED_CONTENT, GRestrictedContentClass))
+#define G_TYPE_RESTRICTED_CONTENT (g_restricted_content_get_type())
+DECLARE_GTYPE(GRestrictedContent, g_restricted_content, G, RESTRICTED_CONTENT);
-/* Contenu de données binaires issues d'un contenu restreint (instance) */
-typedef struct _GRestrictedContent GRestrictedContent;
-
-/* Contenu de données binaires issues d'un contenu restreint (classe) */
-typedef struct _GRestrictedContentClass GRestrictedContentClass;
-
-
-/* Indique le type défini par la GLib pour les contenus de données. */
-GType g_restricted_content_get_type(void);
/* Charge en mémoire le contenu d'un contenu restreint. */
GBinContent *g_restricted_content_new(GBinContent *, const mrange_t *);
diff --git a/src/glibext/helpers.h b/src/glibext/helpers.h
index 752eb07..71a7269 100644
--- a/src/glibext/helpers.h
+++ b/src/glibext/helpers.h
@@ -56,36 +56,36 @@
* préalable de manière globale et cohérente dans l'ensemble du code d'emploi.
*/
-#define DECLARE_GTYPE(TN, t_n, MOD, NAME) \
- \
- GType t_n##_get_type(void); \
- \
- typedef struct _##TN TN; \
- typedef struct _##TN##Class TN##Class; \
- \
- G_GNUC_UNUSED static inline TN *MOD##_##NAME(gpointer obj) \
- { \
- return G_TYPE_CHECK_INSTANCE_CAST(obj, MOD##_TYPE_##NAME, TN); \
- } \
- \
- G_GNUC_UNUSED static inline TN##Class *MOD##_##NAME##_CLASS(gpointer klass) \
- { \
- return G_TYPE_CHECK_CLASS_CAST(klass, MOD##_TYPE_##NAME, TN##Class); \
- } \
- \
- G_GNUC_UNUSED static inline gboolean MOD##_IS_##NAME(gpointer obj) \
- { \
- return G_TYPE_CHECK_INSTANCE_TYPE(obj, MOD##_TYPE_##NAME); \
- } \
- \
- G_GNUC_UNUSED static inline gboolean MOD##_IS_##NAME##_CLASS(gpointer klass) \
- { \
- return G_TYPE_CHECK_CLASS_TYPE(klass, MOD##_TYPE_##NAME); \
- } \
- \
- G_GNUC_UNUSED static inline TN##Class *MOD##_##NAME##_GET_CLASS(gpointer obj) \
- { \
- return G_TYPE_INSTANCE_GET_CLASS(obj, MOD##_TYPE_##NAME, TN##Class); \
+#define DECLARE_GTYPE(TN, t_n, MOD, NAME) \
+ \
+ GType t_n##_get_type(void) G_GNUC_CONST; \
+ \
+ typedef struct _##TN TN; \
+ typedef struct _##TN##Class TN##Class; \
+ \
+ G_GNUC_UNUSED static inline TN *MOD##_##NAME(gconstpointer obj) \
+ { \
+ return G_TYPE_CHECK_INSTANCE_CAST(obj, MOD##_TYPE_##NAME, TN); \
+ } \
+ \
+ G_GNUC_UNUSED static inline TN##Class *MOD##_##NAME##_CLASS(gconstpointer klass) \
+ { \
+ return G_TYPE_CHECK_CLASS_CAST(klass, MOD##_TYPE_##NAME, TN##Class); \
+ } \
+ \
+ G_GNUC_UNUSED static inline gboolean MOD##_IS_##NAME(gconstpointer obj) \
+ { \
+ return G_TYPE_CHECK_INSTANCE_TYPE(obj, MOD##_TYPE_##NAME); \
+ } \
+ \
+ G_GNUC_UNUSED static inline gboolean MOD##_IS_##NAME##_CLASS(gconstpointer klass) \
+ { \
+ return G_TYPE_CHECK_CLASS_TYPE(klass, MOD##_TYPE_##NAME); \
+ } \
+ \
+ G_GNUC_UNUSED static inline TN##Class *MOD##_##NAME##_GET_CLASS(gconstpointer obj) \
+ { \
+ return G_TYPE_INSTANCE_GET_CLASS(obj, MOD##_TYPE_##NAME, TN##Class); \
}
diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h
index 7e51f6e..5c473b2 100644
--- a/src/plugins/plugin.h
+++ b/src/plugins/plugin.h
@@ -31,6 +31,7 @@
#include "plugin-def.h"
#include "../core/logs.h"
+#include "../glibext/helpers.h"
#if 0
#include "../analysis/binary.h"
#include "../core/logs.h"
@@ -46,11 +47,9 @@
-/* Greffon pour Chrysalide (instance) */
-typedef struct _GPluginModule GPluginModule;
+#define G_TYPE_PLUGIN_MODULE (g_plugin_module_get_type())
-/* Greffon pour Chrysalide (classe) */
-typedef struct _GPluginModuleClass GPluginModuleClass;
+DECLARE_GTYPE(GPluginModule, g_plugin_module, G, PLUGIN_MODULE);
/* Fanions indiquant le statut du greffon */
@@ -68,17 +67,6 @@ typedef enum _PluginStatusFlags
#define BROKEN_PLUGIN_STATUS (PSF_UNKNOW_DEP | PSF_DEP_LOOP | PSF_FAILURE)
-#define G_TYPE_PLUGIN_MODULE (g_plugin_module_get_type())
-#define G_PLUGIN_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_PLUGIN_MODULE, GPluginModule))
-#define G_IS_PLUGIN_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_PLUGIN_MODULE))
-#define G_PLUGIN_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_PLUGIN_MODULE, GPluginModuleClass))
-#define G_IS_PLUGIN_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_PLUGIN_MODULE))
-#define G_PLUGIN_MODULE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_PLUGIN_MODULE, GPluginModuleClass))
-
-
-/* Indique le type défini pour un greffon. */
-GType g_plugin_module_get_type(void);
-
/* Crée un module pour un greffon donné. */
GPluginModule *g_plugin_module_new(const gchar *);