From 2e981895642a778ef96adf0396e7d5d1965ac03f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 2 Feb 2022 15:53:23 +1300 Subject: [PATCH] [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/ --- CHANGES.current | 4 ++++ .../test-suite/ruby/ruby_naming_bugs_runme.rb | 16 ++++++++++++++++ Examples/test-suite/ruby_naming_bugs.i | 9 +++++++++ Source/Modules/ruby.cxx | 5 +++-- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/ruby/ruby_naming_bugs_runme.rb create mode 100644 Examples/test-suite/ruby_naming_bugs.i diff --git a/CHANGES.current b/CHANGES.current index 230ff333b..46c567a02 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-02-02: olly + [Ruby] https://sourceforge.net/p/swig/bugs/1136/ Fix remove of prefix + from method name to only remove it at the start. + 2022-02-01: olly #231 Handle returning an object by reference in a C++ trailing return type. diff --git a/Examples/test-suite/ruby/ruby_naming_bugs_runme.rb b/Examples/test-suite/ruby/ruby_naming_bugs_runme.rb new file mode 100644 index 000000000..49311352d --- /dev/null +++ b/Examples/test-suite/ruby/ruby_naming_bugs_runme.rb @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# Regression tests for Ruby naming bugs +# + +require 'swig_assert' + +require 'ruby_naming_bugs' + +# Prior to SWIG 4.1.0 the "Cool_" here was overzealously removed +# while trying to remove a class name prefix, so this method would be +# named "somethingFast" in Ruby instead. +c = Ruby_naming_bugs::Cool.new() +if c.somethingCool_Fast != 42 + raise RuntimeError, "Incorrect value for somethingCool_Fast" +end diff --git a/Examples/test-suite/ruby_naming_bugs.i b/Examples/test-suite/ruby_naming_bugs.i new file mode 100644 index 000000000..6449addf1 --- /dev/null +++ b/Examples/test-suite/ruby_naming_bugs.i @@ -0,0 +1,9 @@ +%module ruby_naming_bugs + +%inline %{ + // Prior to SWIG 4.1.0 the "Cool_" here was overzealously removed while + // trying to remove a class name prefix. + struct Cool { + int somethingCool_Fast() { return 42; } + }; +%} diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index ec4a75dbd..e3678a3a6 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -106,9 +106,10 @@ public: char *strip(const_String_or_char_ptr s) { Clear(temp); - Append(temp, s); if (Strncmp(s, prefix, Len(prefix)) == 0) { - Replaceall(temp, prefix, ""); + Append(temp, Char(s) + Len(prefix)); + } else { + Append(temp, s); } return Char(temp); }