Backport #1063
closedin `write': Not enough space - <STDOUT> (Errno::ENOMEM) on Windows XP
Description
=begin
Hi, All.
I'm getting an error message when running my test codes on Windows XP under latest ruby-1.9.1-preview - that I downloaded of the website in binary form ( I didn't compile it).
test.rb:34:in `write': Not enough space - (Errno::ENOMEM)
from test.rb:34:in `puts'
from test.rb:34:in `puts'
from test.rb:34:in `'
Now the error message I'm getting is strange - all I could find about it is actually - that somebody had it on *nix machines, but not on windows. Also the same code runs fine under my ruby-1.8.6 - patch 111. As I understand that code means that it's a running out of swap space. Well there is a pagefile on windows, which I guess I guess is windows swap equivalent, but I'm running on a fairly fast machine ( dual core pent 4, with 4 gbs of RAM and system managed pagefile.) So I don't think I'm actually running of memory. :-)
Below is my code that I run ( mind it's just a stupid benchmark code - there is no utility to it, but I was surprised that 1.9.1 couldn't handle what 1.8.6 did) :
a = Time.now
k = []
class Array
def inject(n)
each { |value| n = yield(n, value) }
n
end
def sum
inject(0) { |n, value| n + value }
end
def product
inject(1) { |n, value| n * value }
end
end
def fibUpTo(max)
i1, i2 = 1, 1 # parallel assignment
while i1 <= max
yield i1
i1, i2 = i2, i1+i2
end
end
fibUpTo(100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) { |f| k.push(f) }
puts "k is: "
puts k
s = k.sum
p = k.product
puts "s is: "
puts s
puts "p is: "
puts p
b = Time.now
c = b-a
puts c
puts "it took: " + c.to_s + " seconds to complete"
=end
Files
Updated by konung (Nick Gorbikoff) almost 16 years ago
=begin
Also the same code - attached in an rb file.
I understand that I might be tryign to calculate a number out of bounds, but it seems to me that if I can do it in 1.8.6 - I should be able in 1.9.1 .
Thanks
Let me know if I can provide any additional information.
=end
Updated by rogerdpack (Roger Pack) almost 16 years ago
=begin
Hmm. It does seem that running
STDOUT.write "a"*100000000
works on windows in 1.8.6 but not 1.9
Linux seems fine, however.
=end
Updated by usa (Usaku NAKAMURA) almost 16 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
=begin
Applied in changeset r21903.
=end
Updated by usa (Usaku NAKAMURA) almost 16 years ago
=begin
Hello,
In message "[ruby-core:21616] [Bug #1063] in `write': Not enough space - (Errno::ENOMEM) on Windows XP"
on Jan.28,2009 03:06:21, redmine@ruby-lang.org wrote:
Hmm. It does seem that running
STDOUT.write "a"*100000000
works on windows in 1.8.6 but not 1.9
It's Windows' bug. The border is about 60KB.
I found this bug about 7 years ago, and I considered that
it is not critical.
If you want to reproduce on 1.8.6,
STDOUT.binmode.write "a"*100000000
And if you want to reproduce it without ruby,
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#define LEN 100000000
int main()
{
DWORD sz;
char *str = malloc(LEN + 1);
memset(str, 'a', LEN);
str[LEN] = '\0';
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), str, LEN, &sz, NULL);
printf("%d, %d\n", sz, GetLastError());
free(str);
return 0;
}
Regards,¶
U.Nakamura usa@garbagecollect.jp
=end
Updated by rogerdpack (Roger Pack) over 15 years ago
=begin
Would it be possible to get this backported to 1.9.1?
Currently with 1.9.1p129 it seems to not be
C:\dev\blade_copy>gem list -r
*** REMOTE GEMS ***
ERROR: While executing gem ... (Errno::ENOMEM)
Not enough space -
Thanks!
-=r
=end
Updated by d-snp (Tinco Andringa) about 15 years ago
=begin
It's still broken/broken again :(
ruby --version: ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mswin32]
Code: puts 'a' * 100000
echo.rb:1:in write': Not enough space - <STDOUT> (Errno::ENOMEM) from echo.rb:1:in
puts'
from echo.rb:1:in puts' from echo.rb:1:in
'
Please not that although that code is rather theoretical the error occurs in very fast making it unworkable.
=end
Updated by usa (Usaku NAKAMURA) about 15 years ago
=begin
Hello,
In message "[ruby-core:26833] [Bug #1063] in `write': Not enough space - (Errno::ENOMEM) on Windows XP"
on Nov.20,2009 07:42:39, redmine@ruby-lang.org wrote:
It's still broken/broken again :(
ruby --version: ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mswin32]
You should request backporting r21903 to ruby_1_9_1.
Regards,¶
U.Nakamura usa@garbagecollect.jp
=end
Updated by usa (Usaku NAKAMURA) about 15 years ago
- Status changed from Closed to Assigned
- Assignee set to yugui (Yuki Sonoda)
=begin
=end
Updated by yugui (Yuki Sonoda) about 15 years ago
- Status changed from Assigned to Closed
=begin
This issue was solved with changeset r26004.
Nick, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
=end
Updated by rogerdpack (Roger Pack) almost 14 years ago
=begin
For followers, a hackey kludgey work-around is the following:
class String
def to_2d_array(value)
unpack("a#{value}"*((size/value)+((size%value>0)?1:0)))
end
end
class << $stdout; alias old_write write; def write a; a.to_s.to_2d_array(1024).each{|little| old_write little}; end; end
Cheers!
-r
=end