/* test.c generated by valac 0.24.0, the Vala compiler
 * generated from test.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>


#define TYPE_FOO (foo_get_type ())
#define FOO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOO, Foo))
#define FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOO, FooClass))
#define IS_FOO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FOO))
#define IS_FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FOO))
#define FOO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FOO, FooClass))

typedef struct _Foo Foo;
typedef struct _FooClass FooClass;
typedef struct _FooPrivate FooPrivate;

#define TYPE_BAR (bar_get_type ())
#define BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BAR, Bar))
#define BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BAR, BarClass))
#define IS_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_BAR))
#define IS_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_BAR))
#define BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_BAR, BarClass))

typedef struct _Bar Bar;
typedef struct _BarClass BarClass;
typedef struct _BarPrivate BarPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block1Data Block1Data;

#define TYPE_BAR2 (bar2_get_type ())
#define BAR2(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BAR2, Bar2))
#define BAR2_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BAR2, Bar2Class))
#define IS_BAR2(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_BAR2))
#define IS_BAR2_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_BAR2))
#define BAR2_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_BAR2, Bar2Class))

typedef struct _Bar2 Bar2;
typedef struct _Bar2Class Bar2Class;
typedef struct _Bar2Private Bar2Private;
typedef struct _Block2Data Block2Data;

struct _Foo {
	GObject parent_instance;
	FooPrivate * priv;
};

struct _FooClass {
	GObjectClass parent_class;
};

struct _Bar {
	GObject parent_instance;
	BarPrivate * priv;
};

struct _BarClass {
	GObjectClass parent_class;
};

struct _BarPrivate {
	Foo* foo;
};

struct _Block1Data {
	int _ref_count_;
	Bar* self;
	gint x;
};

struct _Bar2 {
	GObject parent_instance;
	Bar2Private * priv;
};

struct _Bar2Class {
	GObjectClass parent_class;
};

struct _Bar2Private {
	Foo* foo;
};

struct _Block2Data {
	int _ref_count_;
	Bar2* self;
	gint y;
};


static gpointer foo_parent_class = NULL;
static gpointer bar_parent_class = NULL;
static gpointer bar2_parent_class = NULL;

GType foo_get_type (void) G_GNUC_CONST;
enum  {
	FOO_DUMMY_PROPERTY
};
Foo* foo_new (void);
Foo* foo_construct (GType object_type);
static void foo_finalize (GObject* obj);
GType bar_get_type (void) G_GNUC_CONST;
#define BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_BAR, BarPrivate))
enum  {
	BAR_DUMMY_PROPERTY
};
Bar* bar_new (Foo* foo);
Bar* bar_construct (GType object_type, Foo* foo);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda3_ (Block1Data* _data1_);
static void ___lambda3__foo_sig (Foo* _sender, gpointer self);
static void bar_finalize (GObject* obj);
GType bar2_get_type (void) G_GNUC_CONST;
#define BAR2_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_BAR2, Bar2Private))
enum  {
	BAR2_DUMMY_PROPERTY
};
Bar2* bar2_new (Foo* foo);
Bar2* bar2_construct (GType object_type, Foo* foo);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static void __lambda4_ (Block2Data* _data2_);
static void ___lambda4__foo_sig (Foo* _sender, gpointer self);
static void bar2_finalize (GObject* obj);
void do_thing_with_foo (Foo* f);
void _vala_main (gchar** args, int args_length1);


Foo* foo_construct (GType object_type) {
	Foo * self = NULL;
	self = (Foo*) g_object_new (object_type, NULL);
	return self;
}


Foo* foo_new (void) {
	return foo_construct (TYPE_FOO);
}


static void foo_class_init (FooClass * klass) {
	foo_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = foo_finalize;
	g_signal_new ("sig", TYPE_FOO, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}


static void foo_instance_init (Foo * self) {
}


static void foo_finalize (GObject* obj) {
	Foo * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FOO, Foo);
	g_message ("test.vala:5: Foo finalized");
	G_OBJECT_CLASS (foo_parent_class)->finalize (obj);
}


GType foo_get_type (void) {
	static volatile gsize foo_type_id__volatile = 0;
	if (g_once_init_enter (&foo_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FooClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) foo_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Foo), 0, (GInstanceInitFunc) foo_instance_init, NULL };
		GType foo_type_id;
		foo_type_id = g_type_register_static (G_TYPE_OBJECT, "Foo", &g_define_type_info, 0);
		g_once_init_leave (&foo_type_id__volatile, foo_type_id);
	}
	return foo_type_id__volatile;
}


static Block1Data* block1_data_ref (Block1Data* _data1_) {
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}


static void block1_data_unref (void * _userdata_) {
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		Bar* self;
		self = _data1_->self;
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static void __lambda3_ (Block1Data* _data1_) {
	Bar* self;
	self = _data1_->self;
	g_message ("test.vala:15: Foo.sig: x = %d", _data1_->x);
}


static void ___lambda3__foo_sig (Foo* _sender, gpointer self) {
	__lambda3_ (self);
}


Bar* bar_construct (GType object_type, Foo* foo) {
	Bar * self = NULL;
	Block1Data* _data1_;
	Foo* _tmp0_ = NULL;
	Foo* _tmp1_ = NULL;
	Foo* _tmp2_ = NULL;
	g_return_val_if_fail (foo != NULL, NULL);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	self = (Bar*) g_object_new (object_type, NULL);
	_data1_->self = g_object_ref (self);
	_tmp0_ = foo;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->foo);
	self->priv->foo = _tmp1_;
	_data1_->x = 1;
	_tmp2_ = foo;
	g_signal_connect_data (_tmp2_, "sig", (GCallback) ___lambda3__foo_sig, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return self;
}


Bar* bar_new (Foo* foo) {
	return bar_construct (TYPE_BAR, foo);
}


static void bar_class_init (BarClass * klass) {
	bar_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (BarPrivate));
	G_OBJECT_CLASS (klass)->finalize = bar_finalize;
}


static void bar_instance_init (Bar * self) {
	self->priv = BAR_GET_PRIVATE (self);
}


static void bar_finalize (GObject* obj) {
	Bar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_BAR, Bar);
	g_message ("test.vala:19: Bar finalized");
	_g_object_unref0 (self->priv->foo);
	G_OBJECT_CLASS (bar_parent_class)->finalize (obj);
}


GType bar_get_type (void) {
	static volatile gsize bar_type_id__volatile = 0;
	if (g_once_init_enter (&bar_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (BarClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bar_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Bar), 0, (GInstanceInitFunc) bar_instance_init, NULL };
		GType bar_type_id;
		bar_type_id = g_type_register_static (G_TYPE_OBJECT, "Bar", &g_define_type_info, 0);
		g_once_init_leave (&bar_type_id__volatile, bar_type_id);
	}
	return bar_type_id__volatile;
}


static Block2Data* block2_data_ref (Block2Data* _data2_) {
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}


static void block2_data_unref (void * _userdata_) {
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		Bar2* self;
		self = _data2_->self;
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}


static void __lambda4_ (Block2Data* _data2_) {
	Bar2* self;
	self = _data2_->self;
	g_message ("test.vala:29: Foo.sig: y = %d", _data2_->y);
}


static void ___lambda4__foo_sig (Foo* _sender, gpointer self) {
	__lambda4_ (self);
}


Bar2* bar2_construct (GType object_type, Foo* foo) {
	Bar2 * self = NULL;
	Block2Data* _data2_;
	Foo* _tmp0_ = NULL;
	Foo* _tmp1_ = NULL;
	Foo* _tmp2_ = NULL;
	g_return_val_if_fail (foo != NULL, NULL);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	self = (Bar2*) g_object_new (object_type, NULL);
	_data2_->self = g_object_ref (self);
	_tmp0_ = foo;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->foo);
	self->priv->foo = _tmp1_;
	_data2_->y = 2;
	_tmp2_ = foo;
	g_signal_connect_data (_tmp2_, "sig", (GCallback) ___lambda4__foo_sig, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	block2_data_unref (_data2_);
	_data2_ = NULL;
	return self;
}


Bar2* bar2_new (Foo* foo) {
	return bar2_construct (TYPE_BAR2, foo);
}


static void bar2_class_init (Bar2Class * klass) {
	bar2_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (Bar2Private));
	G_OBJECT_CLASS (klass)->finalize = bar2_finalize;
}


static void bar2_instance_init (Bar2 * self) {
	self->priv = BAR2_GET_PRIVATE (self);
}


static void bar2_finalize (GObject* obj) {
	Bar2 * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_BAR2, Bar2);
	g_message ("test.vala:33: Bar2 finalized");
	_g_object_unref0 (self->priv->foo);
	G_OBJECT_CLASS (bar2_parent_class)->finalize (obj);
}


GType bar2_get_type (void) {
	static volatile gsize bar2_type_id__volatile = 0;
	if (g_once_init_enter (&bar2_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (Bar2Class), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bar2_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Bar2), 0, (GInstanceInitFunc) bar2_instance_init, NULL };
		GType bar2_type_id;
		bar2_type_id = g_type_register_static (G_TYPE_OBJECT, "Bar2", &g_define_type_info, 0);
		g_once_init_leave (&bar2_type_id__volatile, bar2_type_id);
	}
	return bar2_type_id__volatile;
}


void do_thing_with_foo (Foo* f) {
	Bar* bar = NULL;
	Foo* _tmp0_ = NULL;
	Bar* _tmp1_ = NULL;
	g_return_if_fail (f != NULL);
	_tmp0_ = f;
	_tmp1_ = bar_new (_tmp0_);
	bar = _tmp1_;
	_g_object_unref0 (bar);
}


void _vala_main (gchar** args, int args_length1) {
	Foo* foo = NULL;
	Foo* _tmp0_ = NULL;
	Bar2* bar2 = NULL;
	Bar2* _tmp1_ = NULL;
	_tmp0_ = foo_new ();
	foo = _tmp0_;
	do_thing_with_foo (foo);
	_tmp1_ = bar2_new (foo);
	bar2 = _tmp1_;
	g_signal_emit_by_name (foo, "sig");
	_g_object_unref0 (bar2);
	_g_object_unref0 (foo);
}


int main (int argc, char ** argv) {
#if !GLIB_CHECK_VERSION (2,35,0)
	g_type_init ();
#endif
	_vala_main (argv, argc);
	return 0;
}



