Closed p5pRT closed 13 years ago
The following code fails:
package Foo; use IO::Socket; use base qw(IO::Socket::INET);
sub new { my ($pack\,$tk) = @_; my $obj = $pack->SUPER::new(Proto => 'udp');
$$obj->{Foo_prop1} = "value1"; # OK\, foo's property $tk->fileevent($obj\, 'readable'\, sub {warn "FooBar"});
## The above line badly ties the object\, ## so the following line fails $$obj->{Foo_prop2} = "value2";
return $obj; }
package main; my $tk = Tk::MainWindow->new(); my $foo = Foo->new($tk); Tk::MainLoop;
Error: Can't locate object method "FETCH" via package "Tk::Event::IO" at ./test.pl line 14.
I can work arroun this\, by duping my $obj as a IO::Handle\, but it's ugly. Why does Tk tie my $obj without asking?
Cheers\, Gavin
Gavin Brock \zaragoza@​usa\.net writes:
This is a bug report for perl from zaragoza@usa.net\, generated with the help of perlbug 1.26 running under perl 5.00503.
----------------------------------------------------------------- [Please enter your report here]
The following code fails:
package Foo; use IO::Socket; use base qw(IO::Socket::INET);
sub new { my ($pack\,$tk) = @_; my $obj = $pack->SUPER::new(Proto => 'udp');
$$obj->{Foo_prop1} = "value1"; # OK\, foo's property $tk->fileevent($obj\, 'readable'\, sub {warn "FooBar"});
## The above line badly ties the object\,
It does not "badly tie" it it ties it with TIEHANDLE.
I can work arroun this\, by duping my $obj as a IO::Handle\, but it's ugly.
You could also work round it by defining :
sub Tk::Event::IO::FETCH { my ($globref\,$key) = @_; ... }
Why does Tk tie my $obj
So that: A. if you close() the handle I get a chance to remove the thing from data structures before Tk crashes due to access to no longer valid file handle. B. if you attempt to read() more than is there I can despatch Tk events while waiting.
without asking?
So what should I do ? - popup a dialogue
->messageBox(-message => "May I tie $obj"\, -type => 'YesNo')
You have (via the fileevent call) "given" the object to Tk. So you "asked me" to "look after this object" ;-)
Nick Ing-Simmons writes:
## The above line badly ties the object\,
It does not "badly tie" it it ties it with TIEHANDLE.
Which is not expected\, thus bad.
I can work arroun this\, by duping my $obj as a IO::Handle\, but it's ugly.
You could also work round it by defining :
sub Tk::Event::IO::FETCH {
If so\, this should have been done by Tk itself. But I doubt it.
$tk->fileevent($obj\, 'readable'\, sub {warn "FooBar"});
$obj is probably a glob ref\, right?
$$obj->{Foo_prop1} = "value1";
$obj is a hash ref ref\, right? I'm confused.
Unles a glob can work as a hash ref in the above syntax\, and you tie the glob ref instead of the glob.
Ilya
Ilya Zakharevich \ilya@​math\.ohio\-state\.edu writes:
Nick Ing-Simmons writes:
## The above line badly ties the object\,
It does not "badly tie" it it ties it with TIEHANDLE.
Which is not expected\, thus bad.
fileevent is passed a filehandle - it happens to implement its behaviour by tie-ing that handle.
I can work arroun this\, by duping my $obj as a IO::Handle\, but it's ugly.
You could also work round it by defining :
sub Tk::Event::IO::FETCH {
If so\, this should have been done by Tk itself.
Why - Tk was expecting to be passed a file handle (globref) - it was not expecting calling code to be messing with glob elements via that ref. FETCH would presumably have to handle SCALAR\, ARRAY and HASH elements of the glob - I was not even aware that tie'ing the glob (as a HANDLE) has any effects on the other elements.
$tk->fileevent($obj\, 'readable'\, sub {warn "FooBar"});
$obj is probably a glob ref\, right?
Yes.
$$obj->{Foo_prop1} = "value1";
$obj is a hash ref ref\, right? I'm confused.
Unles a glob can work as a hash ref in the above syntax\, and you tie the glob ref instead of the glob.
I assumed that syntax is messing with the hash part of the glob via the reference. Doing that is asking for trouble when multiple modules are involved (IO::Socket\, Tk::Event::IO\, ...) and user has found that trouble ;-)
On Sat\, May 13\, 2000 at 10:41:15AM +0100\, Nick Ing-Simmons wrote:
It does not "badly tie" it it ties it with TIEHANDLE.
Which is not expected\, thus bad.
fileevent is passed a filehandle - it happens to implement its behaviour by tie-ing that handle.
You could also work round it by defining :
sub Tk::Event::IO::FETCH {
If so\, this should have been done by Tk itself.
Why - Tk was expecting to be passed a file handle (globref) - it was not ^^^^^^^ expecting calling code to be messing with glob elements via that ref. ^^^^^^^^^
... and *this* is a bug.
If Tk meeds messing with the FH\, it should be messing with IO part of the glob\, not with the glob as a whole.
Ilya
Ilya Zakharevich \ilya@​math\.ohio\-state\.edu writes:
On Sat\, May 13\, 2000 at 10:41:15AM +0100\, Nick Ing-Simmons wrote:
It does not "badly tie" it it ties it with TIEHANDLE.
Which is not expected\, thus bad.
fileevent is passed a filehandle - it happens to implement its behaviour by tie-ing that handle.
You could also work round it by defining :
sub Tk::Event::IO::FETCH {
If so\, this should have been done by Tk itself.
Why - Tk was expecting to be passed a file handle (globref) - it was not ^^^^^^^ expecting calling code to be messing with glob elements via that ref. ^^^^^^^^^
... and *this* is a bug.
If Tk meeds messing with the FH\, it should be messing with IO part of the glob\, not with the glob as a whole.
Ok. But as far as I am aware you have to pass a glob to tie to achieve TIEHANDLE behaviour.
What I have at present is:
sub fileevent { my ($widget\,$file\,$mode\,$cb) = @_; my $imode = imode($mode); unless (ref $file) { no strict 'refs'; $file = Symbol::qualify($file\,(caller)[0]); $file = \*{$file}; } my $obj = tied(*$file); $obj = tie *$file\,'Tk::Event::IO'\, $file unless $obj && $obj->isa('Tk::Event::IO'); if (@_ == 3) { return $obj->handler($imode); } else { my $h = $obj->handler($imode\,$cb); undef $obj; untie *$file unless $h; } }
I will gladly change that to any incantation which will effect a tie of the incoming HANDLE so that I can intercept close()\, readline() read() etc.
On Sat\, May 13\, 2000 at 02:59:37PM +0100\, Nick Ing-Simmons wrote:
If Tk meeds messing with the FH\, it should be messing with IO part of the glob\, not with the glob as a whole.
Ok. But as far as I am aware you have to pass a glob to tie to achieve TIEHANDLE behaviour.
Then *this* is a bug. ;-) Or if it is not\, the fact that tiehandle()ing messes the SCALAR etc. parts is a bug.
my $obj = tied(*$file); $obj = tie *$file\,'Tk::Event::IO'\, $file unless $obj && $obj->isa('Tk::Event::IO');
No warning on re-tie()ing? [Not that it will help in the discussed case...]
Ilya
Ilya Zakharevich (lists.p5p):
Then *this* is a bug. ;-)
I seriously hate to say this\, but in the past two days you have identified seven bugs and fixed zero.
Simon Cozens writes:
Then *this* is a bug. ;-)
I seriously hate to say this\, but in the past two days you have identified seven bugs and fixed zero.
And your point is "So shut up"? Sorry\, but you need to have more credentials that what you have for me to listen to such an advice.
And BTW\, this is going to continue. I'm not interested much in perl development any more. And I do not consider this as *my* fault.
Hope this helps\, Ilya
Nick\, Ilya\,
I sent a reply on this thread a while back\, but it seems to have disappeared. The highlight was that when I defined my own Tk::Event::IO::FETCH sub\, it turned out that is was the scalar tie fetch (not the hash one) that was being called. Once this was defined "sub Tk::Event::IO::Fetch { $_[0] }" all worked fine under 5.005. No other function (eg STORE) were required.
However\, I then tested under 5.6.0\, when I tried to access the hash key in the DESTROY sub\, I got the following:
(in cleanup) Can't call method "FETCH" on an undefined value at test.pl line 21 during global destruction.
Below is the perl-bug output for my 5.6 build.
Cheers\,
Gavin
On Sun\, May 14\, 2000 at 11:12:56PM +0900\, Gavin Brock wrote:
I sent a reply on this thread a while back\, but it seems to have disappeared. The highlight was that when I defined my own Tk::Event::IO::FETCH sub\, it turned out that is was the scalar tie fetch (not the hash one) that was being called. Once this was defined "sub Tk::Event::IO::Fetch { $_[0] }" all worked fine under 5.005. No other function (eg STORE) were required.
Here is the problem:
perl -MDevel::Peek -wle "sub a::TIEHANDLE {bless []} tie *x\,'a'; Dump \*x" SV = RV(0x5b814) at 0x40c94 REFCNT = 1 FLAGS = (TEMP\,ROK) RV = 0x319d0 SV = PVGV(0x3e7c0) at 0x319d0 REFCNT = 4 FLAGS = (GMG\,SMG\,RMG\,MULTI) IV = 0 NV = 0 MAGIC = 0x84518 MG_VIRTUAL = &vtbl_packelem [...]
There is no reason why this tie should have set SMG and RMG flags.
Ilya
On perl 5.14.0\, output is "FLAGS = (MULTI\,IN_PAD)" and example from the first message of ticket does not die.
On Sun May 14 02:48:14 2000\, RT_System wrote:
On Sun\, May 14\, 2000 at 11:12:56PM +0900\, Gavin Brock wrote:
I sent a reply on this thread a while back\, but it seems to have disappeared. The highlight was that when I defined my own Tk::Event::IO::FETCH sub\, it turned out that is was the scalar tie fetch (not the hash one) that was being called. Once this was defined "sub Tk::Event::IO::Fetch { $_[0] }" all worked fine under 5.005. No other function (eg STORE) were required.
Here is the problem:
perl -MDevel::Peek -wle "sub a::TIEHANDLE {bless []} tie *x\,'a'; Dump \*x" SV = RV(0x5b814) at 0x40c94 REFCNT = 1 FLAGS = (TEMP\,ROK) RV = 0x319d0 SV = PVGV(0x3e7c0) at 0x319d0 REFCNT = 4 FLAGS = (GMG\,SMG\,RMG\,MULTI) IV = 0 NV = 0 MAGIC = 0x84518 MG_VIRTUAL = &vtbl_packelem [...]
There is no reason why this tie should have set SMG and RMG flags.
Ilya
-- Alexandr Ciornii\, http://chorny.net
@iabyn - Status changed from 'open' to 'resolved'
Thanks Alexandr\, never expect to see this old one show up again!! Have to go and find out why I wanted it again...
Migrated from rt.perl.org#3235 (status was 'resolved')
Searchable as RT3235$