Project

General

Profile

Bug #11027

Named Argument assignment from Hash failure

Added by alangano (Alan Gano) almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]
[ruby-core:<unknown>]

Description

I am call a method, which has named arguments, a Hash, which then as expected, maps the keys of the Hash to the argument names.

I boiled down a problem scenario wherein it fails to do this. In the code below the argument i_field2 of the ack() method, is failing to be set from the Hash. It gets set to nil.

This also occurs in 2.2.0p0.

require 'base64'

def ack(i_field1:,i_field2:,**i_others)
   puts '-'*79
   puts i_field1.inspect
   puts ">>> #{i_field2.inspect} <<< SHOULD be 'field2'"
   puts i_others.inspect
end

# create the marshaled hash in another execution
#t_args = {i_field1:"field1",i_field2:"field2",something:"something"}
#puts Base64.strict_encode64(Marshal.dump(t_args))
#exit

t_marshal = 'BAh7CDoNaV9maWVsZDFJIgtmaWVsZDEGOgZFVDoNaV9maWVsZDJJIgtmaWVsZDIGOwZUOg5zb21ldGhpbmdJIg5zb21ldGhpbmcGOwZU'

t_args = Marshal.load(Base64.strict_decode64(t_marshal))

puts t_args.inspect
# => {:i_field1=>"field1", :i_field2=>"field2", :something=>"something"}

ack(t_args)

#_ = { something:'?' }         # makes it work
#_ = { :something => '?' }     # makes it work
#_ = :something                # makes it work

Related issues

Related to Ruby trunk - Bug #11382: Keyword arguments randomly nullified Closed
Duplicated by Ruby trunk - Bug #11091: Symbolized Strings May Break Keyword Arguments Closed

Associated revisions

Revision 50172
Added by ko1 (Koichi Sasada) almost 2 years ago

  • vm_args.c: protect value stack from calling other methods during complex parameter setting process (splat, kw, and so on). [Bug #11027]
  • vm_core.h: remove rb_thead_t::mark_stack_len. With this modification, we don't need to use th->mark_stack_len.
  • test/ruby/test_keyword.rb: add a test.
  • cont.c (cont_capture): catch up this fix.
  • vm.c (rb_thread_mark): ditto.

Revision 50172
Added by ko1 (Koichi Sasada) almost 2 years ago

  • vm_args.c: protect value stack from calling other methods during complex parameter setting process (splat, kw, and so on). [Bug #11027]
  • vm_core.h: remove rb_thead_t::mark_stack_len. With this modification, we don't need to use th->mark_stack_len.
  • test/ruby/test_keyword.rb: add a test.
  • cont.c (cont_capture): catch up this fix.
  • vm.c (rb_thread_mark): ditto.

Revision 50172
Added by ko1 (Koichi Sasada) almost 2 years ago

  • vm_args.c: protect value stack from calling other methods during complex parameter setting process (splat, kw, and so on). [Bug #11027]
  • vm_core.h: remove rb_thead_t::mark_stack_len. With this modification, we don't need to use th->mark_stack_len.
  • test/ruby/test_keyword.rb: add a test.
  • cont.c (cont_capture): catch up this fix.
  • vm.c (rb_thread_mark): ditto.

Revision 50562
Added by nagachika (Tomoyuki Chikanaga) almost 2 years ago

merge revision(s) 50172,50173: [Backport #11027]

* vm_args.c: protect value stack from calling other methods
  during complex parameter setting process (splat, kw, and so on).
  [Bug #11027]

* vm_core.h: remove rb_thead_t::mark_stack_len.
  With this modification, we don't need to use th->mark_stack_len.

* test/ruby/test_keyword.rb: add a test.

* cont.c (cont_capture): catch up this fix.

* vm.c (rb_thread_mark): ditto.

History

#1 Updated by alangano (Alan Gano) almost 2 years ago

Restatement:

I have a method with named arguments. I am calling it with a Hash, whose keys match up with the names of the method arguments.

This has been working.

I boiled down a problem scenario wherein it fails to do this. In the code below the argument i_field2 of the ack() method, is failing to be set from the Hash. It gets set to nil.

This also occurs in 2.2.0p0.

Formatting fix ...


require 'base64'

def ack(i_field1:,i_field2:,**i_others)
   puts '-'*79
   puts i_field1.inspect
   puts ">>> #{i_field2.inspect} <<< SHOULD be 'field2'"
   puts i_others.inspect
end

# create the marshaled hash in another execution
#t_args = {i_field1:"field1",i_field2:"field2",something:"something"}
#puts Base64.strict_encode64(Marshal.dump(t_args))
#exit

t_marshal = 'BAh7CDoNaV9maWVsZDFJIgtmaWVsZDEGOgZFVDoNaV9maWVsZDJJIgtmaWVsZDIGOwZUOg5zb21ldGhpbmdJIg5zb21ldGhpbmcGOwZU'

t_args = Marshal.load(Base64.strict_decode64(t_marshal))

puts t_args.inspect
# => {:i_field1=>"field1", :i_field2=>"field2", :something=>"something"}

ack(t_args)

#_ = { something:'?' }         # makes it work
#_ = { :something => '?' }     # makes it work
#_ = :something                # makes it work

#2 Updated by nobu (Nobuyoshi Nakada) almost 2 years ago

  • Description updated (diff)

Marshal is not mandatory.

It can reproduce with a dynamic symbol keyword argument.

ack(i_field1:"field1", i_field2:"field2", "something".intern=>"something")

#3 Updated by nobu (Nobuyoshi Nakada) almost 2 years ago

  • Assignee set to ko1 (Koichi Sasada)
  • Status changed from Open to Assigned

Ko1 is going to fix this issue by advancing sp prior to arguments setup instead of mark_stack_len.

#4 Updated by ko1 (Koichi Sasada) almost 2 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: REQUIRED

#5 Updated by ko1 (Koichi Sasada) almost 2 years ago

  • % Done changed from 0 to 100
  • Status changed from Assigned to Closed

Applied in changeset r50172.


  • vm_args.c: protect value stack from calling other methods during complex parameter setting process (splat, kw, and so on). [Bug #11027]
  • vm_core.h: remove rb_thead_t::mark_stack_len. With this modification, we don't need to use th->mark_stack_len.
  • test/ruby/test_keyword.rb: add a test.
  • cont.c (cont_capture): catch up this fix.
  • vm.c (rb_thread_mark): ditto.

#6 Updated by nobu (Nobuyoshi Nakada) almost 2 years ago

  • Duplicated by Bug #11091: Symbolized Strings May Break Keyword Arguments added

#7 [ruby-core:68979] Updated by nobu (Nobuyoshi Nakada) almost 2 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: REQUIRED to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: REQUIRED

#8 Updated by nagachika (Tomoyuki Chikanaga) almost 2 years ago

  • Backport changed from 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: REQUIRED to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONE

Backorted into ruby_2_2 branch at r50562.

#9 Updated by nagachika (Tomoyuki Chikanaga) over 1 year ago

  • Related to Bug #11382: Keyword arguments randomly nullified added

Also available in: Atom PDF