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:Jan Dubois (ja@activestate.com)
Date:Mar 4, 2010 6:53:06 pm
List:org.perl.perl5-porters

On Thu, 04 Mar 2010, Dave Mitchell wrote:

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

XSUB.h: #define fputs PerlSIO_fputs

That one is correct. PerlSIO_* APIs are supposed to have the same prototype as their corresponding stdio ones.

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

This however is busted. The parameters should not be swapped.

The same problem exists for the fputc() function as well. I've attached my attempt at correcting all the mistakes I found. Core Perl still builds fine on Windows and OS X; but I haven't tried building any extensions that use fputs() or fputc().

In case the patch gets mangled by email and/or RT, you can read it on github:

http://github.com/jandubois/perl/commit/8656122df48f238e6526299295e8f96524ac4158

or download the raw diff at:

http://github.com/jandubois/perl/commit/8656122df48f238e6526299295e8f96524ac4158.diff

So please test and report back if this fixes the problem for Math::Pari on
Windows!

Cheers, -Jan

--- a/iperlsys.h +++ b/iperlsys.h @@ -78,8 +78,8 @@ typedef int (*LPGetCnt)(struct IPerlStdIO*, FILE*); typedef STDCHAR* (*LPGetPtr)(struct IPerlStdIO*, FILE*); typedef char* (*LPGets)(struct IPerlStdIO*, FILE*, char*, int); -typedef int (*LPPutc)(struct IPerlStdIO*, FILE*, int); -typedef int (*LPPuts)(struct IPerlStdIO*, FILE*, const char*); +typedef int (*LPPutc)(struct IPerlStdIO*, int, FILE*); +typedef int (*LPPuts)(struct IPerlStdIO*, const char *, FILE*); typedef int (*LPFlush)(struct IPerlStdIO*, FILE*); typedef int (*LPUngetc)(struct IPerlStdIO*, int,FILE*); typedef int (*LPFileno)(struct IPerlStdIO*, FILE*); @@ -225,10 +225,10 @@ (*PL_StdIO->pGetCnt)(PL_StdIO, (f)) #define PerlSIO_get_ptr(f) \ (*PL_StdIO->pGetPtr)(PL_StdIO, (f)) -#define PerlSIO_fputc(f,c) \ - (*PL_StdIO->pPutc)(PL_StdIO, (f),(c)) -#define PerlSIO_fputs(f,s) \ - (*PL_StdIO->pPuts)(PL_StdIO, (f),(s)) +#define PerlSIO_fputc(c,f) \ + (*PL_StdIO->pPutc)(PL_StdIO, (c),(f)) +#define PerlSIO_fputs(s,f) \ + (*PL_StdIO->pPuts)(PL_StdIO, (s),(f)) #define PerlSIO_fflush(f) \ (*PL_StdIO->pFlush)(PL_StdIO, (f)) #define PerlSIO_fgets(s, n, fp) \ @@ -311,8 +311,8 @@ #define PerlSIO_get_cnt(f) 0 #define PerlSIO_get_ptr(f) NULL #endif -#define PerlSIO_fputc(f,c) fputc(c,f) -#define PerlSIO_fputs(f,s) fputs(s,f) +#define PerlSIO_fputc(c,f) fputc(c,f) +#define PerlSIO_fputs(s,f) fputs(s,f) #define PerlSIO_fflush(f) Fflush(f) #define PerlSIO_fgets(s, n, fp) fgets(s,n,fp) #if defined(VMS) && defined(__DECC) --- a/perlsdio.h +++ b/perlsdio.h @@ -34,8 +34,8 @@ #define PerlIO_fdopen PerlSIO_fdopen #define PerlIO_reopen PerlSIO_freopen #define PerlIO_close(f) PerlSIO_fclose(f) -#define PerlIO_puts(f,s) PerlSIO_fputs(f,s) -#define PerlIO_putc(f,c) PerlSIO_fputc(f,c) +#define PerlIO_puts(f,s) PerlSIO_fputs(s,f) +#define PerlIO_putc(f,c) PerlSIO_fputc(c,f) #if defined(VMS) # if defined(__DECC) /* Unusual definition of ungetc() here to accomodate fast_sv_gets()' --- a/win32/perlhost.h +++ b/win32/perlhost.h @@ -669,13 +669,13 @@ }

int -PerlStdIOPutc(struct IPerlStdIO* piPerl, FILE* pf, int c) +PerlStdIOPutc(struct IPerlStdIO* piPerl, int c, FILE* pf) { return win32_fputc(c, pf); }

int -PerlStdIOPuts(struct IPerlStdIO* piPerl, FILE* pf, const char *s) +PerlStdIOPuts(struct IPerlStdIO* piPerl, const char *s, FILE* pf) { return win32_fputs(s, pf); }