Skip to content

Adjust source formatting - #29383

Closed
levitte wants to merge 7 commits into
openssl:masterfrom
levitte:adjust-formatting
Closed

levitte wants to merge 7 commits into
openssl:masterfrom
levitte:adjust-formatting

Conversation

@levitte

@levitte levitte commented Dec 12, 2025

Copy link
Copy Markdown
Member

When reformatting the source, a few spots were missed.

Furthermore, a few more StatementMacros are needed, and reformatting
following that became a bit less trippy.

Finally, OpenSSL has a huge number of typedefs that clang-format had
no information about. Also, some types were macros, which makes them
hard to find, so they are converted to proper typedefs. With all this
added to .clang-format, another reformat results in more trippiness
being made less trippy.

For some reason, source reformatting didn't catch everything.
This resulted in an adjustment of reformatting that is a bit less trippy
in some places.
I looked for them with the following grep pipe, and then read through
the output to discern what are actual type definitions, and converted
what I found manually.

    git grep -En -e '#define [a-zA-Z_0-9]+ ' -- '*.h' \
        | sed -e 's|//.*||' -e 's|/\*.*\*/||g' \
        | grep -Ev ' ([0-9]|.*".*|.*\\$)'
@github-actions github-actions Bot added the severity: fips change The pull request changes FIPS provider sources label Dec 12, 2025
@paulidale

Copy link
Copy Markdown
Contributor

To me this highlights the premature application of the enforced source formatting 😞

@t8m

t8m commented Dec 15, 2025

Copy link
Copy Markdown
Member

In general this should be backported to all the active branches except for the define -> typedef changes in public headers. Those have to stay as defines in stable branches.

@t8m t8m added branch: master Applies to master branch triaged: bug The issue/pr is/fixes a bug branch: 3.0 Applies to openssl-3.0 branch (EOL) tests: exempted The PR is exempt from requirements for testing branch: 3.3 Applies to openssl-3.3 (EOL) branch: 3.4 Applies to openssl-3.4 (EOL) branch: 3.5 Applies to openssl-3.5 branch: 3.6 Applies to openssl-3.6 (EOL) labels Dec 15, 2025
@levitte
levitte marked this pull request as ready for review December 15, 2025 19:46
@levitte levitte added the approval: review pending This pull request needs review by a committer label Dec 15, 2025
@levitte

levitte commented Dec 15, 2025

Copy link
Copy Markdown
Member Author

Made this ready for review

t8m
t8m previously approved these changes Dec 15, 2025
Comment thread crypto/x509/x_pubkey.c Resolved
This was done by calling a script I made on the spot:

    bash add-types-to-clang-format > .clang-format.new && mv .clang-format.new .clang-format

This is what that script looked like:

    #! /bin/bash

    sed -ne '1,/^CommentPragmas:/p' < .clang-format

    cat <<_____
    # OpenSSL uses typedefs extensively. Tell clang-format about them.
    TypeNames:
    _____

    include_re=$(yq -r '.repos.[].hooks.[] | select(.id == "clang-format") | .files' < .pre-commit-config.yaml)
    include_dirs=( apps crypto include providers ssl )
    git ls-files "${include_dirs[@]}" \
        | grep -E $include_re \
        | xargs ctags -f - \
        | awk -F "\t" -- '$2 ~ /\.h/ && $4 == "t" { printf "  - \"%s\"\n", $1 }' \
        | sort \
        | uniq

    cat <<_____
      # The following types are macros, and need to remain that way, unfortunately
      - "HASH_CTX"
      - "HASH_LONG"
      - "MD32_REG_T"
    _____

    sed -ne '/^# OpenSSL uses macros extensively/,$p' < .clang-format
This resulted in some source reformatting becoming a bit less trippy

