[yast-devel] Slight incompatibility between Ruby and YCP
Hi, I think I found a slight incompatibility between Ruby and YCP in YCP, I have the following code: map btrfs = GetTargetMap()["/dev/btrfs"]:$[]; map ret = filter( map p, btrfs["partitions"]:[], ``(p["uuid"]:""==uuid))[0]:$[]; which, in case of an empty list returned by filter call, relies on default parameter "$[]" after index operation. In RUby this is: btrfs = Ops.get(GetTargetMap(), "/dev/btrfs", {}) ret = Ops.get( Builtins.filter(Ops.get_list(btrfs, "partitions", [])) do |p| Ops.get_string(p, "uuid", "") == uuid end, 0, {} ) This works as before in assigning empty map to ret, but it now has the side effect of a line being written to y2log stating: [Ruby] yast/ops.rb:62 Index 0 is out of array size while the equivalent YCP code did not create any y2log entries. Is this intentional? Depending on the number of occurrences of such accesses in YCP code it could clutter y2log a lot. Tschuess, Thomas Fehr -- Thomas Fehr, SuSE Linux Products GmbH, Maxfeldstr. 5, 90409 Nuernberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg) Tel: +49-911-74053-0, Fax: +49-911-74053-482, Email: fehr@suse.de GPG public key available. -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Thu, 1 Aug 2013 13:11:16 +0200 Thomas Fehr <fehr@suse.de> wrote:
Hi,
I think I found a slight incompatibility between Ruby and YCP
in YCP, I have the following code:
map btrfs = GetTargetMap()["/dev/btrfs"]:$[]; map ret = filter( map p, btrfs["partitions"]:[], ``(p["uuid"]:""==uuid))[0]:$[];
which, in case of an empty list returned by filter call, relies on default parameter "$[]" after index operation.
In RUby this is:
btrfs = Ops.get(GetTargetMap(), "/dev/btrfs", {}) ret = Ops.get( Builtins.filter(Ops.get_list(btrfs, "partitions", [])) do |p| Ops.get_string(p, "uuid", "") == uuid end, 0, {} )
This works as before in assigning empty map to ret, but it now has the side effect of a line being written to y2log stating: [Ruby] yast/ops.rb:62 Index 0 is out of array size while the equivalent YCP code did not create any y2log entries.
Is this intentional? Depending on the number of occurrences of such accesses in YCP code it could clutter y2log a lot.
Tschuess, Thomas Fehr
Hi Thomas, at first it is feature of ruby bindings that can be disabled, but I found it quite useful, because for me it is usually indication of error if you access array out of its index. If team agree then it can be removed at https://github.com/yast/yast-ruby-bindings/blob/master/src/ruby/yast/ops.rb#... But you detect also another bug, that integer passed to log should be inside while cycle 2 and not 1, so you get where in your code you access out of array dimensions. Josef -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Thu, Aug 01, Josef Reidinger wrote:
Hi Thomas, at first it is feature of ruby bindings that can be disabled, but I found it quite useful, because for me it is usually indication of error if you access array out of its index.
Due to the default parameter it was not necessarily an indication of an error in YCP code. I assumed whole concept of Ops module was to become compatible with YCP behavior, while accessing lists and maps. Consequently one would also need to consider it an error to access a nonexistent key of a map (since this is more or less the same as access to an nonexistent index). But this does not trigger an entry in y2log file.
If team agree then it can be removed at https://github.com/yast/yast-ruby-bindings/blob/master/src/ruby/yast/ops.rb#... But you detect also another bug, that integer passed to log should be inside while cycle 2 and not 1, so you get where in your code you access out of array dimensions. Josef
Tschuess, Thomas Fehr -- Thomas Fehr, SuSE Linux Products GmbH, Maxfeldstr. 5, 90409 Nuernberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg) Tel: +49-911-74053-0, Fax: +49-911-74053-482, Email: fehr@suse.de GPG public key available. -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
Dne 1.8.2013 13:21, Josef Reidinger napsal(a):
On Thu, 1 Aug 2013 13:11:16 +0200 Thomas Fehr <fehr@suse.de> wrote:
I think I found a slight incompatibility between Ruby and YCP
[...]
This works as before in assigning empty map to ret, but it now has the side effect of a line being written to y2log stating: [Ruby] yast/ops.rb:62 Index 0 is out of array size while the equivalent YCP code did not create any y2log entries.
at first it is feature of ruby bindings that can be disabled, but I found it quite useful, because for me it is usually indication of error if you access array out of its index.
We should be bug-to-bug compatible with YCP and not cause any unexpected behavior. Judging what is or isn't a bad practice wasn't the scope of YCP Killer project. If it wasn't an error before, it shouldn't become an error now. (Also note that out-of-bounds access isn't an error in Ruby itself when you use native [] operator -- at least for arrays and hashes.) -- David Majda SUSE Studio developer http://susestudio.com/ -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
participants (3)
-
David Majda
-
Josef Reidinger
-
Thomas Fehr