Skip to content

Commit 2e98189

Browse files
committed
[Ruby] Fix remove of prefix from method name
The prefix is now only removed at the start. Fixes https://sourceforge.net/p/swig/bugs/1136/
1 parent 27a3d16 commit 2e98189

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

CHANGES.current

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
77
Version 4.1.0 (in progress)
88
===========================
99

10+
2022-02-02: olly
11+
[Ruby] https://sourceforge.net/p/swig/bugs/1136/ Fix remove of prefix
12+
from method name to only remove it at the start.
13+
1014
2022-02-01: olly
1115
#231 Handle returning an object by reference in a C++ trailing
1216
return type.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# Regression tests for Ruby naming bugs
4+
#
5+
6+
require 'swig_assert'
7+
8+
require 'ruby_naming_bugs'
9+
10+
# Prior to SWIG 4.1.0 the "Cool_" here was overzealously removed
11+
# while trying to remove a class name prefix, so this method would be
12+
# named "somethingFast" in Ruby instead.
13+
c = Ruby_naming_bugs::Cool.new()
14+
if c.somethingCool_Fast != 42
15+
raise RuntimeError, "Incorrect value for somethingCool_Fast"
16+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
%module ruby_naming_bugs
2+
3+
%inline %{
4+
// Prior to SWIG 4.1.0 the "Cool_" here was overzealously removed while
5+
// trying to remove a class name prefix.
6+
struct Cool {
7+
int somethingCool_Fast() { return 42; }
8+
};
9+
%}

Source/Modules/ruby.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ class RClass {
106106

107107
char *strip(const_String_or_char_ptr s) {
108108
Clear(temp);
109-
Append(temp, s);
110109
if (Strncmp(s, prefix, Len(prefix)) == 0) {
111-
Replaceall(temp, prefix, "");
110+
Append(temp, Char(s) + Len(prefix));
111+
} else {
112+
Append(temp, s);
112113
}
113114
return Char(temp);
114115
}

0 commit comments

Comments
 (0)