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

Improve const-correctness in C code #545

Merged
merged 2 commits into from
May 6, 2024

Conversation

musicinmybrain
Copy link
Contributor

The commit “Do not cast the result of PyArray_DATA()” is in this PR because it touches most of the same lines that needed to be touched to fix const-related warnings.

I’d like to suggest that a broader change to stop explicitly casting void * return values could make sense; I claim that they add clutter and repetition but don’t reduce errors. They are not required because void * happily converts implicitly to any data pointer type (in C, not C++). Such a change would affect at least malloc(), calloc(), realloc(), and PyArray_ITER_DATA(). However, I don’t want to get that tangled up with the const-correctness changes, especially if it’s not desired.

@codecov
Copy link

codecov bot commented Oct 15, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ca70df9) 84.70% compared to head (608c6c2) 84.70%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #545   +/-   ##
=======================================
  Coverage   84.70%   84.70%           
=======================================
  Files         297      297           
  Lines       27590    27590           
  Branches     3361     3361           
=======================================
  Hits        23370    23370           
  Misses       3266     3266           
  Partials      954      954           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

My C is pretty rusty, but this looks right to me.

Since it returns void *, which is implicitly convertible to any data
pointer type, explicitly casting the result only adds clutter and
repetition.
Fixes a number of warnings.
@effigies effigies merged commit 15cc3f7 into nipy:main May 6, 2024
18 checks passed
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.

None yet

2 participants