From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=0.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 0C4D31F4CC for ; Mon, 6 Jan 2025 12:37:48 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=R7vUeEQi; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=lR5A7hvr; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1736167064; bh=O96a0MefYdxjlDaBIumYWx3u1o4KjKee9oLaGkKKIis=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=R7vUeEQiXRYsSZfQYITD5LEyNrMAX7pcTmLliCvEXiHZCuYjnc6/bOq+hlfqY+kZT SMo/Q3v/bZtBylNBO2dTFgUcNNP0qfCXnY5Tj+9hq7TkG4lDiQPduHncC4OkUg9gCy ZcyltP6P7/BJ3K7uuW1FXeXWDzqY1Z/KygERovf0= Received: from nue.mailmanlists.eu (localhost [IPv6:::1]) by nue.mailmanlists.eu (Postfix) with ESMTP id A2412465E0 for ; Mon, 6 Jan 2025 12:37:44 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=lR5A7hvr; dkim-atps=neutral Received: from s.wrqvwxzv.outbound-mail.sendgrid.net (s.wrqvwxzv.outbound-mail.sendgrid.net [149.72.154.232]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 96B9446534 for ; Mon, 6 Jan 2025 12:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=M4HfBrFo0XMiSVtbyqxQmC+dRquqZG2EsVssHP9TJgs=; b=lR5A7hvrDlDggyPipUdkuUaucsTVovXFFrFsjSX4UMTTH9j0+DLeS0OWdrklS+wC1ADG aVDGtZxQgntALLiAA5B/1DYZLmMWk940SYWjKzDP/kljx5Y4JsN9O5bI+wcvjD7zF/BysR f+j8Bu6/PiCgQEbD4m3Cl2ZkN5+2Ou7y7Y18vbCM5QHVMS5EvkuBGGp7pjXFqVhie9cHnI G1W6YXZ2NydFpV42CO0wNu09pd8MpTxZQqM5CPf7PcF6QjldpZBhCTJkxh0i+nMjNzneql tQqHi+XuCiYYWD6b9n9yGcsmx4X331Hxw9HsftCsakuAtj2iV8D3RrzJ7HmHHGgA== Received: by recvd-69cbc48b94-8fhm8 with SMTP id recvd-69cbc48b94-8fhm8-1-677BCE90-16 2025-01-06 12:37:36.498991807 +0000 UTC m=+4547766.465018294 Received: from herokuapp.com (unknown) by geopod-ismtpd-1 (SG) with ESMTP id J7n6VjskTmaTwFQ5SwICZg for ; Mon, 06 Jan 2025 12:37:36.466 +0000 (UTC) Date: Mon, 06 Jan 2025 12:37:36 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 20998 X-Redmine-Issue-Author: Eregon X-Redmine-Issue-Priority: Normal X-Redmine-Sender: Eregon X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 97175 X-SG-EID: =?us-ascii?Q?u001=2EByjZWvxTCjdoV8K03xEuhE7KqN4thWULFLM7+oH78KY30oYB3qFthsDpL?= =?us-ascii?Q?4w4cbYa3ttBh8bAHPOnE=2FkzPba67JNu7Lnrked2?= =?us-ascii?Q?O7K9VQ=2FJax3=2Fxmz6cjFYB6kNbx0PF7Gh4n7eSql?= =?us-ascii?Q?DvUaBzyAgnfMDikYbJGXZ6pB9ONktPdV3vcFygB?= =?us-ascii?Q?Orh7Xsq+rTm0+D=2Fdko1601YB3b+cc14P0vO7zJ+?= =?us-ascii?Q?CraDKwtyHuk+QSXqcYVndnZSDwk1rWFwjIIi9ik?= =?us-ascii?Q?F6X2STCPk7OaSh=2FrTZEB4xN4ww=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: UBX3AIMY4RLBJSMZLBBTCWW3LWUUMKWS X-Message-ID-Hash: UBX3AIMY4RLBJSMZLBBTCWW3LWUUMKWS X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:120499] [Ruby master Bug#20998] rb_str_locktmp() changes flags of frozen strings and string literals List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "Eregon (Benoit Daloze) via ruby-core" Cc: "Eregon (Benoit Daloze)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20998 has been updated by Eregon (Benoit Daloze). @byroot but that's mutating the string, @nobu is asking for a case not mutating the string, which I think there is none. ---------------------------------------- Bug #20998: rb_str_locktmp() changes flags of frozen strings and string literals https://bugs.ruby-lang.org/issues/20998#change-111292 * Author: Eregon (Benoit Daloze) * Status: Open * ruby -v: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- ```ruby # frozen_string_literal: true # BOILERPLATE START require 'tmpdir' require 'rbconfig' def inline_c_extension(c_code) Dir.mktmpdir('inline_c_extension') do |dir| File.write("#{dir}/cext.c", c_code) File.write("#{dir}/extconf.rb", <<~RUBY) require 'mkmf' create_makefile('cext') RUBY out = IO.popen([RbConfig.ruby, 'extconf.rb'], chdir: dir, &:read) raise "ruby extconf.rb failed: #{$?.inspect}\n#{out}" unless $?.success? out = IO.popen(['make'], chdir: dir, &:read) raise "make failed: #{$?.inspect}\n#{out}" unless $?.success? require "#{dir}/cext.#{RbConfig::CONFIG['DLEXT']}" end end inline_c_extension <<~C #include "ruby.h" static VALUE foo(VALUE self, VALUE str) { rb_str_locktmp(str); return str; } void Init_cext(void) { VALUE c = rb_define_class("Foo", rb_cObject); rb_define_singleton_method(c, "foo", foo, 1); } C # BOILERPLATE END a = "str" Foo.foo(a) # imagine a million lines of code in between b = "str" b << "." # can't modify string; temporarily locked (RuntimeError) # What? Who "locked" that immutable frozen string literal? # It should be: can't modify frozen String: "str" (FrozenError) ``` Same problem with: ```ruby Foo.foo("abc") # imagine a million lines of code in between Foo.foo("abc") # temporal locking already locked string (RuntimeError) ``` Related: https://github.com/oracle/truffleruby/issues/3752 It seems a clear bug to mutate a frozen string (with visible side effects), even more so for shared frozen string literals. I think rb_str_locktmp() should raise (a FrozenError, as it's effectively attempting to mutate it, same as calling `rb_str_modify()`) if called on a frozen string, because it makes little sense, I think "locking a string" only makes sense for mutable strings. The alternative would be to noop on frozen strings for rb_str_locktmp() and rb_str_unlocktmp(), I think that's susprising, and potentially hiding more bugs, e.g. if one by mistake tries to mutate the RSTRING_PTR() or so, and also rb_str_locktmp() wouldn't imply the flag is set after it returns. Any attempt to mutate a frozen string should fail, so might as well fail early. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/