Skip to content

Commit

Permalink
Fix attribute parsing
Browse files Browse the repository at this point in the history
This is the real signature for rb_define_attr(). There is only four
arguments.

    void rb_define_attr(VALUE klass, const char *name, int read, int write)
  • Loading branch information
avsej committed Dec 26, 2011
1 parent 580cd86 commit a23b72d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions lib/yard/parser/c_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ def handle_alias(var_name, new_name, old_name)

namespace.aliases[new_obj] = old_meth
end
def handle_attribute(var_name, name, func_name, read, write, source_file = nil)

def handle_attribute(var_name, name, read, write, source_file = nil)
values = {:read => read.to_i, :write => write.to_i}
{:read => name, :write => "#{name}="}.each do |type, meth_name|
next unless values[type] > 0
obj = handle_method(:instance, var_name, meth_name, func_name, source_file)
obj = handle_method(:instance, var_name, meth_name, nil, source_file)
ensure_loaded!(obj.namespace)
obj.namespace.attributes[:instance][name] ||= SymbolHash[:read => nil, :write => nil]
obj.namespace.attributes[:instance][name][type] = obj
Expand Down Expand Up @@ -420,18 +420,17 @@ def parse_attributes
@content.scan(%r{rb_define_attr
\s*\(\s*([\w\.]+),
\s*"([^"]+)",
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
\s*(0|1)\s*,\s*(0|1)\s*\)
(?:;\s*/[*/]\s+in\s+(.+?\.[cy]))?
}xm) do |var_name, name, func_name, read, write, source_file|
}xm) do |var_name, name, read, write, source_file|

# Ignore top-object and weird struct.c dynamic stuff
next if var_name == "ruby_top_self"
next if var_name == "nstr"
next if var_name == "envtbl"

var_name = "rb_cObject" if var_name == "rb_mKernel"
handle_attribute(var_name, name, func_name, read, write, source_file)
handle_attribute(var_name, name, read, write, source_file)
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/parser/c_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def run(read, write, commented = nil)
void Init_Foo() {
rb_cFoo = rb_define_class("Foo", rb_cObject);
#{commented ? '/*' : ''}
rb_define_attr(rb_cFoo, "foo", foo, #{read}, #{write});
rb_define_attr(rb_cFoo, "foo", #{read}, #{write});
#{commented ? '*/' : ''}
}
eof
Expand Down Expand Up @@ -228,4 +228,4 @@ def run(read, write, commented = nil)
neg_self.source.should be_nil
end
end
end
end

0 comments on commit a23b72d

Please sign in to comment.