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)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 5582E1F4CC for ; Tue, 7 Jan 2025 10:36:10 +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=WFGYB1Gw; 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=Xyq9zyfh; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1736246167; bh=EsRJWe18aurm2jobVdCiz+uSB7z81lMAsmdOEZ8Id10=; 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=WFGYB1GwkhH007TDM0ljIxCpWoP/QcMXuuXtNHaXunKJK98HBv8/YhwY7Py6Uw4i7 PubLbFtcMuAVH47d1ZJrD8vBoxCdR8tbj82XUrOPU7E8DUNfhNZX/MCUmszbJmmxle E5vocnllrA+TOxzhR5dgnHsQ459GttW6Y6cI8p3E= Received: from nue.mailmanlists.eu (localhost [IPv6:::1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 36D4546684 for ; Tue, 7 Jan 2025 10:36:07 +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=Xyq9zyfh; dkim-atps=neutral Received: from s.wrqvtbkv.outbound-mail.sendgrid.net (s.wrqvtbkv.outbound-mail.sendgrid.net [149.72.123.24]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 14DB54666B for ; Tue, 7 Jan 2025 10:36:01 +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=GsCePH3qZcTS46WaC8MMg3mEV0bWiC+NQUNWQBoTcL4=; b=Xyq9zyfh5wqA0QnV1jPTX4p4r4QUwkX+sK1MFbUu8JUMVPVRsJDFEmEWEAEmSlukDow4 SG6o7sPMOZQUCF6FxSh+nDMskUHgRuxQPxx7+igxftchHXpIWYyCHMP4dly/yWwY5r1LQ9 dyjixNFOg0YE6G1zmjszkGQ4xmUn+xCiHpuPcXUuckiAxy7kntgZ8RNXr+LZPDPS/OyA+D kMxL6ePLT0n9SqPspwOnpvXj8c8L0l5Mp5upF7AE5ueTYLKWmsr7SY3zIyLZYX8NsL13Dw cQ4q9uuCFrmYmnArMZ3Qh4Lb6MgYXwyhtAgX5LlLWghM2ykDid9JUv7NmQAIB8tg== Received: by recvd-5f54b5d587-4kg6v with SMTP id recvd-5f54b5d587-4kg6v-1-677D0390-17 2025-01-07 10:36:00.58737635 +0000 UTC m=+4626733.869977909 Received: from herokuapp.com (unknown) by geopod-ismtpd-5 (SG) with ESMTP id jjBSQcPhTyerisip9jS5lw for ; Tue, 07 Jan 2025 10:36:00.529 +0000 (UTC) Date: Tue, 07 Jan 2025 10:36:00 +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: byroot 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: 97196 X-SG-EID: =?us-ascii?Q?u001=2EKmNZ1u3n1vIpO8NNTdp+Q9c0ai7potxbEDLMO7SOJO=2F4KkRUz0d23466m?= =?us-ascii?Q?naiq=2F5fmA4hb60MdRMUAwHZnjIWVFu=2FrqiBOz5c?= =?us-ascii?Q?nOvkBudsSThrweIhU9=2F=2FT9Aqpg0gklr=2F5qdaDKt?= =?us-ascii?Q?rdlsvsIAaKyKbpyh0rfVo7q7tkBirLbkqsnIUrZ?= =?us-ascii?Q?hsID15kNUOoa5pmEhYca2LroBTjjclpWbDv87tN?= =?us-ascii?Q?1dpNFeyi+h4Gsc4VeqdtmB2CpOfgjK8cn8jdmeh?= =?us-ascii?Q?l0xjLBaAco5aexUIjdiPW9fDYg=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: SKNLAXQP7XCEMVQRFO57VIDTSTAOUMLM X-Message-ID-Hash: SKNLAXQP7XCEMVQRFO57VIDTSTAOUMLM 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:120520] [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: "byroot (Jean Boussier) via ruby-core" Cc: "byroot (Jean Boussier)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20998 has been updated by byroot (Jean Boussier). > It seems clearly wrong that two threads using Zlib with a frozen String literal (which happens to have the same contents/characters for both threads) would fail with temporal locking already locked string (RuntimeError) though. That I totally agree. ---------------------------------------- Bug #20998: rb_str_locktmp() changes flags of frozen strings and string literals https://bugs.ruby-lang.org/issues/20998#change-111325 * 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/