@@ -1353,15 +1353,20 @@ boolean classes(boolean handleExceptions, boolean defineAdapters, boolean conver
1353
1353
for (Class c : functions ) {
1354
1354
String [] typeName = cppTypeName (c );
1355
1355
String [] returnConvention = typeName [0 ].split ("\\ (" );
1356
+ String [] returnType = {returnConvention [0 ] + (returnConvention .length > 2 ? "(*" : "" ),
1357
+ returnConvention .length > 2 ? ")(" + returnConvention [2 ] : "" };
1358
+ if (returnConvention .length > 2 ) {
1359
+ returnConvention = Arrays .copyOfRange (returnConvention , 2 , returnConvention .length );
1360
+ }
1356
1361
returnConvention [1 ] = constValueTypeName (returnConvention [1 ]);
1357
1362
String parameterDeclaration = typeName [1 ].substring (1 );
1358
1363
String instanceTypeName = functionClassName (c );
1359
1364
out .println ("struct JavaCPP_hidden " + instanceTypeName + " {" );
1360
1365
out .println (" " + instanceTypeName + "() : ptr(NULL), obj(NULL) { }" );
1361
1366
if (parameterDeclaration != null && parameterDeclaration .length () > 0 ) {
1362
- out .println (" " + returnConvention [0 ] + "operator()" + parameterDeclaration + ";" );
1367
+ out .println (" " + returnType [0 ] + "operator()" + parameterDeclaration + returnType [ 1 ] + ";" );
1363
1368
}
1364
- out .println (" " + typeName [0 ] + "ptr" + typeName [1 ] + ";" );
1369
+ out .println (" " + returnType [0 ] + "(" + returnConvention [ 1 ] + "* ptr) " + parameterDeclaration + returnType [1 ] + ";" );
1365
1370
out .println (" jobject obj; static jmethodID mid;" );
1366
1371
out .println ("};" );
1367
1372
out .println ("jmethodID " + instanceTypeName + "::mid = NULL;" );
@@ -2772,6 +2777,11 @@ void callback(Class<?> cls, Method callbackMethod, String callbackName, int allo
2772
2777
String instanceTypeName = functionClassName (cls );
2773
2778
String [] callbackTypeName = cppFunctionTypeName (callbackMethod );
2774
2779
String [] returnConvention = callbackTypeName [0 ].split ("\\ (" );
2780
+ String [] returnType = {returnConvention [0 ] + (returnConvention .length > 2 ? "(*" : "" ),
2781
+ returnConvention .length > 2 ? ")(" + returnConvention [2 ] : "" };
2782
+ if (returnConvention .length > 2 ) {
2783
+ returnConvention = Arrays .copyOfRange (returnConvention , 2 , returnConvention .length );
2784
+ }
2775
2785
returnConvention [1 ] = constValueTypeName (returnConvention [1 ]);
2776
2786
String parameterDeclaration = callbackTypeName [1 ].substring (1 );
2777
2787
String fieldName = mangle (callbackMethod .getName ()) + "__" + mangle (signature (callbackMethod .getParameterTypes ()));
@@ -2818,9 +2828,9 @@ void callback(Class<?> cls, Method callbackMethod, String callbackName, int allo
2818
2828
if (needUsing ) {
2819
2829
member += usingLine + "\n " ;
2820
2830
}
2821
- member += "virtual " + returnConvention [0 ] + (returnConvention .length > 1 ? returnConvention [1 ] : "" )
2822
- + methodInfo .memberName [0 ] + parameterDeclaration + " JavaCPP_override;\n "
2823
- + returnConvention [0 ] + "super_" + methodInfo .name + nonconstParamDeclaration + " { " ;
2831
+ member += "virtual " + returnType [0 ] + (returnConvention .length > 1 ? returnConvention [1 ] : "" )
2832
+ + methodInfo .memberName [0 ] + parameterDeclaration + returnType [ 1 ] + " JavaCPP_override;\n "
2833
+ + returnType [0 ] + "super_" + methodInfo .name + nonconstParamDeclaration + returnType [ 1 ] + " { " ;
2824
2834
if (methodInfo .method .getAnnotation (Virtual .class ).value ()) {
2825
2835
member += "throw JavaCPP_exception(\" Cannot call pure virtual function " + valueTypeName + "::" + methodInfo .memberName [0 ] + "().\" ); }" ;
2826
2836
} else {
@@ -2833,8 +2843,8 @@ void callback(Class<?> cls, Method callbackMethod, String callbackName, int allo
2833
2843
}
2834
2844
member += "); }" ;
2835
2845
}
2836
- firstLine = returnConvention [0 ] + (returnConvention .length > 1 ? returnConvention [1 ] : "" )
2837
- + subType + "::" + methodInfo .memberName [0 ] + parameterDeclaration + " {" ;
2846
+ firstLine = returnType [0 ] + (returnConvention .length > 1 ? returnConvention [1 ] : "" )
2847
+ + subType + "::" + methodInfo .memberName [0 ] + parameterDeclaration + returnType [ 1 ] + " {" ;
2838
2848
functionList .add (fieldName );
2839
2849
}
2840
2850
memberList .add (member );
@@ -2849,11 +2859,11 @@ void callback(Class<?> cls, Method callbackMethod, String callbackName, int allo
2849
2859
}
2850
2860
for (int i = 0 ; i < allocatorMax ; i ++) {
2851
2861
if (out2 != null ) {
2852
- out2 .println ("JNIIMPORT " + returnConvention [0 ] + (returnConvention .length > 1 ?
2853
- returnConvention [1 ] : "" ) + callbackName + (i > 0 ? i : "" ) + parameterDeclaration + ";" );
2862
+ out2 .println ("JNIIMPORT " + returnType [0 ] + (returnConvention .length > 1 ?
2863
+ returnConvention [1 ] : "" ) + callbackName + (i > 0 ? i : "" ) + parameterDeclaration + returnType [ 1 ] + ";" );
2854
2864
}
2855
- out .println ("JNIEXPORT " + returnConvention [0 ] + (returnConvention .length > 1 ?
2856
- returnConvention [1 ] : "" ) + callbackName + (i > 0 ? i : "" ) + parameterDeclaration + " {" );
2865
+ out .println ("JNIEXPORT " + returnType [0 ] + (returnConvention .length > 1 ?
2866
+ returnConvention [1 ] : "" ) + callbackName + (i > 0 ? i : "" ) + parameterDeclaration + returnType [ 1 ] + " {" );
2857
2867
out .print ((callbackReturnType != void .class ? " return " : " " ) + instanceTypeName + "_instances[" + i + "](" );
2858
2868
for (int j = 0 ; j < callbackParameterTypes .length ; j ++) {
2859
2869
out .print ("arg" + j );
@@ -2870,8 +2880,8 @@ void callback(Class<?> cls, Method callbackMethod, String callbackName, int allo
2870
2880
out2 .println ("}" );
2871
2881
}
2872
2882
}
2873
- out .println ("static " + returnConvention [0 ] + "(" + (returnConvention .length > 1 ?
2874
- returnConvention [1 ] : "" ) + "*" + callbackName + "s[" + allocatorMax + "])" + parameterDeclaration + " = {" );
2883
+ out .println ("static " + returnType [0 ] + "(" + (returnConvention .length > 1 ?
2884
+ returnConvention [1 ] : "" ) + "*" + callbackName + "s[" + allocatorMax + "])" + parameterDeclaration + returnType [ 1 ] + " = {" );
2875
2885
for (int i = 0 ; i < allocatorMax ; i ++) {
2876
2886
out .print (" " + callbackName + (i > 0 ? i : "" ));
2877
2887
if (i + 1 < allocatorMax ) {
@@ -2880,7 +2890,7 @@ void callback(Class<?> cls, Method callbackMethod, String callbackName, int allo
2880
2890
}
2881
2891
out .println (" };" );
2882
2892
2883
- firstLine = returnConvention [0 ] + instanceTypeName + "::operator()" + parameterDeclaration + " {" ;
2893
+ firstLine = returnType [0 ] + instanceTypeName + "::operator()" + parameterDeclaration + returnType [ 1 ] + " {" ;
2884
2894
}
2885
2895
2886
2896
if (!needDefinition ) {
@@ -3160,6 +3170,11 @@ void callback(Class<?> cls, Method callbackMethod, String callbackName, int allo
3160
3170
")(rarg == NULL ? 0 : env->Get" + S + "Field(rarg, JavaCPP_" + s + "ValueFID));" );
3161
3171
}
3162
3172
} else if (Pointer .class .isAssignableFrom (callbackReturnType )) {
3173
+ if (FunctionPointer .class .isAssignableFrom (callbackReturnType )) {
3174
+ functions .index (callbackReturnType );
3175
+ returnTypeName [0 ] = functionClassName (callbackReturnType ) + "*" ;
3176
+ returnTypeName [1 ] = "" ;
3177
+ }
3163
3178
out .println (" " + returnTypeName [0 ] + " rptr" + returnTypeName [1 ] + " = rarg == NULL ? NULL : (" +
3164
3179
returnTypeName [0 ] + returnTypeName [1 ] + ")jlong_to_ptr(env->GetLongField(rarg, JavaCPP_addressFID));" );
3165
3180
if (returnAdapterInfo != null ) {
@@ -3228,7 +3243,7 @@ void callback(Class<?> cls, Method callbackMethod, String callbackName, int allo
3228
3243
} else if (returnBy instanceof ByVal || returnBy instanceof ByRef ) {
3229
3244
out .println (" if (rptr == NULL) {" );
3230
3245
out .println (" JavaCPP_log(\" Return pointer address is NULL in callback for " + cls .getCanonicalName () + ".\" );" );
3231
- out .println (" static " + constValueTypeName (returnConvention [0 ].trim ()) + " empty" + returnTypeName [1 ] + ";" );
3246
+ out .println (" static " + constValueTypeName (( returnType [0 ] + returnType [ 1 ]) .trim ()) + " empty" + returnTypeName [1 ] + ";" );
3232
3247
out .println (" return empty;" );
3233
3248
out .println (" } else {" );
3234
3249
out .println (" return *" + callbackReturnCast + "rptr;" );
0 commit comments