Skip to content

Commit

Permalink
Suppress warning of keyword arguments introduced in Ruby 2.7 (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
david942j authored Oct 26, 2019
1 parent 6416bb2 commit a4c7669
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
AllCops:
TargetRubyVersion: 2.3
DisplayCopNames: true
DisplayStyleGuide: true

Expand Down
4 changes: 2 additions & 2 deletions lib/elftools/sections/sections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class << Section
# @param [#pos=, #read] stream Streaming object.
# @return [ELFTools::Sections::Section]
# Return object dependes on +header.sh_type+.
def create(header, stream, *args)
def create(header, stream, *args, **kwargs)
klass = case header.sh_type
when Constants::SHT_DYNAMIC then DynamicSection
when Constants::SHT_NULL then NullSection
Expand All @@ -31,7 +31,7 @@ def create(header, stream, *args)
when Constants::SHT_SYMTAB, Constants::SHT_DYNSYM then SymTabSection
else Section
end
klass.new(header, stream, *args)
klass.new(header, stream, *args, **kwargs)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/elftools/segments/segments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class << Segment
# @param [#pos=, #read] stream Streaming object.
# @return [ELFTools::Segments::Segment]
# Return object dependes on +header.p_type+.
def create(header, stream, *args)
def create(header, stream, *args, **kwargs)
klass = case header.p_type
when Constants::PT_DYNAMIC then DynamicSegment
when Constants::PT_INTERP then InterpSegment
when Constants::PT_LOAD then LoadSegment
when Constants::PT_NOTE then NoteSegment
else Segment
end
klass.new(header, stream, *args)
klass.new(header, stream, *args, **kwargs)
end
end
end
Expand Down
32 changes: 19 additions & 13 deletions lib/elftools/structs.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

require 'bindata'

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

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

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

# Pack integer into string.
# Packs an integer to string.
# @param [Integer] val
# @param [Integer] bytes
# @return [String]
Expand Down Expand Up @@ -112,7 +116,7 @@ class ELF_Shdr < ELFStruct
choice :sh_entsize, **CHOICE_SIZE_T
end

# Program header structure for 32bit.
# Program header structure for 32-bit.
class ELF32_Phdr < ELFStruct
endian :big_and_little
uint32 :p_type
Expand All @@ -125,7 +129,7 @@ class ELF32_Phdr < ELFStruct
uint32 :p_align
end

# Program header structure for 64bit.
# Program header structure for 64-bit.
class ELF64_Phdr < ELFStruct
endian :big_and_little
uint32 :p_type
Expand All @@ -137,13 +141,14 @@ class ELF64_Phdr < ELFStruct
uint64 :p_memsz
uint64 :p_align
end
# Get program header class according to bits.

# Gets the class of program header according to bits.
ELF_Phdr = {
32 => ELF32_Phdr,
64 => ELF64_Phdr
}.freeze

# Symbol structure for 32bit.
# Symbol structure for 32-bit.
class ELF32_sym < ELFStruct
endian :big_and_little
uint32 :st_name
Expand All @@ -154,7 +159,7 @@ class ELF32_sym < ELFStruct
uint16 :st_shndx
end

# Symbol structure for 64bit.
# Symbol structure for 64-bit.
class ELF64_sym < ELFStruct
endian :big_and_little
uint32 :st_name # Symbol name, index in string tbl
Expand All @@ -164,6 +169,7 @@ class ELF64_sym < ELFStruct
uint64 :st_value # Value of the symbol
uint64 :st_size # Associated symbol size
end

# Get symbol header class according to bits.
ELF_sym = {
32 => ELF32_sym,
Expand Down

0 comments on commit a4c7669

Please sign in to comment.