Skip to content

Commit

Permalink
Merge Richard Cohen's 'remove-gnc-define-type' into stable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jralls committed Jun 16, 2023
2 parents 827bfab + 68b689c commit 0c6ae19
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 144 deletions.
32 changes: 21 additions & 11 deletions gnucash/gnome-utils/gnc-embedded-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static QofLogModule log_module = GNC_MOD_GUI;


/* Declarations *********************************************************/
static void gnc_embedded_window_constructed (GObject *object);
static void gnc_embedded_window_finalize (GObject *object);
static void gnc_embedded_window_dispose (GObject *object);

Expand Down Expand Up @@ -98,10 +99,10 @@ typedef struct GncEmbeddedWindowPrivate
GtkWidget *parent_window;
} GncEmbeddedWindowPrivate;

GNC_DEFINE_TYPE_WITH_CODE(GncEmbeddedWindow, gnc_embedded_window, GTK_TYPE_BOX,
G_DEFINE_TYPE_WITH_CODE(GncEmbeddedWindow, gnc_embedded_window, GTK_TYPE_BOX,
G_ADD_PRIVATE(GncEmbeddedWindow)
GNC_IMPLEMENT_INTERFACE(GNC_TYPE_WINDOW,
gnc_window_embedded_window_init))
G_IMPLEMENT_INTERFACE(GNC_TYPE_WINDOW,
gnc_window_embedded_window_init))

#define GNC_EMBEDDED_WINDOW_GET_PRIVATE(o) \
((GncEmbeddedWindowPrivate*)gnc_embedded_window_get_instance_private((GncEmbeddedWindow*)o))
Expand Down Expand Up @@ -187,6 +188,7 @@ gnc_embedded_window_class_init (GncEmbeddedWindowClass *klass)
ENTER("klass %p", klass);
object_class = G_OBJECT_CLASS (klass);

object_class->constructed = gnc_embedded_window_constructed;
object_class->finalize = gnc_embedded_window_finalize;
object_class->dispose = gnc_embedded_window_dispose;

Expand Down Expand Up @@ -215,17 +217,14 @@ gnc_embedded_window_class_init (GncEmbeddedWindowClass *klass)


/** Initialize a new instance of a gnucash embedded window. This
* function initializes the object private storage space. It also
* adds the new object to a list (for memory tracking purposes).
* function initializes the object private storage space.
*
* @param view The new object instance created by the object system.
*
* @param klass A pointer to the class data structure for this
* object. */
* */
static void
gnc_embedded_window_init (GncEmbeddedWindow *window, void *data)
gnc_embedded_window_init (GncEmbeddedWindow *window)
{
GncEmbeddedWindowClass *klass = (GncEmbeddedWindowClass*)data;
ENTER("window %p", window);

gtk_orientable_set_orientation (GTK_ORIENTABLE(window), GTK_ORIENTATION_VERTICAL);
Expand All @@ -235,11 +234,22 @@ gnc_embedded_window_init (GncEmbeddedWindow *window, void *data)

gnc_embedded_window_setup_window (window);

gnc_gobject_tracking_remember (G_OBJECT(window),
G_OBJECT_CLASS(klass));
LEAVE(" ");
}

/** The object has been fully constructed.
* This function adds the object to the tracking system.
*
* @param obj The new object instance created by the object
* system.
*/
static void
gnc_embedded_window_constructed (GObject *obj)
{
gnc_gobject_tracking_remember(obj);

G_OBJECT_CLASS (gnc_embedded_window_parent_class)->constructed (obj);
}

