summaryrefslogtreecommitdiff
path: root/tests/methods/bug639054.c-expected
blob: b62b6f5555c1c3277a9c00a11307cd19b3f368b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/* methods_bug639054.c generated by valac, the Vala compiler
 * generated from methods_bug639054.vala, do not modify */

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

#if !defined(VALA_EXTERN)
#if defined(_WIN32) || defined(__CYGWIN__)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

typedef struct _Baz Baz;
typedef struct _Block1Data Block1Data;
typedef struct _FooData FooData;
typedef struct _Block2Data Block2Data;
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))
#define _baz_free0(var) ((var == NULL) ? NULL : (var = (baz_free (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _Baz {
	int dummy;
};

struct _Block1Data {
	int _ref_count_;
	guint8* bar;
	gint bar_length1;
	Baz* baz;
	gpointer _async_data_;
};

struct _FooData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	guint8* bar;
	gint bar_length1;
	Baz* baz;
	Block1Data* _data1_;
	GSourceFunc f;
	gpointer f_target;
	GDestroyNotify f_target_destroy_notify;
};

struct _Block2Data {
	int _ref_count_;
	GMainLoop* loop;
	guint8* bar;
	gint bar_length1;
	gint _bar_size_;
};

VALA_EXTERN void baz_free (Baz * self);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Baz, baz_free)
static void baz_instance_init (Baz * self);
VALA_EXTERN Baz* baz_new (void);
static void foo_data_free (gpointer _data);
VALA_EXTERN void foo (guint8* bar,
          gint bar_length1,
          Baz* baz,
          GAsyncReadyCallback _callback_,
          gpointer _user_data_);
VALA_EXTERN void foo_finish (GAsyncResult* _res_);
static gboolean foo_co (FooData* _data_);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static gboolean __lambda4_ (Block1Data* _data1_);
static gboolean ___lambda4__gsource_func (gpointer self);
static void _vala_main (void);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static guint8* _vala_array_dup1 (guint8* self,
                          gssize length);
static void __lambda5_ (Block2Data* _data2_);
static void ___lambda5__gasync_ready_callback (GObject* source_object,
                                        GAsyncResult* res,
                                        gpointer self);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

Baz*
baz_new (void)
{
	Baz* self;
	self = g_slice_new0 (Baz);
	baz_instance_init (self);
	return self;
}

static void
baz_instance_init (Baz * self)
{
}

void
baz_free (Baz * self)
{
	g_slice_free (Baz, self);
}

static void
foo_data_free (gpointer _data)
{
	FooData* _data_;
	_data_ = _data;
	g_slice_free (FooData, _data_);
}

void
foo (guint8* bar,
     gint bar_length1,
     Baz* baz,
     GAsyncReadyCallback _callback_,
     gpointer _user_data_)
{
	FooData* _data_;
	g_return_if_fail (baz != NULL);
	_data_ = g_slice_new0 (FooData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, foo_data_free);
	_data_->bar = bar;
	_data_->bar_length1 = bar_length1;
	_data_->baz = baz;
	foo_co (_data_);
}

void
foo_finish (GAsyncResult* _res_)
{
	FooData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

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_)) {
		g_slice_free (Block1Data, _data1_);
	}
}

static gboolean
__lambda4_ (Block1Data* _data1_)
{
	gboolean result;
	_data1_->bar[0] = (guint8) 'b';
	_data1_->baz = NULL;
	result = FALSE;
	return result;
}

static gboolean
___lambda4__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda4_ (self);
	return result;
}

static gboolean
foo_co (FooData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data1_ = g_slice_new0 (Block1Data);
	_data_->_data1_->_ref_count_ = 1;
	_data_->_data1_->bar = _data_->bar;
	_data_->_data1_->bar_length1 = _data_->bar_length1;
	_data_->_data1_->baz = _data_->baz;
	_data_->_data1_->_async_data_ = _data_;
	_data_->f = ___lambda4__gsource_func;
	_data_->f_target = block1_data_ref (_data_->_data1_);
	_data_->f_target_destroy_notify = block1_data_unref;
	_data_->f (_data_->f_target);
	(_data_->f_target_destroy_notify == NULL) ? NULL : (_data_->f_target_destroy_notify (_data_->f_target), NULL);
	_data_->f = NULL;
	_data_->f_target = NULL;
	_data_->f_target_destroy_notify = NULL;
	block1_data_unref (_data_->_data1_);
	_data_->_data1_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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_)) {
		_data2_->bar = (g_free (_data2_->bar), NULL);
		_g_main_loop_unref0 (_data2_->loop);
		g_slice_free (Block2Data, _data2_);
	}
}

static guint8*
string_get_data (const gchar* self,
                 gint* result_length1)
{
	guint8* result;
	guint8* res = NULL;
	gint res_length1;
	gint _res_size_;
	gint _tmp0_;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static guint8*
_vala_array_dup1 (guint8* self,
                  gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static void
__lambda5_ (Block2Data* _data2_)
{
	guint8 _tmp0_;
	_tmp0_ = _data2_->bar[0];
	_vala_assert (_tmp0_ == ((guint8) 'b'), "bar[0] == 'b'");
	g_main_loop_quit (_data2_->loop);
}

static void
___lambda5__gasync_ready_callback (GObject* source_object,
                                   GAsyncResult* res,
                                   gpointer self)
{
	__lambda5_ (self);
	block2_data_unref (self);
}

static void
_vala_main (void)
{
	Block2Data* _data2_;
	GMainLoop* _tmp0_;
	guint8* _tmp1_;
	gint _tmp1__length1;
	gint _tmp2_ = 0;
	guint8* _tmp3_;
	gint _tmp3__length1;
	guint8* _tmp4_;
	gint _tmp4__length1;
	Baz* _tmp5_;
	Baz* _tmp6_;
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_tmp0_ = g_main_loop_new (NULL, FALSE);
	_data2_->loop = _tmp0_;
	_tmp1_ = string_get_data ("foo", &_tmp2_);
	_tmp1__length1 = _tmp2_;
	_tmp3_ = _tmp1_;
	_tmp3__length1 = _tmp1__length1;
	_tmp4_ = (_tmp3_ != NULL) ? _vala_array_dup1 (_tmp3_, _tmp3__length1) : _tmp3_;
	_tmp4__length1 = _tmp3__length1;
	_data2_->bar = _tmp4_;
	_data2_->bar_length1 = _tmp4__length1;
	_data2_->_bar_size_ = _data2_->bar_length1;
	_tmp5_ = baz_new ();
	_tmp6_ = _tmp5_;
	foo (_data2_->bar, (gint) _data2_->bar_length1, _tmp6_, ___lambda5__gasync_ready_callback, block2_data_ref (_data2_));
	_baz_free0 (_tmp6_);
	g_main_loop_run (_data2_->loop);
	block2_data_unref (_data2_);
	_data2_ = NULL;
}

int
main (int argc,
      char ** argv)
{
	_vala_main ();
	return 0;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}