ares_channel -> ares_channel_t *: don't bury the pointer - #595
Conversation
ares_channel -> ares_channel_t *: don't bury the pointer
|
cf #96. fwiw I continue to maintain a fork that scatters some |
Now that I'm completely reworking the internals of c-ares to modernize the codebase, I think there is a stronger argument these days to accomplish this. Also, your fork is likely impossible to maintain due to my recent not-so-insignificant changes :) We're also scanning with sonarcloud, and I can point to that to strengthen the case: SonarCloud issues the warning based on a violation of the MISRA-C standard. I have a long-term goal of getting to zero SonarCloud reported issues (without simply marking them as false positives or won't fix). There will likely be a few instances that this isn't technically possible, but that's the goal. |
the changes in my fork are so minimal - it really is just a scattering of So while this is a +1, as in that older issue I would not ask or expect you to give that too much weight. |
ares_channelis defined astypedef struct ares_channeldata *ares_channel;. The problem with this, is it embeds the pointer into the typedef, which means anares_channelcan never be declared asconstas if you writeconst ares_channel channel, that expands tostruct ares_channeldata * const ares_channeland notconst struct ares_channeldata *channel.We will now typedef
ares_channel_tastypedef struct ares_channeldata ares_channel_t;, so if you writeconst ares_channel_t *channel, it properly expands toconst struct ares_channeldata *channel.We are maintaining the old typedef for API compatibility with existing integrations, and due to typedef expansion this should not even cause any compiler warnings for existing code. There are no ABI implications with this change. I could be convinced to keep existing public functions as
ares_channelif a sufficient argument exists, but internally we really need make this change for modern best practices.This change will allow us to internally use
const ares_channel_t *where appropriate. Whether or not we decide to change any public interfaces to useconstmay require further discussion on if there might be ABI implications (I don't think so, but I'm also not 100% sure what a compiler internally does withconstwhen emitting machine code ... I think more likely ABI implications would occur going the opposite direction).FYI, This PR was done via a combination of sed and clang-format, the only manual code change was the addition of the new typedef :)
Fix By: Brad House (@bradh352)