gnome-perl-introspection r31 - in trunk/Glib-Object-Introspection: . xs



Author: tsch
Date: Sat Nov  8 19:51:32 2008
New Revision: 31
URL: http://svn.gnome.org/viewvc/gnome-perl-introspection?rev=31&view=rev

Log:
Add initial wrappers of GIUnionInfo.  Move everything from IdlBoxedInfo.xs into
IdlStructInfo.xs where it belongs, conceptionally.  Treat boxed objects,
structs, and unions alike when it comes to type registration and method
invocation.


Added:
   trunk/Glib-Object-Introspection/xs/IdlUnionInfo.xs
Removed:
   trunk/Glib-Object-Introspection/xs/IdlBoxedInfo.xs
Modified:
   trunk/Glib-Object-Introspection/gobject-introspection.typemap
   trunk/Glib-Object-Introspection/xs/IdlBaseInfo.xs
   trunk/Glib-Object-Introspection/xs/IdlRepository.xs
   trunk/Glib-Object-Introspection/xs/IdlStructInfo.xs

Modified: trunk/Glib-Object-Introspection/gobject-introspection.typemap
==============================================================================
--- trunk/Glib-Object-Introspection/gobject-introspection.typemap	(original)
+++ trunk/Glib-Object-Introspection/gobject-introspection.typemap	Sat Nov  8 19:51:32 2008
@@ -15,6 +15,7 @@
 GISignalInfo *		T_GPERL_GENERIC_WRAPPER
 GIStructInfo *		T_GPERL_GENERIC_WRAPPER
 GITypeInfo *		T_GPERL_GENERIC_WRAPPER
+GIUnionInfo *		T_GPERL_GENERIC_WRAPPER
 GIValueInfo *		T_GPERL_GENERIC_WRAPPER
 GIVFuncInfo *		T_GPERL_GENERIC_WRAPPER
 

Modified: trunk/Glib-Object-Introspection/xs/IdlBaseInfo.xs
==============================================================================
--- trunk/Glib-Object-Introspection/xs/IdlBaseInfo.xs	(original)
+++ trunk/Glib-Object-Introspection/xs/IdlBaseInfo.xs	Sat Nov  8 19:51:32 2008
@@ -120,7 +120,7 @@
 	gperl_set_isa ("Glib::Object::Introspection::SignalInfo", "Glib::Object::Introspection::CallableInfo");
 	gperl_set_isa ("Glib::Object::Introspection::StructInfo", "Glib::Object::Introspection::RegisteredTypeInfo");
 	gperl_set_isa ("Glib::Object::Introspection::TypeInfo", "Glib::Object::Introspection::BaseInfo");
-	gperl_set_isa ("Glib::Object::Introspection::UnionInfo", "Glib::Object::Introspection::BaseInfo");
+	gperl_set_isa ("Glib::Object::Introspection::UnionInfo", "Glib::Object::Introspection::RegisteredTypeInfo");
 	gperl_set_isa ("Glib::Object::Introspection::VFuncInfo", "Glib::Object::Introspection::CallableInfo");
 	gperl_set_isa ("Glib::Object::Introspection::ValueInfo", "Glib::Object::Introspection::BaseInfo");
 

Modified: trunk/Glib-Object-Introspection/xs/IdlRepository.xs
==============================================================================
--- trunk/Glib-Object-Introspection/xs/IdlRepository.xs	(original)
+++ trunk/Glib-Object-Introspection/xs/IdlRepository.xs	Sat Nov  8 19:51:32 2008
@@ -118,9 +118,12 @@
 
 		info = g_irepository_get_info (repository, namespace, i);
 		info_type = g_base_info_get_type (info);
