Skip to content

ext/pdo: Pack _pdo_dbh_t struct #17741

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
Mar 4, 2025
Merged

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Feb 8, 2025

This reduces the size from 176 to 152 bytes

* equal 32 */
unsigned _reserved_flags:14;
/* bitmap for pdo_param_event(s) to skip in dispatch_param_event */
uint8_t skip_param_evt;
Copy link
Member Author

Choose a reason for hiding this comment

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

Annoyingly, being able to specify the size of a C enum is a C23 feature, otherwise we could just use pdo_param_event here.

@Girgias Girgias force-pushed the pdo-dbh_struct-pack branch from beffcfc to 8fb42f4 Compare February 8, 2025 21:22
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

I'm not a big fan of converting enums to plain old integers for the sake of packing them in a bitfield. It's more error-prone, and reading from a bitfield is also slower than just reading an enum/integer.

@Girgias Girgias force-pushed the pdo-dbh_struct-pack branch from 8fb42f4 to 2a649c3 Compare February 10, 2025 12:37
@Girgias Girgias requested a review from nielsdos February 10, 2025 12:37
unsigned int refcount;

uint32_t refcount;
uint32_t __reserved_padding;
Copy link
Member

Choose a reason for hiding this comment

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

Don't do this. Also: never use names starting with underscores as they're generally reserved.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW: with "don't do this" I meant adding explicit padding fields

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I understood this, just forgot to get round to this again :)

Girgias added 2 commits March 4, 2025 14:27
This reduces the size from 176 to 152 bytes
@Girgias Girgias force-pushed the pdo-dbh_struct-pack branch from 2a649c3 to cd4f2df Compare March 4, 2025 14:30
@Girgias Girgias requested a review from nielsdos March 4, 2025 14:30
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

On the one hand, I don't like "demoting" the enums to numbers, On the other hand in C there's not really a difference anyway. I guess this is fine.

@Girgias Girgias merged commit fe8d39a into php:master Mar 4, 2025
9 checks passed
@Girgias Girgias deleted the pdo-dbh_struct-pack branch March 4, 2025 22:10
@Girgias
Copy link
Member Author

Girgias commented Mar 4, 2025

C23 would come in handy here with being able to specify the backing type of the enum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants