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

Make gr context objects const #2217

Open
fredrik-johansson opened this issue Jan 29, 2025 · 0 comments
Open

Make gr context objects const #2217

fredrik-johansson opened this issue Jan 29, 2025 · 0 comments

Comments

@fredrik-johansson
Copy link
Collaborator

Currently throughout the gr modules gr_ctx_t is not marked as const. The reason is that some contexts store data that is expected to mutate during computations, notably Calcium. There are also other contexts where it would make sense to implement various caching mechanisms in the future.

However, we could make the gr_ctx_t itself const and require that mutable caches be located in separate memory which is only pointed to by the gr_ctx_t (C allows this for const structures).

Now, some contexts do have mutable inline data, e.g. precisions. I think to be clean only the scope that owns a context object should be allowed to mutate such data. This means that if one wants to change the precision locally, one would need to do something like

my_function(const gr_ctx_t ctx)
{
    gr_ctx_t my_ctx;

    gr_ctx_init_set(my_ctx, ctx);   // or set_shallow?
    gr_ctx_set_real_prec(my_ctx, 1000);
    ...
}

That makes sense for thread safety, anyway.

Also, maybe the method table pointer in the gr_ctx_t should be declared as const * const. I'm not sure if this would allow the compiler to omit some repeated dereferences.

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

No branches or pull requests

1 participant