+		name = g_base_info_get_name (info);
 
 		if (info_type != GI_INFO_TYPE_OBJECT &&
 		    info_type != GI_INFO_TYPE_BOXED &&
+		    info_type != GI_INFO_TYPE_STRUCT &&
+		    info_type != GI_INFO_TYPE_UNION &&
 		    info_type != GI_INFO_TYPE_ENUM &&
 		    info_type != GI_INFO_TYPE_FLAGS) {
 			g_base_info_unref ((GIBaseInfo *) info);
@@ -128,13 +131,17 @@
 		}
 
 		type = gperl_i11n_get_gtype ((GIRegisteredTypeInfo *) info);
+		if (!type)
+			croak ("Could not find GType for type %s::%s",
+			       namespace, name);
 
-		name = g_base_info_get_name (info);
 		full_package = g_strconcat (package, "::", name, NULL);
 
 		/* FIXME: This is a hack to get our AUTOLOAD involved. */
 		if (info_type == GI_INFO_TYPE_OBJECT ||
-		    info_type == GI_INFO_TYPE_BOXED) {
+		    info_type == GI_INFO_TYPE_BOXED ||
+		    info_type == GI_INFO_TYPE_STRUCT ||
+		    info_type == GI_INFO_TYPE_UNION) {
 			gperl_set_isa (full_package, package);
 		}
 
@@ -144,6 +151,8 @@
 			break;
 
 		    case GI_INFO_TYPE_BOXED:
+		    case GI_INFO_TYPE_STRUCT:
+		    case GI_INFO_TYPE_UNION:
 			gperl_register_boxed (type, full_package, NULL);
 			break;
 

Modified: trunk/Glib-Object-Introspection/xs/IdlStructInfo.xs
==============================================================================
--- trunk/Glib-Object-Introspection/xs/IdlStructInfo.xs	(original)
+++ trunk/Glib-Object-Introspection/xs/IdlStructInfo.xs	Sat Nov  8 19:51:32 2008
@@ -19,6 +19,7 @@
  */
 
 #include "gobject-introspection-perl.h"
+#include "gobject-introspection-perl-private.h"
 
 SV *
 newSVGIStructInfo (GIStructInfo *info)
@@ -35,6 +36,24 @@
 
 }
 
+#define ACCESS_VALUE(type, to, fro)									\
+	{												\
+		type tmp;										\
+		if (g_field_info_get_flags (field_info) & GI_FIELD_IS_READABLE) {			\
+			memcpy (&tmp, G_STRUCT_MEMBER_P (pointer, offset), sizeof (type));		\
+			RETVAL = to (tmp);								\
+		}											\
+		if (value) {										\
+			if (g_field_info_get_flags (field_info) & GI_FIELD_IS_WRITABLE) {		\
+				tmp = fro (value);							\
+				memcpy (G_STRUCT_MEMBER_P (pointer, offset), &tmp, sizeof (type));	\
+			} else {									\
+				croak ("Field %s is not writable",					\
+				       g_base_info_get_name ((GIBaseInfo*) field_info));		\
+			}										\
+		}											\
+	}
+
 MODULE = Glib::Object::Introspection::StructInfo	PACKAGE = Glib::Object::Introspection::StructInfo	PREFIX = g_struct_info_
 
 # gint g_struct_info_get_n_fields (GIStructInfo *info);
@@ -66,3 +85,132 @@
 		  g_struct_info_get_method (info, i))));
 
 GIFunctionInfo * g_struct_info_find_method (GIStructInfo *info, const gchar *name);
