Project

General

Profile

Bug #14687

TestM17N#test_str_dump, String.dump, frozen-string

Added by MSP-Greg (Greg L) 3 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.0dev (2018-04-12 trunk 63140) [x64-mingw32]
[ruby-core:86539]

Description

The test TestM17N#test_str_dump located in test/ruby/test_m17n.rb (link at https://github.com/ruby/ruby/blob/83c961665def138e78a66d8bef0b4fa1da49ac69/test/ruby/test_m17n.rb#L324-L363), fails when run with frozen-string.

The test is similar to

def test_str_dump              # Note: several array elements removed to shorten
  [
    "\u3042".encode("UTF-16LE"),
    "\u3042".encode("UTF-16BE"),
  ].each do |str|
    assert_equal(str, eval(str.dump), "")
  end
end

Since the following

"\u3042".encode("UTF-16LE").dump #-> "B0".force_encoding("UTF-16LE")
"\u3042".encode("UTF-16BE").dump #-> "0B".force_encoding("UTF-16BE")

When eval'd by the test, there is a failure due to the string being frozen. Not being a c type, not really sure what the solution is.

Possibly change line 5969 of string.c from

static const char nonascii_suffix[] = ".force_encoding(\"%s\")";

to

static const char nonascii_suffix[] = "dup.force_encoding(\"%s\")";

Thanks, Greg

Associated revisions

Revision cea438b0
Added by nobu (Nobuyoshi Nakada) 3 months ago

string.c: fix dumped suffix

  • string.c (rb_str_dump): get rid of an error on evaling with frozen-string-literal enabled. [Bug #14687]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 63164
Added by nobu (Nobuyoshi Nakada) 3 months ago

string.c: fix dumped suffix

  • string.c (rb_str_dump): get rid of an error on evaling with frozen-string-literal enabled. [Bug #14687]

Revision 63170
Added by nobu (Nobuyoshi Nakada) 3 months ago

string.c: suppress warning

  • string.c (str_undump): get rid of warning C4129 by VC.

History

#1 Updated by MSP-Greg (Greg L) 3 months ago

  • ruby -v set to ruby 2.6.0dev (2018-04-12 trunk 63140) [x64-mingw32]

#2 Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Open to Closed

Applied in changeset trunk|r63164.


string.c: fix dumped suffix

  • string.c (rb_str_dump): get rid of an error on evaling with frozen-string-literal enabled. [Bug #14687]

#3 Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.3: REQUIRED, 2.4: REQUIRED, 2.5: REQUIRED

Also available in: Atom PDF