Skip to content

Commit 59de3b7

Browse files
authored
Merge pull request #291 from yast/backport_sp6
Backport sp6
2 parents 35a3a2e + a69f53a commit 59de3b7

File tree

9 files changed

+88
-55
lines changed

9 files changed

+88
-55
lines changed

package/yast2-ruby-bindings.changes

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
-------------------------------------------------------------------
2-
Fri Sep 01 19:57:03 UTC 2023 - Josef Reidinger <[email protected]>
2+
Mon Apr 3 10:46:37 UTC 2023 - Josef Reidinger <[email protected]>
33

4-
- Branch package for SP6 (bsc#1208913)
4+
- Improve YaST memory consumption related to import+publish (bsc#1210051)
5+
- 4.6.2
6+
7+
-------------------------------------------------------------------
8+
Thu Mar 9 10:36:23 UTC 2023 - Martin Vidner <[email protected]>
9+
10+
- Use ruby-devel versioned to match the gems (bsc#1209098)
11+
- 4.6.1
12+
13+
-------------------------------------------------------------------
14+
Fri Mar 03 14:44:07 UTC 2023 - Ladislav Slezák <[email protected]>
15+
16+
- Bump version to 4.6.0 (bsc#1208913)
517

618
-------------------------------------------------------------------
719
Mon Oct 24 12:51:30 UTC 2022 - Ladislav Slezák <[email protected]>

package/yast2-ruby-bindings.spec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
Name: yast2-ruby-bindings
20-
Version: 4.6.0
20+
Version: 4.6.2
2121
Release: 0
2222
URL: https://github.com/yast/yast-ruby-bindings
2323
BuildRoot: %{_tmppath}/%{name}-%{version}-build
@@ -31,7 +31,8 @@ BuildRequires: yast2-devtools >= 3.1.10
3131
BuildRequires: rubygem(%{rb_default_ruby_abi}:fast_gettext) < 3.0
3232
BuildRequires: rubygem(%{rb_default_ruby_abi}:rspec)
3333
Requires: rubygem(%{rb_default_ruby_abi}:fast_gettext) < 3.0
34-
BuildRequires: ruby-devel
34+
# this is ruby-devel pinned to the default version, matching the gems
35+
BuildRequires: %{rubydevel}
3536
Requires: yast2-core >= 3.2.2
3637
BuildRequires: yast2-core-devel >= 3.2.2
3738
# MenuBar-shortcuts-test.rb

profiling/yast_import.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require "memory_profiler"
2+
3+
usage = <<CMD
4+
cd build # cmake ..; make
5+
# use the built version
6+
ruby -r ../tests/test_helper.rb ../profiling/yast_import.rb # | head -n2
7+
# use the system version
8+
ruby ../profiling/yast_import.rb # | head -n2
9+
CMD
10+
11+
MemoryProfiler.report {
12+
require "yast"
13+
14+
Yast.import "Pkg"
15+
Yast.import "Bootloader"
16+
Yast.import "UI"
17+
Yast.import "Lan"
18+
}.pretty_print

src/binary/YRubyNamespace.cc

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ as published by the Free Software Foundation; either version
3636
#include "YRuby.h"
3737
#include "Y2RubyUtils.h"
3838

39+
40+
// HELPER method to inspect ruby values from C++. Useful for debugging
41+
/*
42+
// usage: log_inspect("surely not nil, foobar", foobar);
43+
static void log_inspect(const char * message, VALUE v)
44+
{
45+
VALUE inspect = rb_funcall(v, rb_intern("inspect"), 0);
46+
y2internal("%s: %s", message, StringValueCStr(inspect));
47+
}
48+
*/
49+
3950
/**
4051
* Exception raised when type signature in ruby class is invalid
4152
*/
@@ -274,15 +285,12 @@ VALUE YRubyNamespace::getRubyModule()
274285
int YRubyNamespace::addMethods(VALUE module)
275286
{
276287
VALUE methods = rb_funcall(module, rb_intern("published_functions"),0);
277-
methods = rb_funcall(methods,rb_intern("values"),0);
278288
int j = 0;
279289
for (int i = 0; i < RARRAY_LEN(methods); ++i)
280290
{
281-
VALUE method = rb_ary_entry(methods,i);
282-
if (getenv("Y2ALLGLOBAL") == NULL && RTEST(rb_funcall(method, rb_intern("private?"), 0)))
283-
continue;
284-
VALUE method_name = rb_funcall(method, rb_intern("function"), 0);
285-
VALUE type = rb_funcall(method,rb_intern("type"),0);
291+
VALUE method = rb_ary_entry(methods, i);
292+
VALUE method_name = rb_ary_entry(method, 0);
293+
VALUE type = rb_ary_entry(method, 1);
286294
string signature = StringValueCStr(type);
287295

288296
addMethod(rb_id2name(SYM2ID(method_name)), signature, j++);
@@ -293,18 +301,12 @@ int YRubyNamespace::addMethods(VALUE module)
293301
int YRubyNamespace::addVariables(VALUE module, int offset)
294302
{
295303
VALUE variables = rb_funcall(module, rb_intern("published_variables"),0);
296-
variables = rb_funcall(variables,rb_intern("values"),0);
297304
int j=0;
298305
for (int i = 0; i < RARRAY_LEN(variables); ++i)
299306
{
300-
VALUE variable = rb_ary_entry(variables,i);
301-
VALUE variable_name = rb_funcall(variable, rb_intern("variable"), 0);
302-
if (getenv("Y2ALLGLOBAL") == NULL && RTEST(rb_funcall(variable, rb_intern("private?"), 0)))
303-
{
304-
y2debug("variable: '%s' is private and not needed", rb_id2name(SYM2ID(variable_name)));
305-
continue;
306-
}
307-
VALUE type = rb_funcall(variable,rb_intern("type"),0);
307+
VALUE variable = rb_ary_entry(variables, i);
308+
VALUE variable_name = rb_ary_entry(variable, 0);
309+
VALUE type = rb_ary_entry(variable, 1);
308310
string signature = StringValueCStr(type);
309311
constTypePtr sym_tp = Type::fromSignature(signature);
310312

src/ruby/yast/exportable.rb

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@ module Yast
44
# Provides ability to export functions and variables to Yast component system.
55
# The most important method is {Yast::Exportable#publish}
66
module Exportable
7-
# Holder for exported data
8-
class ExportData < OpenStruct
9-
# Is exported data only for private purpose.
10-
# It is useful only to test private methods from old Yast testsuite.
11-
def private?
12-
table = marshal_dump
13-
!!table[:private]
14-
end
15-
end
16-
17-
# list of published functions
7+
# @api private
8+
# @return [Array<Array(Symbol,String)>] list of published functions
9+
# @example
10+
# [
11+
# [:doit, "void()"],
12+
# [:is_odd, "boolean(integer)"]
13+
# ]
1814
def published_functions
19-
@__published_functions ||= {}
15+
@__published_functions ||= []
2016
end
2117

22-
# list of published variables
18+
# @api private
19+
# @return [Array<Array(Symbol,String)>] list of published variables
20+
# @example
21+
# [
22+
# [:answer, "integer"],
23+
# [:having_fun, "boolean"]
24+
# ]
2325
def published_variables
24-
@__published_variables ||= {}
26+
@__published_variables ||= []
2527
end
2628

2729
# Publishes function or variable to component system
@@ -37,16 +39,13 @@ def publish(options)
3739
raise "Missing signature" unless options[:type]
3840
# convert type to full specification
3941
type = options[:type].delete " \t"
40-
type = type.gsub(/map([^<]|$)/, 'map<any,any>\\1')
41-
type = type.gsub(/list([^<]|$)/, 'list<any>\\1')
42-
options[:type] = type
42+
type.gsub!(/map([^<]|$)/, 'map<any,any>\\1')
43+
type.gsub!(/list([^<]|$)/, 'list<any>\\1')
4344
if options[:function]
44-
published_functions[options[:function]] = ExportData.new options
45+
published_functions.push([options[:function], type])
4546
elsif options[:variable]
46-
published_variables[options[:variable]] = ExportData.new options
47-
if !options[:private] || ENV["Y2ALLGLOBAL"]
48-
attr_accessor :"#{options[:variable]}"
49-
end
47+
published_variables.push([options[:variable], type])
48+
attr_accessor options[:variable]
5049
else
5150
raise "Missing publish kind"
5251
end

src/ruby/yast/path.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
12
module Yast
23
# Represents paths like it is in ycp. It is path elements separated by dot.
34
# Elements can be simple or complex. Simple can contain only ascii characters [a-zA-Z0-9].
@@ -71,7 +72,7 @@ def <=>(other)
7172
def load_components(value)
7273
state = :initial
7374
skip_next = false
74-
buffer = ""
75+
buffer = "".dup
7576
value.each_char do |c|
7677
case state
7778
when :initial
@@ -91,7 +92,7 @@ def load_components(value)
9192
raise "Invalid path '#{value}'" if invalid_buffer?(buffer)
9293

9394
@components << modify_buffer(buffer)
94-
buffer = ""
95+
buffer = "".dup
9596
next
9697
end
9798
buffer << c
@@ -107,7 +108,7 @@ def load_components(value)
107108
state = :initial
108109
buffer << c
109110
@components << buffer
110-
buffer = ""
111+
buffer = "".dup
111112
next
112113
when '\\'
113114
skip_next = true

src/ruby/yast/yast.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ def self.import(mname)
179179
# do not reimport if already imported and contain some methods
180180
# ( in case namespace contain some methods )
181181
if base.constants.include?(modules.last.to_sym) &&
182-
!(base.const_get(modules.last).methods - Object.methods).empty?
182+
!base.const_get(modules.last).public_methods(false).empty?
183183
return
184184
end
185185

186186
import_pure(mname)
187187

188188
# do not create wrapper if module is in ruby and define itself object
189189
if base.constants.include?(modules.last.to_sym) &&
190-
!(base.const_get(modules.last).methods - Object.methods).empty?
190+
!base.const_get(modules.last).public_methods(false).empty?
191191
return
192192
end
193193

tests/exportable_spec.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,20 @@ def test(_a, _b)
2727

2828
describe "ExportableTest" do
2929
it "tests publish methods" do
30-
expect(MyTest.class.published_functions.keys).to eq([:test])
31-
expect(MyTest.class.published_functions.values.first.function).to eq(:test)
32-
expect(MyTest.class.published_functions[:test].type).to eq("string(integer,term)")
30+
expect(MyTest.class.published_functions).to eq([
31+
[:test, "string(integer,term)"]
32+
])
3333
end
3434

3535
it "tests publish variables" do
36-
expect(MyTest.class.published_variables[:variable_a].type).to eq("map<any,any>")
36+
expect(MyTest.class.published_variables).to eq([
37+
[:complex, "map<string,map<list<any>,map<any,any>>>"],
38+
[:variable_a, "map<any,any>"]
39+
])
3740
end
3841

3942
it "tests variable definition" do
4043
MyTest.variable_a = ({ a: 15 })
4144
expect(MyTest.variable_a).to eq(a: 15)
4245
end
43-
44-
it "tests type full specification" do
45-
expect(MyTest.class.published_variables[:complex].type)
46-
.to eq("map<string,map<list<any>,map<any,any>>>")
47-
end
4846
end

tests/test_module/modules/InvalidTypeModule.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module Yast
22
class InvalidTypeModuleClass < Module
3+
include Yast::Logger
4+
35
def a
46
puts "Fail"
57
end

0 commit comments

Comments
 (0)