ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "peterzhu2118 (Peter Zhu) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "peterzhu2118 (Peter Zhu)" <noreply@ruby-lang.org>
Subject: [ruby-core:116760] [Ruby master Feature#20265] Deprecate and remove rb_newobj and rb_newobj_of
Date: Wed, 14 Feb 2024 17:08:09 +0000 (UTC)	[thread overview]
Message-ID: <redmine.issue-20265.20240214170809.42491@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-20265.20240214170809.42491@ruby-lang.org

Issue #20265 has been reported by peterzhu2118 (Peter Zhu).

----------------------------------------
Feature #20265: Deprecate and remove rb_newobj and rb_newobj_of
https://bugs.ruby-lang.org/issues/20265

* Author: peterzhu2118 (Peter Zhu)
* Status: Open
* Priority: Normal
----------------------------------------
GitHub PR: https://github.com/ruby/ruby/pull/9964

I’m proposing deprecating and removing the rb_newobj and rb_newobj_of APIs because they are difficult to use, fragile to use, and requires knowledge of the internal implementation of data types in Ruby.

The rb_newobj function creates a T_NONE object. T_NONE objects are tricky to deal with since T_NONE objects cannot be marked, T_NONE objects are not reclaimed by the GC, and changing the object to other types require internal knowledge about the data type.

T_NONE objects are not allowed to be marked, so it cannot be GC managed. Since T_NONE objects are skipped during sweeping, it will leak Ruby heap memory if the developer never changes the object to another type.

Changing a T_NONE object to another type is tricky. For example, T_STRING objects have many flags for embedded, shared, shared root, encoding, coderange, etc. Many of these flags are not public, preventing direct use by developers. Developers must understand these flags to convert a T_NONE object into a T_STRING object.

While the rb_newobj_of function is easier to use than the rb_newobj function, it still requires developers to understand flags, meaning some issues of rb_newobj also apply to rb_newobj_of.

Below is the usage of RB_NEWOBJ, rb_newobj, rb_newobj_of, RB_NEWOBJ_OF with vendored Ruby and comments removed. You can see that there are very few gems using these APIs and all are from over a decade ago (the most recent one is from 2011).

```
2009-11-18 /srv/gems/bleak_house-7.2/ruby/ruby-1.8.7.patch:@@ -438,10 +438,8 @@ rb_newobj()
2023-07-01 /srv/gems/daqing_rucaptcha-3.2.2/ext/rucaptcha/target/release/build/rb-sys-6bdd5b2895b9570a/out/bindings-0.9.78-arm64-darwin22-3.2.2.rs:    pub fn rb_newobj() -> VALUE;
2023-07-01 /srv/gems/daqing_rucaptcha-3.2.2/ext/rucaptcha/target/release/build/rb-sys-6bdd5b2895b9570a/out/bindings-0.9.78-arm64-darwin22-3.2.2.rs:    pub fn rb_newobj_of(klass: VALUE, flags: VALUE) -> VALUE;
2010-08-06 /srv/gems/langscan-1.2/ext/langscan/ruby/compat/ripper/ripper.c:    NODE *n = (NODE*)rb_newobj();
2011-02-03 /srv/gems/memprof-0.3.10/ext/memprof.c:  VALUE ret = rb_newobj();
2011-02-03 /srv/gems/memprof-0.3.10/ext/tracers/objects.c:  last_obj = orig_rb_newobj();
2006-02-28 /srv/gems/refe-0.8.0.3/data/refe/function_source/rb/newobj:rb_newobj()
2006-02-28 /srv/gems/refe-0.8.0.3/data/refe/function_source/rb/node/newnode:    NODE *n = (NODE*)rb_newobj();
2011-08-31 /srv/gems/ruby-rpm-1.3.1/ext/rpm/dependency.c:       prov = rb_newobj();
2011-08-31 /srv/gems/ruby-rpm-1.3.1/ext/rpm/dependency.c:       req = rb_newobj();
2011-08-31 /srv/gems/ruby-rpm-1.3.1/ext/rpm/dependency.c:       conf = rb_newobj();
2011-08-31 /srv/gems/ruby-rpm-1.3.1/ext/rpm/dependency.c:       obso = rb_newobj();
2011-08-31 /srv/gems/ruby-rpm-1.3.1/ext/rpm/file.c:     file = rb_newobj();
2011-08-31 /srv/gems/ruby-rpm-1.3.1/ext/rpm/source.c:   src = rb_newobj();
2011-08-31 /srv/gems/ruby-rpm-1.3.1/ext/rpm/source.c:   src = rb_newobj();
2011-08-31 /srv/gems/ruby-rpm-1.3.1/ext/rpm/source.c:   src = rb_newobj();
2011-08-31 /srv/gems/ruby-rpm-1.3.1/ext/rpm/version.c:  ver = rb_newobj();
2011-08-31 /srv/gems/ruby-rpm-1.3.1/ext/rpm/version.c:  ver = rb_newobj();
2011-08-31 /srv/gems/ruby-rpm-1.3.1/ext/rpm/version.c:  ver = rb_newobj();
2006-11-30 /srv/gems/sydparse-1.2.0/sydparse.c:    syd_scope = (struct SCOPE*)rb_newobj();
2006-11-30 /srv/gems/sydparse-1.2.0/sydparse.y:    syd_scope = (struct SCOPE*)rb_newobj();
```



-- 
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/postorius/lists/ruby-core.ml.ruby-lang.org/

       reply	other threads:[~2024-02-14 17:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14 17:08 peterzhu2118 (Peter Zhu) via ruby-core [this message]
2024-02-15  2:08 ` [ruby-core:116766] [Ruby master Feature#20265] Deprecate and remove rb_newobj and rb_newobj_of shyouhei (Shyouhei Urabe) via ruby-core
2024-02-15 10:51 ` [ruby-core:116778] " Eregon (Benoit Daloze) via ruby-core
2024-03-14  9:42 ` [ruby-core:117150] " mame (Yusuke Endoh) via ruby-core

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.issue-20265.20240214170809.42491@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    --cc=ruby-core@ml.ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).