atom feed19 messages in org.perl.perl5-portersRe: [perl #72704] Buggy fputs(f,s) vs...
FromSent OnAttachments
kmx via RTMar 3, 2010 1:47 am 
Steve HayMar 4, 2010 8:40 am 
Dave MitchellMar 4, 2010 12:17 pm 
Steve HayMar 4, 2010 4:17 pm 
Jan DuboisMar 4, 2010 6:53 pm 
Jan DuboisMar 4, 2010 7:07 pm 
kmx via RTMar 4, 2010 11:15 pm 
Jan DuboisMar 5, 2010 12:26 am 
Steve HayMar 5, 2010 1:18 am 
Jan DuboisMar 5, 2010 12:50 pm 
kmxMar 5, 2010 11:52 pm 
Tim BunceMar 6, 2010 1:37 pm 
kmx via RTApr 11, 2010 2:35 am 
Jan Dubois via RTApr 21, 2010 11:55 pm 
kmx via RTApr 22, 2010 10:46 am 
kmx via RTMay 5, 2010 4:30 am 
Jan DuboisMay 5, 2010 12:26 pm 
Tim BunceMay 6, 2010 4:05 am 
Craig A. BerryMay 6, 2010 6:21 am 
Subject:Re: [perl #72704] Buggy fputs(f,s) vs. fputs(s,f) on Win32 (maybe not only)
From:Dave Mitchell (dav@iabyn.com)
Date:Mar 4, 2010 12:17:36 pm
List:org.perl.perl5-porters

On Thu, Mar 04, 2010 at 04:40:41PM -0000, Steve Hay wrote:

Sorry, I meant to reply to this earlier but completely forgot.

I think it is deliberate: it is explicitly mentioned in perlapio.pod that the
arguments have been reversed compared to the C library function (probably so
that all the PerlIO functions have the 'f' first). And there's a further comment
about it in perlxstut.pod too.

Are you sure the arguments are not reversed on Linux too? There's no mention of
the reversal being Win32-specific.

While the args of the PerlIO functions are explicity reversed, I think that OP is right, in that something is probably awry with the macro expansions.

For example in fakesdio.h, you have

#define fputs(s,f) PerlIO_puts(f,s)

which does the correct arg reversal.

*However*: out in XS/win32 land, you appear to have:

XSUB.h: #define fputs PerlSIO_fputs

iperlsys.h:

#if defined(PERL_IMPLICIT_SYS) #define PerlSIO_fputs(f,s) (*PL_StdIO->pPuts)(PL_StdIO, (f),(s)) #else #define PerlSIO_fputs(f,s) fputs(s,f) #endif

and the type of function expected in the pPuts slot is LPPuts, which is defined as

typedef int (*LPPuts)(struct IPerlStdIO*, FILE*, const char*);

So under some circumstances,

fputs(str,handle) => PerlIO_puts(str,handle) => (*PL_StdIO->pPuts)(PL_StdIO, (str),(handle))

which doesn't match the LPPuts definition.

But that's a horrible twisty maze of macros that I don't really understand.