+
+SV *
+access_field (info, field_info, object, value=NULL)
+	GIBaseInfo *info
+	GIFieldInfo *field_info
+	SV *object
+	SV *value
+    PREINIT:
+	GType type;
+	void *pointer;
+	GITypeInfo *field_type_info;
+	GITypeTag tag;
+	gint offset;
+    CODE:
+	type = gperl_i11n_get_gtype ((GIRegisteredTypeInfo *) info);
+	pointer = gperl_get_boxed_check (object, type);
+
+	offset = g_field_info_get_offset (field_info);
+
+	field_type_info = g_field_info_get_type (field_info);
+	tag = g_type_info_get_tag (field_type_info);
+
+	RETVAL = &PL_sv_undef;
+
+	switch (tag) {
+	    case GI_TYPE_TAG_VOID:
+		break;
+
+	    case GI_TYPE_TAG_BOOLEAN:
+		ACCESS_VALUE (gboolean, newSVuv, SvUV);
+		break;
+
+	    case GI_TYPE_TAG_INT8:
+		ACCESS_VALUE (gint8, newSViv, SvIV);
+		break;
+
+	    case GI_TYPE_TAG_UINT8:
+		ACCESS_VALUE (guint8, newSVuv, SvUV);
+		break;
+
+	    case GI_TYPE_TAG_INT16:
+		ACCESS_VALUE (gint16, newSViv, SvIV);
+		break;
+
+	    case GI_TYPE_TAG_UINT16:
+		ACCESS_VALUE (guint16, newSVuv, SvUV);
+		break;
+
+	    case GI_TYPE_TAG_INT32:
+		ACCESS_VALUE (gint32, newSViv, SvIV);
+		break;
+
+	    case GI_TYPE_TAG_UINT32:
+		ACCESS_VALUE (guint32, newSVuv, SvUV);
+		break;
+
+	    case GI_TYPE_TAG_INT64:
+	    case GI_TYPE_TAG_UINT64:
+		croak ("FIXME - 64bit types");
+		break;
+
+	    case GI_TYPE_TAG_INT:
+		ACCESS_VALUE (gint, newSViv, SvIV);
+		break;
+
+	    case GI_TYPE_TAG_UINT:
+		ACCESS_VALUE (guint, newSVuv, SvUV);
+		break;
+
+	    case GI_TYPE_TAG_LONG:
+		ACCESS_VALUE (glong, newSVnv, SvNV);
+		break;
+
+	    case GI_TYPE_TAG_ULONG:
+		ACCESS_VALUE (gulong, newSVnv, SvNV);
+		break;
+
+	    case GI_TYPE_TAG_SSIZE:
+	    case GI_TYPE_TAG_SIZE:
+		croak ("FIXME - size types");
+		break;
+
+	    case GI_TYPE_TAG_FLOAT:
+		ACCESS_VALUE (gfloat, newSVnv, SvNV);
+		break;
+
+	    case GI_TYPE_TAG_DOUBLE:
+		ACCESS_VALUE (gdouble, newSVnv, SvNV);
+		break;
+
+	    case GI_TYPE_TAG_UTF8:
+		ACCESS_VALUE (gchar*, newSVGChar, SvGChar);
+		break;
+
+	    case GI_TYPE_TAG_FILENAME:
+		ACCESS_VALUE (gchar*, gperl_sv_from_filename, gperl_filename_from_sv);
+		break;
+
+	    case GI_TYPE_TAG_INTERFACE:
+	    {
+		if (g_field_info_get_flags (field_info) & GI_FIELD_IS_READABLE) {
+			RETVAL = gperl_i11n_pointer_to_sv (field_type_info, G_STRUCT_MEMBER_P (pointer, offset), FALSE);
+		}
+		if (value) {
+			if (g_field_info_get_flags (field_info) & GI_FIELD_IS_WRITABLE) {
+				memcpy (G_STRUCT_MEMBER_P (pointer, offset), gperl_i11n_sv_to_pointer (field_type_info, value), sizeof (void*));
+			} else {
+				croak ("Field %s is not writable",
+				       g_base_info_get_name ((GIBaseInfo*) field_info));
+			}
+		}
+	    }
+		break;
+
+	    case GI_TYPE_TAG_ARRAY:
+	    case GI_TYPE_TAG_GLIST:
+	    case GI_TYPE_TAG_GSLIST:
+	    case GI_TYPE_TAG_GHASH:
+	    case GI_TYPE_TAG_ERROR:
+		croak ("FIXME - array, list, hash, error types");
+		break;
+
+	    default:
+		croak ("Unhandled type tag: %d", tag);
+	}
+
+	g_base_info_unref ((GIBaseInfo *) field_type_info);
+    OUTPUT:
+	RETVAL

