Projects

Ticket #617 (closed defect: fixed)

Opened 2 years ago

Last modified 21 months ago

Reopening Symbol Appears to Cause auto malloc[16067]: error for object 0x1016090b0: auto_zone_set_associative_ref

Reported by: cwdinfo@… Owned by: lsansonetti@…
Priority: blocker Milestone: MacRuby 0.7
Component: MacRuby Keywords:
Cc:

Description

This works in MRI 1.87 and 1.9.1.

#!/usr/local/bin/macruby

class Predicate
  OPERATOR_MAP = {
    :gt => '>',
    :lt => '<',
    :eq => '='
  }
  
  def initialize(obj, operator, rhs)
    @obj       = obj.to_s
    @predicate = to_condition(operator, rhs)
  end
  
  def gt(rhs)
    @predicate << @conjoin
    @predicate << to_condition(:gt, rhs)
    self
  end
  
  def lt(rhs)
    @predicate << @conjoin
    @predicate << to_condition(:lt, rhs)
    self
  end
  
  def eq(rhs)
    @predicate << @conjoin
    @predicate << to_condition(:lt, rhs)
    self
  end
  
  def and
    @conjoin = ' and '
    self
  end
  
  def or
    @conjoin = ' or '
    self
  end
  
  def to_condition(operator, rhs)
    "#{@obj} #{OPERATOR_MAP[operator]} #{rhs}"
  end
  
  def to_s
    @predicate
  end
end

class Symbol
  def gt(value)
    @predicate = Predicate.new(self, :gt, value)
  end
  
  def lt(value)
    @predicate = Predicate.new(self, :lt, value)
  end
  
  def eq(value)
    @predicate = Predicate.new(self, :eq, value)
  end
end

puts :start_time.eq('2010-10-01')
puts :start_time.eq('2010-10-01').and.lt('2010-10-03')}}}

Error is:

macruby(16067,0x7fff70f36be0) malloc: *** auto malloc[16067]: error for object 0x1016090b0: auto_zone_set_associative_ref: object should point to a GC block or a global address, otherwise associations will leak. Break on auto_zone_association_error() to debug.

Change History

Changed 2 years ago by cwdinfo@…

This appears to be related to the fact that Symbol inherits from NSString, which is immutable. A simple reduced case is:

class Symbol
  def eq
    @foo = 3
  end
end

:zoo.eq

At this point, the object is changed, which appears not to be desirable in the context of immutability, yet Ruby 1.9 allows it and many Ruby idioms take advantage of it (e.g., DataMapper).

Changed 2 years ago by lsansonetti@…

We are rewriting Symbol (as well as String and Regexp) in a separate branch right now. Symbol will be a separate class as in 1.9 and hopefully this problem will disappear.

Changed 23 months ago by lsansonetti@…

As of trunk r3858, it fails like this:

$ cat t.rb
class Symbol
  def eq
    @foo=42
  end
end
p :foo.eq
$ ./miniruby t.rb 
miniruby(70683,0x7fff7056bc00) malloc: *** auto malloc[70683]: error for object 0x7ffee30ba270: auto_zone_set_associative_ref: object should point to a GC block or a global address, otherwise associations will leak. Break on auto_zone_association_error() to debug.
42

This is because symbols are allocated from the regular malloc zone and cannot be used for associative references.

Changed 21 months ago by lsansonetti@…

  • status changed from new to closed
  • resolution set to fixed
  • milestone set to MacRuby 0.7

Should be fixed in r4073.

Note: See TracTickets for help on using tickets.