[perl-Glib] Add new C API gperl_register_boxed_synonym
- From: Torsten SchÃnfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Glib] Add new C API gperl_register_boxed_synonym
- Date: Sun, 26 Aug 2012 17:52:53 +0000 (UTC)
commit 63168c5fbde8066d688ccc5b2ba6a9befea1faa9
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date: Sat Aug 18 22:59:21 2012 +0200
Add new C API gperl_register_boxed_synonym
It lets you make a boxed GType synonymous to another boxed GType so that
objects of the former type are treated as if they were of the latter type.
GBoxed.xs | 49 +++++++++++++++++++++++++++++++++++++++++++++++--
Glib.exports | 1 +
NEWS | 1 +
gperl.h | 1 +
4 files changed, 50 insertions(+), 2 deletions(-)
---
diff --git a/GBoxed.xs b/GBoxed.xs
index 66d346a..94f6702 100644
--- a/GBoxed.xs
+++ b/GBoxed.xs
@@ -117,7 +117,7 @@ struct _BoxedInfo {
};
-BoxedInfo *
+static BoxedInfo *
boxed_info_new (GType gtype,
const char * package,
GPerlBoxedWrapperClass * wrapper_class)
@@ -130,7 +130,16 @@ boxed_info_new (GType gtype,
return boxed_info;
}
-void
+static BoxedInfo *
+boxed_info_copy (BoxedInfo * boxed_info)
+{
+ BoxedInfo * new_boxed_info;
+ new_boxed_info = g_new0 (BoxedInfo, 1);
+ memcpy (new_boxed_info, boxed_info, sizeof (BoxedInfo));
+ return new_boxed_info;
+}
+
+static void
boxed_info_destroy (BoxedInfo * boxed_info)
{
if (boxed_info) {
@@ -257,6 +266,42 @@ gperl_register_boxed_alias (GType gtype,
G_UNLOCK (info_by_package);
}
+=item void gperl_register_boxed_synonym (GType registered_gtype, GType synonym_gtype)
+
+Registers I<synonym_gtype> as a synonym for I<registered_gtype>. All boxed
+objects of type I<synonym_gtype> will then be treated as if they were of type
+I<registered_gtype>, and I<gperl_boxed_package_from_type> will return the
+package associated with I<registered_gtype>.
+
+I<registered_gtype> must have been registered with I<gperl_register_boxed>
+already.
+
+=cut
+
+void
+gperl_register_boxed_synonym (GType registered_gtype,
+ GType synonym_gtype)
+{
+ BoxedInfo * registered_boxed_info, * synonym_boxed_info;
+
+ G_LOCK (info_by_gtype);
+
+ registered_boxed_info = (BoxedInfo *)
+ g_hash_table_lookup (info_by_gtype, (gpointer) registered_gtype);
+
+ if (!registered_boxed_info) {
+ croak ("cannot make %s synonymous to the unregistered type %s",
+ g_type_name (synonym_gtype),
+ g_type_name (registered_gtype));
+ }
+
+ synonym_boxed_info = boxed_info_copy (registered_boxed_info);
+ g_hash_table_insert (info_by_gtype, (gpointer) synonym_gtype,
+ synonym_boxed_info);
+
+ G_UNLOCK (info_by_gtype);
+}
+
=item GType gperl_boxed_type_from_package (const char * package)
Look up the GType associated with package I<package>. Returns 0 if I<type> is
diff --git a/Glib.exports b/Glib.exports
index 843b95f..3ab9e66 100644
--- a/Glib.exports
+++ b/Glib.exports
@@ -76,6 +76,7 @@ gperl_param_spec_type_from_package
gperl_prepend_isa
gperl_register_boxed
gperl_register_boxed_alias
+gperl_register_boxed_synonym
gperl_register_error_domain
gperl_register_fundamental
gperl_register_fundamental_alias
diff --git a/NEWS b/NEWS
index 77998a6..2883c7f 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Overview of changes in Glib <next>
* Make the stack handling of some marshallers more robust, in
preparation for custom Glib::Boxed converters that call back into Perl
code.
+* Add new C API gperl_register_boxed_synonym.
Overview of changes in Glib 1.261 (stable)
==========================================
diff --git a/gperl.h b/gperl.h
index fc9d38f..592e332 100644
--- a/gperl.h
+++ b/gperl.h
@@ -165,6 +165,7 @@ void gperl_register_boxed (GType gtype,
const char * package,
GPerlBoxedWrapperClass * wrapper_class);
void gperl_register_boxed_alias (GType gtype, const char * package);
+void gperl_register_boxed_synonym (GType registered_gtype, GType synonym_gtype);
SV * gperl_new_boxed (gpointer boxed, GType gtype, gboolean own);
SV * gperl_new_boxed_copy (gpointer boxed, GType gtype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]