-
Notifications
You must be signed in to change notification settings - Fork 558
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
stat() warns about unopened filehandle on tied handles #12029
Comments
From @xdgCreated by @xdgCalling stat() on a tied handle warns, even if the tied handle has $ perl -MTie::StdHandle -wE 'tie *FOO, 'Tie::StdHandle', "/etc/services"; print scalar readline *FOO; say fileno *FOO; stat(*FOO)' The bug is still in blead. The same warning used to occur for scalar filehandles, but it Perl Info
|
From @jkeenanOn Sat Mar 31 09:19:10 2012, dagolden@cpan.org wrote:
That was probably: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=71002 |
The RT System itself - Status changed from 'new' to 'open' |
From @cpansproutOn Sat Mar 31 09:19:10 2012, dagolden@cpan.org wrote:
fileno() there is not a real fileno call, but tied(*FOO)->FILENO. perltie.pod says:
So it sounds as though we would need to implement STAT on tied OTOH, a Tie::StdHandle object is a globref: sub TIEHANDLE so I’m not sure why it’s not already working properly. -- Father Chrysostomos |
From @cpansproutOn Sat Mar 31 10:39:01 2012, sprout wrote:
It’s not already working, because there are *two* globs involved. *FOO So, again, we would have to make stat(*FOO) call tied(*FOO)->STAT to fix -- Father Chrysostomos |
From @xdgOn Sat, Mar 31, 2012 at 7:39 PM, Father Chrysostomos via RT
Sure. That was just to confirm the file was indeed opened.
I think that's a good long term goal, but a more immediate fix is that -- David |
From @LeontOn Sat, Mar 31, 2012 at 6:19 PM, David Golden <perlbug-followup@perl.org> wrote:
I think this should do it. Leon |
From @Leont0001-Fix-stat-on-tied-filehandles.patchFrom 78bde9f6abd7a1fc3eea157de223db32b294168c Mon Sep 17 00:00:00 2001
From: Leon Timmermans <fawaka@gmail.com>
Date: Sat, 31 Mar 2012 19:28:47 +0200
Subject: [PATCH] Fix stat on tied filehandles
---
pp_sys.c | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/pp_sys.c b/pp_sys.c
index 49910d2..30b1512 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2784,6 +2784,7 @@ PP(pp_stat)
io = GvIO(gv);
}
if (io) {
+ MAGIC* mg;
if (IoIFP(io)) {
PL_laststatval =
PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache);
@@ -2792,6 +2793,19 @@ PP(pp_stat)
PL_laststatval =
PerlLIO_fstat(my_dirfd(IoDIRP(io)), &PL_statcache);
havefp = TRUE;
+ } else if(SvMAGICAL((SV*)io) && (mg = mg_find((SV*)io, PERL_MAGIC_tiedscalar))) {
+ int fd;
+ ENTER;
+ PUSHMARK(SP);
+ PUSHs(SvTIED_obj(sv, mg));
+ PUTBACK;
+ call_method("FILENO", G_SCALAR);
+ SPAGAIN;
+ fd = POPi;
+ LEAVE;
+
+ PL_laststatval = PerlLIO_fstat(fd, &PL_statcache);
+>>>>>>> 81c3e5c16a3bf84ffcb41fd9e4a3135c4ad190a9
} else {
PL_laststatval = -1;
}
--
1.7.5.4
|
From @cpansproutOn Sat Mar 31 11:08:55 2012, LeonT wrote:
Ah, using FILENO to get the file number and then doing a stat with -- Father Chrysostomos |
From @cpansproutOn Sat Mar 31 10:30:46 2012, jkeenan wrote:
I don’t think so. That dealt with the special casing that _ gets. There have been multiple fixes to stat, but I don’t know exactly which -- Father Chrysostomos |
From @xdgOn Sat, Mar 31, 2012 at 8:19 PM, Father Chrysostomos via RT
As I mentioned to leont in passing at the hackathon, a tied handle Short of tied handles doing STAT, I still think best would be to just -- David |
From @cpansproutOn Sat Mar 31 10:55:15 2012, dagolden@cpan.org wrote:
I’d like to get that done for 5.18. What should the interface be for the STAT call? Should it be expected to return a 13-element list? Should those What should happen if it returns a list with fewer elements? Should pp_stat croak, or assume (@ret, (undef)x(13-@ret))? If it croaks, should it be forgiving with ‘return undef’? (Probably not.) I think I’m in favour of having it croak if @ret != 13 && @ret != 0. Filetest calls like -r and -w can be implemented in terms of STAT, but
This can be the fallback for handles without STAT. -- Father Chrysostomos |
Migrated from rt.perl.org#112164 (status was 'open')
Searchable as RT112164$
The text was updated successfully, but these errors were encountered: