Skip to content

Designated initializers #2131

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

Merged
merged 2 commits into from
Dec 9, 2024
Merged

Conversation

amomchilov
Copy link
Contributor

@amomchilov amomchilov commented Dec 6, 2024

This PR changes several repeated assignments with C99 designated initializers.

We're already requiring C99 (well, the GNU dialect of it), so there shouldn't be any compiler versioning concerns:

append_cflags ['-std=gnu99']

These have 3 benefits:

  1. In some places they can replace a calloc, since they automatically zero-out any fields that that weren't explicitly set.
  2. They have better IDE auto-completions to help remember to set all fields.
  3. As a combination of 1 and 2, using these now will help us land our large C API changes on top.

Verified

This commit was signed with the committer’s verified signature.
amomchilov Alexander Momchilov

Verified

This commit was signed with the committer’s verified signature.
amomchilov Alexander Momchilov
@amomchilov amomchilov force-pushed the designated_initializers branch from 4077aae to 7bda0bf Compare December 6, 2024 18:49
Comment on lines -57 to -61
check_children_cap(loc);

unsigned short i = loc->children->len++;
loc->children->entries[i].name = name;
loc->children->entries[i].rg = rbs_new_loc_range(r);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code is the same as rbs_loc_add_optional_child, so we can reuse that, and just set required_p after.

*self_loc = (rbs_loc) {
.buffer = other_loc->buffer,
.rg = other_loc->rg,
.children = NULL,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not technically necessary, but IMO explicit+clear > implicit+terse

@amomchilov amomchilov mentioned this pull request Dec 6, 2024
7 tasks
Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

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

🙏

@soutaro soutaro added this pull request to the merge queue Dec 9, 2024
@soutaro soutaro added this to the RBS 3.8 milestone Dec 9, 2024
Merged via the queue into ruby:master with commit b18a54d Dec 9, 2024
18 checks passed
@soutaro soutaro added the Released PRs already included in the released version label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Released PRs already included in the released version
Development

Successfully merging this pull request may close these issues.

None yet

2 participants