Merge branch 'property_fix' into 'master'
[pygobject.git] / gi / gimodule.c
blob48ddee26f00564a87e00868f5b7daaaf8463cbc8
1 /* -*- Mode: C; c-basic-offset: 4 -*-
2 * vim: tabstop=4 shiftwidth=4 expandtab
4 * Copyright (C) 2005-2009 Johan Dahlin <johan@gnome.org>
6 * gimodule.c: wrapper for the gobject-introspection library.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21 * USA
24 #include <Python.h>
25 #include <glib-object.h>
27 #include "config.h"
28 #include "pyglib.h"
29 #include "pyginterface.h"
30 #include "pygi-repository.h"
31 #include "pyglib.h"
32 #include "pygtype.h"
33 #include "pygenum.h"
34 #include "pygboxed.h"
35 #include "pygflags.h"
36 #include "pygi-error.h"
37 #include "pygi-foreign.h"
38 #include "pygi-resulttuple.h"
39 #include "pygi-source.h"
40 #include "pygi-ccallback.h"
41 #include "pygi-closure.h"
42 #include "pygi-type.h"
43 #include "pygi-boxed.h"
44 #include "pygi-info.h"
45 #include "pygi-struct.h"
46 #include "pygobject-object.h"
47 #include "pygoptioncontext.h"
48 #include "pygoptiongroup.h"
49 #include "pygspawn.h"
50 #include "gobjectmodule.h"
51 #include "pygparamspec.h"
52 #include "pygpointer.h"
54 #include <pyglib-python-compat.h>
56 PyObject *PyGIWarning;
57 PyObject *PyGIDeprecationWarning;
58 PyObject *_PyGIDefaultArgPlaceholder;
61 /* Defined by PYGLIB_MODULE_START */
62 extern PyObject *pyglib__gobject_module_create (void);
64 /* Returns a new flag/enum type or %NULL */
65 static PyObject *
66 flags_enum_from_gtype (GType g_type,
67 PyObject * (add_func) (PyObject *, const char *,
68 const char *, GType))
70 PyObject *new_type;
71 GIRepository *repository;
72 GIBaseInfo *info;
73 const gchar *type_name;
75 repository = g_irepository_get_default ();
76 info = g_irepository_find_by_gtype (repository, g_type);
77 if (info != NULL) {
78 type_name = g_base_info_get_name (info);
79 new_type = add_func (NULL, type_name, NULL, g_type);
80 g_base_info_unref (info);
81 } else {
82 type_name = g_type_name (g_type);
83 new_type = add_func (NULL, type_name, NULL, g_type);
86 return new_type;
90 static PyObject *
91 _wrap_pyg_enum_add (PyObject *self,
92 PyObject *args,
93 PyObject *kwargs)
95 static char *kwlist[] = { "g_type", NULL };
96 PyObject *py_g_type;
97 GType g_type;
99 if (!PyArg_ParseTupleAndKeywords (args, kwargs,
100 "O!:enum_add",
101 kwlist, &PyGTypeWrapper_Type, &py_g_type)) {
102 return NULL;
105 g_type = pyg_type_from_object (py_g_type);
106 if (g_type == G_TYPE_INVALID) {
107 return NULL;
110 return flags_enum_from_gtype (g_type, pyg_enum_add);
113 static PyObject *
114 _wrap_pyg_enum_register_new_gtype_and_add (PyObject *self,
115 PyObject *args,
116 PyObject *kwargs)
118 static char *kwlist[] = { "info", NULL };
119 PyGIBaseInfo *py_info;
120 GIEnumInfo *info;
121 gint n_values;
122 GEnumValue *g_enum_values;
123 int i;
124 const gchar *namespace;
125 const gchar *type_name;
126 gchar *full_name;
127 GType g_type;
129 if (!PyArg_ParseTupleAndKeywords (args, kwargs,
130 "O:enum_add_make_new_gtype",
131 kwlist, (PyObject *)&py_info)) {
132 return NULL;
135 if (!GI_IS_ENUM_INFO (py_info->info) ||
136 g_base_info_get_type ((GIBaseInfo *) py_info->info) != GI_INFO_TYPE_ENUM) {
137 PyErr_SetString (PyExc_TypeError, "info must be an EnumInfo with info type GI_INFO_TYPE_ENUM");
138 return NULL;
141 info = (GIEnumInfo *)py_info->info;
142 n_values = g_enum_info_get_n_values (info);
144 /* The new memory is zero filled which fulfills the registration
145 * function requirement that the last item is zeroed out as a terminator.
147 g_enum_values = g_new0 (GEnumValue, n_values + 1);
149 for (i = 0; i < n_values; i++) {
150 GIValueInfo *value_info;
151 GEnumValue *enum_value;
152 const gchar *name;
153 const gchar *c_identifier;
155 value_info = g_enum_info_get_value (info, i);
156 name = g_base_info_get_name ((GIBaseInfo *) value_info);
157 c_identifier = g_base_info_get_attribute ((GIBaseInfo *) value_info,
158 "c:identifier");
160 enum_value = &g_enum_values[i];
161 enum_value->value_nick = g_strdup (name);
162 enum_value->value = g_value_info_get_value (value_info);
164 if (c_identifier == NULL) {
165 enum_value->value_name = enum_value->value_nick;
166 } else {
167 enum_value->value_name = g_strdup (c_identifier);
170 g_base_info_unref ((GIBaseInfo *) value_info);
173 /* Obfuscate the full_name by prefixing it with "Py" to avoid conflicts
174 * with real GTypes. See: https://bugzilla.gnome.org/show_bug.cgi?id=692515
176 namespace = g_base_info_get_namespace ((GIBaseInfo *) info);
177 type_name = g_base_info_get_name ((GIBaseInfo *) info);
178 full_name = g_strconcat ("Py", namespace, type_name, NULL);
180 /* If enum registration fails, free all the memory allocated
181 * for the values array. This needs to leak when successful
182 * as GObject keeps a reference to the data as specified in the docs.
184 g_type = g_enum_register_static (full_name, g_enum_values);
185 if (g_type == G_TYPE_INVALID) {
186 for (i = 0; i < n_values; i++) {
187 GEnumValue *enum_value = &g_enum_values[i];
189 /* Only free value_name if it is different from value_nick to avoid
190 * a double free. The pointer might have been is re-used in the case
191 * c_identifier was NULL in the above loop.
193 if (enum_value->value_name != enum_value->value_nick)
194 g_free ((gchar *) enum_value->value_name);
195 g_free ((gchar *) enum_value->value_nick);
198 PyErr_Format (PyExc_RuntimeError, "Unable to register enum '%s'", full_name);
200 g_free (g_enum_values);
201 g_free (full_name);
202 return NULL;
205 g_free (full_name);
206 return pyg_enum_add (NULL, type_name, NULL, g_type);
209 static PyObject *
210 _wrap_pyg_flags_add (PyObject *self,
211 PyObject *args,
212 PyObject *kwargs)
214 static char *kwlist[] = { "g_type", NULL };
215 PyObject *py_g_type;
216 GType g_type;
218 if (!PyArg_ParseTupleAndKeywords (args, kwargs,
219 "O!:flags_add",
220 kwlist, &PyGTypeWrapper_Type, &py_g_type)) {
221 return NULL;
224 g_type = pyg_type_from_object (py_g_type);
225 if (g_type == G_TYPE_INVALID) {
226 return NULL;
229 return flags_enum_from_gtype (g_type, pyg_flags_add);
232 static PyObject *
233 _wrap_pyg_flags_register_new_gtype_and_add (PyObject *self,
234 PyObject *args,
235 PyObject *kwargs)
237 static char *kwlist[] = { "info", NULL };
238 PyGIBaseInfo *py_info;
239 GIEnumInfo *info;
240 gint n_values;
241 GFlagsValue *g_flags_values;
242 int i;
243 const gchar *namespace;
244 const gchar *type_name;
245 gchar *full_name;
246 GType g_type;
248 if (!PyArg_ParseTupleAndKeywords (args, kwargs,
249 "O:flags_add_make_new_gtype",
250 kwlist, (PyObject *)&py_info)) {
251 return NULL;
254 if (!GI_IS_ENUM_INFO (py_info->info) ||
255 g_base_info_get_type ((GIBaseInfo *) py_info->info) != GI_INFO_TYPE_FLAGS) {
256 PyErr_SetString (PyExc_TypeError, "info must be an EnumInfo with info type GI_INFO_TYPE_FLAGS");
257 return NULL;
260 info = (GIEnumInfo *)py_info->info;
261 n_values = g_enum_info_get_n_values (info);
263 /* The new memory is zero filled which fulfills the registration
264 * function requirement that the last item is zeroed out as a terminator.
266 g_flags_values = g_new0 (GFlagsValue, n_values + 1);
268 for (i = 0; i < n_values; i++) {
269 GIValueInfo *value_info;
270 GFlagsValue *flags_value;
271 const gchar *name;
272 const gchar *c_identifier;
274 value_info = g_enum_info_get_value (info, i);
275 name = g_base_info_get_name ((GIBaseInfo *) value_info);
276 c_identifier = g_base_info_get_attribute ((GIBaseInfo *) value_info,
277 "c:identifier");
279 flags_value = &g_flags_values[i];
280 flags_value->value_nick = g_strdup (name);
281 flags_value->value = g_value_info_get_value (value_info);
283 if (c_identifier == NULL) {
284 flags_value->value_name = flags_value->value_nick;
285 } else {
286 flags_value->value_name = g_strdup (c_identifier);
289 g_base_info_unref ((GIBaseInfo *) value_info);
292 /* Obfuscate the full_name by prefixing it with "Py" to avoid conflicts
293 * with real GTypes. See: https://bugzilla.gnome.org/show_bug.cgi?id=692515
295 namespace = g_base_info_get_namespace ((GIBaseInfo *) info);
296 type_name = g_base_info_get_name ((GIBaseInfo *) info);
297 full_name = g_strconcat ("Py", namespace, type_name, NULL);
299 /* If enum registration fails, free all the memory allocated
300 * for the values array. This needs to leak when successful
301 * as GObject keeps a reference to the data as specified in the docs.
303 g_type = g_flags_register_static (full_name, g_flags_values);
304 if (g_type == G_TYPE_INVALID) {
305 for (i = 0; i < n_values; i++) {
306 GFlagsValue *flags_value = &g_flags_values[i];
308 /* Only free value_name if it is different from value_nick to avoid
309 * a double free. The pointer might have been is re-used in the case
310 * c_identifier was NULL in the above loop.
312 if (flags_value->value_name != flags_value->value_nick)
313 g_free ((gchar *) flags_value->value_name);
314 g_free ((gchar *) flags_value->value_nick);
317 PyErr_Format (PyExc_RuntimeError, "Unable to register flags '%s'", full_name);
319 g_free (g_flags_values);
320 g_free (full_name);
321 return NULL;
324 g_free (full_name);
325 return pyg_flags_add (NULL, type_name, NULL, g_type);
328 static void
329 initialize_interface (GTypeInterface *iface, PyTypeObject *pytype)
331 /* pygobject prints a warning if interface_init is NULL */
334 static PyObject *
335 _wrap_pyg_register_interface_info (PyObject *self, PyObject *args)
337 PyObject *py_g_type;
338 GType g_type;
339 GInterfaceInfo *info;
341 if (!PyArg_ParseTuple (args, "O!:register_interface_info",
342 &PyGTypeWrapper_Type, &py_g_type)) {
343 return NULL;
346 g_type = pyg_type_from_object (py_g_type);
347 if (!g_type_is_a (g_type, G_TYPE_INTERFACE)) {
348 PyErr_SetString (PyExc_TypeError, "must be an interface");
349 return NULL;
352 info = g_new0 (GInterfaceInfo, 1);
353 info->interface_init = (GInterfaceInitFunc) initialize_interface;
355 pyg_register_interface_info (g_type, info);
357 Py_RETURN_NONE;
360 static void
361 find_vfunc_info (GIBaseInfo *vfunc_info,
362 GType implementor_gtype,
363 gpointer *implementor_class_ret,
364 gpointer *implementor_vtable_ret,
365 GIFieldInfo **field_info_ret)
367 GType ancestor_g_type = 0;
368 int length, i;
369 GIBaseInfo *ancestor_info;
370 GIStructInfo *struct_info;
371 gpointer implementor_class = NULL;
372 gboolean is_interface = FALSE;
374 ancestor_info = g_base_info_get_container (vfunc_info);
375 is_interface = g_base_info_get_type (ancestor_info) == GI_INFO_TYPE_INTERFACE;
377 ancestor_g_type = g_registered_type_info_get_g_type (
378 (GIRegisteredTypeInfo *) ancestor_info);
379 implementor_class = g_type_class_ref (implementor_gtype);
380 if (is_interface) {
381 GTypeInstance *implementor_iface_class;
382 implementor_iface_class = g_type_interface_peek (implementor_class,
383 ancestor_g_type);
384 if (implementor_iface_class == NULL) {
385 g_type_class_unref (implementor_class);
386 PyErr_Format (PyExc_RuntimeError,
387 "Couldn't find GType of implementor of interface %s. "
388 "Forgot to set __gtype_name__?",
389 g_type_name (ancestor_g_type));
390 return;
393 *implementor_vtable_ret = implementor_iface_class;
395 struct_info = g_interface_info_get_iface_struct ( (GIInterfaceInfo*) ancestor_info);
396 } else {
397 struct_info = g_object_info_get_class_struct ( (GIObjectInfo*) ancestor_info);
398 *implementor_vtable_ret = implementor_class;
401 *implementor_class_ret = implementor_class;
403 length = g_struct_info_get_n_fields (struct_info);
404 for (i = 0; i < length; i++) {
405 GIFieldInfo *field_info;
406 GITypeInfo *type_info;
408 field_info = g_struct_info_get_field (struct_info, i);
410 if (strcmp (g_base_info_get_name ( (GIBaseInfo*) field_info),
411 g_base_info_get_name ( (GIBaseInfo*) vfunc_info)) != 0) {
412 g_base_info_unref (field_info);
413 continue;
416 type_info = g_field_info_get_type (field_info);
417 if (g_type_info_get_tag (type_info) == GI_TYPE_TAG_INTERFACE) {
418 g_base_info_unref (type_info);
419 *field_info_ret = field_info;
420 break;
423 g_base_info_unref (type_info);
424 g_base_info_unref (field_info);
427 g_base_info_unref (struct_info);
430 static PyObject *
431 _wrap_pyg_hook_up_vfunc_implementation (PyObject *self, PyObject *args)
433 PyGIBaseInfo *py_info;
434 PyObject *py_type;
435 PyObject *py_function;
436 GType implementor_gtype = 0;
437 gpointer implementor_class = NULL;
438 gpointer implementor_vtable = NULL;
439 GIFieldInfo *field_info = NULL;
440 gpointer *method_ptr = NULL;
441 PyGICClosure *closure = NULL;
443 if (!PyArg_ParseTuple (args, "O!O!O:hook_up_vfunc_implementation",
444 &PyGIBaseInfo_Type, &py_info,
445 &PyGTypeWrapper_Type, &py_type,
446 &py_function))
447 return NULL;
449 implementor_gtype = pyg_type_from_object (py_type);
450 g_assert (G_TYPE_IS_CLASSED (implementor_gtype));
452 find_vfunc_info (py_info->info, implementor_gtype, &implementor_class, &implementor_vtable, &field_info);
453 if (field_info != NULL) {
454 GITypeInfo *type_info;
455 GIBaseInfo *interface_info;
456 GICallbackInfo *callback_info;
457 gint offset;
459 type_info = g_field_info_get_type (field_info);
461 interface_info = g_type_info_get_interface (type_info);
462 g_assert (g_base_info_get_type (interface_info) == GI_INFO_TYPE_CALLBACK);
464 callback_info = (GICallbackInfo*) interface_info;
465 offset = g_field_info_get_offset (field_info);
466 method_ptr = G_STRUCT_MEMBER_P (implementor_vtable, offset);
468 closure = _pygi_make_native_closure ( (GICallableInfo*) callback_info,
469 GI_SCOPE_TYPE_NOTIFIED, py_function, NULL);
471 *method_ptr = closure->closure;
473 g_base_info_unref (interface_info);
474 g_base_info_unref (type_info);
475 g_base_info_unref (field_info);
477 g_type_class_unref (implementor_class);
479 Py_RETURN_NONE;
482 #if 0
483 /* Not used, left around for future reference */
484 static PyObject *
485 _wrap_pyg_has_vfunc_implementation (PyObject *self, PyObject *args)
487 PyGIBaseInfo *py_info;
488 PyObject *py_type;
489 PyObject *py_ret;
490 gpointer implementor_class = NULL;
491 gpointer implementor_vtable = NULL;
492 GType implementor_gtype = 0;
493 GIFieldInfo *field_info = NULL;
495 if (!PyArg_ParseTuple (args, "O!O!:has_vfunc_implementation",
496 &PyGIBaseInfo_Type, &py_info,
497 &PyGTypeWrapper_Type, &py_type))
498 return NULL;
500 implementor_gtype = pyg_type_from_object (py_type);
501 g_assert (G_TYPE_IS_CLASSED (implementor_gtype));
503 py_ret = Py_False;
504 find_vfunc_info (py_info->info, implementor_gtype, &implementor_class, &implementor_vtable, &field_info);
505 if (field_info != NULL) {
506 gpointer *method_ptr;
507 gint offset;
509 offset = g_field_info_get_offset (field_info);
510 method_ptr = G_STRUCT_MEMBER_P (implementor_vtable, offset);
511 if (*method_ptr != NULL) {
512 py_ret = Py_True;
515 g_base_info_unref (field_info);
517 g_type_class_unref (implementor_class);
519 Py_INCREF(py_ret);
520 return py_ret;
522 #endif
524 static PyObject *
525 _wrap_pyg_variant_type_from_string (PyObject *self, PyObject *args)
527 char *type_string;
528 PyObject *py_type;
529 PyObject *py_variant = NULL;
531 if (!PyArg_ParseTuple (args, "s:variant_type_from_string",
532 &type_string)) {
533 return NULL;
536 py_type = _pygi_type_import_by_name ("GLib", "VariantType");
538 py_variant = _pygi_boxed_new ( (PyTypeObject *) py_type, type_string, FALSE, 0);
540 return py_variant;
543 static PyObject *
544 _wrap_pyg_source_new (PyObject *self, PyObject *args)
546 return pyg_source_new ();
549 #define CHUNK_SIZE 8192
551 static PyObject*
552 pyg_channel_read(PyObject* self, PyObject *args, PyObject *kwargs)
554 int max_count = -1;
555 PyObject *py_iochannel, *ret_obj = NULL;
556 gsize total_read = 0;
557 GError* error = NULL;
558 GIOStatus status = G_IO_STATUS_NORMAL;
559 GIOChannel *iochannel = NULL;
561 if (!PyArg_ParseTuple (args, "Oi:pyg_channel_read", &py_iochannel, &max_count)) {
562 return NULL;
564 if (!pyg_boxed_check (py_iochannel, G_TYPE_IO_CHANNEL)) {
565 PyErr_SetString(PyExc_TypeError, "first argument is not a GLib.IOChannel");
566 return NULL;
569 if (max_count == 0)
570 return PYGLIB_PyBytes_FromString("");
572 iochannel = pyg_boxed_get (py_iochannel, GIOChannel);
574 while (status == G_IO_STATUS_NORMAL
575 && (max_count == -1 || total_read < (gsize)max_count)) {
576 gsize single_read;
577 char* buf;
578 gsize buf_size;
580 if (max_count == -1)
581 buf_size = CHUNK_SIZE;
582 else {
583 buf_size = max_count - total_read;
584 if (buf_size > CHUNK_SIZE)
585 buf_size = CHUNK_SIZE;
588 if ( ret_obj == NULL ) {
589 ret_obj = PYGLIB_PyBytes_FromStringAndSize((char *)NULL, buf_size);
590 if (ret_obj == NULL)
591 goto failure;
593 else if (buf_size + total_read > (gsize)PYGLIB_PyBytes_Size(ret_obj)) {
594 if (PYGLIB_PyBytes_Resize(&ret_obj, buf_size + total_read) == -1)
595 goto failure;
598 buf = PYGLIB_PyBytes_AsString(ret_obj) + total_read;
600 Py_BEGIN_ALLOW_THREADS;
601 status = g_io_channel_read_chars (iochannel, buf, buf_size, &single_read, &error);
602 Py_END_ALLOW_THREADS;
604 if (pygi_error_check (&error))
605 goto failure;
607 total_read += single_read;
610 if ( total_read != (gsize)PYGLIB_PyBytes_Size(ret_obj) ) {
611 if (PYGLIB_PyBytes_Resize(&ret_obj, total_read) == -1)
612 goto failure;
615 return ret_obj;
617 failure:
618 Py_XDECREF(ret_obj);
619 return NULL;
622 static PyMethodDef _gi_functions[] = {
623 { "enum_add", (PyCFunction) _wrap_pyg_enum_add, METH_VARARGS | METH_KEYWORDS },
624 { "enum_register_new_gtype_and_add", (PyCFunction) _wrap_pyg_enum_register_new_gtype_and_add, METH_VARARGS | METH_KEYWORDS },
625 { "flags_add", (PyCFunction) _wrap_pyg_flags_add, METH_VARARGS | METH_KEYWORDS },
626 { "flags_register_new_gtype_and_add", (PyCFunction) _wrap_pyg_flags_register_new_gtype_and_add, METH_VARARGS | METH_KEYWORDS },
628 { "register_interface_info", (PyCFunction) _wrap_pyg_register_interface_info, METH_VARARGS },
629 { "hook_up_vfunc_implementation", (PyCFunction) _wrap_pyg_hook_up_vfunc_implementation, METH_VARARGS },
630 { "variant_type_from_string", (PyCFunction) _wrap_pyg_variant_type_from_string, METH_VARARGS },
631 { "source_new", (PyCFunction) _wrap_pyg_source_new, METH_NOARGS },
632 { "source_set_callback", (PyCFunction) pyg_source_set_callback, METH_VARARGS },
633 { "io_channel_read", (PyCFunction) pyg_channel_read, METH_VARARGS },
634 { "require_foreign", (PyCFunction) pygi_require_foreign, METH_VARARGS | METH_KEYWORDS },
635 { "spawn_async",
636 (PyCFunction)pyglib_spawn_async, METH_VARARGS|METH_KEYWORDS,
637 "spawn_async(argv, envp=None, working_directory=None,\n"
638 " flags=0, child_setup=None, user_data=None,\n"
639 " standard_input=None, standard_output=None,\n"
640 " standard_error=None) -> (pid, stdin, stdout, stderr)\n"
641 "\n"
642 "Execute a child program asynchronously within a glib.MainLoop()\n"
643 "See the reference manual for a complete reference.\n" },
644 { "type_name", pyg_type_name, METH_VARARGS },
645 { "type_from_name", pyg_type_from_name, METH_VARARGS },
646 { "type_is_a", pyg_type_is_a, METH_VARARGS },
647 { "type_register", _wrap_pyg_type_register, METH_VARARGS },
648 { "signal_new", pyg_signal_new, METH_VARARGS },
649 { "list_properties",
650 pyg_object_class_list_properties, METH_VARARGS },
651 { "new",
652 (PyCFunction)pyg_object_new, METH_VARARGS|METH_KEYWORDS },
653 { "signal_accumulator_true_handled",
654 (PyCFunction)pyg_signal_accumulator_true_handled, METH_VARARGS },
655 { "add_emission_hook",
656 (PyCFunction)pyg_add_emission_hook, METH_VARARGS },
657 { "_install_metaclass",
658 (PyCFunction)pyg__install_metaclass, METH_O },
659 { "_gvalue_get",
660 (PyCFunction)pyg__gvalue_get, METH_O },
661 { "_gvalue_set",
662 (PyCFunction)pyg__gvalue_set, METH_VARARGS },
663 { NULL, NULL, 0 }
666 static struct PyGI_API CAPI = {
667 pygi_register_foreign_struct,
670 PYGLIB_MODULE_START(_gi, "_gi")
672 PyObject *api;
673 PyObject *module_dict = PyModule_GetDict (module);
675 /* Always enable Python threads since we cannot predict which GI repositories
676 * might accept Python callbacks run within non-Python threads or might trigger
677 * toggle ref notifications.
678 * See: https://bugzilla.gnome.org/show_bug.cgi?id=709223
680 PyEval_InitThreads ();
682 PyModule_AddStringConstant(module, "__package__", "gi._gi");
684 pygi_foreign_init ();
685 pygi_error_register_types (module);
686 _pygi_repository_register_types (module);
687 _pygi_info_register_types (module);
688 _pygi_struct_register_types (module);
689 _pygi_boxed_register_types (module);
690 _pygi_ccallback_register_types (module);
691 pygi_resulttuple_register_types (module);
693 pyglib_spawn_register_types (module_dict);
694 pyglib_option_context_register_types (module_dict);
695 pyglib_option_group_register_types (module_dict);
697 pygobject_register_api (module_dict);
698 pygobject_register_constants (module);
699 pygobject_register_features (module_dict);
700 pygobject_register_version_tuples (module_dict);
701 pygobject_register_warnings (module_dict);
702 pygobject_type_register_types (module_dict);
703 pygobject_object_register_types (module_dict);
704 pygobject_interface_register_types (module_dict);
705 pygobject_paramspec_register_types (module_dict);
706 pygobject_boxed_register_types (module_dict);
707 pygobject_pointer_register_types (module_dict);
708 pygobject_enum_register_types (module_dict);
709 pygobject_flags_register_types (module_dict);
711 PyGIWarning = PyErr_NewException ("gi.PyGIWarning", PyExc_Warning, NULL);
713 /* Use RuntimeWarning as the base class of PyGIDeprecationWarning
714 * for unstable (odd minor version) and use DeprecationWarning for
715 * stable (even minor version). This is so PyGObject deprecations
716 * behave the same as regular Python deprecations in stable releases.
718 #if PYGOBJECT_MINOR_VERSION % 2
719 PyGIDeprecationWarning = PyErr_NewException("gi.PyGIDeprecationWarning",
720 PyExc_RuntimeWarning, NULL);
721 #else
722 PyGIDeprecationWarning = PyErr_NewException("gi.PyGIDeprecationWarning",
723 PyExc_DeprecationWarning, NULL);
724 #endif
726 /* Place holder object used to fill in "from Python" argument lists
727 * for values not supplied by the caller but support a GI default.
729 _PyGIDefaultArgPlaceholder = PyList_New(0);
731 Py_INCREF (PyGIWarning);
732 PyModule_AddObject (module, "PyGIWarning", PyGIWarning);
734 Py_INCREF(PyGIDeprecationWarning);
735 PyModule_AddObject(module, "PyGIDeprecationWarning", PyGIDeprecationWarning);
737 api = PYGLIB_CPointer_WrapPointer ( (void *) &CAPI, "gi._API");
738 if (api == NULL) {
739 return PYGLIB_MODULE_ERROR_RETURN;
741 PyModule_AddObject (module, "_API", api);
743 PYGLIB_MODULE_END