RE: [tcltk-perl] Drop listify [PATCH]
Brought to you by:
hobbs
From: Jeff H. <je...@ac...> - 2004-04-14 18:43:02
|
> You can see the part in SvFromTclObj where I try to create an > AV back from a Tcl list. The problem with this is that we > then return an array reference, and I think it's complicated > by the code in Tcl.xs:prepare_Tcl_result that handles > G_SCALAR and G_ARRAY differently, in addition to the code in > Tcl.pm:call() that does at the end: > > return @res if wantarray; > return $res[0]; OK, I think the real problem was the bit of code at the end of 'call' that conflicted with Tcl.xs:prepare_Tcl_result() which handled the G_SCALAR / G_ARRAY diffs already. I think the following patch is appropriate, and it works with a call.t that I just checked into CVS. Please comment on this, as I am not certain that I'm not breaking some perl basic assumptions here. Index: Tcl.pm =================================================================== RCS file: /cvsroot/tcltkce/Tcl/Tcl.pm,v retrieving revision 1.9 diff -u -r1.9 Tcl.pm --- Tcl.pm 12 Apr 2004 23:09:56 -0000 1.9 +++ Tcl.pm 14 Apr 2004 18:33:09 -0000 @@ -395,15 +395,23 @@ } } } - my (@res,$res); - eval { - @res = $interp->icall(@args); - }; - if ($@) { - confess "Tcl error $@ while invoking call\n \"@args\""; + if (wantarray) { + my @res; + eval { @res = $interp->icall(@args); }; + if ($@) { + confess "Tcl error '$@' while invoking array result call:\n" . + "\t\"@args\""; + } + return @res; + } else { + my $res; + eval { $res = $interp->icall(@args); }; + if ($@) { + confess "Tcl error '$@' while invoking scalar result call:\n" . + "\t\"@args\""; + } + return $res; } - return @res if wantarray; - return $res[0]; } Jeff |