
#include "test.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <gobject/gvaluecollector.h>

typedef struct _MyStruct MyStruct;

#define TYPE_MY_STRUCT (my_struct_get_type ())

#define TYPE_MY_SIMPLECLASS (my_simpleclass_get_type ())
#define MY_SIMPLECLASS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MY_SIMPLECLASS, MySimpleClass))
#define MY_SIMPLECLASS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MY_SIMPLECLASS, MySimpleClassClass))
#define IS_MY_SIMPLECLASS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MY_SIMPLECLASS))
#define IS_MY_SIMPLECLASS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MY_SIMPLECLASS))
#define MY_SIMPLECLASS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MY_SIMPLECLASS, MySimpleClassClass))

typedef struct _MySimpleClass MySimpleClass;
typedef struct _MySimpleClassClass MySimpleClassClass;
typedef struct _MySimpleClassPrivate MySimpleClassPrivate;
typedef struct _ParamSpecMySimpleClass ParamSpecMySimpleClass;

#define TYPE_MYCLASS (myclass_get_type ())
#define MYCLASS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MYCLASS, MyClass))
#define MYCLASS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MYCLASS, MyClassClass))
#define IS_MYCLASS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MYCLASS))
#define IS_MYCLASS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MYCLASS))
#define MYCLASS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MYCLASS, MyClassClass))

typedef struct _MyClass MyClass;
typedef struct _MyClassClass MyClassClass;
typedef struct _MyClassPrivate MyClassPrivate;

struct _MyStruct {
	gint a;
};

struct _MySimpleClass {
	GTypeInstance parent_instance;
	volatile int ref_count;
	MySimpleClassPrivate * priv;
};

struct _MySimpleClassClass {
	GTypeClass parent_class;
	void (*finalize) (MySimpleClass *self);
};

struct _ParamSpecMySimpleClass {
	GParamSpec parent_instance;
};

struct _MyClass {
	GObject parent_instance;
	MyClassPrivate * priv;
};

struct _MyClassClass {
	GObjectClass parent_class;
};



static MyStruct* my_struct_dup (const MyStruct* self);
static void my_struct_free (MyStruct* self);
static GType my_struct_get_type (void);
enum  {
	MY_SIMPLECLASS_DUMMY_PROPERTY
};
static void my_simpleclass_method (MySimpleClass* self);
static MySimpleClass* my_simpleclass_construct (GType object_type);
static MySimpleClass* my_simpleclass_new (void);
static GParamSpec* param_spec_my_simpleclass (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
static gpointer value_get_my_simpleclass (const GValue* value);
static void value_set_my_simpleclass (GValue* value, gpointer v_object);
static gpointer my_simpleclass_parent_class = NULL;
static void my_simpleclass_finalize (MySimpleClass* obj);
static GType my_simpleclass_get_type (void);
static gpointer my_simpleclass_ref (gpointer instance);
static void my_simpleclass_unref (gpointer instance);
enum  {
	MYCLASS_DUMMY_PROPERTY
};
static void myclass_hard_method (MyClass* self);
static void myclass_method (MyClass* self);
static MyClass* myclass_construct (GType object_type);
static MyClass* myclass_new (void);
static gpointer myclass_parent_class = NULL;
static void myclass_finalize (GObject* obj);
static GType myclass_get_type (void);
static gint _main (void);



static MyStruct* my_struct_dup (const MyStruct* self) {
	MyStruct* dup;
	dup = g_new0 (MyStruct, 1);
	memcpy (dup, self, sizeof (MyStruct));
	return dup;
}


static void my_struct_free (MyStruct* self) {
	g_free (self);
}


static GType my_struct_get_type (void) {
	static GType my_struct_type_id = 0;
	if (my_struct_type_id == 0) {
		my_struct_type_id = g_boxed_type_register_static ("MyStruct", (GBoxedCopyFunc) my_struct_dup, (GBoxedFreeFunc) my_struct_free);
	}
	return my_struct_type_id;
}


static void my_simpleclass_method (MySimpleClass* self) {
	GError * inner_error;
	MySimpleClass* ku;
	g_return_if_fail (self != NULL);
	inner_error = NULL;
	ku = my_simpleclass_new ();
	inner_error = g_error_new_literal (G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "test exception");
	if (inner_error != NULL) {
		(ku == NULL) ? NULL : (ku = (my_simpleclass_unref (ku), NULL));
		g_critical ("file %s: line %d: uncaught error: %s", __FILE__, __LINE__, inner_error->message);
		g_clear_error (&inner_error);
	}
	(ku == NULL) ? NULL : (ku = (my_simpleclass_unref (ku), NULL));
}


static MySimpleClass* my_simpleclass_construct (GType object_type) {
	MySimpleClass* self;
	self = (MySimpleClass*) g_type_create_instance (object_type);
	return self;
}


static MySimpleClass* my_simpleclass_new (void) {
	return my_simpleclass_construct (TYPE_MY_SIMPLECLASS);
}


static void value_my_simpleclass_init (GValue* value) {
	value->data[0].v_pointer = NULL;
}


static void value_my_simpleclass_free_value (GValue* value) {
	if (value->data[0].v_pointer) {
		my_simpleclass_unref (value->data[0].v_pointer);
	}
}


static void value_my_simpleclass_copy_value (const GValue* src_value, GValue* dest_value) {
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = my_simpleclass_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}


static gpointer value_my_simpleclass_peek_pointer (const GValue* value) {
	return value->data[0].v_pointer;
}


static gchar* value_my_simpleclass_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		MySimpleClass* object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = my_simpleclass_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* value_my_simpleclass_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	MySimpleClass** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags && G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = my_simpleclass_ref (value->data[0].v_pointer);
	}
	return NULL;
}


