ffi-win32-extensions 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a61a497ca132d28a6d17298a8551281955678458
4
- data.tar.gz: 3976608e5b17ee479765ab737c8d7576e21236b0
3
+ metadata.gz: 222fca76d4a26f80510379101b6cdcbb35983631
4
+ data.tar.gz: c552a2d5f78aafd64c993fed870819d3f983b4b9
5
5
  SHA512:
6
- metadata.gz: 1518bab2ccbc0114d46edfb17b96461c25b4747c556f9287213776b06899c30526db0106347841086fc4da8980919cf10a12252431c396484f497d3a0baf5fc0
7
- data.tar.gz: 27048b83b513b98bc6a7fb33a8569d32cb84ed3416d5f26fdab677c57050f1b720fcbaefc7d7a5e32c404d76a94b7b6f23c0743c7ef2a76afb3844b1e44b753c
6
+ metadata.gz: ed1b217b84bf3bc93e382766f156aa8bfc88726a8cf20a51527d1f88bcff208b2e6bf729b70c61d06c5196219e82470b7a7c24d199efc6bdb79b2fb1648defa3
7
+ data.tar.gz: dd629833b40839498f2a49688a4cbe12bb8dfb6d78f81acc6a4dbb631a1710b4fa3e79d152a584a6a7df76391abcfe66b7d89beab212d878f53190d5c1da0a7f
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ = 1.0.2 - 20-Jun-2016
2
+ * Added the String#read_wide_string method.
3
+ * Refactored the windows_error_message method a bit.
4
+
1
5
  = 1.0.1 - 8-May-2016
2
6
  * The String#wstrip method defaults to nil on failure.
3
7
 
data/README CHANGED
@@ -18,8 +18,9 @@
18
18
 
19
19
  The following String instance methods have been added:
20
20
 
21
- * wincode - Converts a string to UTF-16LE for use in wide character functions.
22
- * wstrip - Like String#strip, but for wide strings.
21
+ * wincode - Converts a string to UTF-16LE for use in wide char functions.
22
+ * wstrip - Like String#strip, but for wide strings.
23
+ * read_wide_string - Reads a Ruby string up to the first double null.
23
24
 
24
25
  Example:
25
26
 
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'ffi-win32-extensions'
5
- spec.version = '1.0.1'
5
+ spec.version = '1.0.2'
6
6
  spec.authors = 'Daniel J. Berger'
7
7
  spec.license = 'Apache 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
@@ -41,13 +41,20 @@ module FFI
41
41
  # The message will always be English regardless of your locale.
42
42
  #
43
43
  def windows_error_message(function, err=FFI.errno)
44
- flags = 0x00001000 | 0x00000200 # ARGUMENT_ARRAY + SYSTEM
45
- buf = FFI::MemoryPointer.new(:char, 1024)
44
+ error_message = ''
45
+
46
+ # ARGUMENT_ARRAY + SYSTEM + MAX_WIDTH_MASK
47
+ flags = 0x00001000 | 0x00000200 | 0x000000FF
46
48
 
47
49
  # 0x0409 = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)
48
- FormatMessage(flags, nil, err , 0x0409, buf, 1024, nil)
50
+ # We use English for errors because Ruby uses English for errors.
51
+
52
+ FFI::MemoryPointer.new(:char, 1024) do |buf|
53
+ length = FormatMessage(flags, nil, err , 0x0409, buf, buf.size, nil)
54
+ error_message = function + ': ' + buf.read_string(length).strip
55
+ end
49
56
 
50
- function + ': ' + buf.read_string.strip
57
+ error_message
51
58
  end
52
59
 
53
60
  # Raises a Windows specific error using SystemCallError that is based on
@@ -79,4 +86,11 @@ class String
79
86
  rescue
80
87
  nil
81
88
  end
89
+
90
+ # Read a wide character string up until the first double null, and delete
91
+ # any remaining null characters.
92
+ #
93
+ def read_wide_string
94
+ self[/^.*?(?=\x00{2})/].delete(0.chr)
95
+ end
82
96
  end
@@ -10,8 +10,14 @@ class TC_FFI_Win32_Extensions < Test::Unit::TestCase
10
10
  assert_respond_to(@ptr, :read_array_of_string)
11
11
  end
12
12
 
13
- test 'windows_error_message' do
13
+ test 'windows_error_message basic functionality' do
14
14
  assert_respond_to(FFI, :windows_error_message)
15
+ assert_kind_of(String, FFI.windows_error_message('foo'))
16
+ end
17
+
18
+ test 'windows_error_message returns the expected value' do
19
+ expected = 'foo: The operation completed successfully.'
20
+ assert_equal(expected, FFI.windows_error_message('foo', 0))
15
21
  end
16
22
 
17
23
  test 'raise_windows_error' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-win32-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -30,7 +30,7 @@ cert_chain:
30
30
  EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
31
31
  tGSHgAmcLlkdGgan182qsE/4kKM=
32
32
  -----END CERTIFICATE-----
33
- date: 2016-05-08 00:00:00.000000000 Z
33
+ date: 2016-06-21 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: ffi
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  requirements: []
110
110
  rubyforge_project:
111
- rubygems_version: 2.4.8
111
+ rubygems_version: 2.6.4
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Extends the FFI and String classes on MS Windows
metadata.gz.sig CHANGED
Binary file