Почему падает программа при вызове функции g_object_new
в строке
return g_object_new(OM1_MOTHER, NULL);
Program received signal SIGSEGV, Segmentation fault. In g_type_fundamental () (/usr/lib64/libgobject-2.0.so.0) #3 0x00007ffff5570b06 in om1_mother_new () at /home/user/om1/mother.c:29 /home/user/om1/mother.c:29:478:beg:0x7ffff5570b06 At /home/user/om1/mother.c:29 #3 0x00007ffff5570b06 in om1_mother_new () at /home/user/om1/mother.c:29 /home/user/om1/mother.c:29:478:beg:0x7ffff5570b06
Вот мой код:
main.c
#include "mother.h"
int main (int argc, char *argv[])
{
Om1Mother *mother = om1_mother_new();
om1_mother_wash(mother);
g_clear_object(&mother);
return 0;
}
mother.h
#ifndef GUARD_MOTHER_H
#define GUARD_MOTHER_H
#include <glib-object.h>
G_BEGIN_DECLS
#define OM1_TYPE_MOTHER (om1_mother_get_type())
// #define G_DECLARE_DERIVABLE_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName)
// #define G_DECLARE_FINAL_TYPE (ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName)
G_DECLARE_DERIVABLE_TYPE (Om1Mother, om1_mother, OM1, MOTHER, GObject)
#define OM1_MOTHER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OM1_TYPE_MOTHER, Om1Mother))
struct _Om1MotherClass
{
GObjectClass parent_class;
/* Class virtual function fields. */
void (* wash) (Om1Mother *self, GError **error);
/* Padding to allow adding up to 12 new virtual functions without
* breaking ABI. */
gpointer padding[12];
};
/*
* Method definitions.
*/
Om1Mother *om1_mother_new (void);
G_END_DECLS
#endif // GUARD_MOTHER_H
mother.c
#include <stdio.h>
#include "mother.h"
G_DEFINE_TYPE (Om1Mother, om1_mother, G_TYPE_OBJECT)
static void
om1_mother_wash_real(Om1Mother *self, GError **error)
{
*error = 0;
printf("washing\n");
}
static void
om1_mother_init(Om1Mother* self)
{
printf("Mother was born.\n");
}
static void
om1_mother_class_init(Om1MotherClass* self)
{
printf("First instance of Mother was created\n");
self->wash = om1_mother_wash_real;
}
Om1Mother*
om1_mother_new()
{
return g_object_new(OM1_MOTHER, NULL);
}
void
om1_mother_wash(Om1Mother *self, GError **error)
{
printf("om1_mother_wash\n");
Om1MotherClass* klass = OM1_MOTHER_GET_CLASS (self);
klass->wash(self, error);
}