Bug #4564

mingw-w64, truncate, ftruncate and ftello -- properly evalute it's existence

Added by Luis Lavena about 3 years ago. Updated almost 3 years ago.

[ruby-core:35678]
Status:Closed
Priority:Normal
Assignee:Luis Lavena
Category:core
Target version:2.0.0
ruby -v:- Backport:

Description

=begin
Hello,

I'm using latest mingw-w64 builds that target in a experimental way GCC 4.7.0 codebase (gcc trunk)

mingw-w64 also combines improved CRT and headers support, which in this case included truncate, ftruncate and ftello support.

Ruby's trunk for win32 currently redefines those blindly, and even forces these functions presence to be used.

The attached patch proposes rely on configure's ability to detect these functions presence, conditionally define the missing functions and rename these functions to avoid redefinitions.

Assigning to Mr. Nobuyoshi Nakada and Mr. Usaku Nakamura for review and approval.

I've tested this against GCC 3.4.5, 4.5.1, 4.5.2 and 4.7.0, all on Windows. These patches should not affect any Linux version, however could affect Visual Studio builds.

Thank you for your time looking into this.

=end

0001-properly-detect-truncate-ftruncate-and-ftello-existence.patch Magnifier (2.37 KB) Luis Lavena, 04/10/2011 03:32 AM

Associated revisions

Revision 31351
Added by Nobuyoshi Nakada almost 3 years ago

  • include/ruby/win32.h (ftruncate, truncate, ftello, fseeko): non-64 versions on mingw are useless because they use int32_t. fixes #4564

History

#1 Updated by Usaku NAKAMURA about 3 years ago

  • Status changed from Open to Assigned

=begin
It seems good.
Check in, please.
=end

#2 Updated by Luis Lavena about 3 years ago

  • Status changed from Assigned to Closed
  • Assignee changed from Nobuyoshi Nakada to Luis Lavena
  • % Done changed from 0 to 100

=begin
Thank you.

Committed in r31262
=end

#3 Updated by Nobuyoshi Nakada about 3 years ago

  • Status changed from Closed to Open
  • % Done changed from 100 to 0

=begin
Since ftruncate and truncate on mingw use int32_t and are useless at all, so this change causes failures to handle over 2GB files.
I'll revert this and succeeding changes or fix to use ftruncate64 instead.
=end

#4 Updated by Luis Lavena about 3 years ago

=begin
Thank you Nobu,

Dunno how I missed this detail.

Please revert this until I provide a proper patch that consistently uses ftruncate64.
=end

#5 Updated by Nobuyoshi Nakada almost 3 years ago

=begin
Try:

open("a.data", "w") {|f| f.truncate(1<<32)}

Currently this makes an empty file, while a 4GB file previously.
I consider this is a degrade.
=end

#6 Updated by Nobuyoshi Nakada almost 3 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r31351.
Luis, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • include/ruby/win32.h (ftruncate, truncate, ftello, fseeko): non-64 versions on mingw are useless because they use int32_t. fixes #4564 =end

#7 Updated by Luis Lavena almost 3 years ago

Thank you Nobu,

Thing is that current 1.9.2 with MinGW do not work as you mentioned:

C:\Users\Luis>ruby -ve "File.open('a.data', 'w') { |f| f.truncate(1 << 32) }"
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

C:\Users\Luis>dir a.data
Directory of C:\Users\Luis

22/05/2011 01:36 p.m. 0 a.data

But works on trunk:

C:\Users\Luis>ruby -ve "File.open('a.data', 'w') { |f| f.truncate(1 << 32) }"
ruby 1.9.3dev (2011-05-23 trunk 31696) [i386-mingw32]

C:\Users\Luis>dir a.data
Directory of C:\Users\Luis

22/05/2011 01:37 p.m. 4.294.967.296 a.data

#8 Updated by Nobuyoshi Nakada almost 3 years ago

  • ruby -v changed from ruby 1.9.3dev (2011-04-10 trunk 31255) [i386-mingw32] to -

Hi,

At Mon, 23 May 2011 02:38:25 +0900,
Luis Lavena wrote in :

Thing is that current 1.9.2 with MinGW do not work as you mentioned:

C:\Users\Luis>ruby -ve "File.open('a.data', 'w') { |f| f.truncate(1 << 32) }"
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

C:\Users\Luis>dir a.data
Directory of C:\Users\Luis

22/05/2011 01:36 p.m. 0 a.data

Thanks.
Then it should be a bug in 1.9.2. Mswin32 version works as expected at least.

--
Nobu Nakada

Also available in: Atom PDF