Skip to content

Commit

Permalink
Add CPPStruct/CUnion-reprs where it was forgotten
Browse files Browse the repository at this point in the history
  • Loading branch information
FROGGS committed Apr 27, 2018
1 parent 8610b85 commit 25f165a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/6model/reprs/CArray.c
Expand Up @@ -58,6 +58,14 @@ static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info_hash) {
repr_data->elem_kind = MVM_CARRAY_ELEM_KIND_CSTRUCT;
repr_data->elem_size = sizeof(void *);
}
else if (type_id == MVM_REPR_ID_MVMCPPStruct) {
repr_data->elem_kind = MVM_CARRAY_ELEM_KIND_CPPSTRUCT;
repr_data->elem_size = sizeof(void *);
}
else if (type_id == MVM_REPR_ID_MVMCUnion) {
repr_data->elem_kind = MVM_CARRAY_ELEM_KIND_CUNION;
repr_data->elem_size = sizeof(void *);
}
else if (type_id == MVM_REPR_ID_MVMCPointer) {
repr_data->elem_kind = MVM_CARRAY_ELEM_KIND_CPOINTER;
repr_data->elem_size = sizeof(void *);
Expand Down Expand Up @@ -197,6 +205,8 @@ static void expand(MVMThreadContext *tc, MVMCArrayREPRData *repr_data, MVMCArray
is_complex = (repr_data->elem_kind == MVM_CARRAY_ELEM_KIND_CARRAY
|| repr_data->elem_kind == MVM_CARRAY_ELEM_KIND_CPOINTER
|| repr_data->elem_kind == MVM_CARRAY_ELEM_KIND_CSTRUCT
|| repr_data->elem_kind == MVM_CARRAY_ELEM_KIND_CPPSTRUCT
|| repr_data->elem_kind == MVM_CARRAY_ELEM_KIND_CUNION
|| repr_data->elem_kind == MVM_CARRAY_ELEM_KIND_STRING);

if (is_complex) {
Expand Down Expand Up @@ -371,6 +381,18 @@ static void bind_pos(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void
bind_wrapper_and_ptr(tc, root, body, index, value.o,
IS_CONCRETE(value.o) ? ((MVMCStruct *)value.o)->body.cstruct : NULL);
break;
case MVM_CARRAY_ELEM_KIND_CPPSTRUCT:
if (REPR(value.o)->ID != MVM_REPR_ID_MVMCPPStruct)
MVM_exception_throw_adhoc(tc, "CArray of CPPStruct passed non-CStruct object");
bind_wrapper_and_ptr(tc, root, body, index, value.o,
IS_CONCRETE(value.o) ? ((MVMCPPStruct *)value.o)->body.cppstruct : NULL);
break;
case MVM_CARRAY_ELEM_KIND_CUNION:
if (REPR(value.o)->ID != MVM_REPR_ID_MVMCUnion)
MVM_exception_throw_adhoc(tc, "CArray of CUnion passed non-CStruct object");
bind_wrapper_and_ptr(tc, root, body, index, value.o,
IS_CONCRETE(value.o) ? ((MVMCUnion *)value.o)->body.cunion : NULL);
break;
default:
MVM_exception_throw_adhoc(tc, "Unknown element type in CArray");
}
Expand Down
1 change: 1 addition & 0 deletions src/6model/reprs/CArray.h
Expand Up @@ -32,6 +32,7 @@ struct MVMCArray {
#define MVM_CARRAY_ELEM_KIND_CARRAY 4
#define MVM_CARRAY_ELEM_KIND_CSTRUCT 5
#define MVM_CARRAY_ELEM_KIND_CUNION 6
#define MVM_CARRAY_ELEM_KIND_CPPSTRUCT 7

/* The CArray REPR data contains a little info about the type of array
* that we have. */
Expand Down
15 changes: 15 additions & 0 deletions src/core/nativecall.c
Expand Up @@ -838,6 +838,9 @@ static MVMObject * nativecall_cast(MVMThreadContext *tc, MVMObject *target_spec,
case MVM_REPR_ID_MVMCStruct:
result = MVM_nativecall_make_cstruct(tc, target_type, (void *)cpointer_body);
break;
case MVM_REPR_ID_MVMCPPStruct:
result = MVM_nativecall_make_cppstruct(tc, target_type, (void *)cpointer_body);
break;
case MVM_REPR_ID_MVMCUnion:
result = MVM_nativecall_make_cunion(tc, target_type, (void *)cpointer_body);
break;
Expand Down Expand Up @@ -976,6 +979,9 @@ void MVM_nativecall_refresh(MVMThreadContext *tc, MVMObject *cthingy) {
case MVM_CARRAY_ELEM_KIND_CSTRUCT:
objptr = ((MVMCStructBody *)OBJECT_BODY(body->child_objs[i]))->cstruct;
break;
case MVM_CARRAY_ELEM_KIND_CPPSTRUCT:
objptr = ((MVMCPPStructBody *)OBJECT_BODY(body->child_objs[i]))->cppstruct;
break;
case MVM_CARRAY_ELEM_KIND_CUNION:
objptr = ((MVMCUnionBody *)OBJECT_BODY(body->child_objs[i]))->cunion;
break;
Expand Down Expand Up @@ -1025,6 +1031,9 @@ void MVM_nativecall_refresh(MVMThreadContext *tc, MVMObject *cthingy) {
case MVM_CSTRUCT_ATTR_CSTRUCT:
objptr = (MVMCStructBody *)OBJECT_BODY(body->child_objs[slot]);
break;
case MVM_CSTRUCT_ATTR_CPPSTRUCT:
objptr = (MVMCPPStructBody *)OBJECT_BODY(body->child_objs[slot]);
break;
case MVM_CSTRUCT_ATTR_CUNION:
objptr = (MVMCUnionBody *)OBJECT_BODY(body->child_objs[slot]);
break;
Expand Down Expand Up @@ -1074,6 +1083,12 @@ void MVM_nativecall_refresh(MVMThreadContext *tc, MVMObject *cthingy) {
case MVM_CPPSTRUCT_ATTR_CSTRUCT:
objptr = (MVMCStructBody *)OBJECT_BODY(body->child_objs[slot]);
break;
case MVM_CPPSTRUCT_ATTR_CPPSTRUCT:
objptr = (MVMCPPStructBody *)OBJECT_BODY(body->child_objs[slot]);
break;
case MVM_CPPSTRUCT_ATTR_CUNION:
objptr = (MVMCUnionBody *)OBJECT_BODY(body->child_objs[slot]);
break;
case MVM_CPPSTRUCT_ATTR_STRING:
objptr = NULL;
break;
Expand Down
10 changes: 10 additions & 0 deletions src/core/nativecall_dyncall.c
Expand Up @@ -54,6 +54,7 @@ static char get_signature_char(MVMint16 type_id) {
case MVM_NATIVECALL_ARG_UTF8STR:
case MVM_NATIVECALL_ARG_UTF16STR:
case MVM_NATIVECALL_ARG_CSTRUCT:
case MVM_NATIVECALL_ARG_CPPSTRUCT:
case MVM_NATIVECALL_ARG_CPOINTER:
case MVM_NATIVECALL_ARG_CARRAY:
case MVM_NATIVECALL_ARG_CUNION:
Expand Down Expand Up @@ -267,6 +268,12 @@ static char callback_handler(DCCallback *cb, DCArgs *cb_args, DCValue *cb_result
MVM_gc_root_temp_push(tc, (MVMCollectable **)&(args[i - 1].o));
num_roots++;
break;
case MVM_NATIVECALL_ARG_CPPSTRUCT:
args[i - 1].o = MVM_nativecall_make_cppstruct(tc, type,
dcbArgPointer(cb_args));
MVM_gc_root_temp_push(tc, (MVMCollectable **)&(args[i - 1].o));
num_roots++;
break;
case MVM_NATIVECALL_ARG_CPOINTER:
args[i - 1].o = MVM_nativecall_make_cpointer(tc, type,
dcbArgPointer(cb_args));
Expand Down Expand Up @@ -387,6 +394,9 @@ static char callback_handler(DCCallback *cb, DCArgs *cb_args, DCValue *cb_result
case MVM_NATIVECALL_ARG_CSTRUCT:
cb_result->p = MVM_nativecall_unmarshal_cstruct(tc, res.o);
break;
case MVM_NATIVECALL_ARG_CPPSTRUCT:
cb_result->p = MVM_nativecall_unmarshal_cppstruct(tc, res.o);
break;
case MVM_NATIVECALL_ARG_CPOINTER:
cb_result->p = MVM_nativecall_unmarshal_cpointer(tc, res.o);
break;
Expand Down
8 changes: 8 additions & 0 deletions src/core/nativecall_libffi.c
Expand Up @@ -265,6 +265,11 @@ static void callback_handler(ffi_cif *cif, void *cb_result, void **cb_args, void
MVM_gc_root_temp_push(tc, (MVMCollectable **)&(args[i - 1].o));
num_roots++;
break;
case MVM_NATIVECALL_ARG_CPPSTRUCT:
args[i - 1].o = MVM_nativecall_make_cppstruct(tc, type, *(void **)cb_args[i - 1]);
MVM_gc_root_temp_push(tc, (MVMCollectable **)&(args[i - 1].o));
num_roots++;
break;
case MVM_NATIVECALL_ARG_CPOINTER:
args[i - 1].o = MVM_nativecall_make_cpointer(tc, type, *(void **)cb_args[i - 1]);
MVM_gc_root_temp_push(tc, (MVMCollectable **)&(args[i - 1].o));
Expand Down Expand Up @@ -381,6 +386,9 @@ static void callback_handler(ffi_cif *cif, void *cb_result, void **cb_args, void
case MVM_NATIVECALL_ARG_CSTRUCT:
*(void **)cb_result = MVM_nativecall_unmarshal_cstruct(tc, res.o);
break;
case MVM_NATIVECALL_ARG_CPPSTRUCT:
*(void **)cb_result = MVM_nativecall_unmarshal_cppstruct(tc, res.o);
break;
case MVM_NATIVECALL_ARG_CPOINTER:
*(void **)cb_result = MVM_nativecall_unmarshal_cpointer(tc, res.o);
break;
Expand Down

0 comments on commit 25f165a

Please sign in to comment.