From 31ecd935564984068e6646676392122bdc03e42e Mon Sep 17 00:00:00 2001 From: Simon Feltman Date: Mon, 5 May 2014 19:42:59 -0700 Subject: Initialize the foreign API at PyGI load time Initialize the foreign struct list at gi._gi module load time. This ensures we always have a valid (non-null) list of foreign marshalers outside of the context of marshaling. https://bugzilla.gnome.org/show_bug.cgi?id=694604 --- gi/gimodule.c | 3 ++- gi/pygi-foreign.c | 12 ++++++++---- gi/pygi-foreign.h | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'gi') diff --git a/gi/gimodule.c b/gi/gimodule.c index 1731190c..47cd33ca 100644 --- a/gi/gimodule.c +++ b/gi/gimodule.c @@ -661,13 +661,14 @@ PYGLIB_MODULE_START(_gi, "_gi") PyModule_AddObject (module, "_gobject", _gobject_module); PyModule_AddStringConstant(module, "__package__", "gi._gi"); + pygi_foreign_init (); pygi_error_register_types (module); _pygi_repository_register_types (module); _pygi_info_register_types (module); _pygi_struct_register_types (module); _pygi_boxed_register_types (module); _pygi_ccallback_register_types (module); - _pygi_argument_init(); + _pygi_argument_init (); /* Use RuntimeWarning as the base class of PyGIDeprecationWarning * for unstable (odd minor version) and use DeprecationWarning for diff --git a/gi/pygi-foreign.c b/gi/pygi-foreign.c index 6e0bf79d..8a83c351 100644 --- a/gi/pygi-foreign.c +++ b/gi/pygi-foreign.c @@ -70,10 +70,6 @@ pygi_struct_foreign_lookup (GIBaseInfo *base_info) const gchar *namespace = g_base_info_get_namespace (base_info); const gchar *name = g_base_info_get_name (base_info); - if (foreign_structs == NULL) { - init_foreign_structs (); - } - result = do_lookup (namespace, name); if (result == NULL) { @@ -166,3 +162,11 @@ pygi_register_foreign_struct (const char* namespace_, g_ptr_array_add (foreign_structs, new_struct); } + +void +pygi_foreign_init (void) +{ + if (foreign_structs == NULL) { + init_foreign_structs (); + } +} diff --git a/gi/pygi-foreign.h b/gi/pygi-foreign.h index acec0698..ca4f75b6 100644 --- a/gi/pygi-foreign.h +++ b/gi/pygi-foreign.h @@ -44,4 +44,6 @@ void pygi_register_foreign_struct (const char* namespace_, PyGIArgOverrideFromGIArgumentFunc from_func, PyGIArgOverrideReleaseFunc release_func); +void pygi_foreign_init (void); + #endif /* __PYGI_FOREIGN_H__ */ -- cgit v1.2.1