Skip to content

Commit

Permalink
JNAerator: started cleanup of function pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
ochafik committed Jul 3, 2013
1 parent 7f1998a commit 56a653b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
tmp
.DS_Store
build_out
_jnaerator.*
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public <M extends ModifiableElement> M annotateRawType(M element) throws Unsuppo
break;
case Struct:
case ComplexDouble:
case FunctionSignature:
case Default:
//throw new UnsupportedConversionException(typeRef, "Struct by value not supported yet");
break;
Expand Down Expand Up @@ -206,14 +207,7 @@ public NL4JConversion convertTypeToNL4J(TypeRef valueType, Identifier libraryCla
JavaPrim prim = getPrimitive(valueType, libraryClassName);
if (prim != null) {
return convertPrimitiveTypeRefToNL4J(prim, structIOExpr, fieldIndex, valueExpr);
} else if (valueType instanceof TypeRef.Pointer) {
// Treat callback pointers as callbacks.
TypeRef targetRef = ((TypeRef.Pointer) (valueType)).getTarget();
if (targetRef instanceof TypeRef.FunctionSignature) {
valueType = targetRef;
}
}

if (valueType instanceof TypeRef.TargettedTypeRef) {
TypeRef targetRef = ((TypeRef.TargettedTypeRef) valueType).getTarget();

Expand Down Expand Up @@ -276,12 +270,7 @@ public NL4JConversion convertTypeToNL4J(TypeRef valueType, Identifier libraryCla
} else if (valueType.getResolvedJavaIdentifier() != null) {
conv.typeRef = typeRef(valueType.getResolvedJavaIdentifier().clone());
if (valueType instanceof TypeRef.FunctionSignature) {
conv.type = ConvType.Pointer;
conv.typeRef = typeRef(ident(result.config.runtime.pointerClass, expr(conv.typeRef)));
if (structIOExpr != null) {
conv.setExpr = methodCall(structIOExpr.clone(), "setPointerField", thisRef(), expr(fieldIndex), valueExpr);
conv.getExpr = methodCall(structIOExpr.clone(), "getPointerField", thisRef(), expr(fieldIndex));
}
conv.type = ConvType.FunctionSignature;
} else if (valueType instanceof Enum) {
conv.type = ConvType.Enum;
conv.typeRef = typeRef(ident(IntValuedEnum.class, expr(conv.typeRef)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ public enum ConvType {

Enum,
Pointer,
FunctionSignature,
Primitive,
Struct,
NativeLong,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
typedef struct sdk_private sdk_private;
typedef sdk_private *sdk_t;
void sdk_new(sdk_t *sdk, const char* msg);
void sdk_free(sdk_t sdk);

typedef struct _cl_event * cl_event;
void f(cl_event, cl_event*);

--
#runtime(JNAerator)

import test.*;
import static test.TestLibrary.*;

sdk_new((PointerByReference)null, (String)null);
sdk_new((Pointer)null, (Pointer)null);
sdk_free((sdk_t)null);

f((Pointer)null, (Pointer)null);
f((cl_event)null, (PointerByReference)null);

--
#runtime(BridJ)

import test.*;
import static test.TestLibrary.*;

sdk_new((Pointer<sdk_t>)null, (Pointer<Byte>)null);
sdk_free((sdk_t)null);

f((cl_event)null, (Pointer<cl_event>)null);
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ struct ReSampleContext;
typedef struct ReSampleContext ReSampleContext;
void f2(ReSampleContext*);

typedef void FC(int);
void f3(FC a, FC* b);
typedef float FC(int);
void f3(FC* a);
FC f4;

typedef void (fshort1)(short x);
typedef void (fshort2)(short);
Expand Down Expand Up @@ -40,7 +41,8 @@ f2((Pointer<ReSampleContext>)null);

Callback cb = (FC)null;
Pointer<FC> pfc = null;
f3(pfc, pfc);
f3(pfc);
float ret = f4(0);

((fshort1)null).apply((short)0);
((fshort2)null).apply((short)0);
Expand Down

0 comments on commit 56a653b

Please sign in to comment.