Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

… param (related to ffi/ffi#242)
  • Loading branch information...
commit 56c77168c805fc2b4bd3785094a028a2f9560584 1 parent 1a88a15
Wayne Meissner authored
Showing with 6 additions and 8 deletions.
  1. +6 −8 src/org/jruby/ext/ffi/jffi/JITRuntime.java
14 src/org/jruby/ext/ffi/jffi/JITRuntime.java
View
@@ -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) {
Please sign in to comment.
Something went wrong with that request. Please try again.