-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Buggy fputs(f,s) vs. fputs(s,f) on Win32 (maybe not only) #10156
Comments
From @kmxHi, I have hit into a strange "maybe-bug" on Win32 platform. The problem occurs when a XS modules tries to call function fputs() from The standard UNIX declaration of fputs looks AFAIK like this: Thus one would expect that also in XS/C code you just use Pari.xs: In function 'XS_Math__Pari_dumpStack': Swapping the arguments fixed the warning, so it seems to me than in whereas on Linux/perl box it is expected to use: I have tracked this issue to iperlsys.h where I lost in a bunch of Note: 5.11.4 used for testing is based on release tarball, gcc compiler, Thanks for any help. -- Perl Info
|
From @kmxDne st 10.02.2010 12:44:10, kmxx napsal(a):
Can somebody please comment on this issue. I know that is not new in Thanks in advance for any suggestions. -- |
@kmx - Status changed from 'new' to 'open' |
From @steve-m-haykmx via RT wrote on 2010-03-03:
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. |
From @iabynOn Thu, Mar 04, 2010 at 04:40:41PM -0000, Steve Hay wrote:
While the args of the PerlIO functions are explicity reversed, I think 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) and the type of function expected in the pPuts slot is LPPuts, which is typedef int (*LPPuts)(struct IPerlStdIO*, FILE*, const char*); So under some circumstances, fputs(str,handle) which doesn't match the LPPuts definition. But that's a horrible twisty maze of macros that I don't really understand. -- |
From @steve-m-hayOn 4 March 2010 20:17, Dave Mitchell <davem@iabyn.com> wrote:
I'm not claiming to fully understand this macro maze myself, but I The way I see it (which could be entirely wrong...) is this: If you're using PerlIO and you want to access an original CRT IO iperlsys.h defines PerlSIO_fputs(f, s) as (*PL_StdIO->pPuts)(PL_StdIO, (f),(s)) when using PERL_IMPLICIT_SYS (with the pPuts slot typedef'ed as you fputs(s, f) otherwise. The latter is the original CRT function, with its args put int (note that the args get reversed in there!) and in win32/win32.c we have DllExport int i.e. the default implementation simply takes us back to the original There's also something in win32/win32iop.h which I'm not entirely The OP is using Strawberry Perl, which does build with The other big problem here is that none of the PerlLIO / PerlSIO I guess the problem doesn't bite often because only Win32 makes use of |
From @janduboisOn Thu, 04 Mar 2010, Dave Mitchell wrote:
That one is correct. PerlSIO_* APIs are supposed to have the same prototype
This however is busted. The parameters should not be swapped. The same problem exists for the fputc() function as well. I've attached my 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, --- a/iperlsys.h int int |
From @janduboisOn Thu, 04 Mar 2010, Jan Dubois wrote:
Note that is would be _possible_ to make a much smaller patch than the #define PerlSIO_fputs(f,s) (*PL_StdIO->pPuts)(PL_StdIO, (f),(s)) (and also in the corresponding PerlSIO_fputc() #define). It would Cheers, |
From @kmxHi, firts of all thaks for your effort you have invested into this issue.
I will do, however my build env is slighly disorganised at the moment so But I have prepared a small failing test example - see attached Thanks again. -- |
From @kmxI forgot to Cc: p5p list Dne čt 04.bře.2010 22:09:09, kmxx napsal(a):
attachment link: |
From @janduboisOn Thu, 04 Mar 2010, Steve Hay wrote:
I believe that is wrong. At least the PerlSIO_* names are an implementation XS code should not have to care if it is being compiled using PerlIO
XSUB.h already redefines fputs to PerlSIO_fputs for PERL_IMPLICIT_SYS. Note that this is just a theory; I have not verified that it actually
I don't understand why you need to call PerlSIO_flcose() in that module Cheers, |
From @steve-m-hayJan Dubois wrote on 2010-03-05:
Clearly I'm still on a learning exercise now ;-)
Sounds good, but it didn't work at the time. It does now, though, after trying it again with a current perl...
I just looked at the module again. The Changes file says fclose() was changed to PerlSIO_fclose() to allow building with perl-5.8.0 with PERL_IMPLICIT_SYS, so I tried that with the PerlSIO_ prefix deleted. It builds and passes all tests, but emits two compiler warnings: SharedFileOpen.xs(499) : warning C4047: 'function' : 'struct _PerlIO ** ' differs in levels of indirection from 'struct _iobuf *' Using PerlSIO_fclose() instead fixes that. However, trying with bleadperl I don't get the same result. The problem is that perl-5.8.0's XSUB.h didn't redefine fclose to PerlSIO_fclose: it redefined it to PerlIO_close instead. It got fixed (by NI-S) on 26 Jan 2003, the very day after I uploaded my "fixed" CPAN module: http://perl5.git.perl.org/perl.git/commit/f9415d2 So it looks like I should undo all my PerlSIO_/PerlLIO_ stuff, and add a local fix for the fclose bug in perl-5.8.0 to maintain compatibility with that version of perl. You live and learn. |
From @jandubois
Yes, the patch fixes the issue exhibited by your test example. Given the current code freeze this fix will have to wait until after So assuming it won't make it into 5.12 I plan to add the attached simple Cheers, Inline Patch--- iperlsys.h~ 2010-02-09 12:34:54.000000000 -0800
+++ iperlsys.h 2010-03-05 12:24:17.674828900 -0800
@@ -226,9 +226,9 @@
#define PerlSIO_get_ptr(f) \
(*PL_StdIO->pGetPtr)(PL_StdIO, (f))
#define PerlSIO_fputc(f,c) \
- (*PL_StdIO->pPutc)(PL_StdIO, (f),(c))
+ (*PL_StdIO->pPutc)(PL_StdIO, (c),(f))
#define PerlSIO_fputs(f,s) \
- (*PL_StdIO->pPuts)(PL_StdIO, (f),(s))
+ (*PL_StdIO->pPuts)(PL_StdIO, (s),(f))
#define PerlSIO_fflush(f) \
(*PL_StdIO->pFlush)(PL_StdIO, (f))
#define PerlSIO_fgets(s, n, fp) \ |
From @csjewellOn Fri Mar 05 12:51:32 2010, jdb wrote:
I have one question. Would this patch be required for 5.10.x versions of [The reason I ask is that I plan to build a 5.10.x version of strawberry --Curtis |
From @timbunceCould this be the cause of this NYTProf failure on Windows? Tim. On Fri, Mar 05, 2010 at 12:50:34PM -0800, Jan Dubois wrote:
|
From @kmx
Thanks for testing, Jan.
From that point of view it is not a blocker as both ActivePerl + If not accepted in 5.12 please do not forget to commit this patch after
Definitely yes. -- |
From @kmxMay I nominate the patch fixings RT proposed by Jan to get into 5.12.1? Thanks. -- |
From @kmxDne čt 04.bře.2010 18:55:26, jdb napsal(a):
Now - after blead unfreeze - can I ask somebody (perhaps Jan, the author Thanks. -- |
From @janduboisOn Wed Apr 14 23:55:56 2010, kmxx wrote:
Fix has been committed as change 634b482. I'll ask for supporting votes to integrate into maint-5.12 once rgs has Same thing for commit 20c8f8f which is similar (fgets() doesn't have |
From @kmxDne st 21.dub.2010 23:55:55, jdb napsal(a):
If my vote counts I would like to support including 634b482 + 20c8f8f -- |
From @janduboisOn Wed, 05 May 2010, kmx via RT wrote:
634b482 is already in maint-5.12 as 72c7417: http://perl5.git.perl.org/perl.git/commitdiff/72c7417 20c8f8f has been requested (by me) and got a second vote from Vincent. Given that this bug was detected with Devel::NYTProf, maybe Tim is Cheers, commit 20c8f8f XSUB.h is supposed to redefine fgets under PERL_IMPLICIT_SYS, but doesn't. Inline Patchdiff --git a/XSUB.h b/XSUB.h
index f23df37..06cb1c3 100644
--- a/XSUB.h
+++ b/XSUB.h
@@ -507,6 +507,7 @@ Rethrows a previously caught exception. See L<perlguts/"Exception
# define ferror PerlSIO_ferror
# define clearerr PerlSIO_clearerr
# define getc PerlSIO_getc
+# define fgets PerlSIO_fgets
# define fputc PerlSIO_fputc
# define fputs PerlSIO_fputs
# define fflush PerlSIO_fflush |
From @timbunceOn Wed, May 05, 2010 at 12:27:02PM -0700, Jan Dubois wrote:
It certainly gets a nod from me. (Strictly speaking I don't have a vote Tim.
|
From @craigberryOn Thu, May 6, 2010 at 6:05 AM, Tim Bunce <Tim.Bunce@pobox.com> wrote:
20c8f8f is now in maint-5.12 as: <http://perl5.git.perl.org/perl.git/commitdiff/e560917618a7d70a9f3420f75c62e08872bf97b5> |
@iabyn - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#72704 (status was 'resolved')
Searchable as RT72704$
The text was updated successfully, but these errors were encountered: