Skip to content
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

Re: Open filehandles for 'used' files... #249

Closed
p5pRT opened this issue Jul 27, 1999 · 2 comments
Closed

Re: Open filehandles for 'used' files... #249

p5pRT opened this issue Jul 27, 1999 · 2 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 27, 1999

Migrated from rt.perl.org#1065 (status was 'resolved')

Searchable as RT1065$

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 1999

From @nwc10

I think the answer is "yes unless it encounters __DATA__ or __END__ in that
package, in which case it keeps the FILE* open, attaching it to the package's
DATA filehandle."

See

  case KEY___DATA__​:
  case KEY___END__​: {
  GV *gv;

  /*SUPPRESS 560*/
  if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
  char *pname = "main";
  if (PL_tokenbuf[2] == 'D')
  pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash);
  gv = gv_fetchpv(form("%s​::DATA", pname), TRUE, SVt_PVIO);
  GvMULTI_on(gv);
  if (!GvIO(gv))
  GvIOp(gv) = newIO();
  IoIFP(GvIOp(gv)) = PL_rsfp;
#if defined(HAS_FCNTL) && defined(F_SETFD)
  {
  int fd = PerlIO_fileno(PL_rsfp);
  fcntl(fd,F_SETFD,fd >= 3);
  }
#endif
  /* Mark this internal pseudo-handle as clean */
  IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
  if (PL_preprocess)
  IoTYPE(GvIOp(gv)) = '|';
  else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
  IoTYPE(GvIOp(gv)) = '-';
  else
  IoTYPE(GvIOp(gv)) = '<';
  PL_rsfp = Nullfp;
  }
  goto fake_eof;
  }

in toke.c

note how it copies PL_rsfp into the IoIFP, then sets PL_rsfp = Nullfp before
going to fake_eof, which does fclose on PL_rsfp.

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 1999

From @gbarr

case KEY\_\_\_DATA\_\_&#8203;:
case KEY\_\_\_END\_\_&#8203;: \{

Ouch!!!

I always thought you only got the DATA filehandle if you had __DATA__

This means that all the modules that put pod at the end after a __END__
or use AutoLoader are using a filehandle. I can now see how it is
very easy to run out of filehandles.

perl5.005_58 $ find lib -name \*.pm | wc -l
187
perl5.005_58 $ find lib -name \*.pm -exec grep -l ^__END__ {} \; | wc -l
109
perl5.005_58 $ find lib -name \*.pm -exec grep -l DATA {} \; | wc -l
20

It is probably to late to change __END__, so I think we need a new __ keyword
to denote the end and close the file.

--
Since you're clearly mad as a mongoose, I'll bid you good-day.
  -- Edmund to Captain Rum : Black Adder II "Potato"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant