Skip Menu |

This queue is for tickets about the X11-Protocol CPAN distribution.

Report information
The Basics
Id: 5640
Status: resolved
Priority: 0/
Queue: X11-Protocol

People
Owner: Nobody in particular
Requestors: marc [...] mit.edu
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.03
Fixed in: 0.52



From: Marc Horowitz <marc [...] mit.edu>
To: bug-X11-Protocol [...] rt.cpan.org
Subject: $x->ReqName(...) will fail if the request returns a scalar
Date: 12 Mar 2004 00:11:10 -0500
The following code does not work properly the first time: my $atom = $x->InternAtom("STRING", 1); The definition of X11::Protocol's AUTOLOAD uses a code path which ends with return @ret; the first time any particular request is called. But with the execution pattern above, the function is called in a scalar context, which means @ret is interpreted in a scalar context, which means the method will always return 1 the first time. This is true the first time any protocol request which returns a scalar is called this way. I believe the correct fix is to replace return @ret; with return wantarray ? @ret : $ret[0]; Marc
[marc@mit.edu - Fri Mar 12 00:14:11 2004]: Show quoted text
> The following code does not work properly the first time: > > my $atom = $x->InternAtom("STRING", 1); > > The definition of X11::Protocol's AUTOLOAD uses a code path which ends > with > > return @ret;
Thank you for a clear and accurate bug report, and for tracking down the cause of the problem. I'm going to go with a slightly different fix, though. I think that a better fix would be to move to eliminate the temporary array "@ret" and move the call to req() down to the end of the block, so that it ends in return $obj->req($name, @_); then Perl will automatically propagate the appropriate context down to req(), and in turn the sub that implements each request. This should make the AUTOLOADed versions more compatible with just calling req() directly, since many requests return something whose scalar context value isn't the first element of their list context value. (Including arrays, and lists of multiple elements. In retrospect, the scalar context returns of many requests are not the most useful ones, but I think it's too late to change them). This will be fixed in the next release, which I expect I'll make sometime in the next week or two (I'm working on some feature additions, too, which are taking a bit longer than expected). P.S. In most cases, it's more convenient to use the "atom" method, rather than InternAtom directly. You might want to give it a try, if you didn't already know about it.
Fixed in 0.53 with a change to AUTOLOAD as I described above.
While cleaning up the queue, I noticed I never closed this bug when fixing it.