Skip to content

zend_inheritance.c: make a bunch of pointers const #15934

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
Sep 17, 2024

Conversation

DanielEScherzer
Copy link
Member

No description provided.

@iluuu1994 iluuu1994 merged commit a3583d7 into php:master Sep 17, 2024
9 of 10 checks passed
@iluuu1994
Copy link
Member

iluuu1994 commented Sep 17, 2024

Thanks @DanielEScherzer! Before continuing this work, I think it would be good to have some consensus on how we want to continue on this matter. In reality, I don't think local const declarations are super useful, because they are mostly inferrable by the compiler. What is more useful is const declarations in exported function signatures because they (possibly?) enable some additional compiler optimizations, but they are also breaking, which is why they are avoided here.

I'm not sure where this conversation should be held. The ML is generally not a great place, because most people there aren't C developers and will still generate a lot of noise.

@iluuu1994
Copy link
Member

Maybe @cmb69 @arnaud-lb @nielsdos can pitch by sharing their opinion.

@cmb69
Copy link
Member

cmb69 commented Sep 17, 2024

In reality, I don't think local const declarations are super useful, because they are mostly inferrable by the compiler.

In my opinion, this is not only about the compiler, but also for developers reading the code. One particular issue are pointers, though. Some reading const zval *zv may assume that zv can't be reassigned, but that is not the case in C (you would need zval * const zv for this).

Even for local variable declarations either form of constness (or even both) can make sense, but I don't think it would be a good idea to go through the whole code base and change that. It might be better if this is part of some larger refactorings for particular parts of php-src; there is still a huge amount of code suffering from accidential complexity, which could be improved.

@nielsdos
Copy link
Member

I agree const is mostly for developers. In fact, I don't think the C compiler really uses the fact something is const since you can just cast it away (I think it's not allowed in C++ though).
I also don't think it's a good idea to change everything in one go.

@DanielEScherzer DanielEScherzer deleted the patch-3 branch September 18, 2024 20:12
@DanielEScherzer
Copy link
Member Author

In reality, I don't think local const declarations are super useful, because they are mostly inferrable by the compiler.

In my opinion, this is not only about the compiler, but also for developers reading the code. One particular issue are pointers, though. Some reading const zval *zv may assume that zv can't be reassigned, but that is not the case in C (you would need zval * const zv for this).

Even for local variable declarations either form of constness (or even both) can make sense, but I don't think it would be a good idea to go through the whole code base and change that. It might be better if this is part of some larger refactorings for particular parts of php-src; there is still a huge amount of code suffering from accidential complexity, which could be improved.

Sure - I like to write code, so if you want to point me to the parts that need refactoring, I'm happy to make an attempt

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.

5 participants