/** Finish destruction of an embedded window.
*
Expand Down
19 changes: 5 additions & 14 deletions gnucash/gnome-utils/gnc-gobject-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,16 @@ gnc_gobject_tracking_dump (void)
/** Tell gnucash to remember this object in the database.
*/
void
gnc_gobject_tracking_remember (GObject *object, GObjectClass *klass)
gnc_gobject_tracking_remember (GObject *object)
{
GHashTable *table;
GList *list;
const gchar *name;

g_return_if_fail(G_IS_OBJECT(object));

/* Little dance here to handle startup conditions. During object
* initialization the object type changes as each parent class
* is initialized. The class passed to the initialization function
* is always the ultimate class of the object. */
if (klass == NULL)
klass = G_OBJECT_GET_CLASS(object);
name = g_type_name(G_TYPE_FROM_CLASS(klass));
GObjectClass *klass = G_OBJECT_GET_CLASS(object);
const gchar *name = g_type_name(G_TYPE_FROM_CLASS(klass));

//printf("Enter %s: object %p of type %s\n", G_STRFUNC, object, name);
table = gnc_gobject_tracking_table();
list = g_hash_table_lookup(table, name);
GHashTable *table = gnc_gobject_tracking_table();
GList *list = g_hash_table_lookup(table, name);

if (g_list_index(list, object) != -1)
{
Expand Down
70 changes: 2 additions & 68 deletions gnucash/gnome-utils/gnc-gobject-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,9 @@ extern "C" {

/** Tell gnucash to remember this object in the database.
*
* @param object The object to be tracked. This can be a fully or
* partially instantiated object.
*
* @param klass The class structure for the object. This argument
* may be NULL if a fully instantiated object is passed in as the
* first argument. If a partially instantiated object is provided
* (I.E. a parent class called this function) then this argument is
* required. This is necessary because the class of the object
* changes as each of the parent class is instantiated. The class
* structure, however, status constant and always reflects the fully
* instantiated object.
* @param object The fully constructed object to be tracked.
*/
void gnc_gobject_tracking_remember (GObject *object, GObjectClass *klass);
void gnc_gobject_tracking_remember (GObject *object);

/** Tell gnucash to drop this object from the database.
*
Expand Down Expand Up @@ -113,62 +103,6 @@ void gnc_gobject_tracking_dump (void);

/** @} */

/** Some macros derived from glib type macros.
* In glib type_name##init function only has one parameter. We need
* the 2nd class parameter in certain calls. The main difference is
* static void type_name##_init (TypeName *self, void *class);
* instead of
* static void type_name##_init (TypeName *self);
* this code may need updating in future releases as glib changes.
**/
#define GNC_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) { \
const GInterfaceInfo g_implement_interface_info = { \
(GInterfaceInitFunc)(void (*)(void *, void *)) iface_init, NULL, NULL \
}; \
g_type_add_interface_static (g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \
}

#define GNC_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _GNC_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, 0) {_C_;} _GNC_DEFINE_TYPE_EXTENDED_END()

#define _GNC_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
\
static void type_name##_init (TypeName *self, void *klass); \
static void type_name##_class_init (TypeName##Class *klass); \
static gpointer type_name##_parent_class = NULL; \
static gint TypeName##_private_offset; \
\
_G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
\
G_GNUC_UNUSED \
static inline gpointer \
type_name##_get_instance_private (TypeName *self) \
{ \
return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \
} \
\
GType \
type_name##_get_type (void) \
{ \
static gsize g_define_type_id_static = 0; \
if (g_once_init_enter (&g_define_type_id_static)) \
{ \
GType g_define_type_id = \
g_type_register_static_simple (TYPE_PARENT, \
g_intern_static_string (#TypeName), \
sizeof (TypeName##Class), \
(GClassInitFunc) type_name##_class_intern_init, \
sizeof (TypeName), \
(GInstanceInitFunc) type_name##_init, \
(GTypeFlags) flags); \
{ /* custom code follows */
#define _GNC_DEFINE_TYPE_EXTENDED_END() \
/* following custom code */ \
} \
g_once_init_leave (&g_define_type_id_static, g_define_type_id); \
} \
return g_define_type_id_static; \
} /* closes type_name##_get_type() */

#ifdef __cplusplus
}
#endif
Expand Down
34 changes: 20 additions & 14 deletions gnucash/gnome-utils/gnc-main-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ static guint secs_to_save = 0;
#define MSG_AUTO_SAVE _("Changes will be saved automatically in %u seconds")

/* Declarations *********************************************************/
static void gnc_main_window_constructed (GObject *object);
static void gnc_main_window_finalize (GObject *object);
static void gnc_main_window_destroy (GtkWidget *widget);

Expand Down Expand Up @@ -259,7 +260,7 @@ typedef struct GncMainWindowPrivate

} GncMainWindowPrivate;

GNC_DEFINE_TYPE_WITH_CODE(GncMainWindow, gnc_main_window, GTK_TYPE_APPLICATION_WINDOW,
G_DEFINE_TYPE_WITH_CODE(GncMainWindow, gnc_main_window, GTK_TYPE_APPLICATION_WINDOW,
G_ADD_PRIVATE (GncMainWindow)
G_IMPLEMENT_INTERFACE (GNC_TYPE_WINDOW,
gnc_window_main_window_init))
Expand Down Expand Up @@ -2622,6 +2623,7 @@ gnc_main_window_class_init (GncMainWindowClass *klass)

window_type = g_quark_from_static_string ("gnc-main-window");

object_class->constructed = gnc_main_window_constructed;
object_class->finalize = gnc_main_window_finalize;

/* GtkWidget signals */
Expand Down Expand Up @@ -2704,21 +2706,14 @@ gnc_main_window_class_init (GncMainWindowClass *klass)


/** Initialize a new instance of a gnucash main window. This function
* initializes the object private storage space. It also adds the
* new object to a list (for memory tracking purposes).
* initializes the object private storage space.
*
* @param window The new object instance created by the object system.
*
* @param klass A pointer to the class data structure for this
* object. */
* */
static void
gnc_main_window_init (GncMainWindow *window, void *data)
gnc_main_window_init (GncMainWindow *window)
{
GncMainWindowPrivate *priv;

GncMainWindowClass *klass = (GncMainWindowClass*)data;

priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
GncMainWindowPrivate *priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);

// Set the name for this dialog so it can be easily manipulated with css
gtk_widget_set_name (GTK_WIDGET(window), "gnc-id-main-window");
Expand All @@ -2745,10 +2740,21 @@ gnc_main_window_init (GncMainWindow *window, void *data)
window);

gnc_main_window_setup_window (window);
gnc_gobject_tracking_remember(G_OBJECT(window),
G_OBJECT_CLASS(klass));
}

/** The object has been fully constructed.
* This function adds the object to the tracking system.
*
* @param obj The new object instance created by the object
* system.
*/
static void
gnc_main_window_constructed (GObject *obj)
{
gnc_gobject_tracking_remember(obj);

G_OBJECT_CLASS (gnc_main_window_parent_class)->constructed (obj);
}

/** Finalize the GncMainWindow object. This function is called from
* the G_Object level to complete the destruction of the object. It
Expand Down
35 changes: 20 additions & 15 deletions gnucash/gnome-utils/gnc-plugin-page.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
/** The debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_GUI;

static void gnc_plugin_page_constructed (GObject *object);
static void gnc_plugin_page_finalize (GObject *object);
static void gnc_plugin_page_set_property (GObject *object,
guint prop_id,
Expand Down Expand Up @@ -106,7 +107,7 @@ typedef struct _GncPluginPagePrivate

} GncPluginPagePrivate;

GNC_DEFINE_TYPE_WITH_CODE(GncPluginPage, gnc_plugin_page, G_TYPE_OBJECT,
G_DEFINE_TYPE_WITH_CODE(GncPluginPage, gnc_plugin_page, G_TYPE_OBJECT,
G_ADD_PRIVATE(GncPluginPage))

#define GNC_PLUGIN_PAGE_GET_PRIVATE(o) \
Expand Down Expand Up @@ -351,6 +352,7 @@ gnc_plugin_page_class_init (GncPluginPageClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);

gobject_class->constructed = gnc_plugin_page_constructed;
gobject_class->finalize = gnc_plugin_page_finalize;
gobject_class->set_property = gnc_plugin_page_set_property;
gobject_class->get_property = gnc_plugin_page_get_property;
Expand Down Expand Up @@ -451,21 +453,14 @@ gnc_plugin_page_class_init (GncPluginPageClass *klass)


/** Initialize a new instance of a gnucash content plugin. This
* function initializes the object private storage space, and adds
* the object to the tracking system.
* function initializes the object private storage space.
*
* @param page The new object instance created by the object system.
*
* @param klass A pointer to the class data structure for this
* object. */
* */
static void
gnc_plugin_page_init (GncPluginPage *page, void *data)
gnc_plugin_page_init (GncPluginPage *page)
{
GncPluginPagePrivate *priv;

GncPluginPageClass *klass = (GncPluginPageClass*)data;

priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
GncPluginPagePrivate *priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
priv->page_name = NULL;
priv->page_color = NULL;
priv->page_changed_id = 0;
Expand All @@ -474,11 +469,21 @@ gnc_plugin_page_init (GncPluginPage *page, void *data)

page->window = NULL;
page->summarybar = NULL;

gnc_gobject_tracking_remember (G_OBJECT(page),
G_OBJECT_CLASS(klass));
}

/** The object has been fully constructed.
* This function adds the object to the tracking system.
*
* @param obj The new object instance created by the object
* system.
*/
static void
gnc_plugin_page_constructed (GObject *obj)
{
gnc_gobject_tracking_remember(obj);

G_OBJECT_CLASS (gnc_plugin_page_parent_class)->constructed (obj);
}

/** Finalize the gnucash plugin object. This function is called from
* the G_Object level to complete the destruction of the object. It
Expand Down

0 comments on commit 0c6ae19

Please sign in to comment.