Skip to content

Commit a4c7669

Browse files
authored
Suppress warning of keyword arguments introduced in Ruby 2.7 (#42)
1 parent 6416bb2 commit a4c7669

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
AllCops:
2+
TargetRubyVersion: 2.3
23
DisplayCopNames: true
34
DisplayStyleGuide: true
45

lib/elftools/sections/sections.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class << Section
2121
# @param [#pos=, #read] stream Streaming object.
2222
# @return [ELFTools::Sections::Section]
2323
# Return object dependes on +header.sh_type+.
24-
def create(header, stream, *args)
24+
def create(header, stream, *args, **kwargs)
2525
klass = case header.sh_type
2626
when Constants::SHT_DYNAMIC then DynamicSection
2727
when Constants::SHT_NULL then NullSection
@@ -31,7 +31,7 @@ def create(header, stream, *args)
3131
when Constants::SHT_SYMTAB, Constants::SHT_DYNSYM then SymTabSection
3232
else Section
3333
end
34-
klass.new(header, stream, *args)
34+
klass.new(header, stream, *args, **kwargs)
3535
end
3636
end
3737
end

lib/elftools/segments/segments.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ class << Segment
1919
# @param [#pos=, #read] stream Streaming object.
2020
# @return [ELFTools::Segments::Segment]
2121
# Return object dependes on +header.p_type+.
22-
def create(header, stream, *args)
22+
def create(header, stream, *args, **kwargs)
2323
klass = case header.p_type
2424
when Constants::PT_DYNAMIC then DynamicSegment
2525
when Constants::PT_INTERP then InterpSegment
2626
when Constants::PT_LOAD then LoadSegment
2727
when Constants::PT_NOTE then NoteSegment
2828
else Segment
2929
end
30-
klass.new(header, stream, *args)
30+
klass.new(header, stream, *args, **kwargs)
3131
end
3232
end
3333
end

lib/elftools/structs.rb

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# frozen_string_literal: true
22

33
require 'bindata'
4+
45
module ELFTools
56
# Define ELF related structures in this module.
67
#
78
# Structures are fetched from https://github.com/torvalds/linux/blob/master/include/uapi/linux/elf.h.
8-
# Using the bindata gem to make these structures support 32/64 bits and
9-
# little/big endian simultaneously.
9+
# Use gem +bindata+ to have these structures support 32/64 bits and little/big endian simultaneously.
1010
module Structs
1111
# The base structure to define common methods.
1212
class ELFStruct < BinData::Record
@@ -25,9 +25,13 @@ def patches
2525
end
2626

2727
class << self
28-
# Hook constructor, while +BinData::Record+ doesn't allow us to override +#initialize+,
29-
# so we hack +new+ here.
30-
def new(**kwargs)
28+
# Hooks the constructor.
29+
#
30+
# +BinData::Record+ doesn't allow us to override +#initialize+, so we hack +new+ here.
31+
def new(*args)
32+
# XXX: The better implementation is +new(*args, **kwargs)+, but we can't do this unless bindata changed
33+
# lib/bindata/dsl.rb#override_new_in_class to invoke +new+ with both +args+ and +kwargs+.
34+
kwargs = args.last.is_a?(Hash) ? args.last : {}
3135
offset = kwargs.delete(:offset)
3236
super.tap do |obj|
3337
obj.offset = offset
@@ -44,13 +48,13 @@ def new(**kwargs)
4448
end
4549
end
4650

47-
# Hacking to get endian of current class
48-
# @return [Symbol, nil] +:little+ or +:big+.
51+
# Gets the endianness of current class.
52+
# @return [:little, :big] The endianness.
4953
def self_endian
5054
bindata_name[-2..-1] == 'be' ? :big : :little
5155
end
5256

53-
# Pack integer into string.
57+
# Packs an integer to string.
5458
# @param [Integer] val
5559
# @param [Integer] bytes
5660
# @return [String]
@@ -112,7 +116,7 @@ class ELF_Shdr < ELFStruct
112116
choice :sh_entsize, **CHOICE_SIZE_T
113117
end
114118

115-
# Program header structure for 32bit.
119+
# Program header structure for 32-bit.
116120
class ELF32_Phdr < ELFStruct
117121
endian :big_and_little
118122
uint32 :p_type
@@ -125,7 +129,7 @@ class ELF32_Phdr < ELFStruct
125129
uint32 :p_align
126130
end
127131

128-
# Program header structure for 64bit.
132+
# Program header structure for 64-bit.
129133
class ELF64_Phdr < ELFStruct
130134
endian :big_and_little
131135
uint32 :p_type
@@ -137,13 +141,14 @@ class ELF64_Phdr < ELFStruct
137141
uint64 :p_memsz
138142
uint64 :p_align
139143
end
140-
# Get program header class according to bits.
144+
145+
# Gets the class of program header according to bits.
141146
ELF_Phdr = {
142147
32 => ELF32_Phdr,
143148
64 => ELF64_Phdr
144149
}.freeze
145150

146-
# Symbol structure for 32bit.
151+
# Symbol structure for 32-bit.
147152
class ELF32_sym < ELFStruct
148153
endian :big_and_little
149154
uint32 :st_name
@@ -154,7 +159,7 @@ class ELF32_sym < ELFStruct
154159
uint16 :st_shndx
155160
end
156161

157-
# Symbol structure for 64bit.
162+
# Symbol structure for 64-bit.
158163
class ELF64_sym < ELFStruct
159164
endian :big_and_little
160165
uint32 :st_name # Symbol name, index in string tbl
@@ -164,6 +169,7 @@ class ELF64_sym < ELFStruct
164169
uint64 :st_value # Value of the symbol
165170
uint64 :st_size # Associated symbol size
166171
end
172+
167173
# Get symbol header class according to bits.
168174
ELF_sym = {
169175
32 => ELF32_sym,

0 commit comments

Comments
 (0)