Skip to content

Commit

Permalink
nci: bring back t sig, for nci cstring support
Browse files Browse the repository at this point in the history
WIP. needed in most external code. #601
  • Loading branch information
Reini Urban committed Jan 14, 2015
1 parent 08bfc0b commit 721ca73
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/parrot/nci.h
@@ -1,5 +1,5 @@
/* nci.h
* Copyright (C) 2001-2007, Parrot Foundation.
* Copyright (C) 2001-2014, Parrot Foundation.
* Overview:
* The nci API handles building native call frames
* Data Structure and Algorithms:
Expand Down
32 changes: 26 additions & 6 deletions src/nci/libffi.c
@@ -1,6 +1,4 @@
/* Copyright (C) 2010, Parrot Foundation.
/* Copyright (C) 2010-2014, Parrot Foundation.
=head1 NAME
Expand Down Expand Up @@ -86,6 +84,7 @@ typedef union nci_var_t {
#endif
void *p;
INTVAL I; FLOATVAL N; STRING *S; PMC *P;
char *t;
} nci_var_t;


Expand Down Expand Up @@ -340,6 +339,7 @@ nci_to_ffi_type(SHIM_INTERP, PARROT_DATA_TYPE nci_t)
case enum_type_INTVAL: return &ffi_type_parrot_intval;

case enum_type_STRING:
case enum_type_cstr:
case enum_type_ptr:
case enum_type_PMC:
return &ffi_type_pointer;
Expand Down Expand Up @@ -432,6 +432,13 @@ prep_pcc_ret_arg(PARROT_INTERP, PARROT_DATA_TYPE t, parrot_var_t *pv, void **rv,
pv->s = *(STRING **)val;
*rv = &pv->s;
break;
case enum_type_cstr:
{
char *s = *(char **)val;
pv->s = Parrot_str_new(interp, s, 0);
*rv = &pv->s;
}
break;
case enum_type_PMC:
pv->p = *(PMC **)val;
*rv = &pv->p;
Expand All @@ -448,8 +455,7 @@ prep_pcc_ret_arg(PARROT_INTERP, PARROT_DATA_TYPE t, parrot_var_t *pv, void **rv,
break;

default:
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_KEY_NOT_FOUND,
"Impossible NCI signature code");
Parrot_ex_throw_from_c_args(interp, NULL, 0, "Invalid NCI signature code %c", (char)t);
}
}

Expand Down Expand Up @@ -522,7 +528,7 @@ call_ffi_thunk(PARROT_INTERP, ARGMOD(PMC *nci_pmc), ARGMOD(PMC *self))
pcc_arg_ptr[i] = &pcc_arg[i].p;
break;
default:
PARROT_ASSERT(!"Impossible PCC signature");
PARROT_ASSERT(!"Invalid PCC signature");
break;
}

Expand Down Expand Up @@ -622,6 +628,19 @@ call_ffi_thunk(PARROT_INTERP, ARGMOD(PMC *nci_pmc), ARGMOD(PMC *self))
VTABLE_get_pointer(interp, pcc_arg[i].p);
nci_arg_ptr[i] = &nci_val[i].p;
break;
case enum_type_cstr:
nci_val[i].t = STRING_IS_NULL(pcc_arg[i].s) ?
(char *)NULL :
Parrot_str_to_cstring(interp, pcc_arg[i].s);
nci_arg_ptr[i] = &nci_val[i].t;
#if 0
translation_pointers[i] = STRING_IS_NULL(pcc_arg[j].s) ?
(char *)NULL :
Parrot_str_to_cstring(interp, pcc_arg[j].s);
j++;
values[i] = &translation_pointers[i];
#endif
break;

default:
PARROT_ASSERT("Unhandled NCI signature");
Expand Down Expand Up @@ -668,6 +687,7 @@ call_ffi_thunk(PARROT_INTERP, ARGMOD(PMC *nci_pmc), ARGMOD(PMC *self))
for (j = 1; i < pcc_retc; j++) {
arg_t = (PARROT_DATA_TYPE)VTABLE_get_integer_keyed_int(interp, nci->signature, j);
if (arg_t & enum_type_ref_flag) {
/* TODO return t */
prep_pcc_ret_arg(interp, (PARROT_DATA_TYPE)(arg_t & ~enum_type_ref_flag),
&pcc_retv[i], &call_arg[i + 3], nci_arg[j - 1]);
i++;
Expand Down
3 changes: 3 additions & 0 deletions src/nci/signatures.c
Expand Up @@ -99,6 +99,9 @@ Parrot_nci_parse_signature(PARROT_INTERP, ARGIN(STRING *sig_str))
case 'S':
e = enum_type_STRING;
break;
case 't': /* string as cstring */
e = enum_type_cstr;
break;

case 'p': /* push pmc->data */
e = enum_type_ptr;
Expand Down

0 comments on commit 721ca73

Please sign in to comment.