[Patch, libfortran] PR 40812 Large file support on MinGW

Kai Tietz ktietz70@googlemail.com
Thu Dec 3 09:12:00 GMT 2009


2009/12/3 Kai Tietz <ktietz70@googlemail.com>:
> 2009/12/3 Danny Smith <dannysmith@clear.net.nz>:
>>
>> ----- Original Message ----- From: "Danny Smith"
>>>
>>> Test of  Janne's patch on mingw32 (using Vista) shows problems.
>>> Although it fixes the testcases in the PR,  I get new failure
>>> FAIL: gfortran.dg/PR19872.f execution test
>>>
>>> Ditto for my revised patch that is pre-w2k compatible.
>>>
>>> I suspect one problem is that we fail to lock the lowio handle for the
>>> filedes in raw_truncate, as would be done in the libc chsize().  The lowio
>>> stuff (eg, the ioinfo control structure) is not fully documented by MS,
>>> although some of it is exposed in 3rd party code.
>>>
>>> Kai, did you get the PR19872.f  failure in your testsuite runs?
>>>
>>
>> With Janne's patch, I also get new failures on backspace-2.f :
>> (At line 10 of file backspace_2.f (unit = 11, file = 'fort.11')
>> Fortran runtime error: I/O past end of record on unformatted file)
>>
>> and backspace-6.f: (abort)
>>
>> Danny
>>
>
> Hmm, yes. I get this too. Well, we could use here the exports of
> msvcrt _lock/_unlock. Those are sadly undocumented. I'll give it a try
> to see if this would help here.
>
> Cheers,
> Kai
>
> --
> |  (\_/) This is Bunny. Copy and paste
> | (='.'=) Bunny into your signature to help
> | (")_(") him gain world domination
>

Ok, I found the issue and now this testcases all work as expected. The
issue is that the fileposition is changed in
rar_truncate, but it hasn't (see man pages about truncate/ftruncate).

By changing this function to

static int
raw_truncate (unix_stream * s, gfc_offset length)
{
#ifdef __MINGW32__
  LARGE_INTEGER cur, tmp;
  HANDLE h;
  intptr_t htmp;
  gfc_offset old;

  if (isatty (s->fd))
    {
      errno = EBADF;
      return -1;
    }
  old = lseek (s->fd, 0, SEEK_CUR);
  htmp = (intptr_t) _get_osfhandle (s->fd);
  if (htmp == INVALID_HANDLE_VALUE)
    {
      runtime_error ("Couldn't get handle from fd");
      return -1;
    }
  h = (HANDLE) htmp;
  tmp.LowPart = 0;
tmp.HighPart = 0;
if (!SetFilePointerEx (h, tmp, &cur, FILE_CURRENT))
  {
    runtime_error ("Couldn't determine file position");
    return -1;
  }
tmp.QuadPart = length;
if (!SetFilePointerEx (h, tmp, NULL, FILE_CURRENT))
  {
    runtime_error ("Couldn't seek to specified position for truncation");
    return -1;
  }
if (!SetEndOfFile (h))
  {
    runtime_error ("Couldn't truncate file");
    return -1;
  }
if (!SetFilePointerEx (h, cur, NULL, FILE_BEGIN))
  {
    runtime_error ("Couldn't seek back after truncating");
    return -1;
  }
lseek (s->fd, old, SEEK_END);
return 0;
}

Things are working without regression.

Cheers,
Kai
-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination



More information about the Gcc-patches mailing list