Skip to content

Refactor definition of ZEND_MM_ALIGNMENT #6981

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
Apr 1, 2022

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented May 13, 2021

Currently ZEND_MM_ALIGNMENT might get defined during config,
in which case it is an 'int' and not a 'zend_ulong'.

This fixes many [-Wsign-conversion] warnings.

Co-authored-by: Guillaume Charifi [email protected]

@Girgias Girgias force-pushed the confix-zend-mm-alginment branch from b48a9b8 to 2f287cc Compare May 13, 2021 21:41
# define ZEND_MM_ALIGNMENT_LOG2 Z_UL(2)
#else
# define ZEND_MM_ALIGNMENT Z_UL(CONFIG_ZEND_MM_ALIGNMENT)
# define ZEND_MM_ALIGNMENT_LOG2 Z_UL(CONFIG_ZEND_MM_ALIGNMENT_LOG2)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't these be of type size_t rather than zend_ulong?

Copy link
Member Author

Choose a reason for hiding this comment

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

They probably should, but ZEND_MM_ALIGNMENT_LOG2 seemed to be used with hashkeys which are zend_ulong, I'll look some more into this.

@Girgias Girgias force-pushed the confix-zend-mm-alginment branch 2 times, most recently from 9283962 to 844d6b9 Compare May 14, 2021 16:58
@Girgias Girgias requested a review from nikic May 17, 2021 08:31
# define ZEND_MM_ALIGNMENT_LOG2 Z_L(3)
#ifndef CONFIG_ZEND_MM_ALIGNMENT
# define ZEND_MM_ALIGNMENT (size_t)8
# define ZEND_MM_ALIGNMENT_LOG2 (size_t)3
#elif ZEND_MM_ALIGNMENT < 4
Copy link
Member

Choose a reason for hiding this comment

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

This check should be checking for CONFIG_ZEND_MM_ALIGNMENT.

Overall, I don't really like this change. configure should always determine an alignment (there is even a fallback for cross-compiling). I believe ZEND_MM_ALIGNMENT is currently only not defined on windows, where we should define it in config.w32.h.in.

I think we would be better off moving the check for alignment < 4 into

int i = ZEND_MM_ALIGNMENT;
and add u suffixes to
fprintf(fp, "%d %d\n", ZEND_MM_ALIGNMENT, zeros);
and drop the code here entirely.

Copy link
Member

Choose a reason for hiding this comment

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

Gah, it looks like just adding u will make ZEND_MM_ALIGNED_SIZE incorrect. It works right now because ZEND_MM_ALIGNMENT_MASK is a signed integer, so the mask is signed extended. It wouldn't work for an unsigned integer. So looks like that does need to be size_t specifically if we switch it to unsigned.

Copy link
Member Author

Choose a reason for hiding this comment

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

ACK, I'll look into making the changes in config and dropping this.

Also add a new ZEND_MM_NEED_EIGHT_BYTE_REALIGNMENT definition.

This fixes many [-Wsign-conversion] warnings.

Co-authored-by: Guillaume Charifi <[email protected]>
@Girgias Girgias force-pushed the confix-zend-mm-alginment branch from d33241d to 6774266 Compare April 1, 2022 11:35
Co-authored-by: Bob Weinand <[email protected]>
@Girgias Girgias merged commit 2c2ecba into php:master Apr 1, 2022
@Girgias Girgias deleted the confix-zend-mm-alginment branch April 1, 2022 14:43
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.

4 participants