Conversation
apps/asn1parse.c
Outdated
| }; | ||
|
|
||
| static int do_generate(char *genstr, const char *genconf, BUF_MEM *buf); | ||
| static int do_generate(char* genstr, const char* genconf, BUF_MEM* buf); |
There was a problem hiding this comment.
Is the intention really to reformat the * in all pointer declarations?
There was a problem hiding this comment.
'When declaring pointer data or a function that returns a pointer type, the asterisk goes next to the data or function name, and not the type:'
There was a problem hiding this comment.
I know that's what's currently written. I was wondering if a change was coming or this was an omission of some kind.
There was a problem hiding this comment.
This appears to be part of the webkit format.
There was a problem hiding this comment.
I dont think we should be changing this regardless of what a tool decides to do.
There was a problem hiding this comment.
It turns out that clang-format does this because it assumes C++. If you read the webkit code style guidelines, you can see that this particular detail differs depending on if the language is C or C++
| { "offset", OPT_OFFSET, 'p', "offset into file" }, | ||
| { "length", OPT_LENGTH, 'p', "length of section in file" }, | ||
| { "strparse", OPT_STRPARSE, 'p', | ||
| "offset; a series of these can be used to 'dig'" }, |
There was a problem hiding this comment.
This indenting seems off? Why does it not align with the previous line "
There was a problem hiding this comment.
I suppose the webkit format is pretty strict with the 4 space indents...
| case OPT_EOF: | ||
| case OPT_ERR: | ||
| opthelp: | ||
| opthelp: |
There was a problem hiding this comment.
Should we be doing this indenting with labels?
There was a problem hiding this comment.
Actually, this one make complete sense to me.
apps/asn1parse.c
Outdated
| } | ||
| str = (unsigned char *)buf->data; | ||
|
|
||
| str = (unsigned char*)buf->data; |
There was a problem hiding this comment.
I dont think this space should be removed.
| if (do_ver) { | ||
| if ((store = setup_verify(CAfile, noCAfile, CApath, noCApath, | ||
| CAstore, noCAstore)) == NULL) | ||
| CAstore, noCAstore)) |
There was a problem hiding this comment.
Is this indenting less readable?
slontis
left a comment
There was a problem hiding this comment.
There probably needs to be a consensus before these changes are merged
| # OpenSSL Style Guide | ||
|
|
||
| OpenSSL usually follows the | ||
| [Linux kernel coding style](https://www.kernel.org/doc/html/next/process/coding-style.html#codingstyle) | ||
| The rest of this document describes differences and clarifications on | ||
| top of the base guide. | ||
|
|
There was a problem hiding this comment.
Well... with that .clang-format, none of this is true, is it?
There was a problem hiding this comment.
Yes, that needs to be fixed.
| const char *key; /* the name of the parameter */ | ||
| unsigned int data_type; /* declare what kind of content is in buffer */ | ||
| void *data; /* value being passed in or out */ | ||
| size_t data_size; /* data size */ | ||
| size_t return_size; /* returned content size */ | ||
| const char* key; /* the name of the parameter */ | ||
| unsigned int data_type; /* declare what kind of content is in buffer */ | ||
| void* data; /* value being passed in or out */ | ||
| size_t data_size; /* data size */ | ||
| size_t return_size; /* returned content size */ |
There was a problem hiding this comment.
If there's one thing that really makes me sad, it's this move of after-statement comments to be flush against the statement they follow. That doesn't help readability.
There was a problem hiding this comment.
That being said, this is stipulated by the webkit style guidelines, so...
|
A note on this effort re pointer declarations: WebKit style makes a difference between C and C++: https://webkit.org/code-style-guidelines/#pointers-non-cpp clang-format, if not told otherwise, will assume C++ over C, and that's the reason we get all those I've tried adding I tried that on one file on top of this PR, here's the diff: diff --git a/.clang-format b/.clang-format
index 2413d23d1d..a668fac4dd 100644
--- a/.clang-format
+++ b/.clang-format
@@ -4,6 +4,9 @@ BasedOnStyle: WebKit
#
# OpenSSL Customizations start here.
#
+# It's important to specify the main language (hmm, "C" unknown???)
+#Language: C
+PointerAlignment: Right
# we add matches for /** and /*- at the top
# of a comment block to protect comments as
# per STYLE.md
diff --git a/apps/asn1parse.c b/apps/asn1parse.c
index c277b36ba3..fbd9d7c334 100644
--- a/apps/asn1parse.c
+++ b/apps/asn1parse.c
@@ -67,26 +67,26 @@ const OPTIONS asn1parse_options[] = {
{ NULL }
};
-static int do_generate(char* genstr, const char* genconf, BUF_MEM* buf);
+static int do_generate(char *genstr, const char *genconf, BUF_MEM *buf);
-int asn1parse_main(int argc, char** argv)
+int asn1parse_main(int argc, char **argv)
{
- ASN1_TYPE* at = NULL;
+ ASN1_TYPE *at = NULL;
BIO *in = NULL, *b64 = NULL, *derout = NULL;
- BUF_MEM* buf = NULL;
- STACK_OF(OPENSSL_STRING)* osk = NULL;
+ BUF_MEM *buf = NULL;
+ STACK_OF(OPENSSL_STRING) *osk = NULL;
char *genstr = NULL, *genconf = NULL;
char *infile = NULL, *oidfile = NULL, *derfile = NULL;
- unsigned char* str = NULL;
+ unsigned char *str = NULL;
char *name = NULL, *header = NULL, *prog;
- const unsigned char* ctmpbuf;
+ const unsigned char *ctmpbuf;
int indent = 0, noout = 0, dump = 0, informat = FORMAT_PEM;
int offset = 0, ret = 1, i, j;
long num, tmplen;
- unsigned char* tmpbuf;
+ unsigned char *tmpbuf;
unsigned int length = 0;
OPTION_CHOICE o;
- const ASN1_ITEM* it = NULL;
+ const ASN1_ITEM *it = NULL;
prog = opt_init(argc, argv, asn1parse_options);
@@ -196,7 +196,7 @@ int asn1parse_main(int argc, char** argv)
ERR_print_errors(bio_err);
goto end;
}
- buf->data = (char*)str;
+ buf->data = (char *)str;
buf->length = buf->max = num;
} else {
if (!BUF_MEM_grow(buf, BUFSIZ * 8))
@@ -211,7 +211,7 @@ int asn1parse_main(int argc, char** argv)
} else {
if (informat == FORMAT_BASE64) {
- BIO* tmp;
+ BIO *tmp;
if ((b64 = BIO_new(BIO_f_base64())) == NULL)
goto end;
@@ -234,7 +234,7 @@ int asn1parse_main(int argc, char** argv)
num += i;
}
}
- str = (unsigned char*)buf->data;
+ str = (unsigned char *)buf->data;
}
/* If any structs to parse go through in sequence */
@@ -243,7 +243,7 @@ int asn1parse_main(int argc, char** argv)
tmpbuf = str;
tmplen = num;
for (i = 0; i < sk_OPENSSL_STRING_num(osk); i++) {
- ASN1_TYPE* atmp;
+ ASN1_TYPE *atmp;
int typ;
j = strtol(sk_OPENSSL_STRING_value(osk, i), NULL, 0);
if (j <= 0 || j >= tmplen) {
@@ -295,10 +295,10 @@ int asn1parse_main(int argc, char** argv)
}
}
if (!noout) {
- const unsigned char* p = str + offset;
+ const unsigned char *p = str + offset;
if (it != NULL) {
- ASN1_VALUE* value = ASN1_item_d2i(NULL, &p, length, it);
+ ASN1_VALUE *value = ASN1_item_d2i(NULL, &p, length, it);
if (value == NULL) {
BIO_printf(bio_err, "Error parsing item %s\n", it->sname);
ERR_print_errors(bio_err);
@@ -328,12 +328,12 @@ end:
return ret;
}
-static int do_generate(char* genstr, const char* genconf, BUF_MEM* buf)
+static int do_generate(char *genstr, const char *genconf, BUF_MEM *buf)
{
- CONF* cnf = NULL;
+ CONF *cnf = NULL;
int len;
- unsigned char* p;
- ASN1_TYPE* atyp = NULL;
+ unsigned char *p;
+ ASN1_TYPE *atyp = NULL;
if (genconf != NULL) {
if ((cnf = app_load_config(genconf)) == NULL)
@@ -361,7 +361,7 @@ static int do_generate(char* genstr, const char* genconf, BUF_MEM* buf)
if (!BUF_MEM_grow(buf, len))
goto err;
- p = (unsigned char*)buf->data;
+ p = (unsigned char *)buf->data;
i2d_ASN1_TYPE(atyp, &p);
|
|
I checked through the rest of the WebKit code style guidelines. The pointer style was the only significant language-specific thing I could find. |
|
So, the reason that this update will include a STYLE.md file and will
include changes to this is that adopting the webkit style
means adopting the webkit style. It *will* do things differently than the
current style guide, so yes, these sorts of things *will* change.
The existing Style guide's portions on whitespace and indenting will be
superseded by webkit style as per clang-format.
…On Wed, Oct 1, 2025 at 10:42 PM Richard Levitte ***@***.***> wrote:
*levitte* left a comment (openssl/openssl#28691)
<#28691 (comment)>
I checked through the rest of the WebKit code style guidelines. The
pointer style was the only language-specific thing I could find.
—
Reply to this email directly, view it on GitHub
<#28691 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB57M5M535H334FOP3HZCAT3VSUM3AVCNFSM6AAAAACHZ4IUIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGNJZGAZTQMJYGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
@bob-beck, you might want to consider corrections for when clang-format makes the wrong choice based on assumed language (see my commentary above on that). |
|
Yes, it defaults to Cpp for everything "unknown"
…On Thu, Oct 2, 2025 at 8:37 AM Richard Levitte ***@***.***> wrote:
*levitte* left a comment (openssl/openssl#28691)
<#28691 (comment)>
@bob-beck <https://github.com/bob-beck>, you might want to consider
corrections for when clang-format makes the wrong choice based on assumed
language (see my commentary above on that).
—
Reply to this email directly, view it on GitHub
<#28691 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB57M5N77DW3EOKDGUJAUPD3VU2C7AVCNFSM6AAAAACHZ4IUIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGNRRGUYTCMBVGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This puts the style guide into the repository which is sort of the modern "norm". This has taken the text from the existing style guide in the web page and adapted it to how things will be with an automatic clang-format enforcement. What I have done is: - Referenced the Linux kernel style guide as the base we are using including the link to it. - Removed any reference to spacing, indenting, continuations, etc etc. which are contained in the Linux kernel style guide and enforced by clang-format. - Added a section on Integers. - Added a section for "new code" to Function return values preserving the existing advice for legacy code. - Added a secion on Header Files As I believe we can move to cleaner header files soon, this merely documents the expectation that I believe we can get to (clang-format does not yet do any header re-ordering)
In particular fix the regex magic to be tolerant of different ways of formatting a main program. My past life had forgotten this magic 14 years ago when we converted it to just a table of commands in the forks. https://www.youtube.com/watch?v=mWbbjvYmN8A
gcc and clang report __LINE__ differently when a macro is invoked over multiple lines. gcc always reports the first line of the invocation and clang reports the last. This means that this test as it was will break if for any reason the invocation line wrapping is changed. To make this paradigm less fragile, we record and check for the start and end of the invocation, and accept it as allright if either of them matches. In the future we might want to consider if testing this is relevant here, but that's for another day
(in it's final form it will work with either compiler because it's currently one line, but was tripped up before by the #ifdef, so redid it to be consistent with the other changes previously in this stack) While I am here correct the test to test for all possible return values of ERR_get_error_all, without the #ifdefs
Similar to the previous errtest.c fix this also is not broken by any reformatting today, but this change makes this follow the same pattern as the other things that test OPENSSL_LINE after the fact so we maintain the same paradigm everywhere.
we assume these to be order sensitive and not self contained, so as per our new style we disable clang format around them. we should consider renaming to .inc, or doing away with some of these and just putting the code inline, but that's for later consideration.
Because {- are valid C tokens.
And because we start initalizers with { - which can legit be reformatted to {-
and the choice of perl delimeter is horrible...
Done with a script.
04d4e78 to
df257d1
Compare
this is the same thing, we've just added the pointer alignment to actually do the WebKit C style instead of C++
|
|
I did a quick write-up of stuff that I found makes our code less readable, about a month ago, see https://openssl-communities.org/d/PyEH0sRW/your-thoughts-wanted-openssl-source-code-reformat/11 I now wonder if what transpired in that discussion ever made it back to @bob-beck In short, the webkit format has a few shortcommings, two of them being about wanting to flush everything on a line together, example: struct ossl_param_st {
- const char *key; /* the name of the parameter */
- unsigned int data_type; /* declare what kind of content is in buffer */
- void *data; /* value being passed in or out */
- size_t data_size; /* data size */
- size_t return_size; /* returned content size */
+ const char *key; /* the name of the parameter */
+ unsigned int data_type; /* declare what kind of content is in buffer */
+ void *data; /* value being passed in or out */
+ size_t data_size; /* data size */
+ size_t return_size; /* returned content size */
};The other thing is losing the indentation of pre-processor directives... considering that how pre-processor heavy OpenSSL is, the result of losing the indentation is a mess that's very hard to follow when you look. Of course, those could be refactored, but as far as I can tell, we're not there. So here's a wishlist of tweaks that I'd like to see to not uglify the code too much: I'm pondering strongly not consenting to a .clang-format without those directives. |
No I was not aware of this. This PR would have been the place to discuss it, as your other issue with C was also dealt with here. |
Personally I do like the aligned versions better, however, int the interest of not being different WebKit is explicit that it should be one space: Use only one space before end of line comments and in between sentences in comments Given that it is explict about it and we were clear we did not want to invent our own thing here, this will
Changing this I almost personally dislike, but for the opposite reason, I find the indented preprocessor blocks Nevertheless whatever the default WebKit setting was, again, I'd be willing to live with it. I have heard comments from people who are glad this change removes the preprocessor indentation, so I think this is again a matter of personal taste, and not a universally liked thing. Nevertheless, aside from sorted #includes (which we are not going to tackle just yet) WebKit style itself is |
|
I'm all in for this .clang-format tweak I actually prefer to drop the indentation for preprocessor directives. so I'm with @bob-beck on this. |
|
I think we should be able to reason around the strictness of complying with the base style. That's what I voted for, to base what we come up with on webkit, but I never thought that would become some sort of purist thing. I'd argue that since we're now three who would prefer to leave trailing comments aligned, and the style remains mainly webkit, I really don't see that as a bad thing. |
|
I concur |
Well, I've at least been clear all along for a preference of sticking to something established: As well as in numerous discussions, so perhaps you missed this. I know @tjh has also expressed the desire to stick to a standard format and not invent our own on a number of occasions. So I believe people have been well informed that we do not want to do significant deviations from a standard format. While I'm not super "purist" about it, I want other tools that are aware of the format to work, and not go "oh it's webkit but not webkit." |
I'm very much not in favour of "Leave" , unless that is what we really mean. I.E. We do not care, and whatever I do with trailing comments if it passes clang-format, it's ok stylistically. (i.e. specifically, nits about "please change the trailing comments to line up differently" can be ignored and closed) I suspect what you mean here is not the webkit style, and not "Leave" but rather to force alignment. |
|
I would be perfectly OK with forced alignment. In our previous reformat, we had trailing comments aligned at column 33. I'm not particularly attached to that specific column, that's just to show that we did have an idea of enforcing a specific alignment. |
ok so I took a closer look to what I want here. This is the sample.c file I was using to convey my tests: in sample above comments are separated by tabs. this is clang-format does when running with .clang-format as found in this PR This is what I get if I apply diff to .clang-format the resulting sample.c reads as follows: And this is what I get for .clang-format with this diff applied: With so |
|
That |
|
Although I first disliked it I think I can live with both removing indentation on preprocessor directives and removing the comment alignment. I am afraid What I really hate about the reformat is the removal of alignment of function call arguments on split lines. I did not find anything about that on the Webkit style guide. Can we please please consider keeping this? It makes the code much more readable. |
|
Regarding preprocessor directives, I've already given in, 'cause indentation is inconsistent anyway seen over a whole file. What clang-format documentation isn't quite clear about is that it only considers consecutive preprocessor directives. A line that isn't a preprocessor directive resets the preprocessor indentation "state", so to say. As for webkit and continuation of function parameters, @t8m, they do start with saying that the indent size is 4 spaces, and follow that with cases that are the exception. Since they don't say anything specific about function continuation, then the indent size is... 4 spaces. |
|
giving it another thought here. like sticking to vanilla webkit also makes sort of sense because people just see a webkit and can apply style configuration changes to their editor/ide saying use webkit style without further tweaks. and my vim uses dark blue color for comments, so the indentation is actually less important. |
|
Yeah that's how it looks like when tools are put before the people reading the code. But yeah well, I already gave up on that matter so I am not blocking this. |
So you rely on a christmas tree style to say what's what. Me, with a popular red-green impairment, find issue with a majority of them, and would rather go with monochrome, which is a bit more limited in the color space. |
It is all personal preference in terms of a choice of a style - and we need to simply accept that grabbing a small subset of people and creating our own unique set of things - a set which basically we never actually agree on completely - and is not a consensus - and then forcing something unique and unusual on our users does our community a disservice. There is nothing inherently different about the OpenSSL Library that requires a different choice. We went into this discussion all with the explicit understanding that we were picking between a set of common styles and we were not going to basically argue out each setting to tweak things around personal preferences. There are things in every one of the styles we looked that would not be my choice in terms of a style to use - but the objective is to simply go with a commonly used and recognised style and to stop treating this as as area to diverge. There are many more important things we should be focused on about the actual code itself rather than formatting tweaks. The decision we made (which in itself was a compromise) was vanilla webkit and @bob-beck has done his work on that basis. All the feedback in this PR should be on the basis of has Bob messed it up and not on suggesting additional tweaks that conflict with the vanilla webkit decision which was clearly made. |
I concur that. |
I keep forgetting that not everybody can read this. From that perspective the deviation from webkit style is justified. The drawback of this tweak is the clang-format may exceed the line length as can be seen on the diff here: adding make lines to exceed line length of 80 characters, so that's the price of .clang-format tweak. as I've said I'm fine with X-mass tree colors. but if we want to go for this change then it makes sense to do it now.. |
This branch includes preparatory and mechanical reformat, which I will probably land as independent PR's,
this is together for now for visibility as work in progress (as I rebase to current and adapt to other branches)
Checklist