[#104169] [Ruby master Feature#17938] Keyword alternative for boolean positional arguments — matheusrichardt@...

Issue #17938 has been reported by matheusrich (Matheus Richard).

12 messages 2021/06/04

[#104213] [Ruby master Feature#17942] Add a `initialize(public @a, private @b)` shortcut syntax for defining public/private accessors for instance vars — tyler@...

SXNzdWUgIzE3OTQyIGhhcyBiZWVuIHJlcG9ydGVkIGJ5IFR5bGVyUmljayAoVHlsZXIgUmljayku

6 messages 2021/06/09

[#104288] [Ruby master Bug#17992] Upstreaming the htmlentities gem into CGI#.(un)escape_html — alexandermomchilov@...

Issue #17992 has been reported by AMomchilov (Alexander Momchilov).

9 messages 2021/06/15

[#104338] [Ruby master Misc#17997] DevelopersMeeting20210715Japan — mame@...

Issue #17997 has been reported by mame (Yusuke Endoh).

10 messages 2021/06/17

[#104361] [Ruby master Bug#18000] have_library doesn't work when ruby is compiled with --disable-shared --disable-install-static-library — jean.boussier@...

Issue #18000 has been reported by byroot (Jean Boussier).

9 messages 2021/06/18

[#104381] [Ruby master Feature#18004] Add Async to the stdlib — shannonskipper@...

Issue #18004 has been reported by shan (Shannon Skipper).

9 messages 2021/06/22

[#104401] [Ruby master Feature#18007] Help developers of C extensions meet requirements in "doc/extension.rdoc" — mike.dalessio@...

Issue #18007 has been reported by mdalessio (Mike Dalessio).

16 messages 2021/06/25

[#104430] [Ruby master Bug#18011] `Method#parameters` is incorrect for forwarded arguments — josh.cheek@...

Issue #18011 has been reported by josh.cheek (Josh Cheek).

12 messages 2021/06/29

[ruby-core:104366] [Ruby master Bug#16383] TracePoint does not report calls to attribute reader methods

From: merch-redmine@...
Date: 2021-06-18 22:10:19 UTC
List: ruby-core #104366
Issue #16383 has been updated by jeremyevans0 (Jeremy Evans).


After thinking more regarding this issue, if we want no overhead by default, and only overhead if this feature is enabled via a command line flag (similar to JRuby's `--debug` flag), one possibility is to just use BMETHOD (or ISEQ) methods instead of IVAR/ATTRSET methods for attributes.  A proof of concept for this can be implemented by adding the following to the top of `prelude.rb`:

```ruby
if $DEBUG
  class Module
    remove_method(:attr_accessor)
    def attr_accessor(*meths)
      attr_reader(*meths)
      attr_writer(*meths)
      meths
    end

    remove_method(:attr_reader)
    def attr_reader(*meths)
      module_exec do
        meths.each do |meth|
          instance_variable_get(:"@#{meth}") # check valid
          define_method(meth) do
            instance_variable_get(:"@#{meth}")
          end
        end
      end
      meths
    end

    remove_method(:attr_writer)
    def attr_writer(*meths)

      module_exec do
        meths.each do |meth|
          instance_variable_get(:"@#{meth}") # check valid
          define_method(:"#{meth}=") do |v|
            instance_variable_set(:"@#{meth}", v)
          end
        end
      end
      meths
    end
  end
end
```

Then you can run ruby with the `--debug` flag to enable tracing of attribute methods.  As this approach uses BMETHOD instead of ISEQ, it needs the fix for #13392 to be committed for it to make sense.

This approach doesn't handle direct `rb_attr` use by C-extensions, though that could theoretically be fixed by making `rb_attr` use `rb_funcall`, at least for IDs that are valid instance variable names.

----------------------------------------
Bug #16383: TracePoint does not report calls to attribute reader methods
https://bugs.ruby-lang.org/issues/16383#change-92601

* Author: AndyMaleh (Andy Maleh)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.5.7p206 (2019-10-01 revision 67816) [x86_64-darwin19]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
TracePoint does not report calls to attribute reader methods (e.g. methods defined using `attr_accessor` or `attr_reader`.)

**Code sample to demonstrate:**

```ruby
class Person
  attr_accessor :first_name
  attr_accessor :last_name
  def name
    "#{self.last_name}, #{self.first_name}"
  end
end

person = Person.new
person.first_name = 'Josh'
person.last_name = 'McGibbon'
trace = TracePoint.new(:call) do |tp|
  p [tp.path, tp.lineno, tp.defined_class, tp.event, tp.method_id]
end
trace.enable
person.name
trace.disable

class Person
  attr_writer :first_name
  attr_writer :last_name
  def name
    "#{self.last_name}, #{self.first_name}"
  end
  def first_name
    @first_name
  end
  def last_name
    @last_name
  end
end

person = Person.new
person.first_name = 'Josh'
person.last_name = 'McGibbon'
trace = TracePoint.new(:call) do |tp|
  p [tp.path, tp.lineno, tp.defined_class, tp.event, tp.method_id]
end
trace.enable
person.name
trace.disable
```

**Output:**

```
["trace_point_issue.rb", 4, Person, :call, :name]
["trace_point_issue.rb", 22, Person, :call, :name]
["trace_point_issue.rb", 28, Person, :call, :last_name]
["trace_point_issue.rb", 25, Person, :call, :first_name]
```

Please note how `:last_name` and `:first_name` show up only the second time `Person#name` is called. In other words, they show up when defined as actual methods using `def` keyword, but not when defined via `attr_accessor`.

**Expected Output:**

```
["trace_point_issue.rb", 22, Person, :call, :name]
["trace_point_issue.rb", 28, Person, :call, :last_name]
["trace_point_issue.rb", 25, Person, :call, :first_name]
["trace_point_issue.rb", 22, Person, :call, :name]
["trace_point_issue.rb", 28, Person, :call, :last_name]
["trace_point_issue.rb", 25, Person, :call, :first_name]
```

Your help in fixing or explaining this issue is greatly appreciated.

My goal is to monitor all method calls when invoking a certain method (Person#name in this case) in order to attach observers to them dynamically for desktop UI data-binding use in my open-source project Glimmer: https://github.com/AndyObtiva/glimmer

Cheers,

Andy Maleh

---Files--------------------------------
trace_point_issue.rb (791 Bytes)
tracepoint-attr-16383.patch (1.97 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next