Skip to content

Commit

Permalink
Coerce to String instead of raising an error when handed a non-String…
Browse files Browse the repository at this point in the history
… param (related to ffi/ffi#242)
  • Loading branch information
vp-of-awesome committed Jan 6, 2013
1 parent 1a88a15 commit 56c7716
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/org/jruby/ext/ffi/jffi/JITRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,15 @@ private static MemoryIO convertToStringMemoryIO(IRubyObject parameter, ThreadCon
} else if (parameter instanceof RubyNil) {
return NilPointerParameterStrategy.NullMemoryIO.INSTANCE;

} else if (callSite != null && !(conversionMethod = callSite.retrieveCache(parameter.getMetaClass(), callSite.getMethodName()).method).isUndefined()) {
} else if (!(conversionMethod = callSite.retrieveCache(parameter.getMetaClass(), callSite.getMethodName()).method).isUndefined()) {
IRubyObject convertedParameter = conversionMethod.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK);
if (!context.runtime.getString().isInstance(convertedParameter)) {
throw context.runtime.newTypeError(parameter.getMetaClass() + "#" + callSite.getMethodName() + " should return String");
if (convertedParameter instanceof RubyString) {
return StringParameterStrategy.getMemoryIO((RubyString) convertedParameter, isDirect, checkStringSafety);
}

return StringParameterStrategy.getMemoryIO((RubyString) convertedParameter, isDirect, checkStringSafety);

} else {
return StringParameterStrategy.getMemoryIO(parameter.convertToString(), isDirect, checkStringSafety);
// Fall through to the default conversion which will raise an error if the converted value is not of the correct type.
}

return StringParameterStrategy.getMemoryIO(parameter.convertToString(), isDirect, checkStringSafety);
}

public static MemoryIO convertToStringMemoryIO(IRubyObject parameter, ThreadContext context, CachingCallSite callSite) {
Expand Down

0 comments on commit 56c7716

Please sign in to comment.