Project

General

Profile

Actions

Bug #10485

closed

NoMethodError "undefined method `initialize_copy'" when trying to execute Queue#dup

Added by bubo47 (Jakub Jursa) over 9 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.0dev (2014-11-07 trunk 48313) [x86_64-linux]
[ruby-core:66128]

Description

Queue#dup raises NoMethodError (Queue#clone as well)

 :001 > q = Queue.new
 => #<Thread::Queue:0x00000001507ca0> 
 :002 > q.dup
NoMethodError: undefined method `initialize_copy' for #<Thread::Queue:0x00000001504c08>
	from (irb):2:in `initialize_dup'
	from (irb):2:in `dup'
	from (irb):2
	from /home/bubo/.rvm/rubies/ruby-head/bin/irb:11:in `<main>'

Related issues 2 (0 open2 closed)

Related to Ruby master - Bug #9440: Calling methods on a `Queue.new.dup` or `Queue.new.clone` causes SegfaultClosed01/22/2014Actions
Related to Ruby master - Feature #8639: Add Queue#eachClosedko1 (Koichi Sasada)Actions

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Related to Bug #9440: Calling methods on a `Queue.new.dup` or `Queue.new.clone` causes Segfault added

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Category changed from lib to ext
  • Status changed from Open to Feedback

Why do you need to copy Queues?

Updated by bubo47 (Jakub Jursa) over 9 years ago

why not? :)
actually I bumped into this by accident when implementing Queue#to_a (which basically clones self and empties it into new array which it then returns). So it's not really some kind of blocker bug. But since #clone and #dup are methods of Object, I expected them to work on Queues as well.

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

Not all methods in super classes always work on all subclasses.

Queues hold waiting Threads, and copying it may cause them waken up unexpectedly.

Updated by recursive-madman (Recursive Madman) over 9 years ago

Not all methods in super classes always work on all subclasses.

If a method that works on a superclass doesn't work on a subclass, I would expect the subclass to at least mark it as private and definitely not segfault.

Updated by bubo47 (Jakub Jursa) over 9 years ago

Recursive Madman wrote:

Not all methods in super classes always work on all subclasses.

If a method that works on a superclass doesn't work on a subclass, I would expect the subclass to at least mark it as private and definitely not segfault.

definitely.

Actions #8

Updated by naruse (Yui NARUSE) over 6 years ago

  • Target version deleted (2.2.0)
Actions #9

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Feedback to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0