Skip to content

Add Set C-API #13735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add Set C-API #13735

wants to merge 3 commits into from

Conversation

jeremyevans
Copy link
Contributor

This should be a minimal C-API needed to deal with Set objects. It
supports creating the sets, checking whether an element is the set,
adding and removing elements, iterating over the elements, clearing
a set, and returning the size of the set.

As some of the function names I wanted to use in the C-API were
already used internally, I had to rename some existing internal functions.

This comment has been minimized.

@st0012
Copy link
Member

st0012 commented Jun 30, 2025

Should rb_cSet also be exposed in include/ruby/internal/globals.h?
Having it exposed will also allow ZJIT's to optimize for Set objects more easily (PR).

@jeremyevans
Copy link
Contributor Author

Should rb_cSet also be exposed in include/ruby/internal/globals.h? Having it exposed will also allow ZJIT's to optimize for Set objects more easily (PR).

Yes, it should. I updated this to include that change.

@st0012
Copy link
Member

st0012 commented Jun 30, 2025

Headsup: I've exposed rb_cSet in zjit.c for now. So you'll need to remove it when rebasing this PR.


load_extension("set")

describe "C-API Set function" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding these C API specs, that will definitely help implementing those functions on other Rubies.

These functions conflict with the planned C-API functions. Since they
deal with the underlying set_table pointers and not Set instances,
this seems like a more accurate name as well.
@jeremyevans
Copy link
Contributor Author

Headsup: I've exposed rb_cSet in zjit.c for now. So you'll need to remove it when rebasing this PR.

Rebased and updated to remove it from zjit.c.

jeremyevans and others added 2 commits June 30, 2025 18:30
This should be a minimal C-API needed to deal with Set objects. It
supports creating the sets, checking whether an element is the set,
adding and removing elements, iterating over the elements, clearing
a set, and returning the size of the set.

Co-authored-by: Nobuyoshi Nakada <nobu.nakada@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants