Project

General

Profile

Bug #2369 ยป test.rb

wanabe (_ wanabe), 11/15/2009 02:11 PM

 
require 'dl/import'
module Kernel32
extend DL::Importer
dlload "kernel32.dll"
typealias('DWORD', 'unsigned long')
typealias('LPCSTR', 'const unsigned char *')
typealias('LPSTR', 'unsigned char *')
extern 'DWORD GetEnvironmentVariableA(LPCSTR,LPSTR,DWORD)'
end

ENV["FOO"] = "x" * 0x7ff8

### != 0x7ff8
p ENV["FOO"].length

### == 0x7ff8
buf = "\0" * 0x8000
Kernel32.GetEnvironmentVariableA("FOO", buf, buf.size)
p buf.gsub("\0", "").length

1000.times do |i|
ENV["FOO"] = "x" * 0x8000
end

### not reached (SEGV)
puts "ok"
    (1-1/1)