List Info

Thread: Problems with data returned from Gtk2::SimpleList




Problems with data returned from Gtk2::SimpleList
user name
2006-08-03 13:50:49
[ new subject, since this has nothing to do with the
original thread ]

> Subject: RE: capturing output from running process
crashes gtk2
> 
> How do I write
> 
>      my $filename = $list -> [$page[0]][0];
>      $image = Gtk2::Image -> new_from_file
($filename);
> 
> on one line?
> 
>      $image = Gtk2::Image -> new_from_file ($list
-> 
> [$page[0]][0]);
> 
> doesn't work.

I'm guessing $list here is a Gtk2::SimpleList?
I can confirm this behaviour: $list->[0][0]
correctly
contains the expected value in row 0 and column 0 
(assuming column 0 is of type "text"),
but when it is directly fed into
Gtk2::Image->new_from_file
nothing is shown in the returned image (not even the
"broken image"
logo). 

Now Gtk2::Image->new_from_file is apparently just an XS
wrapper
for gtk_image_new_from_file... Looking at
$list->[0][0]
with Devel::Peek I can see it contains some heavy magic
(it's actually an lvalue), maybe it isn't correctly
converted down to a simple string when passed from
Perl to C level?

Cheers, Roderich
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Problems with data returned from Gtk2::SimpleList
user name
2006-08-03 14:14:54
On Thursday 03 August 2006 14:50, Roderich Schupp (ext)
wrote:
> > How do I write
> >      my $filename = $list ->
[$page[0]][0];
> >      $image = Gtk2::Image -> new_from_file
($filename);
> > on one line?
> >      $image = Gtk2::Image -> new_from_file
($list ->
> > [$page[0]][0]);
> > doesn't work.

one word: _context_ 

-- 
It's clever, but is it art?
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Problems with data returned from Gtk2::SimpleList
user name
2006-08-03 14:19:21
> one word: _context_ 

Can you elaborate?

Cheers, Roderich
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Problems with data returned from Gtk2::SimpleList
user name
2006-08-03 14:33:01
Roderich Schupp (ext) wrote:
>> one word: _context_ 
>
> Can you elaborate?

I believe that he means evaluation of the tied SimpleList
data value may be
different in scalar versus array content.


Try

   $image = Gtk2::Image->new_from_file (scalar
($slist->{$i][0]));



-- 
muppet <scott at asofyet dot org>

_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Problems with data returned from Gtk2::SimpleList
user name
2006-08-03 15:39:39
> I believe that he means evaluation of the tied
SimpleList 
> data value may be
> different in scalar versus array content.
> 
> 
> Try
> 
>    $image = Gtk2::Image->new_from_file (scalar 
> ($slist->{$i][0]));

Indeed, that work's. But is not your average 
scalar-vs-list-context, because after

data
= $slist->[$i][0];	# force list context on right

data
contains just one element. It works because
scalar() takes the magic away. I tried it with
the most simpleminded tied scalar:

  package Foo;
  sub TIESCALAR { my ($class, $val) = _; return bless \$val,
$class; }
  sub FETCH { my ($self) = _; print STDERR
"FETCH($self)\n"; $$self; }

  package main;
  my $foo;
  tie $foo, Foo => "some.png";
  my $image = Gtk2::Image->new_from_file($foo);

Foo::FETCH doesn't get called at all.

Cheers, Roderich

_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Problems with data returned from Gtk2::SimpleList
user name
2006-08-04 12:53:51
Hi,
it's definitely not a problem with list-vs-scalar context,
something deeper goes on. Can you try the attached minimal
example (untar, "perl Makefile.PL",
"make", and then run test.pl).
It mimicks a call to Gtk2::Image->new_from_file($n)
where $n is (1) a simple scalar and (2) a tied scalar.
You should see a "FETCH(...)" when the tied
scalar's FETCH
method is invoked. simple() is a minimal XS sub that
just passes its only parameter down (as an SV*).
I get the following output for Perl 5.8.8 on Debian Linux
(same for Perl 5.8.7 from ActiveState and cygwin):

simple(red.png) at test.pl line 16.
FETCH(Foo=SCALAR(0x81da484)) at test.pl line 6.
	# OK: tied scalar's FETCH was invoked for
simple($tied_scalar)
simple(blue.png) at test.pl line 17.
gperl_filename_from_sv: got "red.png" at test.pl
line 22.
gperl_filename_from_sv: dup "red.png" at test.pl
line 22.
gtk_image_new_from_file(red.png) at test.pl line 22.
	# now calling Bar->gtk_image_new_from_file($tied_scalar)
	# not OK: FETCH missing
gtk_image_new_from_file((null)) at test.pl line 23.
	# finally a NULL pointer was passed down

Further inspection shows that the problem is the
filename parameter to the XS sub. It's declared 
as a GPerlFilename_ornull. The latter has an input mapping
of

$var = ($type)(($arg && SvOK ($arg))
                 ? gperl_filename_from_sv ($arg)
                 : NULL)

Turns out that SvOK($tied_scalar) is false (but
SvMAGICAL($tied_scalar) is true). That explains why NULL
is passed down.

I tried the same on an old Perl 5.8.0 on Solaris
and there I get the expected second FETCH and indeed
SvOK($tied_scalar) is true there.

AFAICT the check "$arg && SvOK ($arg)"
is supposed to be
the XS equivalent of "defined $arg"? Apparently
that's
broken for recent Perls when $arg is a tied variable.

Cheers, Roderich
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Problems with data returned from Gtk2::SimpleList
user name
2006-08-04 14:15:43
Following up on my own post: 

> AFAICT the check "$arg && SvOK
($arg)" is supposed to be
> the XS equivalent of "defined $arg"?
Apparently that's
> broken for recent Perls when $arg is a tied variable.

Actually, "defined $arg" involves a lot more
than just
testing SvOK($arg), here's the source for perl 5.8.8:

PP(pp_defined)
{
    dSP;
    register SV* const sv = POPs;

    if (!sv || !SvANY(sv))
        RETPUSHNO;
    switch (SvTYPE(sv)) {
    case SVt_PVAV:
        if (AvMAX(sv) >= 0 || SvGMAGICAL(sv)
                || (SvRMAGICAL(sv) && mg_find(sv,
PERL_MAGIC_tied)))
            RETPUSHYES;
        break;
    case SVt_PVHV:
        if (HvARRAY(sv) || SvGMAGICAL(sv)
                || (SvRMAGICAL(sv) && mg_find(sv,
PERL_MAGIC_tied)))
            RETPUSHYES;
        break;
    case SVt_PVCV:
        if (CvROOT(sv) || CvXSUB(sv))
            RETPUSHYES;
        break;
    default:
        if (SvGMAGICAL(sv))
            mg_get(sv);
        if (SvOK(sv))
            RETPUSHYES;
    }
    RETPUSHNO;
}

Cheers, Roderich
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list
[1-7]

about | contact  Other archives ( Real Estate discussion Medical topics )