Skip to content
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

Add some const qualifiers in HashTable foreach macros #8671

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented May 31, 2022

I couldn't apply the const modifier to the ZEND_HASH_MAP_REVERSE_FOREACH() macro as it is sometimes ended with the ZEND_HASH_MAP_FOREACH_END_DEL() which deletes entries from the HashTable (thus clearly violating the const qualifier).

I stumbled upon this when I wanted to add a const qualifier in PECL/csv to a HashTable that I don't modify and just traverse. But the fact that ZEND_HASH_MAP_FOREACH_END_DEL() exists makes me unsure how to proceed.

@adoy adoy added this to the PHP 8.2 milestone Jun 2, 2022
@adoy adoy removed this from the PHP 8.2 milestone Feb 16, 2023
@Girgias Girgias requested a review from dstogov as a code owner October 7, 2023 13:51
@Girgias Girgias merged commit 76a773b into php:master Oct 9, 2023
@Girgias Girgias deleted the const-hash branch October 9, 2023 16:20
@nielsdos
Copy link
Member

I think this patch is wrong, I wanted to write a loop like this:

	ZEND_HASH_FOREACH_VAL(ht, zv) {
		// Do something with zval
	} ZEND_HASH_FOREACH_END_DEL();

But I can't anymore because the hash table is now const. Also the reverse version of this also doesn't work anymore.

@Girgias
Copy link
Member Author

Girgias commented Apr 21, 2024

I think this patch is wrong, I wanted to write a loop like this:

	ZEND_HASH_FOREACH_VAL(ht, zv) {
		// Do something with zval
	} ZEND_HASH_FOREACH_END_DEL();

But I can't anymore because the hash table is now const. Also the reverse version of this also doesn't work anymore.

Feel free to revert, I suppose what should be constant is the HashTable pointer, not the HashTable itself.

I do wonder if it makes sense to introduce some other, const version of it for people that want to be able to const mark their extension functions as they know they are not going to modify the HashTable.

@dstogov
Copy link
Member

dstogov commented Apr 22, 2024

I think this patch is wrong, I wanted to write a loop like this:

	ZEND_HASH_FOREACH_VAL(ht, zv) {
		// Do something with zval
	} ZEND_HASH_FOREACH_END_DEL();

But I can't anymore because the hash table is now const. Also the reverse version of this also doesn't work anymore.

I think, this never worked before.
FOREACH_END_DEL is useful only for REVERSE iteration to delete the "tail" of the hash table.

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