java-gobject-introspection r153 - in trunk/src/org/gnome/gir: compiler repository



Author: walters
Date: Sat Dec 20 03:41:02 2008
New Revision: 153
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=153&view=rev

Log:
Expand fixed Pointer[N] into Pointer0, Pointer1 for structures

This pattern shows up with structure padding, and JNA requires
special handling if we want to treat it as a JVM array, which
really we don't since no one should be touching it.

Modified:
   trunk/src/org/gnome/gir/compiler/CodeFactory.java
   trunk/src/org/gnome/gir/repository/GIntrospectionAPI.java
   trunk/src/org/gnome/gir/repository/TypeInfo.java

Modified: trunk/src/org/gnome/gir/compiler/CodeFactory.java
==============================================================================
--- trunk/src/org/gnome/gir/compiler/CodeFactory.java	(original)
+++ trunk/src/org/gnome/gir/compiler/CodeFactory.java	Sat Dec 20 03:41:02 2008
@@ -1692,14 +1692,30 @@
 				continue;
 			writeCallable(ACC_PUBLIC, compilation, fi, ctx);
 		}
+		Type pointerType = getType(Pointer.class);
 		for (FieldInfo fi : fields) {
 			String name = NameMap.ucaseToCamel(fi.getName());
 			Type fieldType = TypeMap.toJava(fi);
 			if (fieldType.equals(Type.VOID_TYPE)) // FIXME Temporary hack for
 													// GdkAtom
-				fieldType = Type.getType(Pointer.class);
-			FieldVisitor fv = compilation.writer.visitField(ACC_PUBLIC, name, fieldType.getDescriptor(), null, null);
-			fv.visitEnd();
+				fieldType = pointerType;
+			// This occurs for arrays that act as padding; expand into a list of
+			// pointers.
+			if (fi.getType().getTag().equals(TypeTag.ARRAY) &&
+					fi.getType().getParamType(0).getTag().equals(TypeTag.VOID)) {
+				int fixed = fi.getType().getArrayFixedSize();
+				if (fixed > 0) {
+					for (int i = 0; i < fixed; i++) {
+						String nameN = name + i;
+						FieldVisitor fv = compilation.writer.visitField(ACC_PUBLIC, nameN, getType(Pointer.class).getDescriptor(), null, null);
+						fv.visitEnd();						
+					}
+				}
+			} else {
+				// A regular field.
+				FieldVisitor fv = compilation.writer.visitField(ACC_PUBLIC, name, fieldType.getDescriptor(), null, null);
+				fv.visitEnd();
+			}
 		}
 	}
 

Modified: trunk/src/org/gnome/gir/repository/GIntrospectionAPI.java
==============================================================================
--- trunk/src/org/gnome/gir/repository/GIntrospectionAPI.java	(original)
+++ trunk/src/org/gnome/gir/repository/GIntrospectionAPI.java	Sat Dec 20 03:41:02 2008
@@ -98,6 +98,7 @@
 						                                  int       n);
 	BaseInfo            g_type_info_get_interface       (TypeInfo info);
 	int                  g_type_info_get_array_length    (TypeInfo info);
+	int                  g_type_info_get_array_fixed_size    (TypeInfo info);	
 	boolean              g_type_info_is_zero_terminated  (TypeInfo info);
 
 	int                  g_type_info_get_n_error_domains (TypeInfo info);

Modified: trunk/src/org/gnome/gir/repository/TypeInfo.java
==============================================================================
--- trunk/src/org/gnome/gir/repository/TypeInfo.java	(original)
+++ trunk/src/org/gnome/gir/repository/TypeInfo.java	Sat Dec 20 03:41:02 2008
@@ -41,6 +41,9 @@
 	public int getArrayLength() {
 		return Repository.getNativeLibrary().g_type_info_get_array_length(this);		
 	}
+	public int getArrayFixedSize() {
+		return Repository.getNativeLibrary().g_type_info_get_array_fixed_size(this);		
+	}	
 	public boolean isZeroTerminated() {
 		return Repository.getNativeLibrary().g_type_info_is_zero_terminated(this);		
 	}



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