Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
handle type objects as source in nativecallcast on jvm
Type objects represent a typed NULL.
  • Loading branch information
FROGGS committed Mar 31, 2015
1 parent 0ccec45 commit e204d8a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/NativeCallOps.java
Expand Up @@ -172,7 +172,7 @@ else if (obj instanceof org.perl6.nqp.sixmodel.reprs.CStructInstance) {
public static SixModelObject nativecallcast(SixModelObject target_spec, SixModelObject target_type, SixModelObject source, ThreadContext tc) {
Pointer o = null;

if (source instanceof CPointerInstance) { // TODO Care about CPointer type object
if (source instanceof CPointerInstance) {
o = ((CPointerInstance)source).pointer;
}
else if (source instanceof CArrayInstance) {
Expand All @@ -182,8 +182,14 @@ else if (source instanceof CStructInstance) {
o = ((CStructInstance)source).storage.getPointer();
}
else {
throw ExceptionHandling.dieInternal(tc,
"Native call expected object with CPointer representation, but got something else");
/* If we got something that is either a CPointer, CArray or CStruct but is not an instance,
* it is the type object which represents NULL. So, just don't throw and we are fine. */
if ( !(source.st.REPR instanceof org.perl6.nqp.sixmodel.reprs.CPointer
|| source.st.REPR instanceof org.perl6.nqp.sixmodel.reprs.CArray
|| source.st.REPR instanceof org.perl6.nqp.sixmodel.reprs.CStruct) ) {
throw ExceptionHandling.dieInternal(tc,
"Native call expected object with CPointer representation, but got something else");
}
}

return castNativeCall(tc, target_spec, target_type, o);
Expand Down

0 comments on commit e204d8a

Please sign in to comment.