From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.6 required=3.0 tests=AWL,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 0854D211B9 for ; Wed, 26 Dec 2018 01:45:00 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 34661120959; Wed, 26 Dec 2018 10:44:57 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 9427C120A58 for ; Wed, 26 Dec 2018 10:44:55 +0900 (JST) Received: by filter0133p3mdw1.sendgrid.net with SMTP id filter0133p3mdw1-8105-5C22DD14-10 2018-12-26 01:44:52.218667924 +0000 UTC m=+445377.762471148 Received: from herokuapp.com (ec2-54-160-207-19.compute-1.amazonaws.com [54.160.207.19]) by ismtpd0010p1iad2.sendgrid.net (SG) with ESMTP id p6_4PxzVQf2H00FetOY6PA for ; Wed, 26 Dec 2018 01:44:52.254 +0000 (UTC) Date: Wed, 26 Dec 2018 01:44:53 +0000 (UTC) From: shyouhei@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 66142 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15460 X-Redmine-Issue-Author: gettalong X-Redmine-Sender: shyouhei 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-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4h+CpFr6C4kgYiXDqEHgQJNb8xOjJTOj4dQP hYSowj5CmDmGQh1nmfi2zkcxyQcIH9zLj/+to5INVlJSgnC6+XrEz2ZxVyQzCG4QhQUgfwHyJYnjRM hq15yHVaYVcOek4eBvhnXImf6KQSu8r2isR+EWM54yT56HYK8vglCrnkDA== X-ML-Name: ruby-core X-Mail-Count: 90723 Subject: [ruby-core:90723] [Ruby trunk Bug#15460] Behaviour of String#setbyte changed X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #15460 has been updated by shyouhei (Shyouhei Urabe). We may want to define the behaviour of these methods without introducing fixnum / bignum distinction. One possible way is: ```patch Index: io.c =================================================================== --- io.c (revision 66566) +++ io.c (working copy) @@ -4259,8 +4259,8 @@ rb_io_ungetbyte(VALUE io, VALUE b) GetOpenFile(io, fptr); rb_io_check_byte_readable(fptr); if (NIL_P(b)) return Qnil; - if (FIXNUM_P(b)) { - int i = FIX2INT(b); + if (RB_TYPE_P(b, T_FIXNUM) || RB_TYPE_P(b, T_BIGNUM)) { + int i = NUM2INT(rb_int_modulo(b, INT2FIX(256))); if (0 <= i && i <= UCHAR_MAX) { unsigned char cc = i & 0xFF; b = rb_str_new((const char *)&cc, 1); Index: string.c =================================================================== --- string.c (revision 66566) +++ string.c (working copy) @@ -5411,7 +5411,7 @@ static VALUE rb_str_setbyte(VALUE str, VALUE index, VALUE value) { long pos = NUM2LONG(index); - int byte = NUM2INT(value); + int byte = NUM2INT(rb_int_modulo(value, INT2FIX(256))); long len = RSTRING_LEN(str); char *head, *left = 0; unsigned char *ptr; ``` ---------------------------------------- Bug #15460: Behaviour of String#setbyte changed https://bugs.ruby-lang.org/issues/15460#change-75900 * Author: gettalong (Thomas Leitner) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- I just installed Ruby 2.6.0 for benchmarking reasons and found that the change [string.c: setbyte silently ignores upper bits](https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/65804) broke my library/application HexaPDF. Before using String#setbyte I tested how it would respond to values lower than 0 or greater than 255 and found that it automatically performed the needed modulo 256 operation (at least up to Ruby 2.5.3). Therefore I left out the explicit modulo operation for performance reasons. Would it make sense to change the String#setbyte implementation to perform the modulo operation? This would restore compatibility with prior Ruby versions and may be what people would expect. -- https://bugs.ruby-lang.org/