Project

General

Profile

ActionsLike0

Bug #19427

closed

Marshal.load(source, freeze: true) doesn't freeze in some cases

Added by andrykonchin (Andrew Konchin) almost 2 years ago. Updated 8 months ago.


Description

I've noticed that the freeze option doesn't work in the following cases:

  • when dumped object extends a module
  • when dumped object responds to #marshal_dump and #marshal_load methods
  • when dumped object responds to #_dump method

Is it expected behaviour or maybe a known issue?

Examples:

module M
end

object = Object.new
object.extend(M)

object = Marshal.load(Marshal.dump(object), freeze: true)
object.frozen? # => false
class UserMarshal
  attr_accessor :data

  def initialize
    @data = 'stuff'
  end
  def marshal_dump() :data end
  def marshal_load(data) @data = data end
end

object = Marshal.load(Marshal.dump(UserMarshal.new), freeze: true)
object.frozen? # => false
class UserDefined
  attr_reader :a, :b

  def initialize
    @a = 'stuff'
    @b = @a
  end

  def _dump(depth)
    Marshal.dump [:stuff, :stuff]
  end

  def self._load(data)
    a, b = Marshal.load data

    obj = allocate
    obj.instance_variable_set :@a, a
    obj.instance_variable_set :@b, b

    obj
  end
end

object = Marshal.load(Marshal.dump(UserDefined.new), freeze: true)
object.frozen? # => false

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #18148: Marshal.load freeze optionClosedActions
#1

Updated by andrykonchin (Andrew Konchin) almost 2 years ago

  • Description updated (diff)
#2

Updated by Eregon (Benoit Daloze) almost 2 years ago

#9

Updated by byroot (Jean Boussier) almost 2 years ago

  • Status changed from Open to Closed
#10

Updated by byroot (Jean Boussier) almost 2 years ago

  • Backport changed from 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN to 2.7: WONTFIX, 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED
#11

Updated by byroot (Jean Boussier) almost 2 years ago

  • Backport changed from 2.7: WONTFIX, 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED to 2.7: DONTNEED, 3.0: DONTNEED, 3.1: REQUIRED, 3.2: REQUIRED

Updated by byroot (Jean Boussier) almost 2 years ago

  • Status changed from Closed to Open

Updated by Eregon (Benoit Daloze) over 1 year ago

  • Assignee set to byroot (Jean Boussier)
#18

Updated by byroot (Jean Boussier) over 1 year ago

  • Status changed from Open to Closed

Updated by nagachika (Tomoyuki Chikanaga) 8 months ago

  • Backport changed from 2.7: DONTNEED, 3.0: DONTNEED, 3.1: REQUIRED, 3.2: REQUIRED to 2.7: DONTNEED, 3.0: DONTNEED, 3.1: WONTFIX, 3.2: WONTFIX
ActionsLike0

Also available in: Atom PDF