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

Quiets most const warnings in the fractal heap code #1188

Merged
merged 1 commit into from
Nov 13, 2021

Conversation

derobins
Copy link
Member

@derobins derobins commented Nov 11, 2021

The biggest problem here is the 'generic operation' scheme that combines a const void pointer to arbitrary data + a callback that can sometimes modify said arbitrary data, thus undermining the const-ness in certain cases. Since nobody is going to rearchitect this scheme anytime soon, I've at least quieted the warnings that we know are not a problem since the "sometimes const" pointers won't be modified when they point to const data given the existing code.

In case anyone is wondering, making the operation callbacks simply take a non-const pointer is a bit like pulling on the loose yarn in a sweater. I started going down this road, but I think this is a more minimalist and cleaner solution for now.

I left the file pointer const warnings in the cache client code alone. That's a can of worms I'm unwilling to touch at this time and I also don't want to just glibly turn off the cast warnings.

if (H5HF__man_op_real(hdr, id, H5HF__op_write, (void *)obj, H5HF_OP_MODIFY) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTOPERATE, FAIL, "unable to operate on heap object")
H5_GCC_CLANG_DIAG_ON("cast-qual")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is quite a wordy way to de-const a pointer.

Other C projects de-const pointers without making the compiler warn by using a macro or function that casts through uintptr_t. Something like this should do the trick,

static inline void *
deconst(const void *p)
{
    return (void *)(uintptr_t)p;
}

The H5HF__man_op_real() call would turn to H5HF__man_op_real(hdr, id, H5HF__op_write, deconst(obj), H5HF_OP_MODIFY).

@lrknox lrknox merged commit d224f98 into HDFGroup:develop Nov 13, 2021
@derobins derobins deleted the dev/fractal_heap_const branch April 14, 2022 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants