| 1 |
|
| 2 |
|
| 3 |
#define UNION_REBLESSERS_HV "Glib::Object::Introspection::_REBLESSERS" |
| 4 |
#define UNION_MEMBER_TYPE_SUFFIX "::_i11n_gtype" |
| 5 |
|
| 6 |
static SV * |
| 7 |
rebless_union_sv (GType type, const char *package, gpointer mem, gboolean own) |
| 8 |
{ |
| 9 |
SV *sv, **reblesser_p; |
| 10 |
HV *reblessers; |
| 11 |
|
| 12 |
sv = gperl_default_boxed_wrapper_class ()->wrap (type, package, mem, own); |
| 13 |
|
| 14 |
reblessers = get_hv (UNION_REBLESSERS_HV, 0); |
| 15 |
g_assert (reblessers); |
| 16 |
reblesser_p = hv_fetch (reblessers, package, strlen (package), 0); |
| 17 |
if (reblesser_p && gperl_sv_is_defined (*reblesser_p)) { |
| 18 |
dSP; |
| 19 |
ENTER; |
| 20 |
SAVETMPS; |
| 21 |
PUSHMARK (SP); |
| 22 |
XPUSHs (sv_2mortal (SvREFCNT_inc (sv))); |
| 23 |
PUTBACK; |
| 24 |
call_sv (*reblesser_p, G_DISCARD); |
| 25 |
FREETMPS; |
| 26 |
LEAVE; |
| 27 |
} |
| 28 |
|
| 29 |
return sv; |
| 30 |
} |
| 31 |
|
| 32 |
static void |
| 33 |
associate_union_members_with_gtype (GIUnionInfo *info, const gchar *package, GType type) |
| 34 |
{ |
| 35 |
gint i, n_fields; |
| 36 |
n_fields = g_union_info_get_n_fields (info); |
| 37 |
for (i = 0; i < n_fields; i++) { |
| 38 |
GIFieldInfo *field_info; |
| 39 |
GITypeInfo *field_type; |
| 40 |
GIBaseInfo *field_interface; |
| 41 |
const gchar *type_name; |
| 42 |
gchar *full_name; |
| 43 |
SV *sv; |
| 44 |
|
| 45 |
field_info = g_union_info_get_field (info, i); |
| 46 |
field_type = g_field_info_get_type (field_info); |
| 47 |
field_interface = g_type_info_get_interface (field_type); |
| 48 |
|
| 49 |
|
| 50 |
if (!field_interface) { |
| 51 |
g_base_info_unref ((GIBaseInfo *) field_type); |
| 52 |
g_base_info_unref ((GIBaseInfo *) field_info); |
| 53 |
continue; |
| 54 |
} |
| 55 |
|
| 56 |
type_name = g_base_info_get_name (field_interface); |
| 57 |
full_name = g_strconcat (package, "::", type_name, UNION_MEMBER_TYPE_SUFFIX, NULL); |
| 58 |
dwarn ("%s::%s => %"G_GSIZE_FORMAT" (%s)\n", |
| 59 |
package, type_name, type, g_type_name (type)); |
| 60 |
sv = get_sv (full_name, GV_ADD); |
| 61 |
sv_setuv (sv, type); |
| 62 |
g_free (full_name); |
| 63 |
|
| 64 |
g_base_info_unref ((GIBaseInfo *) field_interface); |
| 65 |
g_base_info_unref ((GIBaseInfo *) field_type); |
| 66 |
g_base_info_unref ((GIBaseInfo *) field_info); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
static GType |
| 71 |
find_union_member_gtype (const gchar *package, const gchar *namespace) |
| 72 |
{ |
| 73 |
gchar *type_sv_name; |
| 74 |
SV *type_sv; |
| 75 |
type_sv_name = g_strconcat (package, "::", namespace, |
| 76 |
UNION_MEMBER_TYPE_SUFFIX, NULL); |
| 77 |
type_sv = get_sv (type_sv_name, 0); |
| 78 |
g_free (type_sv_name); |
| 79 |
return type_sv ? SvUV (type_sv) : G_TYPE_NONE; |
| 80 |
} |