Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NCI and libparrot Question

6 views
Skip to first unread message

Chromatic

unread,
Jul 21, 2006, 1:53:24 AM7/21/06
to parrot-...@perl.org
Should this code work? I think so.

I don't think it's necessarily *good* practice, but I do think it should work.

-- c

string_roundtrip.pir

Leopold Toetsch

unread,
Jul 21, 2006, 3:57:43 AM7/21/06
to perl6-i...@perl.org
Am Freitag, 21. Juli 2006 07:53 schrieb chromatic:
> Should this code work? I think so.

This can't work for several reasons:

1) the NCI call signatures don't match the C functions' args:

.store_nci_func( 'const_string', 'ppt' )

should be: 'SIt' (return STRING*, interp & C-cstring args)

.store_nci_func( 'string_to_cstring', 'tpp' )

should be: "tIS" (return C-string, interp & STRING args)

(You could use 'pIt' and 'pIp' signatures too, then the STRING* result of the
'const_string' would be wrapped into a ManagedStruct PMC).

2) print does *not* take c-strings, but STRINGs, therefore:

hello = string_to_cstring( interpreter, greet_string )
print hello

is likely to just segfault.

> -- c

leo

Chromatic

unread,
Jul 21, 2006, 2:08:35 PM7/21/06
to perl6-i...@perl.org, Leopold Toetsch
On Friday 21 July 2006 00:57, Leopold Toetsch wrote:

> This can't work for several reasons:
>
> 1) the NCI call signatures don't match the C functions' args:
>
> .store_nci_func( 'const_string', 'ppt' )
>
> should be: 'SIt' (return STRING*, interp & C-cstring args)
>
> .store_nci_func( 'string_to_cstring', 'tpp' )
>
> should be: "tIS" (return C-string, interp & STRING args)
>
> (You could use 'pIt' and 'pIp' signatures too, then the STRING* result of
> the 'const_string' would be wrapped into a ManagedStruct PMC).

I don't see documentation for the S or I parameters anywhere in the NCI PDD.
Is there a better place for them?

> 2) print does *not* take c-strings, but STRINGs, therefore:
>
> hello = string_to_cstring( interpreter, greet_string )
> print hello
>
> is likely to just segfault.

I did oversimplify the code somewhat. Here's what I really want to run.

-- c

embed_parrot.pir
greet.pir

Leopold Toetsch

unread,
Jul 21, 2006, 2:43:27 PM7/21/06
to perl6-i...@perl.org
Am Freitag, 21. Juli 2006 20:08 schrieb chromatic:
> On Friday 21 July 2006 00:57, Leopold Toetsch wrote:
> > (You could use 'pIt' and 'pIp' signatures too, then the STRING* result of
> > the 'const_string' would be wrapped into a ManagedStruct PMC).
>
> I don't see documentation for the S or I parameters anywhere in the NCI
> PDD. Is there a better place for them?

src/call_list.txt is probably the best place to look. And a good one to look
into occasionally, I've mixed up 'I' and 'J' - sorry.

> I did oversimplify the code somewhat. Here's what I really want to run.

Without futher looking - you have to replace a lot of 'p's (some structure)
with 'J' (the Interpreter* interp structure). E.g.

.store_nci_func( 'Parrot_readbc', 'ppt' )

=>

.store_nci_func( 'Parrot_readbc', 'pJt' )

You migh also grep for enter_nci_method in src/pmc/*.c - all METHODs in .pmc
are converted to NCI calls in the .c files with appropriate signatures.

> -- c

leo

Chromatic

unread,
Jul 21, 2006, 4:55:32 PM7/21/06
to perl6-i...@perl.org, Leopold Toetsch
On Friday 21 July 2006 11:43, Leopold Toetsch wrote:

> Without futher looking - you have to replace a lot of 'p's (some structure)
> with 'J' (the Interpreter* interp structure). E.g.
>
> .store_nci_func( 'Parrot_readbc', 'ppt' )
>
> =>
>
> .store_nci_func( 'Parrot_readbc', 'pJt' )

I'm not convinced; this works just fine from the Perl 5 and Ruby bindings.
Most of that code uses the interpreter returned from Parrot_new(), rather than
the current interpreter. (It only uses the current interpreter as the parent
argument to Parrot_new()).

> You migh also grep for enter_nci_method in src/pmc/*.c - all METHODs in
> .pmc are converted to NCI calls in the .c files with appropriate
> signatures.

That ought to work.

-- c

0 new messages