Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Handle string returns.
  • Loading branch information
jnthn committed Nov 27, 2011
1 parent 65cfe28 commit 4aade5a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/ops/nqp_dyncall.ops
Expand Up @@ -185,6 +185,33 @@ make_num_result(PARROT_INTERP, PMC *type, FLOATVAL value) {
return result;
}

/* Constructs a boxed result from a string return. */
static PMC *
make_str_result(PARROT_INTERP, PMC *type, INTVAL ret_type, char *cstring) {
PMC *result = type;
if (result != NULL && !PMC_IS_NULL(type)) {
STRING *value = STRINGNULL;
switch (ret_type & DYNCALL_ARG_TYPE_MASK) {
case DYNCALL_ARG_ASCIISTR:
value = Parrot_str_new_init(interp, cstring, strlen(cstring), Parrot_ascii_encoding_ptr, 0);
break;
case DYNCALL_ARG_UTF8STR:
value = Parrot_str_new_init(interp, cstring, strlen(cstring), Parrot_utf8_encoding_ptr, 0);
break;
case DYNCALL_ARG_UTF16STR:
value = Parrot_str_new_init(interp, cstring, strlen(cstring), Parrot_utf16_encoding_ptr, 0);
break;
}
result = REPR(type)->allocate(interp, STABLE(type));
REPR(result)->initialize(interp, STABLE(result), OBJECT_BODY(result));
REPR(result)->set_str(interp, STABLE(result), OBJECT_BODY(result), value);
PARROT_GC_WRITE_BARRIER(interp, result);
if (ret_type & DYNCALL_ARG_FREE_STR)
free(cstring);
}
return result;
}

PMC * decontainerize(PARROT_INTERP, PMC *var) {
ContainerSpec *spec = STABLE(var)->container_spec;
if (spec && IS_CONCRETE(var)) {
Expand Down Expand Up @@ -407,6 +434,9 @@ inline op nqp_native_call(out PMC, in PMC, in PMC, in PMC) :base_core {
case DYNCALL_ARG_ASCIISTR:
case DYNCALL_ARG_UTF8STR:
case DYNCALL_ARG_UTF16STR:
result = make_str_result(interp, $2, body->ret_type,
(char *)dcCallPointer(vm, body->entry_point));
break;
case DYNCALL_ARG_CSTRUCT:
case DYNCALL_ARG_PACKEDARRAY:
case DYNCALL_ARG_CALLBACK:
Expand Down

0 comments on commit 4aade5a

Please sign in to comment.