Added: trunk/Glib-Object-Introspection/xs/IdlUnionInfo.xs
==============================================================================
--- (empty file)
+++ trunk/Glib-Object-Introspection/xs/IdlUnionInfo.xs	Sat Nov  8 19:51:32 2008
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2005 by the gtk2-perl team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * $Id: IdlUnionInfo.xs,v 1.1.1.1 2005/08/21 14:39:45 torsten Exp $
+ */
+
+#include "gobject-introspection-perl.h"
+#include "gobject-introspection-perl-private.h"
+
+SV *
+newSVGIUnionInfo (GIUnionInfo *info)
+{
+        SV *sv = newSV (0);
+
+        return sv_setref_pv (sv, "Glib::Object::Introspection::UnionInfo", info);
+}
+
+GIUnionInfo *
+SvGIUnionInfo (SV *info)
+{
+        return INT2PTR (GIUnionInfo *, SvIV (SvRV (info)));
+
+}
+
+#define ACCESS_VALUE(type, to, fro)									\
+	{												\
+		type tmp;										\
+		if (g_field_info_get_flags (field_info) & GI_FIELD_IS_READABLE) {			\
+			memcpy (&tmp, pointer, sizeof (type));						\
+			RETVAL = to (tmp);								\
+		}											\
+		if (value) {										\
+			if (g_field_info_get_flags (field_info) & GI_FIELD_IS_WRITABLE) {		\
+				tmp = fro (value);							\
+				memcpy (pointer, &tmp, sizeof (type));					\
+			} else {									\
+				croak ("Field %s is not writable",					\
+				       g_base_info_get_name ((GIBaseInfo*) field_info));		\
+			}										\
+		}											\
+	}
+
+MODULE = Glib::Object::Introspection::UnionInfo	PACKAGE = Glib::Object::Introspection::UnionInfo	PREFIX = g_union_info_
+
+# gint g_union_info_get_n_fields (GIUnionInfo *info);
+# GIFieldInfo * g_union_info_get_field (GIUnionInfo *info, gint n);
+void
+g_union_info_get_fields (info)
+	GIUnionInfo *info
+    PREINIT:
+	gint number, i;
+    PPCODE:
+	number = g_union_info_get_n_fields (info);
+	EXTEND (sp, number);
+	for (i = 0; i < number; i++)
+		PUSHs (sv_2mortal (newSVGIFieldInfo (
+		  g_union_info_get_field (info, i))));
+
+# gint g_union_info_get_n_methods (GIUnionInfo *info);
+# GIFunctionInfo * g_union_info_get_method (GIUnionInfo *info, gint n);
+
+# gboolean g_union_info_is_discriminated (GIUnionInfo *info);
+
+# gint g_union_info_get_discriminator_offset (GIUnionInfo *info);
+
+# GITypeInfo * g_union_info_get_discriminator_type (GIUnionInfo *info);
+
+# GIConstantInfo * g_union_info_get_discriminator (GIUnionInfo *info, gint n);
+
+GIFunctionInfo * g_union_info_find_method (GIUnionInfo *info, const gchar *name);
+
+SV *
+access_field (info, field_info, object, value=NULL)
+	GIBaseInfo *info
+	GIFieldInfo *field_info
+	SV *object
+	SV *value
+    PREINIT:
+	GType type;
+	void *pointer;
+	GITypeInfo *field_type_info;
+	GITypeTag tag;
+    CODE:
+	warn ("%p", g_union_info_get_discriminator ((GIUnionInfo *) info, 0));
+	type = gperl_i11n_get_gtype ((GIRegisteredTypeInfo *) info);
+	pointer = gperl_get_boxed_check (object, type);
+
+	field_type_info = g_field_info_get_type (field_info);
+	tag = g_type_info_get_tag (field_type_info);
+
+	RETVAL = &PL_sv_undef;
+
+	switch (tag) {
+	    case GI_TYPE_TAG_VOID:
+		break;
+
+	    case GI_TYPE_TAG_BOOLEAN:
+		ACCESS_VALUE (gboolean, newSVuv, SvUV);
+		break;
+
+	    case GI_TYPE_TAG_INT8:
+		ACCESS_VALUE (gint8, newSViv, SvIV);
+		break;
+
+	    case GI_TYPE_TAG_UINT8:
+		ACCESS_VALUE (guint8, newSVuv, SvUV);
+		break;
+
+	    case GI_TYPE_TAG_INT16:
+		ACCESS_VALUE (gint16, newSViv, SvIV);
+		break;
+
+	    case GI_TYPE_TAG_UINT16:
+		ACCESS_VALUE (guint16, newSVuv, SvUV);
+		break;
+
+	    case GI_TYPE_TAG_INT32:
+		ACCESS_VALUE (gint32, newSViv, SvIV);
+		break;
+
+	    case GI_TYPE_TAG_UINT32:
+		ACCESS_VALUE (guint32, newSVuv, SvUV);
+		break;
+
+	    case GI_TYPE_TAG_INT64:
+	    case GI_TYPE_TAG_UINT64:
+		croak ("FIXME - 64bit types");
+		break;
+
+	    case GI_TYPE_TAG_INT:
+		ACCESS_VALUE (gint, newSViv, SvIV);
+		break;
+
+	    case GI_TYPE_TAG_UINT:
+		ACCESS_VALUE (guint, newSVuv, SvUV);
+		break;
+
+	    case GI_TYPE_TAG_LONG:
+		ACCESS_VALUE (glong, newSVnv, SvNV);
+		break;
+
+	    case GI_TYPE_TAG_ULONG:
+		ACCESS_VALUE (gulong, newSVnv, SvNV);
+		break;
+
+	    case GI_TYPE_TAG_SSIZE:
+	    case GI_TYPE_TAG_SIZE:
+		croak ("FIXME - size types");
+		break;
+
+	    case GI_TYPE_TAG_FLOAT:
+		ACCESS_VALUE (gfloat, newSVnv, SvNV);
+		break;
+
+	    case GI_TYPE_TAG_DOUBLE:
+		ACCESS_VALUE (gdouble, newSVnv, SvNV);
+		break;
+
+	    case GI_TYPE_TAG_UTF8:
+		ACCESS_VALUE (gchar*, newSVGChar, SvGChar);
+		break;
+
+	    case GI_TYPE_TAG_FILENAME:
+		ACCESS_VALUE (gchar*, gperl_sv_from_filename, gperl_filename_from_sv);
+		break;
+
+	    case GI_TYPE_TAG_INTERFACE:
+	    {
+		if (g_field_info_get_flags (field_info) & GI_FIELD_IS_READABLE) {
+			RETVAL = gperl_i11n_pointer_to_sv (field_type_info, pointer, FALSE);
+		}
+		if (value) {
+			if (g_field_info_get_flags (field_info) & GI_FIELD_IS_WRITABLE) {
+				memcpy (pointer, gperl_i11n_sv_to_pointer (field_type_info, value), sizeof (void*));
+			} else {
+				croak ("Field %s is not writable",
+				       g_base_info_get_name ((GIBaseInfo*) field_info));
+			}
+		}
+	    }
+		break;
+
+	    case GI_TYPE_TAG_ARRAY:
+	    case GI_TYPE_TAG_GLIST:
+	    case GI_TYPE_TAG_GSLIST:
+	    case GI_TYPE_TAG_GHASH:
+	    case GI_TYPE_TAG_ERROR:
+		croak ("FIXME - array, list, hash, error types");
+		break;
+
+	    default:
+		croak ("Unhandled type tag: %d", tag);
+	}
+
+	g_base_info_unref ((GIBaseInfo *) field_type_info);
+    OUTPUT:
+	RETVAL



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]