Permalink
Browse files

Coerce to String instead of raising an error when handed a non-String…

… param (related to ffi/ffi#242)
  • Loading branch information...
1 parent 1a88a15 commit 56c77168c805fc2b4bd3785094a028a2f9560584 Wayne Meissner committed Jan 2, 2013
Showing with 6 additions and 8 deletions.
  1. +6 −8 src/org/jruby/ext/ffi/jffi/JITRuntime.java
@@ -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) {

0 comments on commit 56c7716

Please sign in to comment.