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

Formatted C files #416

Merged
merged 2 commits into from
Jun 26, 2017
Merged

Formatted C files #416

merged 2 commits into from
Jun 26, 2017

Conversation

Richard-Degenne
Copy link
Contributor

This PR is a continuation of the work started in PRs #400 and #409 about issue #393.

I added a .clang-format file enforcing Google-style formatting for C files. I also applied this style to Lwt's C codebase.

Overall, I'm happy with the way the files were indented, even if I find the 80-column limit too strict sometimes (example).

clang-format has quite a lot of options and if you have remarks on what the files look like, please go ahead, I should be able to find the right configuration. :)

@aantron
Copy link
Collaborator

aantron commented Jun 23, 2017

Thanks for looking into this!

I haven't reviewed it in any detail yet, but from the CI, it looks like clang-format may have been a little lossy :(

@Richard-Degenne
Copy link
Contributor Author

I ran the tests on my machine and had no errors. I'll look into it.

@Richard-Degenne
Copy link
Contributor Author

Nailed it. I think I messed with lwt_unix_stubs.c when browsing it. 🤦‍♂️

@aantron
Copy link
Collaborator

aantron commented Jun 23, 2017

😱 <- that should be a reaction option :)

@aantron
Copy link
Collaborator

aantron commented Jun 24, 2017

It looks pretty good.

clang-format has quite a lot of options and if you have remarks on what the files look like, please go ahead, I should be able to find the right configuration. :)

Two things jump out:

  • I think switching to 4-space indentation would be nice, as this is (or was?) a typical standard for C.
  • It would be good to leave the curly braces on function headers (only) alone as they are now, i.e. on new lines.

@aantron
Copy link
Collaborator

aantron commented Jun 26, 2017

Thanks for adjusting the rules. The C files look a lot better than their state before this PR, IMO.

I believe two things remain:

  • Apply the formatting to our .h files:
    ./src/unix/lwt_unix.h
    ./src/unix/lwt_unix_unix.h
    ./src/unix/lwt_unix_windows.h
    
  • Squash this history down a bit. The main goal is to avoid doing two large whitespace changes back-to-back to the same files, since we really mean for it to be one. The original history (one commit to introduce .clang-format and one to apply the changes) is good, or any other history that achieves the goal. I can do this boring stuff, let me know if you'd like me to.

#include <caml/socketaddr.h>
#include <caml/unixsupport.h>
#include <lwt_config.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Argh, this build failure suggests that either caml/unixsupport.h or lwt_config.h has to manually be moved above caml/socketaddr.h. This is an upstream issue due to one of the headers not including the other one internally, but we have to work around it :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A trick is to have separate "paragraphs", clang-format will order includes by-paragraph. I've amended the commit. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks, I'm learning :)

@aantron aantron merged commit 2799cc1 into ocsigen:master Jun 26, 2017
@aantron
Copy link
Collaborator

aantron commented Jun 26, 2017

Much appreciated. I find these files much easier to read now, hopefully others will too.

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