Skip to content

Commit

Permalink
another bunch of fixes needed to run modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Apr 25, 2013
1 parent 24aa34e commit 180868a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 25 deletions.
23 changes: 18 additions & 5 deletions src/binary/Y2RubyReference.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ class ClientFunction : public Y2Function
YCPList m_call;
public:
ClientFunction(VALUE m_object) : object(m_object)
{}
{
}

~ClientFunction()
{
}

YCPValue evaluateCall ();

Expand Down Expand Up @@ -69,14 +74,22 @@ class ClientFunction : public Y2Function
class ClientNamespace : public Y2Namespace
{
private:
ClientFunction f;
VALUE object;
public:
ClientNamespace(VALUE m_object) : f(m_object)
{}
ClientNamespace(VALUE m_object) : object(m_object)
{
// register object, so noone will destroy it under out hands
rb_gc_register_address(&object);
}

~ClientNamespace()
{
rb_gc_unregister_address(&object);
}

Y2Function* createFunctionCall(const string name, constFunctionTypePtr type)
{
return &f;
return new ClientFunction(object);
}

virtual const string filename() const
Expand Down
2 changes: 1 addition & 1 deletion src/binary/Y2RubyTypeConv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static YCPValue rbreference_2_ycpreference( VALUE value )
{
VALUE signature = rb_funcall(value,rb_intern("signature"),0);
constTypePtr sym_tp = Type::fromSignature(RSTRING_PTR(signature));
//FIXME memory leak
//FIXME memory leak , probably link it with reference, but then copy is broken :(
const Y2Namespace *ns = new ClientNamespace(value);
SymbolEntry *s_entry = new SymbolEntry(ns, 0, "ruby_reference", SymbolEntry::c_function, sym_tp);
return YCPReference(s_entry);
Expand Down
8 changes: 5 additions & 3 deletions src/ruby/ycp/builtins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def self.sformat format, *args
# Sleeps a number of milliseconds.
def self.sleep milisecs
# ruby sleep() accepts seconds (float)
sleep milisecs / 1000.0
Kernel.sleep milisecs / 1000.0
end

# time() YCP built-in
Expand Down Expand Up @@ -672,8 +672,10 @@ def self.dpgettext
end

# Filters characters out of a ::String
def self.filterchars
raise "Builtin filterchars() is not implemented yet"
def self.filterchars string, chars
return nil if string.nil? || chars.nil?

return string.gsub(/[^#{Regexp.escape chars}]/, "")
end

# Searches string for the first non matching chars
Expand Down
4 changes: 4 additions & 0 deletions src/ruby/ycp/convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def self.convert(object, options)
return nil unless object.is_a? Float
YCP.y2warning "Conversion from integer to float lead to loose precision."
return object.to_i
elsif to == "locale" && from == "string"
return object
elsif to == "string" && from == "locale"
return object
else
YCP.y2warning "Cannot convert #{object.class} from '#{from}' to '#{to}'"
return nil
Expand Down
33 changes: 17 additions & 16 deletions src/ruby/ycp/ops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,28 @@ module Ops
'list' => ::Array,
'map' => ::Hash,
'term' => YCP::Term,
'path' => YCP::Path
'path' => YCP::Path,
'locale' => ::String
}

def self.index (object, indexes, default)
res = object
indexes.each do |i|
case res
when ::Array, YCP::Term
if i.is_a? Fixnum
if (0..res.size-1).include? i
res = res[i]
def self.index (object, indexes, default)
res = object
indexes.each do |i|
case res
when ::Array, YCP::Term
if i.is_a? Fixnum
if (0..res.size-1).include? i
res = res[i]
else
YCP.y2warning "Index #{i} is out of array size"
return default
end
else
YCP.y2warning "Index #{i} is out of array size"
YCP.y2warning "Passed #{i.inspect} as index key for array."
return default
end
else
YCP.y2warning "Passed #{i.inspect} as index key for array."
return default
end
when ::Hash
if res.has_key? i
when ::Hash
if res.has_key? i
res = res[i]
else
return default
Expand Down
2 changes: 2 additions & 0 deletions src/ruby/ycp/reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class Reference

def initialize met, signature
@remote_method = met
raise "invalid argument #{met.inspect}" unless met.respond_to? :call

# expand signature to containt full spec of lists and maps
signature = signature.gsub(/map(\s*([^<\s]|$))/,"map<any,any>\\1")
signature = signature.gsub(/list(\s*([^<\s]|$))/,"list<any>\\1")
Expand Down

0 comments on commit 180868a

Please sign in to comment.