Skip to content

Commit

Permalink
Raise a ruby exception if a non-native pointer backed struct is put into
Browse files Browse the repository at this point in the history
a pointer field
  • Loading branch information
vp-of-awesome committed May 21, 2009
1 parent e7d6ace commit 49968e2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/org/jruby/ext/ffi/StructLayoutBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,13 @@ public void put(Ruby runtime, StructLayout.Storage cache, IRubyObject ptr, IRuby
if (value instanceof Pointer) {
getMemoryIO(ptr).putMemoryIO(getOffset(ptr), ((Pointer) value).getMemoryIO());
} else if (value instanceof Struct) {
getMemoryIO(ptr).putMemoryIO(getOffset(ptr), ((Struct) value).getMemoryIO());
MemoryIO mem = ((Struct) value).getMemoryIO();

if (!(mem instanceof DirectMemoryIO)) {
throw runtime.newArgumentError("Struct memory not backed by a native pointer");
}
getMemoryIO(ptr).putMemoryIO(getOffset(ptr), mem);

} else if (value instanceof RubyInteger) {
getMemoryIO(ptr).putAddress(offset, Util.int64Value(ptr));
} else if (value.respondsTo("to_ptr")) {
Expand Down

0 comments on commit 49968e2

Please sign in to comment.