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.5 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=no 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 24B131F4BD for ; Tue, 8 Oct 2019 23:35:03 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 475831209EA; Wed, 9 Oct 2019 08:34:54 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 227601209E3 for ; Wed, 9 Oct 2019 08:34:51 +0900 (JST) Received: by filter0038p3iad2.sendgrid.net with SMTP id filter0038p3iad2-14327-5D9D1D1C-5C 2019-10-08 23:34:52.710902892 +0000 UTC m=+447769.947125740 Received: from herokuapp.com (unknown [54.157.57.165]) by ismtpd0033p1mdw1.sendgrid.net (SG) with ESMTP id XlF9fepMQ5q0vXytEpd8Jw for ; Tue, 08 Oct 2019 23:34:52.565 +0000 (UTC) Date: Tue, 08 Oct 2019 23:34:52 +0000 (UTC) From: sam.saffron@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70872 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16029 X-Redmine-Issue-Author: byroot X-Redmine-Sender: sam.saffron 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: =?us-ascii?Q?GD31AXMrLYtZC3ZmvheLkg5nAqKYtjT=2Fa5aksj98ZWPyBTRhfOnSTtymEEgsSS?= =?us-ascii?Q?yem2dYIVXf1+8+swqttmbPqKe2BGgJsjTQTGKT3?= =?us-ascii?Q?eos3mEjc6O9SG8CQM0j1LrV1=2FsBKcWUqS4CPA5L?= =?us-ascii?Q?kj5mYcTaedVFuemEHvJVDlvP=2FTB=2F02t9kYOiiDF?= =?us-ascii?Q?p=2FT0SDStMUJBpsUd6l=2FgHtdkdWGLFEsP3VA=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95285 Subject: [ruby-core:95285] [Ruby master Feature#16029] Expose fstring related APIs to C-extensions 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 #16029 has been updated by sam.saffron (Sam Saffron). I think when it gets called it expects to reuse the memory allocated by the cstr eventually https://github.com//blob/96753e8475ee69537134ab3d966c3d25cb5c467c/string.c#L287-L292 So if your library is in charge of the memory for the object this is not desirable, you want to simply ask the question "do you have an fstring for the current string eg" VALUE rb_fstring_lookup(char *ptr); This non const char means it would not take ownership and the thing can return Qnil if there is no fstring. Then if 99.999% of the string your library has are already fstrings, the lookup becomes a super cheap function you can use to lookup. ---------------------------------------- Feature #16029: Expose fstring related APIs to C-extensions https://bugs.ruby-lang.org/issues/16029#change-81965 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- As discussed with @tenderlove here: https://github.com/ruby/ruby/pull/2287#issuecomment-513865160 We'd like to update various data format parsers (JSON, MessagePack, etc) to add the possibility to deduplicate strings while parsing. But unfortunately the `rb_fstring_*` family of functions isn't available to C-extensions, so the only available fallback is `rb_funcall(str, rb_intern("-@"))` which most parsers will likely consider too slow. So the various `rb_fstring_*` functions would need to be public. Proposed patch: https://github.com/ruby/ruby/pull/2299 -- https://bugs.ruby-lang.org/