Skip to content

Commit 0e52a03

Browse files
committed
Fix mapping of pointer and array types
1 parent f797d66 commit 0e52a03

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/gir2java/ConvertedType.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,20 @@ public ConvertedType forCType(ParsingContext context, String ctype) {
108108

109109
ConvertedType pointerConvType = new ConvertedType(this);
110110

111+
JType currentJType = getJType();
112+
int currentIndirection = 0;
113+
114+
while ( (currentJType != null) && currentJType.name().startsWith("Pointer<")) {
115+
currentIndirection++;
116+
if ( ((JClass)currentJType).getTypeParameters().size() == 0 ) {
117+
break;
118+
}
119+
currentJType = ((JClass)currentJType).getTypeParameters().get(0);
120+
}
121+
111122
JType indirectJType = getJType();
112-
int indirection = NameUtils.getIndirectionLevel(ctype);
123+
int indirection = NameUtils.getIndirectionLevel(ctype) - currentIndirection;
124+
113125
for (; indirection > 0; indirection--) {
114126
indirectJType = context.getCm().ref(Pointer.class).narrow(indirectJType);
115127
}

src/gir2java/GirParser.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,12 @@ private ConvertedType findType(Element root, ParsingContext context) {
619619
Element child = children.get(i);
620620
String childQualName = child.getQualifiedName();
621621
if (childQualName.equals("array")) {
622-
//found an <array>, treat it like a pointer to its element type
622+
//found an <array>, try taking its c:type, and the name of the core type, and using that
623+
//to make a ConvertedType
623624
convType = findSimpleType(child, context);
625+
String arrayCType = child.getAttributeValue("type", Constants.GIR_XMLNS_C);
624626
if (convType != null) {
625-
convType = convType.pointerTypeTo();
627+
convType = convType.forCType(context, arrayCType);
626628
}
627629
System.out.println("found an array, treating it as " + convType);
628630
break;
@@ -816,7 +818,8 @@ private void parseMethodOrFunction(Element root, ParsingContext context) {
816818

817819
if (returnsPointer) {
818820
// Pointer.pointerToAddress(native(...), ReturnType.class)
819-
JClass returnClass = (JClass)returnType.forCType(nextContext, returnType.getCtype()).getJType();
821+
ConvertedType returnConvType = returnType.forCType(nextContext, returnType.getCtype());
822+
JClass returnClass = (JClass)returnConvType.getJType();
820823

821824
JInvocation pointerToAddressCall =
822825
context

0 commit comments

Comments
 (0)