This is the script I used to run clang-format appropriately enough:

    #! /bin/bash

    include_re=$(yq -r '.repos.[].hooks.[] | select(.id == "clang-format") | .files' < .pre-commit-config.yaml)
    known_generated=( crypto/bn/bn_prime.h
                      crypto/objects/obj_dat.h
                      crypto/objects/obj_xref.h
                      include/openssl/obj_mac.h
                      crypto/conf/conf_def.h
                      crypto/asn1/charmap.h
                      '*_err.c'
                      '*err.h' )

    exclusions=()
    for g in "${known_generated[@]}"; do
        # Convert pattern to a regex
        g=${g//\./\\.}
        g=${g//\*/.\*}
        exclusions+=( "^${g}\$" )
    done
    # Join all exclusions into one regex
    exclude_re=$(IFS='|'; echo "${exclusions[*]}")

    (set -x; git ls-files | grep -E $include_re | grep -Ev $exclude_re | xargs clang-format -i)
@levitte

levitte commented Dec 16, 2025

Copy link
Copy Markdown
Member Author

I found a couple of more things, so included them too. This PR needs another review

@levitte

levitte commented Dec 16, 2025

Copy link
Copy Markdown
Member Author

In general this should be backported to all the active branches except for the define -> typedef changes in public headers. Those have to stay as defines in stable branches.

Yeah, it also seems like I must make a separate PR for those branches

websurfer5 pushed a commit to websurfer5/openssl that referenced this pull request Dec 23, 2025
Reviewed-by: Paul Yang <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
(Merged from openssl#29383)
websurfer5 pushed a commit to websurfer5/openssl that referenced this pull request Dec 23, 2025
Reviewed-by: Paul Yang <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
(Merged from openssl#29383)
websurfer5 pushed a commit to websurfer5/openssl that referenced this pull request Dec 29, 2025
For some reason, source reformatting didn't catch everything.

Reviewed-by: Paul Yang <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
(Merged from openssl#29383)
websurfer5 pushed a commit to websurfer5/openssl that referenced this pull request Dec 29, 2025
This resulted in an adjustment of reformatting that is a bit less trippy
in some places.

Reviewed-by: Paul Yang <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
(Merged from openssl#29383)
websurfer5 pushed a commit to websurfer5/openssl that referenced this pull request Dec 29, 2025
I looked for them with the following grep pipe, and then read through
the output to discern what are actual type definitions, and converted
what I found manually.

    git grep -En -e '#define [a-zA-Z_0-9]+ ' -- '*.h' \
        | sed -e 's|//.*||' -e 's|/\*.*\*/||g' \
        | grep -Ev ' ([0-9]|.*".*|.*\\$)'

Reviewed-by: Paul Yang <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
(Merged from openssl#29383)
websurfer5 pushed a commit to websurfer5/openssl that referenced this pull request Dec 29, 2025
This was done by calling a script I made on the spot:

    bash add-types-to-clang-format > .clang-format.new && mv .clang-format.new .clang-format

This is what that script looked like:

    #! /bin/bash

    sed -ne '1,/^CommentPragmas:/p' < .clang-format

    cat <<_____
    # OpenSSL uses typedefs extensively. Tell clang-format about them.
    TypeNames:
    _____

    include_re=$(yq -r '.repos.[].hooks.[] | select(.id == "clang-format") | .files' < .pre-commit-config.yaml)
    include_dirs=( apps crypto include providers ssl )
    git ls-files "${include_dirs[@]}" \
        | grep -E $include_re \
        | xargs ctags -f - \
        | awk -F "\t" -- '$2 ~ /\.h/ && $4 == "t" { printf "  - \"%s\"\n", $1 }' \
        | sort \
        | uniq

    cat <<_____
      # The following types are macros, and need to remain that way, unfortunately
      - "HASH_CTX"
      - "HASH_LONG"
      - "MD32_REG_T"
    _____

    sed -ne '/^# OpenSSL uses macros extensively/,$p' < .clang-format

Reviewed-by: Paul Yang <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
(Merged from openssl#29383)
websurfer5 pushed a commit to websurfer5/openssl that referenced this pull request Dec 29, 2025
This resulted in some source reformatting becoming a bit less trippy

This is the script I used to run clang-format appropriately enough:

    #! /bin/bash

    include_re=$(yq -r '.repos.[].hooks.[] | select(.id == "clang-format") | .files' < .pre-commit-config.yaml)
    known_generated=( crypto/bn/bn_prime.h
                      crypto/objects/obj_dat.h
                      crypto/objects/obj_xref.h
                      include/openssl/obj_mac.h
                      crypto/conf/conf_def.h
                      crypto/asn1/charmap.h
                      '*_err.c'
                      '*err.h' )

    exclusions=()
    for g in "${known_generated[@]}"; do
        # Convert pattern to a regex
        g=${g//\./\\.}
        g=${g//\*/.\*}
        exclusions+=( "^${g}\$" )
    done
    # Join all exclusions into one regex
    exclude_re=$(IFS='|'; echo "${exclusions[*]}")

    (set -x; git ls-files | grep -E $include_re | grep -Ev $exclude_re | xargs clang-format -i)

Reviewed-by: Paul Yang <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
(Merged from openssl#29383)
websurfer5 pushed a commit to websurfer5/openssl that referenced this pull request Dec 29, 2025
Reviewed-by: Paul Yang <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
(Merged from openssl#29383)
websurfer5 pushed a commit to websurfer5/openssl that referenced this pull request Dec 29, 2025
Reviewed-by: Paul Yang <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
(Merged from openssl#29383)
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
This resulted in an adjustment of reformatting that is a bit less trippy
in some places.

Original-PR: openssl#29383
Original-Commit: 821b265 "Add a few more ASN.1 related StatementMacros"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
This was done by calling a script I made on the spot:

    bash add-types-to-clang-format > .clang-format.new && mv .clang-format.new .clang-format

This is what that script looked like:

    #! /bin/bash

    sed -ne '1,/^CommentPragmas:/p' < .clang-format

    cat <<_____
    # OpenSSL uses typedefs extensively. Tell clang-format about them.
    TypeNames:
    _____

    include_re=$(yq -r '.repos.[].hooks.[] | select(.id == "clang-format") | .files' < .pre-commit-config.yaml)
    include_dirs=( apps crypto include providers ssl )
    git ls-files "${include_dirs[@]}" \
        | grep -E $include_re \
        | xargs ctags -f - \
        | awk -F "\t" -- '$2 ~ /\.h/ && $4 == "t" { printf "  - \"%s\"\n", $1 }' \
        | sort \
        | uniq

    cat <<_____
      # The following types are macros, and need to remain that way, unfortunately
      - "HASH_CTX"
      - "HASH_LONG"
      - "MD32_REG_T"
    _____

    sed -ne '/^# OpenSSL uses macros extensively/,$p' < .clang-format

Original-PR: openssl#29383
Original-Commit: aa9defa "Dump all known typedefs into .clang-format"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
Original-PR: openssl#29383
Original-Commit: 16fa01b "Add a couple of DH related StatementMacros, and adjust"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
This resulted in an adjustment of reformatting that is a bit less trippy
in some places.

Original-PR: openssl#29383
Original-Commit: 821b265 "Add a few more ASN.1 related StatementMacros"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
This was done by calling a script I made on the spot:

    bash add-types-to-clang-format > .clang-format.new && mv .clang-format.new .clang-format

This is what that script looked like:

    #! /bin/bash

    sed -ne '1,/^CommentPragmas:/p' < .clang-format

    cat <<_____
    # OpenSSL uses typedefs extensively. Tell clang-format about them.
    TypeNames:
    _____

    include_re=$(yq -r '.repos.[].hooks.[] | select(.id == "clang-format") | .files' < .pre-commit-config.yaml)
    include_dirs=( apps crypto include providers ssl )
    git ls-files "${include_dirs[@]}" \
        | grep -E $include_re \
        | xargs ctags -f - \
        | awk -F "\t" -- '$2 ~ /\.h/ && $4 == "t" { printf "  - \"%s\"\n", $1 }' \
        | sort \
        | uniq

    cat <<_____
      # The following types are macros, and need to remain that way, unfortunately
      - "HASH_CTX"
      - "HASH_LONG"
      - "MD32_REG_T"
    _____

    sed -ne '/^# OpenSSL uses macros extensively/,$p' < .clang-format

Original-PR: openssl#29383
Original-Commit: aa9defa "Dump all known typedefs into .clang-format"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
Original-PR: openssl#29383
Original-Commit: 16fa01b "Add a couple of DH related StatementMacros, and adjust"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
This resulted in an adjustment of reformatting that is a bit less trippy
in some places.

Original-PR: openssl#29383
Original-Commit: 821b265 "Add a few more ASN.1 related StatementMacros"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
This was done by calling a script I made on the spot:

    bash add-types-to-clang-format > .clang-format.new && mv .clang-format.new .clang-format

This is what that script looked like:

    #! /bin/bash

    sed -ne '1,/^CommentPragmas:/p' < .clang-format

    cat <<_____
    # OpenSSL uses typedefs extensively. Tell clang-format about them.
    TypeNames:
    _____

    include_re=$(yq -r '.repos.[].hooks.[] | select(.id == "clang-format") | .files' < .pre-commit-config.yaml)
    include_dirs=( apps crypto include providers ssl )
    git ls-files "${include_dirs[@]}" \
        | grep -E $include_re \
        | xargs ctags -f - \
        | awk -F "\t" -- '$2 ~ /\.h/ && $4 == "t" { printf "  - \"%s\"\n", $1 }' \
        | sort \
        | uniq

    cat <<_____
      # The following types are macros, and need to remain that way, unfortunately
      - "HASH_CTX"
      - "HASH_LONG"
      - "MD32_REG_T"
    _____

    sed -ne '/^# OpenSSL uses macros extensively/,$p' < .clang-format

Original-PR: openssl#29383
Original-Commit: aa9defa "Dump all known typedefs into .clang-format"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
Original-PR: openssl#29383
Original-Commit: 16fa01b "Add a couple of DH related StatementMacros, and adjust"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
This resulted in an adjustment of reformatting that is a bit less trippy
in some places.

Original-PR: openssl#29383
Original-Commit: 821b265 "Add a few more ASN.1 related StatementMacros"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
This was done by calling a script I made on the spot:

    bash add-types-to-clang-format > .clang-format.new && mv .clang-format.new .clang-format

This is what that script looked like:

    #! /bin/bash

    sed -ne '1,/^CommentPragmas:/p' < .clang-format

    cat <<_____
    # OpenSSL uses typedefs extensively. Tell clang-format about them.
    TypeNames:
    _____

    include_re=$(yq -r '.repos.[].hooks.[] | select(.id == "clang-format") | .files' < .pre-commit-config.yaml)
    include_dirs=( apps crypto include providers ssl )
    git ls-files "${include_dirs[@]}" \
        | grep -E $include_re \
        | xargs ctags -f - \
        | awk -F "\t" -- '$2 ~ /\.h/ && $4 == "t" { printf "  - \"%s\"\n", $1 }' \
        | sort \
        | uniq

    cat <<_____
      # The following types are macros, and need to remain that way, unfortunately
      - "HASH_CTX"
      - "HASH_LONG"
      - "MD32_REG_T"
    _____

    sed -ne '/^# OpenSSL uses macros extensively/,$p' < .clang-format

Original-PR: openssl#29383
Original-Commit: aa9defa "Dump all known typedefs into .clang-format"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
Original-PR: openssl#29383
Original-Commit: 16fa01b "Add a couple of DH related StatementMacros, and adjust"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
This resulted in an adjustment of reformatting that is a bit less trippy
in some places.

Original-PR: openssl#29383
Original-Commit: 821b265 "Add a few more ASN.1 related StatementMacros"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
This was done by calling a script I made on the spot:

    bash add-types-to-clang-format > .clang-format.new && mv .clang-format.new .clang-format

This is what that script looked like:

    #! /bin/bash

    sed -ne '1,/^CommentPragmas:/p' < .clang-format

    cat <<_____
    # OpenSSL uses typedefs extensively. Tell clang-format about them.
    TypeNames:
    _____

    include_re=$(yq -r '.repos.[].hooks.[] | select(.id == "clang-format") | .files' < .pre-commit-config.yaml)
    include_dirs=( apps crypto include providers ssl )
    git ls-files "${include_dirs[@]}" \
        | grep -E $include_re \
        | xargs ctags -f - \
        | awk -F "\t" -- '$2 ~ /\.h/ && $4 == "t" { printf "  - \"%s\"\n", $1 }' \
        | sort \
        | uniq

    cat <<_____
      # The following types are macros, and need to remain that way, unfortunately
      - "HASH_CTX"
      - "HASH_LONG"
      - "MD32_REG_T"
    _____

    sed -ne '/^# OpenSSL uses macros extensively/,$p' < .clang-format

Original-PR: openssl#29383
Original-Commit: aa9defa "Dump all known typedefs into .clang-format"
esyr pushed a commit to esyr/openssl that referenced this pull request Apr 1, 2026
Original-PR: openssl#29383
Original-Commit: 16fa01b "Add a couple of DH related StatementMacros, and adjust"
openssl-machine pushed a commit that referenced this pull request Apr 3, 2026
This resulted in an adjustment of reformatting that is a bit less trippy
in some places.

Original-PR: #29383
Original-Commit: 821b265 "Add a few more ASN.1 related StatementMacros"

Reviewed-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Fri Apr  3 14:48:52 2026
(Merged from #29822)
openssl-machine pushed a commit that referenced this pull request Apr 3, 2026
This was done by calling a script I made on the spot:

    bash add-types-to-clang-format > .clang-format.new && mv .clang-format.new .clang-format

This is what that script looked like:

    #! /bin/bash

    sed -ne '1,/^CommentPragmas:/p' < .clang-format

    cat <<_____
    # OpenSSL uses typedefs extensively. Tell clang-format about them.
    TypeNames:
    _____

    include_re=$(yq -r '.repos.[].hooks.[] | select(.id == "clang-format") | .files' < .pre-commit-config.yaml)
    include_dirs=( apps crypto include providers ssl )
    git ls-files "${include_dirs[@]}" \
        | grep -E $include_re \
        | xargs ctags -f - \
        | awk -F "\t" -- '$2 ~ /\.h/ && $4 == "t" { printf "  - \"%s\"\n", $1 }' \
        | sort \
        | uniq

    cat <<_____
      # The following types are macros, and need to remain that way, unfortunately
      - "HASH_CTX"
      - "HASH_LONG"
      - "MD32_REG_T"
    _____

    sed -ne '/^# OpenSSL uses macros extensively/,$p' < .clang-format

Original-PR: #29383
Original-Commit: aa9defa "Dump all known typedefs into .clang-format"

Reviewed-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Fri Apr  3 14:48:54 2026
(Merged from #29822)
openssl-machine pushed a commit that referenced this pull request Apr 3, 2026
Original-PR: #29383
Original-Commit: 16fa01b "Add a couple of DH related StatementMacros, and adjust"

Reviewed-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Fri Apr  3 14:48:55 2026
(Merged from #29822)
openssl-machine pushed a commit that referenced this pull request Apr 3, 2026
This resulted in an adjustment of reformatting that is a bit less trippy
in some places.

Original-PR: #29383
Original-Commit: 821b265 "Add a few more ASN.1 related StatementMacros"

Reviewed-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Fri Apr  3 14:47:51 2026
(Merged from #29821)
openssl-machine pushed a commit that referenced this pull request Apr 3, 2026
This was done by calling a script I made on the spot:

    bash add-types-to-clang-format > .clang-format.new && mv .clang-format.new .clang-format

This is what that script looked like:

    #! /bin/bash

    sed -ne '1,/^CommentPragmas:/p' < .clang-format

    cat <<_____
    # OpenSSL uses typedefs extensively. Tell clang-format about them.
    TypeNames:
    _____

    include_re=$(yq -r '.repos.[].hooks.[] | select(.id == "clang-format") | .files' < .pre-commit-config.yaml)
    include_dirs=( apps crypto include providers ssl )
    git ls-files "${include_dirs[@]}" \
        | grep -E $include_re \
        | xargs ctags -f - \
        | awk -F "\t" -- '$2 ~ /\.h/ && $4 == "t" { printf "  - \"%s\"\n", $1 }' \
        | sort \
        | uniq

    cat <<_____
      # The following types are macros, and need to remain that way, unfortunately
      - "HASH_CTX"
      - "HASH_LONG"
      - "MD32_REG_T"
    _____

    sed -ne '/^# OpenSSL uses macros extensively/,$p' < .clang-format

Original-PR: #29383
Original-Commit: aa9defa "Dump all known typedefs into .clang-format"

Reviewed-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Fri Apr  3 14:47:52 2026
(Merged from #29821)
openssl-machine pushed a commit that referenced this pull request Apr 3, 2026
Original-PR: #29383
Original-Commit: 16fa01b "Add a couple of DH related StatementMacros, and adjust"

Reviewed-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
MergeDate: Fri Apr  3 14:47:53 2026
(Merged from #29821)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch branch: 3.0 Applies to openssl-3.0 branch (EOL) branch: 3.3 Applies to openssl-3.3 (EOL) branch: 3.4 Applies to openssl-3.4 (EOL) branch: 3.5 Applies to openssl-3.5 branch: 3.6 Applies to openssl-3.6 (EOL) severity: fips change The pull request changes FIPS provider sources tests: exempted The PR is exempt from requirements for testing triaged: bug The issue/pr is/fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants