win32-mmap 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES +5 -0
- data/README +40 -39
- data/Rakefile +6 -1
- data/lib/win32/mmap.rb +43 -29
- data/test/test_win32_mmap.rb +7 -1
- data/win32-mmap.gemspec +1 -1
- metadata +12 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8fd737d1d437da5002b90092c5453761d35e5b51
|
4
|
+
data.tar.gz: c111a6f06fbbe986933dd503d80174a059c9d142
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc7a6cca90f71eac4ea593b4fb7f9098aa89d8c515252e86a9f59983354a0099f2779d74b9f357f8e2d8baf84ff4e92f6bdbd67ed72301e8b4973ae06de3d415
|
7
|
+
data.tar.gz: 16ce6d436951d643f8476a8d673da1274a9e9fdf583aaac265032e1d973e78284a823e473d18914c914dfb8d8e3a7681b81a1d6ec80b10205bedb6b23fde4f9f
|
data/CHANGES
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 0.4.0 - 21-Aug-2013
|
2
|
+
* Added methods for reading or writing raw strings to the underlying
|
3
|
+
memory mapped file (as opposed to marshalled data). Thanks go to
|
4
|
+
Frank Quednau for the patch.
|
5
|
+
|
1
6
|
== 0.3.2 - 28-Apr-2013
|
2
7
|
* Fixed a prototype mismatch in a call to CreateFile. Thanks go to
|
3
8
|
Frank Quednau for the spot.
|
data/README
CHANGED
@@ -1,64 +1,65 @@
|
|
1
1
|
= Description
|
2
|
-
|
2
|
+
This package provides a Ruby interface for memory mapped I/O on MS Windows.
|
3
3
|
|
4
4
|
= Prerequisites
|
5
|
-
|
5
|
+
* ffi
|
6
|
+
* test-unit (Testing only)
|
6
7
|
|
7
8
|
= Installation
|
8
|
-
|
9
|
+
gem install win32-mmap
|
9
10
|
|
10
11
|
= Synopsis
|
11
|
-
|
12
|
-
|
12
|
+
require 'win32/mmap'
|
13
|
+
include Win32
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
map1 = MMap.new(:file => "C:\\test.map", :size => 1024)
|
16
|
+
map1.foo = 'hello'
|
17
|
+
map1.bar = 77
|
18
|
+
map1.close
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
map2 = MMap.new(:file => "C:\\test.map")
|
21
|
+
p map2.foo # 'hello'
|
22
|
+
p map2.bar # 77
|
23
|
+
map2.close
|
23
24
|
|
24
25
|
= About Memory Mapped Files under Windows
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
Under Windows, code and data are both repesented by pages of memory backed
|
27
|
+
by files on disk, code by executable image and data by system pagefile
|
28
|
+
(i.e. swapfile). These are called memory mapped files. Memory mapped files
|
29
|
+
can be used to provide a mechanism for shared memory between processes.
|
30
|
+
Different processes are able to share data backed by the same swapfile,
|
31
|
+
whether it's the system pagefile or a user-defined swapfile.
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
Windows has a tight security system that prevents processes from directly
|
34
|
+
sharing information among each other, but mapped memory files provide a
|
35
|
+
mechanism that works with the Windows security system by using a name that
|
36
|
+
all processes use to open the swapfile.
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
A shared section of the swapfile is translated into pages of memory that are
|
39
|
+
addressable by more than one process, Windows uses a system resource called a
|
40
|
+
prototype page table entry (PPTE) to enable more than one process to address
|
41
|
+
the same physical page of memory, thus multiple process can share the same
|
42
|
+
data without violating the Windows system security.
|
42
43
|
|
43
|
-
|
44
|
+
In short, memory mapped files provide shared memory under Windows.
|
44
45
|
|
45
|
-
|
46
|
-
|
46
|
+
(This explanation was largely borrowed from Roger Lee's Win32::MMF Perl
|
47
|
+
module.)
|
47
48
|
|
48
49
|
= Future Plans
|
49
|
-
|
50
|
+
Suggestions welcome.
|
50
51
|
|
51
52
|
= License
|
52
|
-
|
53
|
+
Artistic 2.0
|
53
54
|
|
54
55
|
= Copyright
|
55
|
-
|
56
|
+
(C) 2003-2013 Daniel J. Berger, All Rights Reserved
|
56
57
|
|
57
58
|
= Warranty
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
This package is provided "as is" and without any express or
|
60
|
+
implied warranties, including, without limitation, the implied
|
61
|
+
warranties of merchantability and fitness for a particular purpose.
|
61
62
|
|
62
63
|
= Authors
|
63
|
-
|
64
|
-
|
64
|
+
Daniel J. Berger
|
65
|
+
Park Heesob
|
data/Rakefile
CHANGED
@@ -8,7 +8,12 @@ namespace 'gem' do
|
|
8
8
|
desc 'Create the win32-mmap gem.'
|
9
9
|
task :create => [:clean] do
|
10
10
|
spec = eval(IO.read('win32-mmap.gemspec'))
|
11
|
-
Gem::
|
11
|
+
if Gem::VERSION.to_f < 2.0
|
12
|
+
Gem::Builder.new(spec).build
|
13
|
+
else
|
14
|
+
require 'rubygems/package'
|
15
|
+
Gem::Package.build(spec)
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
19
|
desc 'Install the win32-mmap gem.'
|
data/lib/win32/mmap.rb
CHANGED
@@ -9,7 +9,7 @@ module Win32
|
|
9
9
|
#
|
10
10
|
class MMap
|
11
11
|
# The version of the win32-mmap library.
|
12
|
-
VERSION = '0.
|
12
|
+
VERSION = '0.4.0'
|
13
13
|
|
14
14
|
include Windows::Constants
|
15
15
|
include Windows::Functions
|
@@ -292,6 +292,25 @@ module Win32
|
|
292
292
|
@autolock
|
293
293
|
end
|
294
294
|
|
295
|
+
# Writes a string directly to the underlying file
|
296
|
+
def write_string(content)
|
297
|
+
lock_pattern do
|
298
|
+
ptr = FFI::Pointer.new(:char, @address)
|
299
|
+
ptr.write_string(content,content.length)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
# Reads a string of a given length from the beginning of the file
|
304
|
+
# if no length is given, reads the file with the @size attribute
|
305
|
+
# of this instance
|
306
|
+
def read_string(length = @size)
|
307
|
+
lock_pattern do
|
308
|
+
FFI::MemoryPointer.new(:char, length)
|
309
|
+
ptr = FFI::Pointer.new(:char, @address)
|
310
|
+
ptr.read_string(length)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
295
314
|
private
|
296
315
|
|
297
316
|
# :stopdoc:
|
@@ -301,8 +320,6 @@ module Win32
|
|
301
320
|
#--
|
302
321
|
# This replaces the getvar/setvar API from 0.1.0.
|
303
322
|
#
|
304
|
-
# TODO: FIX!
|
305
|
-
#
|
306
323
|
def method_missing(method_id, *args)
|
307
324
|
method = method_id.id2name
|
308
325
|
args = args.first if args.length == 1
|
@@ -311,44 +328,41 @@ module Win32
|
|
311
328
|
method.chop!
|
312
329
|
@hash["#{method}"] = args
|
313
330
|
|
314
|
-
|
315
|
-
if mmap_lock
|
316
|
-
instance_variable_set("@#{method}", args)
|
317
|
-
marshal = Marshal.dump(@hash)
|
318
|
-
ptr = FFI::Pointer.new(:char, @address)
|
319
|
-
ptr.write_string(marshal,marshal.length)
|
320
|
-
mmap_unlock
|
321
|
-
end
|
322
|
-
else
|
331
|
+
lock_pattern do
|
323
332
|
instance_variable_set("@#{method}", args)
|
324
333
|
marshal = Marshal.dump(@hash)
|
325
334
|
ptr = FFI::Pointer.new(:char, @address)
|
326
335
|
ptr.write_string(marshal,marshal.length)
|
327
336
|
end
|
337
|
+
|
328
338
|
else # Getter
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
instance_variable_set("@#{method}", val)
|
338
|
-
mmap_unlock
|
339
|
-
end
|
340
|
-
else
|
341
|
-
ptr = FFI::Pointer.new(:char, @address)
|
342
|
-
buf = ptr.read_string(@size)
|
343
|
-
hash = Marshal.load(buf)
|
344
|
-
val = hash["#{method}"]
|
345
|
-
instance_variable_set("@#{method}", val)
|
339
|
+
|
340
|
+
lock_pattern do
|
341
|
+
buf = FFI::MemoryPointer.new(:char, @size)
|
342
|
+
ptr = FFI::Pointer.new(:char, @address)
|
343
|
+
buf = ptr.read_string(@size)
|
344
|
+
hash = Marshal.load(buf)
|
345
|
+
val = hash["#{method}"]
|
346
|
+
instance_variable_set("@#{method}", val)
|
346
347
|
end
|
347
348
|
|
348
349
|
return instance_variable_get("@#{method}")
|
349
350
|
end
|
350
351
|
end
|
351
352
|
|
353
|
+
def lock_pattern
|
354
|
+
if @autolock
|
355
|
+
if mmap_lock
|
356
|
+
output = yield
|
357
|
+
mmap_unlock
|
358
|
+
output
|
359
|
+
end
|
360
|
+
else
|
361
|
+
output = yield
|
362
|
+
output
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
352
366
|
# Adds a semaphore lock the mapping. Only used if +autolock+ is set
|
353
367
|
# to true in the constructor.
|
354
368
|
#
|
data/test/test_win32_mmap.rb
CHANGED
@@ -14,7 +14,7 @@ class TC_Win32_Mmap < Test::Unit::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
test "version is set to expected value" do
|
17
|
-
assert_equal('0.
|
17
|
+
assert_equal('0.4.0', MMap::VERSION)
|
18
18
|
end
|
19
19
|
|
20
20
|
test "dynamic variable names and string values work as expected" do
|
@@ -45,6 +45,12 @@ class TC_Win32_Mmap < Test::Unit::TestCase
|
|
45
45
|
assert_equal([{1=>2}, [1,2,3], 'foo'], @mmap.barray)
|
46
46
|
end
|
47
47
|
|
48
|
+
test "primitive write/read of file" do
|
49
|
+
input = "Greetings, astute reader"
|
50
|
+
assert_nothing_raised{ @mmap.write_string(input) }
|
51
|
+
assert_equal(input, @mmap.read_string(input.length))
|
52
|
+
end
|
53
|
+
|
48
54
|
test "passing an invalid option raises an argument error" do
|
49
55
|
assert_raises(ArgumentError){ MMap.new(:foo => 1) }
|
50
56
|
end
|
data/win32-mmap.gemspec
CHANGED
metadata
CHANGED
@@ -1,34 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32-mmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Daniel J. Berger
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: ffi
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
|
-
description:
|
31
|
-
|
27
|
+
description: |2
|
28
|
+
The win32-mmap library provides an interface for memory mapped IO on
|
29
|
+
MS Windows.
|
32
30
|
email: djberg96@gmail.com
|
33
31
|
executables: []
|
34
32
|
extensions: []
|
@@ -53,27 +51,26 @@ files:
|
|
53
51
|
homepage: https://github.com/djberg96/win32-mmap
|
54
52
|
licenses:
|
55
53
|
- Artistic 2.0
|
54
|
+
metadata: {}
|
56
55
|
post_install_message:
|
57
56
|
rdoc_options: []
|
58
57
|
require_paths:
|
59
58
|
- lib
|
60
59
|
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
60
|
requirements:
|
63
|
-
- -
|
61
|
+
- - '>='
|
64
62
|
- !ruby/object:Gem::Version
|
65
63
|
version: '0'
|
66
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
65
|
requirements:
|
69
|
-
- -
|
66
|
+
- - '>='
|
70
67
|
- !ruby/object:Gem::Version
|
71
68
|
version: '0'
|
72
69
|
requirements: []
|
73
70
|
rubyforge_project: win32utils
|
74
|
-
rubygems_version:
|
71
|
+
rubygems_version: 2.0.7
|
75
72
|
signing_key:
|
76
|
-
specification_version:
|
73
|
+
specification_version: 4
|
77
74
|
summary: Memory mapped IO for Windows.
|
78
75
|
test_files:
|
79
76
|
- test/test_win32_mmap.rb
|