static GParamSpec* param_spec_my_simpleclass (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	ParamSpecMySimpleClass* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TYPE_MY_SIMPLECLASS), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}


static gpointer value_get_my_simpleclass (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_MY_SIMPLECLASS), NULL);
	return value->data[0].v_pointer;
}


static void value_set_my_simpleclass (GValue* value, gpointer v_object) {
	MySimpleClass* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_MY_SIMPLECLASS));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_MY_SIMPLECLASS));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		my_simpleclass_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		my_simpleclass_unref (old);
	}
}


static void my_simpleclass_class_init (MySimpleClassClass * klass) {
	my_simpleclass_parent_class = g_type_class_peek_parent (klass);
	MY_SIMPLECLASS_CLASS (klass)->finalize = my_simpleclass_finalize;
}


static void my_simpleclass_instance_init (MySimpleClass * self) {
	self->ref_count = 1;
}


static void my_simpleclass_finalize (MySimpleClass* obj) {
	MySimpleClass * self;
	self = MY_SIMPLECLASS (obj);
}


static GType my_simpleclass_get_type (void) {
	static GType my_simpleclass_type_id = 0;
	if (my_simpleclass_type_id == 0) {
		static const GTypeValueTable g_define_type_value_table = { value_my_simpleclass_init, value_my_simpleclass_free_value, value_my_simpleclass_copy_value, value_my_simpleclass_peek_pointer, "p", value_my_simpleclass_collect_value, "p", value_my_simpleclass_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (MySimpleClassClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) my_simpleclass_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MySimpleClass), 0, (GInstanceInitFunc) my_simpleclass_instance_init, &g_define_type_value_table };
		static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
		my_simpleclass_type_id = g_type_register_fundamental (g_type_fundamental_next (), "MySimpleClass", &g_define_type_info, &g_define_type_fundamental_info, 0);
	}
	return my_simpleclass_type_id;
}


static gpointer my_simpleclass_ref (gpointer instance) {
	MySimpleClass* self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}


static void my_simpleclass_unref (gpointer instance) {
	MySimpleClass* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		MY_SIMPLECLASS_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}


static void myclass_hard_method (MyClass* self) {
	GError * inner_error;
	g_return_if_fail (self != NULL);
	inner_error = NULL;
	{
		MySimpleClass* mustnotfree1;
		MyClass* mustnotefree2;
		mustnotfree1 = my_simpleclass_new ();
		mustnotefree2 = myclass_new ();
		{
			MySimpleClass* mustfree1;
			MyClass* mustfree2;
			mustfree1 = my_simpleclass_new ();
			mustfree2 = myclass_new ();
			inner_error = g_error_new_literal (G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "test exception");
			if (inner_error != NULL) {
				(mustfree1 == NULL) ? NULL : (mustfree1 = (my_simpleclass_unref (mustfree1), NULL));
				(mustfree2 == NULL) ? NULL : (mustfree2 = (g_object_unref (mustfree2), NULL));
				if (inner_error->domain == G_OPTION_ERROR) {
					goto __catch1_g_option_error;
				}
				g_critical ("file %s: line %d: uncaught error: %s", __FILE__, __LINE__, inner_error->message);
				g_clear_error (&inner_error);
			}
			(mustfree1 == NULL) ? NULL : (mustfree1 = (my_simpleclass_unref (mustfree1), NULL));
			(mustfree2 == NULL) ? NULL : (mustfree2 = (g_object_unref (mustfree2), NULL));
		}
		goto __finally1;
		__catch1_g_option_error:
		{
			GError * e;
			e = inner_error;
			inner_error = NULL;
			{
				(e == NULL) ? NULL : (e = (g_error_free (e), NULL));
			}
		}
		__finally1:
		;
		(mustnotfree1 == NULL) ? NULL : (mustnotfree1 = (my_simpleclass_unref (mustnotfree1), NULL));
		(mustnotefree2 == NULL) ? NULL : (mustnotefree2 = (g_object_unref (mustnotefree2), NULL));
	}
	goto __finally0;
	__catch0_g_option_error:
	{
		GError * e;
		e = inner_error;
		inner_error = NULL;
		{
			(e == NULL) ? NULL : (e = (g_error_free (e), NULL));
		}
	}
	__finally0:
	;
}


