Skip to content

Commit

Permalink
[nci]: Fix NCI::Utils::ncifunc -- don't free up arguments to NCI unti…
Browse files Browse the repository at this point in the history
…l we've established the return value.
  • Loading branch information
pmichaud committed Jun 9, 2011
1 parent 9f6220f commit 8e0711f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
23 changes: 14 additions & 9 deletions runtime/parrot/library/NCI/Utils.pir
Original file line number Diff line number Diff line change
Expand Up @@ -431,25 +431,30 @@ C<signature> are:
func = find_lex 'func'
(retv :slurpy) = func(args :flat)

.local int rett
$S0 = substr signature, 0, 1
rett = iseq $S0, 't'
unless rett goto have_retv
.local string rets
retv = pop retv
rets = null
if null retv goto have_retv
.local string rets
rets = 'str_new'(interp, retv, 0)
have_retv:

free_loop:
unless strfreelist goto free_done
$P0 = pop strfreelist
'str_free_cstring'($P0)
goto free_loop
free_done:

$S0 = substr signature, 0, 1
if $S0 == 't' goto nci_ret_t
if rett goto nci_ret_t
.return (retv :flat)

nci_ret_t:
retv = pop retv # get the first value out of the slurpy
if null retv goto nci_ret_t_null
$S0 = 'str_new'(interp, retv, 0)
.return ($S0)
nci_ret_t_null:
$S0 = null
.return ($S0)
.return (rets)
.end


Expand Down
7 changes: 6 additions & 1 deletion t/library/nciutils.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Testing Perl 6 objects.

have_enough_nci:
## set our plan
plan(13)
plan(14)

## make sure we can load the NCI::Utils library
push_eh load_fail
Expand Down Expand Up @@ -71,6 +71,11 @@ Testing Perl 6 objects.
( $I0 ) = $P0('hello', 'hello')
is($I0, 0, 'strcmp == 0')

$P0 = ncifunc(null_pmc, 'strstr', 'ttt')
( $S0 ) = $P0('hello', 'e')
is($S0, 'ello', 'strstr("hello", "e")')


## load a library
.local pmc libnci_test
libnci_test = loadlib "libnci_test"
Expand Down

0 comments on commit 8e0711f

Please sign in to comment.