Debian Codegraph @

tests/testhelpermodule.c

raw
1 #include <string.h>
2
3 #include <pythoncapi_compat.h>
4 #include <pygobject.h>
5
6 #include "test-floating.h"
7 #include "test-thread.h"
8 #include "test-unknown.h"
9
10 #define PYGI_DEFINE_TYPE(typename, symbol, csymbol) \
11 PyTypeObject symbol = { PyVarObject_HEAD_INIT (NULL, 0) typename, \
12 sizeof (csymbol) };
13
14 static PyObject *_wrap_TestInterface__do_iface_method (PyObject *cls,
15 PyObject *args,
16 PyObject *kwargs);
17
18 static GType
19 test_type_get_type (void)
20 {
21 static GType gtype = 0;
22 GType parent_type;
23
24 if (gtype == 0) {
25 GTypeInfo *type_info;
26 GTypeQuery query;
27
28 parent_type = g_type_from_name ("PyGObject");
29 if (parent_type == 0)
30 g_error ("could not get PyGObject from testmodule");
31
32 type_info = (GTypeInfo *)g_new0 (GTypeInfo, 1);
33
34 g_type_query (parent_type, &query);
35 type_info->class_size = (guint16)query.class_size;
36 type_info->instance_size = (guint16)query.instance_size;
37
38 gtype = g_type_register_static (parent_type, "TestType", type_info, 0);
39 if (!gtype) g_error ("Could not register TestType");
40 }
41
42 return gtype;
43 }
44
45 #define TYPE_TEST (test_type_get_type ())
46
47 static PyObject *
48 _wrap_get_test_thread (PyObject *self)
49 {
50 GObject *obj;
51
52 test_thread_get_type ();
53 g_assert (g_type_is_a (TEST_TYPE_THREAD, G_TYPE_OBJECT));
54 obj = g_object_new (TEST_TYPE_THREAD, NULL);
55 g_assert (obj != NULL);
56
57 return pygobject_new (obj);
58 }
59
60 static PyObject *
61 _wrap_get_unknown (PyObject *self)
62 {
63 GObject *obj;
64 obj = g_object_new (TEST_TYPE_UNKNOWN, NULL);
65 return pygobject_new (obj);
66 }
67
68 static PyObject *
69 _wrap_create_test_type (PyObject *self)
70 {
71 GObject *obj;
72 PyObject *rv;
73 obj = g_object_new (TYPE_TEST, NULL);
74 rv = pygobject_new (obj);
75 g_object_unref (obj);
76 return rv;
77 }
78
79 static PyObject *
80 _wrap_test_g_object_new (PyObject *self)
81 {
82 GObject *obj;
83 PyObject *rv;
84
85 obj = g_object_new (g_type_from_name ("PyGObject"), NULL);
86 rv = PyLong_FromLong (obj->ref_count); /* should be == 2 at this point */
87 g_object_unref (obj);
88 return rv;
89 }
90
91 /* TestUnknown */
92 static PyObject *
93 _wrap_test_interface_iface_method (PyGObject *self, PyObject *args,
94 PyObject *kwargs)
95 {
96 static char *kwlist[] = { NULL };
97
98 if (!PyArg_ParseTupleAndKeywords (args, kwargs, ":", kwlist)) return NULL;
99
100 test_interface_iface_method (TEST_INTERFACE (self->obj));
101
102 Py_RETURN_NONE;
103 }
104
105 static const PyMethodDef _PyTestInterface_methods[] = {
106 { "iface_method", (PyCFunction)_wrap_test_interface_iface_method,
107 METH_VARARGS | METH_KEYWORDS, NULL },
108 { "do_iface_method", (PyCFunction)_wrap_TestInterface__do_iface_method,
109 METH_VARARGS | METH_KEYWORDS | METH_CLASS, NULL },
110 { NULL, NULL, 0, NULL }
111 };
112
113 /* TestInterface */
114 PYGI_DEFINE_TYPE ("test.Interface", PyTestInterface_Type, PyObject);
115
116 static PyObject *
117 _wrap_TestInterface__do_iface_method (PyObject *cls, PyObject *args,
118 PyObject *kwargs)
119 {
120 TestInterfaceIface *iface;
121 static char *kwlist[] = { "self", NULL };
122 PyGObject *self;
123
124 if (!PyArg_ParseTupleAndKeywords (args, kwargs,
125 "O!:TestInterface.iface_method", kwlist,
126 &PyTestInterface_Type, &self))
127 return NULL;
128
129 iface = g_type_interface_peek (
130 g_type_class_peek (pyg_type_from_object (cls)), TEST_TYPE_INTERFACE);
131 if (iface->iface_method)
132 iface->iface_method (TEST_INTERFACE (self->obj));
133 else {
134 PyErr_SetString (
135 PyExc_NotImplementedError,
136 "interface method TestInterface.iface_method not implemented");
137 return NULL;
138 }
139 Py_RETURN_NONE;
140 }
141
142 PYGI_DEFINE_TYPE ("testhelper.Unknown", PyTestUnknown_Type, PyGObject);
143
144 static void
145 _wrap_TestInterface__proxy_do_iface_method (TestInterface *self)
146 {
147 PyGILState_STATE __py_state;
148 PyObject *py_self;
149 PyObject *py_retval;
150 PyObject *py_args;
151 PyObject *py_method;
152
153 __py_state = PyGILState_Ensure ();
154 py_self = pygobject_new ((GObject *)self);
155 if (!py_self) {
156 if (PyErr_Occurred ()) PyErr_Print ();
157 PyGILState_Release (__py_state);
158 return;
159 }
160 py_args = PyTuple_New (0);
161 py_method = PyObject_GetAttrString (py_self, "do_iface_method");
162 if (!py_method) {
163 if (PyErr_Occurred ()) PyErr_Print ();
164 Py_DECREF (py_args);
165 Py_DECREF (py_self);
166 PyGILState_Release (__py_state);
167 return;
168 }
169 py_retval = PyObject_CallObject (py_method, py_args);
170 if (!py_retval) {
171 if (PyErr_Occurred ()) PyErr_Print ();
172 Py_DECREF (py_method);
173 Py_DECREF (py_args);
174 Py_DECREF (py_self);
175 PyGILState_Release (__py_state);
176 return;
177 }
178 if (!Py_IsNone (py_retval)) {
179 if (PyErr_Occurred ()) PyErr_Print ();
180 PyErr_SetString (PyExc_TypeError, "retval should be None");
181 Py_DECREF (py_retval);
182 Py_DECREF (py_method);
183 Py_DECREF (py_args);
184 Py_DECREF (py_self);
185 PyGILState_Release (__py_state);
186 return;
187 }
188
189 Py_DECREF (py_retval);
190 Py_DECREF (py_method);
191 Py_DECREF (py_args);
192 Py_DECREF (py_self);
193 PyGILState_Release (__py_state);
194 }
195
196 static void
197 __TestInterface__interface_init (TestInterfaceIface *iface,
198 PyTypeObject *pytype)
199 {
200 TestInterfaceIface *parent_iface = g_type_interface_peek_parent (iface);
201 PyObject *py_method;
202
203 py_method =
204 pytype ? PyObject_GetAttrString ((PyObject *)pytype, "do_iface_method")
205 : NULL;
206
207 if (py_method && !PyObject_TypeCheck (py_method, &PyCFunction_Type)) {
208 iface->iface_method = _wrap_TestInterface__proxy_do_iface_method;
209 } else {
210 PyErr_Clear ();
211 if (parent_iface) {
212 iface->iface_method = parent_iface->iface_method;
213 }
214 Py_XDECREF (py_method);
215 }
216 }
217
218 static const GInterfaceInfo __TestInterface__iinfo = {
219 (GInterfaceInitFunc)__TestInterface__interface_init, NULL, NULL
220 };
221
222 /* TestFloating */
223 PYGI_DEFINE_TYPE ("testhelper.Floating", PyTestFloating_Type, PyGObject);
224
225 /* TestOwnedByLibrary */
226 PYGI_DEFINE_TYPE ("testhelper.OwnedByLibrary", PyTestOwnedByLibrary_Type,
227 PyGObject);
228
229 static PyObject *
230 _wrap_test_owned_by_library_release (PyGObject *self)
231 {
232 test_owned_by_library_release (TEST_OWNED_BY_LIBRARY (self->obj));
233 return Py_None;
234 }
235
236 static const PyMethodDef _PyTestOwnedByLibrary_methods[] = {
237 { "release", (PyCFunction)_wrap_test_owned_by_library_release, METH_NOARGS,
238 NULL },
239 { NULL, NULL, 0, NULL }
240 };
241
242 /* TestFloatingAndSunk */
243 PYGI_DEFINE_TYPE ("testhelper.FloatingAndSunk", PyTestFloatingAndSunk_Type,
244 PyGObject);
245
246 static PyObject *
247 _wrap_test_floating_and_sunk_release (PyGObject *self)
248 {
249 test_floating_and_sunk_release (TEST_FLOATING_AND_SUNK (self->obj));
250 return Py_None;
251 }
252
253 static const PyMethodDef _PyTestFloatingAndSunk_methods[] = {
254 { "release", (PyCFunction)_wrap_test_floating_and_sunk_release,
255 METH_NOARGS, NULL },
256 { NULL, NULL, 0, NULL }
257 };
258
259 static void
260 test1_callback (GObject *object, char *data)
261 {
262 g_return_if_fail (G_IS_OBJECT (object));
263 g_return_if_fail (!strcmp (data, "user-data"));
264 }
265
266 static void
267 test1_callback_swapped (char *data, GObject *object)
268 {
269 g_return_if_fail (G_IS_OBJECT (object));
270 g_return_if_fail (!strcmp (data, "user-data"));
271 }
272
273 static void
274 test2_callback (GObject *object, char *string)
275 {
276 g_return_if_fail (G_IS_OBJECT (object));
277 g_return_if_fail (!strcmp (string, "string"));
278 }
279
280 static int
281 test3_callback (GObject *object, double d)
282 {
283 g_return_val_if_fail (G_IS_OBJECT (object), -1);
284 g_return_val_if_fail (d == 42.0, -1);
285
286 return 20;
287 }
288
289 static void
290 test4_callback (GObject *object, gboolean b, long l, float f, double d,
291 guint uint, gulong ulong, gpointer user_data)
292 {
293 g_return_if_fail (b == TRUE);
294 g_return_if_fail (l == 10L);
295 g_return_if_fail (f <= 3.14001 && f >= 3.13999);
296 g_return_if_fail (d <= 1.78001 && d >= 1.77999);
297 g_return_if_fail (uint == 20);
298 g_return_if_fail (ulong == 30L);
299 }
300
301 static float
302 test_float_callback (GObject *object, float f)
303 {
304 g_return_val_if_fail (G_IS_OBJECT (object), -1);
305 g_return_val_if_fail (f <= 1.234001 && f >= 1.123999, -1);
306
307 return f;
308 }
309
310 static double
311 test_double_callback (GObject *object, double d)
312 {
313 g_return_val_if_fail (G_IS_OBJECT (object), -1);
314 g_return_val_if_fail (d <= 1.234001 && d >= 1.123999, -1);
315
316 return d;
317 }
318
319 static gint64
320 test_int64_callback (GObject *object, gint64 i)
321 {
322 g_return_val_if_fail (G_IS_OBJECT (object), -1);
323
324 if (i == G_MAXINT64) return i - 1;
325 return i;
326 }
327
328 static char *
329 test_string_callback (GObject *object, char *s)
330 {
331 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
332 g_return_val_if_fail (!strcmp (s, "str"), NULL);
333
334 return g_strdup (s);
335 }
336
337 static GObject *
338 test_object_callback (GObject *object, GObject *o)
339 {
340 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
341
342 return o;
343 }
344
345 static GParamSpec *
346 test_paramspec_callback (GObject *object)
347 {
348 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
349
350 return g_param_spec_boolean ("test-param", "test", "test boolean", TRUE,
351 G_PARAM_READABLE);
352 }
353
354 static GValue *
355 test_gvalue_callback (GObject *object, const GValue *v)
356 {
357 GValue *ret;
358
359 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
360 g_return_val_if_fail (G_IS_VALUE (v), NULL);
361
362 ret = g_malloc0 (sizeof (GValue));
363 g_value_init (ret, G_VALUE_TYPE (v));
364 g_value_copy (v, ret);
365 return ret;
366 }
367
368 static GValue *
369 test_gvalue_ret_callback (GObject *object, GType type)
370 {
371 GValue *ret;
372
373 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
374
375 ret = g_malloc0 (sizeof (GValue));
376 g_value_init (ret, type);
377
378 switch (type) {
379 case G_TYPE_INT:
380 g_value_set_int (ret, G_MAXINT);
381 break;
382 case G_TYPE_INT64:
383 g_value_set_int64 (ret, G_MAXINT64);
384 break;
385 case G_TYPE_UINT:
386 g_value_set_uint (ret, G_MAXUINT);
387 break;
388 case G_TYPE_UINT64:
389 g_value_set_uint64 (ret, G_MAXUINT64);
390 break;
391 case G_TYPE_STRING:
392 g_value_set_string (ret, "hello");
393 break;
394 default:
395 g_critical ("test_gvalue_ret_callback() does not support type %s",
396 g_type_name (type));
397 }
398
399 return ret;
400 }
401
402 static GParamSpec *
403 test_paramspec_in_callback (GObject *object, GParamSpec *p)
404 {
405 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
406 g_return_val_if_fail (G_IS_PARAM_SPEC (p), NULL);
407
408 return p;
409 }
410
411 static void
412 connectcallbacks (GObject *object)
413 {
414 gchar *data = "user-data";
415
416 g_signal_connect (G_OBJECT (object), "test1", G_CALLBACK (test1_callback),
417 data);
418 g_signal_connect_swapped (G_OBJECT (object), "test1",
419 G_CALLBACK (test1_callback_swapped), data);
420 g_signal_connect (G_OBJECT (object), "test2", G_CALLBACK (test2_callback),
421 NULL);
422 g_signal_connect (G_OBJECT (object), "test3", G_CALLBACK (test3_callback),
423 NULL);
424 g_signal_connect (G_OBJECT (object), "test4", G_CALLBACK (test4_callback),
425 NULL);
426 g_signal_connect (G_OBJECT (object), "test_float",
427 G_CALLBACK (test_float_callback), NULL);
428 g_signal_connect (G_OBJECT (object), "test_double",
429 G_CALLBACK (test_double_callback), NULL);
430 g_signal_connect (G_OBJECT (object), "test_int64",
431 G_CALLBACK (test_int64_callback), NULL);
432 g_signal_connect (G_OBJECT (object), "test_string",
433 G_CALLBACK (test_string_callback), NULL);
434 g_signal_connect (G_OBJECT (object), "test_object",
435 G_CALLBACK (test_object_callback), NULL);
436 g_signal_connect (G_OBJECT (object), "test_paramspec",
437 G_CALLBACK (test_paramspec_callback), NULL);
438 g_signal_connect (G_OBJECT (object), "test_gvalue",
439 G_CALLBACK (test_gvalue_callback), NULL);
440 g_signal_connect (G_OBJECT (object), "test_gvalue_ret",
441 G_CALLBACK (test_gvalue_ret_callback), NULL);
442 g_signal_connect (G_OBJECT (object), "test_paramspec_in",
443 G_CALLBACK (test_paramspec_in_callback), NULL);
444 }
445
446 static PyObject *
447 _wrap_connectcallbacks (PyObject *self, PyObject *args)
448 {
449 PyGObject *obj;
450
451 if (!PyArg_ParseTuple (args, "O", &obj)) return NULL;
452
453 connectcallbacks (G_OBJECT (obj->obj));
454
455 Py_RETURN_NONE;
456 }
457
458 static PyObject *
459 _wrap_test_value (PyObject *self, PyObject *args)
460 {
461 GValue tvalue = {0,}, *value = &tvalue;
462 PyObject *obj;
463
464 if (!PyArg_ParseTuple (args, "O", &obj)) return NULL;
465
466 g_value_init (value, G_TYPE_VALUE);
467 if (pyg_value_from_pyobject (value, obj)) {
468 PyErr_SetString (PyExc_TypeError, "Could not convert to GValue");
469 return NULL;
470 }
471
472 return pyg_value_as_pyobject (value, FALSE);
473 }
474
475 static PyObject *
476 _wrap_test_state_ensure_release (PyObject *self, PyObject *args)
477 {
478 int state = pyg_gil_state_ensure ();
479 pyg_gil_state_release (state);
480
481 Py_RETURN_NONE;
482 }
483
484 #define PYGI_TYPE_VALUE_ARRAY (g_value_array_get_type ())
485
486 static PyObject *
487 _wrap_test_value_array (PyObject *self, PyObject *args)
488 {
489 GValue tvalue = {0,}, *value = &tvalue;
490 PyObject *obj;
491
492 if (!PyArg_ParseTuple (args, "O", &obj)) return NULL;
493
494 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
495 g_value_init (value, PYGI_TYPE_VALUE_ARRAY);
496 G_GNUC_END_IGNORE_DEPRECATIONS
497
498 if (pyg_value_from_pyobject (value, obj)) {
499 PyErr_SetString (PyExc_TypeError, "Could not convert to GValueArray");
500 return NULL;
501 }
502
503 return pyg_value_as_pyobject (value, FALSE);
504 }
505
506
507 static PyObject *
508 _wrap_value_array_get_nth_type (PyObject *self, PyObject *args)
509 {
510 guint n;
511 GType type;
512 GValue *nth;
513 GValueArray *arr;
514 PyObject *obj;
515
516 if (!PyArg_ParseTuple (args, "OI", &obj, &n)) return NULL;
517
518 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
519
520 if (pyg_boxed_check (obj, G_TYPE_VALUE)
521 && G_VALUE_HOLDS (pyg_boxed_get (obj, GValue),
522 PYGI_TYPE_VALUE_ARRAY)) {
523 arr = g_value_get_boxed (pyg_boxed_get (obj, GValue));
524 } else if (pyg_boxed_check (obj, PYGI_TYPE_VALUE_ARRAY)) {
525 arr = pyg_boxed_get (obj, GValueArray);
526 } else {
527 PyErr_SetString (PyExc_TypeError, "First argument is not GValueArray");
528 return NULL;
529 }
530
531 if (n >= arr->n_values) {
532 PyErr_SetString (PyExc_TypeError, "Index is out of bounds");
533 return NULL;
534 }
535 nth = g_value_array_get_nth (arr, n);
536 type = G_VALUE_TYPE (nth);
537
538 G_GNUC_END_IGNORE_DEPRECATIONS
539
540 return pyg_type_wrapper_new (type);
541 }
542
543 static PyObject *
544 _wrap_constant_strip_prefix (PyObject *self, PyObject *args)
545 {
546 const char *name, *strip_prefix;
547 const gchar *result;
548
549 if (!PyArg_ParseTuple (args, "ss", &name, &strip_prefix)) return NULL;
550
551 result = pyg_constant_strip_prefix (name, strip_prefix);
552 return PyUnicode_FromString (result);
553 }
554
555 static PyObject *
556 _wrap_test_gerror_exception (PyObject *self, PyObject *args)
557 {
558 PyObject *py_method;
559 PyObject *py_args;
560 PyObject *py_ret;
561 GError *err = NULL;
562
563 if (!PyArg_ParseTuple (args, "O", &py_method)) return NULL;
564
565 py_args = PyTuple_New (0);
566 py_ret = PyObject_CallObject (py_method, py_args);
567 if (pyg_gerror_exception_check (&err)) {
568 pyg_error_check (&err);
569 return NULL;
570 }
571
572 Py_DECREF (py_args);
573 Py_DECREF (py_ret);
574
575 Py_RETURN_NONE;
576 }
577
578 static PyObject *
579 _wrap_test_owned_by_library_get_instance_list (PyObject *self)
580 {
581 PyObject *py_list, *py_obj;
582 GSList *list, *tmp;
583
584 list = test_owned_by_library_get_instance_list ();
585
586 if ((py_list = PyList_New (0)) == NULL) {
587 return NULL;
588 }
589 for (tmp = list; tmp != NULL; tmp = tmp->next) {
590 py_obj = pygobject_new (G_OBJECT (tmp->data));
591 if (py_obj == NULL) {
592 Py_DECREF (py_list);
593 return NULL;
594 }
595 PyList_Append (py_list, py_obj);
596 Py_DECREF (py_obj);
597 }
598 return py_list;
599 }
600
601 static PyObject *
602 _wrap_test_floating_and_sunk_get_instance_list (PyObject *self)
603 {
604 PyObject *py_list, *py_obj;
605 GSList *list, *tmp;
606
607 list = test_floating_and_sunk_get_instance_list ();
608
609 if ((py_list = PyList_New (0)) == NULL) {
610 return NULL;
611 }
612 for (tmp = list; tmp != NULL; tmp = tmp->next) {
613 py_obj = pygobject_new (G_OBJECT (tmp->data));
614 if (py_obj == NULL) {
615 Py_DECREF (py_list);
616 return NULL;
617 }
618 PyList_Append (py_list, py_obj);
619 Py_DECREF (py_obj);
620 }
621 return py_list;
622 }
623
624 static PyObject *
625 _wrap_test_create_and_get_property (PyObject *self, PyObject *args)
626 {
627 PyObject *pygtype, *pyvalue;
628 char *property_name;
629 GType type;
630 GObject *object;
631 GValue value = {
632 0,
633 };
634
635 if (!PyArg_ParseTuple (args, "Os", &pygtype, &property_name)) return NULL;
636
637 type = pyg_type_from_object (pygtype);
638 if (PyErr_Occurred ()) return NULL;
639
640 object = g_object_new (type, NULL);
641
642 g_assert (g_object_is_floating (object));
643
644 g_value_init (&value, G_TYPE_STRING);
645
646 g_object_get_property (object, property_name, &value);
647
648 pyvalue = PyUnicode_FromString (g_value_get_string (&value));
649
650 g_value_unset (&value);
651
652 g_assert (g_object_is_floating (object));
653 g_object_unref (object);
654
655 return pyvalue;
656 }
657
658 static PyObject *
659 _wrap_test_create_and_set_property (PyObject *self, PyObject *args)
660 {
661 PyObject *pygtype;
662 char *property_name, *property_value;
663 GType type;
664 GObject *object;
665 GValue value = {
666 0,
667 };
668
669 if (!PyArg_ParseTuple (args, "Oss", &pygtype, &property_name,
670 &property_value))
671 return NULL;
672
673 type = pyg_type_from_object (pygtype);
674 if (PyErr_Occurred ()) return NULL;
675
676 object = g_object_new (type, NULL);
677
678 g_assert (g_object_is_floating (object));
679
680 g_value_init (&value, G_TYPE_STRING);
681 g_value_set_string (&value, property_value);
682
683 g_object_set_property (object, property_name, &value);
684
685 g_value_unset (&value);
686
687 g_assert (g_object_is_floating (object));
688 g_object_unref (object);
689
690 Py_RETURN_NONE;
691 }
692
693 static PyObject *
694 _wrap_force_g_object_ref (PyObject *self, PyObject *args)
695 {
696 PyGObject *obj;
697
698 if (!PyArg_ParseTuple (args, "O", &obj)) return NULL;
699
700 g_assert (G_IS_OBJECT (obj->obj));
701 g_object_ref (obj->obj);
702
703 Py_RETURN_NONE;
704 }
705
706 static PyObject *
707 _wrap_force_g_object_unref (PyObject *self, PyObject *args)
708 {
709 PyGObject *obj;
710
711 if (!PyArg_ParseTuple (args, "O", &obj)) return NULL;
712
713 g_assert (G_IS_OBJECT (obj->obj));
714 g_object_unref (obj->obj);
715
716 Py_RETURN_NONE;
717 }
718
719 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
720
721 static PyObject *
722 _wrap_test_parse_constructor_args (PyObject *self, PyObject *args)
723 {
724 char *arg_names[] = { "label", NULL };
725 char *prop_names[] = { "label", NULL };
726 GParameter params[1] = { { 0 } };
727 PyObject *parsed_args[1];
728 guint nparams = 0;
729
730 if (!PyArg_ParseTuple (args, "O", &(parsed_args[0]))) return NULL;
731
732 if (!pyg_parse_constructor_args (TYPE_TEST, arg_names, prop_names, params,
733 &nparams, parsed_args)) {
734 return NULL;
735 }
736
737 return PyLong_FromLong (nparams);
738 }
739
740 G_GNUC_END_IGNORE_DEPRECATIONS
741
742 static PyObject *
743 _wrap_test_to_unichar_conv (PyObject *self, PyObject *args)
744 {
745 PyObject *obj;
746 gunichar result;
747
748 if (!PyArg_ParseTuple (args, "O", &obj)) return NULL;
749
750 if (!pyg_pyobj_to_unichar_conv (obj, &result)) return NULL;
751
752 return PyLong_FromLong (result);
753 }
754
755 static PyMethodDef testhelper_functions[] = {
756 { "force_g_object_ref", (PyCFunction)_wrap_force_g_object_ref,
757 METH_VARARGS },
758 { "force_g_object_unref", (PyCFunction)_wrap_force_g_object_unref,
759 METH_VARARGS },
760 { "test_parse_constructor_args",
761 (PyCFunction)_wrap_test_parse_constructor_args, METH_VARARGS },
762 { "get_test_thread", (PyCFunction)_wrap_get_test_thread, METH_NOARGS },
763 { "test_to_unichar_conv", (PyCFunction)_wrap_test_to_unichar_conv,
764 METH_VARARGS },
765 { "get_unknown", (PyCFunction)_wrap_get_unknown, METH_NOARGS },
766 { "create_test_type", (PyCFunction)_wrap_create_test_type, METH_NOARGS },
767 { "test_state_ensure_release",
768 (PyCFunction)_wrap_test_state_ensure_release, METH_NOARGS },
769 { "test_g_object_new", (PyCFunction)_wrap_test_g_object_new, METH_NOARGS },
770 { "connectcallbacks", (PyCFunction)_wrap_connectcallbacks, METH_VARARGS },
771 { "test_value", (PyCFunction)_wrap_test_value, METH_VARARGS },
772 { "test_value_array", (PyCFunction)_wrap_test_value_array, METH_VARARGS },
773 { "value_array_get_nth_type", (PyCFunction)_wrap_value_array_get_nth_type,
774 METH_VARARGS },
775 { "constant_strip_prefix", (PyCFunction)_wrap_constant_strip_prefix,
776 METH_VARARGS },
777 { "test_gerror_exception", (PyCFunction)_wrap_test_gerror_exception,
778 METH_VARARGS },
779 { "owned_by_library_get_instance_list",
780 (PyCFunction)_wrap_test_owned_by_library_get_instance_list,
781 METH_NOARGS },
782 { "floating_and_sunk_get_instance_list",
783 (PyCFunction)_wrap_test_floating_and_sunk_get_instance_list,
784 METH_NOARGS },
785 { "create_and_get_property",
786 (PyCFunction)_wrap_test_create_and_get_property, METH_VARARGS },
787 { "create_and_set_property",
788 (PyCFunction)_wrap_test_create_and_set_property, METH_VARARGS },
789 { NULL, NULL }
790 };
791
792 static struct PyModuleDef _testhelpermodule = { PyModuleDef_HEAD_INIT,
793 "testhelper",
794 NULL,
795 -1,
796 testhelper_functions,
797 NULL,
798 NULL,
799 NULL,
800 NULL };
801
802 #ifdef __GNUC__
803 #define PYGI_MODINIT_FUNC \
804 __attribute__ ((visibility ("default"))) PyMODINIT_FUNC
805 #else
806 #define PYGI_MODINIT_FUNC PyMODINIT_FUNC
807 #endif
808
809 PYGI_MODINIT_FUNC PyInit_testhelper (void);
810
811 PYGI_MODINIT_FUNC
812 PyInit_testhelper (void)
813 {
814 PyObject *module;
815 PyObject *gobject_module;
816 PyObject *m, *d;
817
818 module = PyModule_Create (&_testhelpermodule);
819
820 if ((gobject_module = pygobject_init (-1, -1, -1)) == NULL) return NULL;
821 Py_DECREF (gobject_module);
822
823 d = PyModule_GetDict (module);
824
825 if ((m = PyImport_ImportModule ("gi.repository.GObject")) == NULL) {
826 PyErr_SetString (PyExc_ImportError, "could not import gobject");
827 return NULL;
828 }
829
830 /* TestInterface */
831 PyTestInterface_Type.tp_methods =
832 (struct PyMethodDef *)_PyTestInterface_methods;
833 PyTestInterface_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
834 pyg_register_interface (d, "Interface", TEST_TYPE_INTERFACE,
835 &PyTestInterface_Type);
836 pyg_register_interface_info (TEST_TYPE_INTERFACE, &__TestInterface__iinfo);
837
838
839 /* TestUnknown */
840 PyTestUnknown_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
841 PyTestUnknown_Type.tp_weaklistoffset = offsetof (PyGObject, weakreflist);
842 PyTestUnknown_Type.tp_dictoffset = offsetof (PyGObject, inst_dict);
843 pygobject_register_class (
844 d, "Unknown", TEST_TYPE_UNKNOWN, &PyTestUnknown_Type,
845 Py_BuildValue ("(O)", &PyGObject_Type, &PyTestInterface_Type));
846
847 /* TestFloating */
848 PyTestFloating_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
849 PyTestFloating_Type.tp_weaklistoffset = offsetof (PyGObject, weakreflist);
850 PyTestFloating_Type.tp_dictoffset = offsetof (PyGObject, inst_dict);
851 pygobject_register_class (d, "Floating", TEST_TYPE_FLOATING,
852 &PyTestFloating_Type,
853 Py_BuildValue ("(O)", &PyGObject_Type));
854
855 /* TestOwnedByLibrary */
856 PyTestOwnedByLibrary_Type.tp_flags =
857 (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
858 PyTestOwnedByLibrary_Type.tp_methods =
859 (struct PyMethodDef *)_PyTestOwnedByLibrary_methods;
860 PyTestOwnedByLibrary_Type.tp_weaklistoffset =
861 offsetof (PyGObject, weakreflist);
862 PyTestOwnedByLibrary_Type.tp_dictoffset = offsetof (PyGObject, inst_dict);
863 pygobject_register_class (d, "OwnedByLibrary", TEST_TYPE_OWNED_BY_LIBRARY,
864 &PyTestOwnedByLibrary_Type,
865 Py_BuildValue ("(O)", &PyGObject_Type));
866
867 /* TestFloatingAndSunk */
868 PyTestFloatingAndSunk_Type.tp_flags =
869 (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
870 PyTestFloatingAndSunk_Type.tp_methods =
871 (struct PyMethodDef *)_PyTestFloatingAndSunk_methods;
872 PyTestFloatingAndSunk_Type.tp_weaklistoffset =
873 offsetof (PyGObject, weakreflist);
874 PyTestFloatingAndSunk_Type.tp_dictoffset = offsetof (PyGObject, inst_dict);
875 pygobject_register_class (
876 d, "FloatingAndSunk", TEST_TYPE_FLOATING_AND_SUNK,
877 &PyTestFloatingAndSunk_Type, Py_BuildValue ("(O)", &PyGObject_Type));
878
879 return module;
880 }