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 86A811F4CC for ; Mon, 6 Jan 2025 09:34:57 +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=G3/KZrAJ; 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=ilRoCKhs; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1736156065; bh=5dRYSZzDUIAa4e+w/wWZptZTgOD+67rI7vjzGM8xyOs=; 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=G3/KZrAJnkbRf/c68wI4bwqGr6HoEt1WATeBUXuOFsY+4qStNBO9RD7vY42r87y3A iv8VLSNfcYHy697AvjffAduA4+pdflFH/A8bZEw22VNRWiD9EU0kJ6LI1n5WfRFonq hFFAKqGxqC+QTqqql1Zl7WLz5d0blNlDFv304tqY= Received: from nue.mailmanlists.eu (localhost [IPv6:::1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 4E35646558 for ; Mon, 6 Jan 2025 09:34:25 +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=ilRoCKhs; dkim-atps=neutral Received: from s.wrqvtvvn.outbound-mail.sendgrid.net (s.wrqvtvvn.outbound-mail.sendgrid.net [149.72.120.130]) by nue.mailmanlists.eu (Postfix) with ESMTPS id BAC9B46506 for ; Mon, 6 Jan 2025 09:34:20 +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=LNJo3pouUTQnaJk0PVIgd9aJyunStu6ujFWMmFIApt0=; b=ilRoCKhsLsrdtkfgzvUqFB4VSsqYWxerEEp6dDyI7upGi7spcVqu5CjsRvDs7ST8utzk i1EonLosVk6hfQyQv/7Jj5hbo9I3ghh4MOLoqbozbvo6mBrcmi1bH8GXWo15A2v4dASmM1 4PnkVKod8qDICSmdRTlT9k28WGKpMoDIt9AXsR+W0Sx6cPO1r23gACUvpi+/LI5v7Rl5he jE9Ed1XLpfvqqb0zNIbZka0zgbxmaq5fmxPXigCgponzLz35L8TscHn2y+n/AusRDP+X98 khOGP7JFZrWwgSvDOnwqOMZyrowt/FmcbSzZnD1/JTqT+rwGoUIk+mOLhNNtC8Qw== Received: by recvd-84b546689d-zrqq5 with SMTP id recvd-84b546689d-zrqq5-1-677BA39A-34 2025-01-06 09:34:18.646737514 +0000 UTC m=+4536670.393611876 Received: from herokuapp.com (unknown) by geopod-ismtpd-19 (SG) with ESMTP id vk_v_RMJRrG042IKmgcybA for ; Mon, 06 Jan 2025 09:34:18.574 +0000 (UTC) Date: Mon, 06 Jan 2025 09:34:18 +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: 97171 X-SG-EID: =?us-ascii?Q?u001=2EByjZWvxTCjdoV8K03xEuhE7KqN4thWULFLM7+oH78KY30oYB3qFthsDpL?= =?us-ascii?Q?4w4cbYa3ttBh8bAHPOnE=2FkzPba67JNu7Lnrked2?= =?us-ascii?Q?O7K9VQ=2FJax2y0uB+oSsp8ARWZT6oh3I1x796h3L?= =?us-ascii?Q?BomAI+1vB0EaqnAHT6CGUUdXwEyFG6LsI1jtk7G?= =?us-ascii?Q?HbrCZUMxKwWJA6b7J4ZbfvidBgcCk60pQ16OV8H?= =?us-ascii?Q?ngSCsOTmibDGHixJmsnFGwXqpeO3YY8PVEQ7Yna?= =?us-ascii?Q?7rrM3RZluytT3YYLSgkvBW6kpg=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: GYDPTU3F7IDTCHDGQ6RBOUMEAL77XPAT X-Message-ID-Hash: GYDPTU3F7IDTCHDGQ6RBOUMEAL77XPAT 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:120495] [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). I'm not aware of any such case, and `.freeze` seems much better for that use case. ---------------------------------------- Bug #20998: rb_str_locktmp() changes flags of frozen strings and string literals https://bugs.ruby-lang.org/issues/20998#change-111282 * 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/