Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

handle type objects as source in nativecallcast on jvm

Type objects represent a typed NULL.
  • Loading branch information...
commit e204d8a454a7ef3f7f1f9f0e1efd2f4a5367bf12 1 parent 0ccec45
@FROGGS FROGGS authored
Showing with 9 additions and 3 deletions.
  1. +9 −3 src/vm/jvm/runtime/org/perl6/nqp/runtime/NativeCallOps.java
View
12 src/vm/jvm/runtime/org/perl6/nqp/runtime/NativeCallOps.java
@@ -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) {
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.