static void myclass_method (MyClass* self) {
	GError * inner_error;
	g_return_if_fail (self != NULL);
	inner_error = NULL;
	{
		MySimpleClass* ku;
		ku = my_simpleclass_new ();
		inner_error = g_error_new_literal (G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "test exception");
		if (inner_error != NULL) {
			(ku == NULL) ? NULL : (ku = (my_simpleclass_unref (ku), NULL));
			if (inner_error->domain == G_OPTION_ERROR) {
				goto __catch2_g_option_error;
			}
			g_critical ("file %s: line %d: uncaught error: %s", __FILE__, __LINE__, inner_error->message);
			g_clear_error (&inner_error);
		}
		(ku == NULL) ? NULL : (ku = (my_simpleclass_unref (ku), NULL));
	}
	goto __finally2;
	__catch2_g_option_error:
	{
		GError * e;
		e = inner_error;
		inner_error = NULL;
		{
			(e == NULL) ? NULL : (e = (g_error_free (e), NULL));
		}
	}
	__finally2:
	;
}


static MyClass* myclass_construct (GType object_type) {
	MyClass * self;
	self = g_object_newv (object_type, 0, NULL);
	return self;
}


static MyClass* myclass_new (void) {
	return myclass_construct (TYPE_MYCLASS);
}


static void myclass_class_init (MyClassClass * klass) {
	myclass_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = myclass_finalize;
}


static void myclass_instance_init (MyClass * self) {
}


static void myclass_finalize (GObject* obj) {
	MyClass * self;
	self = MYCLASS (obj);
	{
		fprintf (stdout, "destroying MyObject\n");
	}
	G_OBJECT_CLASS (myclass_parent_class)->finalize (obj);
}


static GType myclass_get_type (void) {
	static GType myclass_type_id = 0;
	if (myclass_type_id == 0) {
		static const GTypeInfo g_define_type_info = { sizeof (MyClassClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) myclass_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MyClass), 0, (GInstanceInitFunc) myclass_instance_init, NULL };
		myclass_type_id = g_type_register_static (G_TYPE_OBJECT, "MyClass", &g_define_type_info, 0);
	}
	return myclass_type_id;
}


static gint _main (void) {
	GError * inner_error;
	inner_error = NULL;
	{
		MyStruct _tmp0 = {0};
		MyStruct st;
		MyClass* s;
		MySimpleClass* u;
		MyClass* b;
		MyClass* c;
		st = (memset (&_tmp0, 0, sizeof (MyStruct)), _tmp0);
		fprintf (stdout, "hello, world\n");
		s = myclass_new ();
		myclass_method (s);
		u = my_simpleclass_new ();
		my_simpleclass_method (u);
		b = myclass_new ();
		inner_error = g_error_new_literal (G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "test exception");
		if (inner_error != NULL) {
			(s == NULL) ? NULL : (s = (g_object_unref (s), NULL));
			(u == NULL) ? NULL : (u = (my_simpleclass_unref (u), NULL));
			(b == NULL) ? NULL : (b = (g_object_unref (b), NULL));
			if (inner_error->domain == G_OPTION_ERROR) {
				goto __catch3_g_option_error;
			}
			g_critical ("file %s: line %d: uncaught error: %s", __FILE__, __LINE__, inner_error->message);
			g_clear_error (&inner_error);
		}
		c = myclass_new ();
		(s == NULL) ? NULL : (s = (g_object_unref (s), NULL));
		(u == NULL) ? NULL : (u = (my_simpleclass_unref (u), NULL));
		(b == NULL) ? NULL : (b = (g_object_unref (b), NULL));
		(c == NULL) ? NULL : (c = (g_object_unref (c), NULL));
	}
	goto __finally3;
	__catch3_g_option_error:
	{
		GError * e;
		e = inner_error;
		inner_error = NULL;
		{
			fprintf (stderr, "error: %s\n", e->message);
			(e == NULL) ? NULL : (e = (g_error_free (e), NULL));
		}
	}
	__finally3:
	;
	return 0;
}


int main (int argc, char ** argv) {
	g_type_init ();
	return _main ();
}




