This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Revised^2 precompiled header support for cygwin

Billinghurst, David (CALCRTS) wrote:
This patch is based on  Earl Chew's 3.4 patch for precompiled header support for cygwin
Earl:  Let we know if you no longer want your name associated with this?

David, thanks for following up and integrating my patch into something more recent.

Mainline has the additional hooks required, so this is much less intrusive.

Yes, the new scheme has improvements over the older one.

One thing I was unsure about. In host-cygwin.c(cygwin_gt_pch_get_address)
I use fdopen to associate a stream with a file descriptor. Should I
close the stream or not? I don't see any "bad things" if I leave the stream open.

This is not nice in the sense that the FILE* is leaked. In hindsight, I think it's better if the code simply use the raw fd as is, rather than trying to paste a FILE* over the top of it. At this point, this code is Cygwin specific, so there is no need to attempt to try to use stdio for portability.

I think the following would be better:

static void *
cygwin_gt_pch_get_address (size_t sz, int fd)
  void *base;
  off_t p = lseek(fd, 0, SEEK_CUR);

  if (p == (off_t) -1)
    fatal_error ("can't get position in PCH file: %m");

   /* Cygwin requires that the underlying file be at least
      as large as the requested mapping.  */
  if ((size_t) p < sz)
    if ( lseek (fd, sz-1, SEEK_SET) != 0
      || write (fd, '\0', 1) == 1 )
      fatal_error ("can't extend PCH file: %m");

base = mmap (NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);

  if (base == MAP_FAILED)
    base = NULL;
    munmap (base, sz);

  if (lseek (fd, p, SEEK_SET) != 0)
    fatal_error ("can't set position in PCH file: %m");

  return base;

> ---------------------------------------------------------------------+
> Earl Chew                            |
> Agilent Technologies           |
> Data Networks Division                 Tel:   +1 604 454 3411        |
> 2500-4710 Kingsway                     Fax:   +1 604 454 3401        |
> Burnaby BC V5H 4M2 Canada                                            |
> ---------------------------------------------------------------------+

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]