Permalink
Browse files

Fix FFI generated methods that have more than 4 params, but less than…

… 3 of them are pointers
  • Loading branch information...
1 parent 242e824 commit f667b0b7dcfdfde7027225a4a9fbdd3defbd7c4f Wayne Meissner committed Aug 9, 2011
Showing with 8 additions and 6 deletions.
  1. +8 −6 src/org/jruby/ext/ffi/jffi/AbstractNumericMethodGenerator.java
@@ -186,12 +186,15 @@ public void generate(AsmClassBuilder builder, SkinnyMethodAdapter mv, JITSignatu
// Handle non-direct pointer parameters
if (pointerCount > 0) {
+ final int MAX_PARAM_COUNT = 4;
+ final int MAX_POINTER_COUNT = 4;
mv.label(indirect);
+ boolean emitFallback = true;
// For functions with only a few pointer args, we can possibly use the jffi object fast-path
- if (signature.getParameterCount() <= 4 && pointerCount <= 4) {
+ if (signature.getParameterCount() <= MAX_PARAM_COUNT && pointerCount <= MAX_POINTER_COUNT) {
Label fallback = new Label();
- if (pointerCount > 3) {
+ if ((emitFallback = pointerCount > 3)) {
mv.iload(heapPointerCountVar);
mv.iconst_3();
mv.if_icmpgt(fallback);
@@ -240,12 +243,11 @@ public void generate(AsmClassBuilder builder, SkinnyMethodAdapter mv, JITSignatu
sig(long.class, paramTypes));
narrow(mv, long.class, nativeIntType);
mv.go_to(boxResult);
- mv.label(fallback);
+ if (emitFallback) mv.label(fallback);
}
- // Emit the fallback code to call the generic invoker path, if
- // more than 3 pointer parameters are present.
- if (pointerCount > 3) {
+ // Emit the fallback code to call the generic invoker path.
+ if (emitFallback) {
// pop all the converted arguments off the stack
for (int i = 0; i < signature.getParameterCount(); i++) {

0 comments on commit f667b0b

Please sign in to comment.