Skip to content

Commit 3ce7a35

Browse files
committed
Updated and improved consistency between these two.
modified: codingstyle.md modified: src/bin/dwarfdump/CODINGSTYLE
1 parent c847717 commit 3ce7a35

File tree

2 files changed

+47
-26
lines changed

2 files changed

+47
-26
lines changed

codingstyle.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ examples that you should imitate. The few negative examples
2424
are clearly marked with a comment of /* Yuck! */. Please
2525
don't submit code for libdwarf that looks like any of these.
2626

27+
Also see the src/lib/libdwarf/CODINGSTYLE document.
28+
2729
Section list:
2830

2931
Indentation
@@ -40,6 +42,7 @@ Section list:
4042
Checking For Overflow
4143
Dwarfdump Flags Data
4244
Never use strcpy strcat strncpy
45+
Static data and functions
4346
Tools that help
4447

4548

@@ -63,7 +66,8 @@ a left parenthesis.
6366

6467
### Tab characters
6568

66-
The tab character must never appear.
69+
The tab character must never appear except in
70+
a printf string.
6771

6872
### Braces
6973
Most of the code in libdwarf uses bracing in the style of K&R:
@@ -126,6 +130,10 @@ with blank lines:
126130
...
127131
};
128132

133+
Having both CamelCase in names and _ in the names
134+
is perhaps unusual, but it's been that way
135+
in the libdwarf source a very long time,
136+
so we sitck with it in most cases.
129137

130138
Never use a space before a function-call left parenthesis
131139
or a macro-call left parenthesis.
@@ -164,7 +172,6 @@ function definitions in libdwarf should always take the following form:
164172
And in dwarfdump, etc, the code tends to follow this form
165173
too (but far from always).
166174

167-
168175
Function prototypes inside libdwarf headers
169176
(as opposed to .c files)
170177
usually have the return type
@@ -227,7 +234,6 @@ field in the code (with grep).
227234
unsigned ns_z;
228235
};
229236

230-
231237
### Managing nested blocks
232238

233239
Long blocks that are deeply nested make the code very hard
@@ -269,7 +275,6 @@ a pattern of handling exceptional cases early and returning:
269275

270276
return DW_DLV_OK;
271277

272-
273278
The return statement is often the best thing to use in a
274279
pattern like this. If it's not available due to additional
275280
nesting above which require some cleanup after the current
@@ -278,7 +283,6 @@ function before using goto.
278283

279284
### Test or Loop with Side Effect
280285

281-
282286
Never do:
283287

284288
if ((foo = malloc (sizeof (foo_t)))) {
@@ -404,7 +408,6 @@ values without duplicating the error-code-setting.
404408

405409
### Dwarfdump Flags Data
406410

407-
408411
Dwarfdump has a large number of options and nearly all the
409412
option values are recorded as fields in a single global
410413
structure glflags (see dwarfdump.c). Option data not in that
@@ -425,7 +428,19 @@ These functions eliminate the need for the three traditional
425428
string functions strcpy, strcat, strncpy and do exactly what
426429
is needed safely while doing nothing extra.
427430

431+
### Static data and functions
432+
433+
Any data or function not referenced outside the
434+
defining source file should be declared 'static'.
428435

436+
In the libdwarf library itself static data is
437+
not appropriate in general.
438+
Because multiple Dwarf_Debug
439+
may be open at the same time in a single
440+
program (dwarfdump or user code).
441+
442+
Function names should be all lower case with underbars
443+
with the goal that statements and comments 'read well'.
429444

430445
### Tools that help
431446

@@ -454,8 +469,10 @@ The primary commands used (in a source directory) are
454469

455470
cobra -f basic *.h
456471
cobra -f basic *.c
457-
cwe *.h
458-
cwe *.c
459472
cobra -terse -f stats *.[ch]
460473
cobra -terse -f metrics *.[ch]
461-
474+
# The cwe command generates lots of spurious output as they
475+
# check things we do not care much about.
476+
# But some of it has been useful.
477+
cwe *.h
478+
cwe *.c

src/bin/dwarfdump/CODINGSTYLE

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
This document is a brief description of the main
2-
coding style conventions in dwarfdump. Many of them
3-
will be obvious from the code, but over time some
4-
accidental diffences crept in.
1+
libdwarf/CODINGSTYLE
2+
Updated 22 December 2021
53

4+
This document is a brief description of the main coding style
5+
conventions in dwarfdump. Many of them will be obvious from
6+
the code, but over time some accidental diffences crept in.
67

7-
Code should be indented in multiples of 4 spaces, and
8-
tabs should not be used to indent the source code.
9-
Use the dicheck program to check indenting.
8+
For further remarks see the file codingstyle.md in the
9+
base directory.
1010

1111
The struct naming convention is 'struct my_struct_s' for the
1212
struct defined here (meaning the name should end with _s).
1313
It is better to not do struct typedefs of local structs.
14-
Coders should type 'struct mystruct_s'. Readability
15-
is much more important than brevity.
14+
Coders should type 'struct mystruct_s'. Readability is much
15+
more important than brevity.
1616

17-
Any data or function not referenced outside the
18-
defining source file should be declared 'static'.
17+
Any data or function not referenced outside the defining
18+
source file should be declared 'static'.
1919

20-
Any duplicated code is a candidate for refactoring
20+
Static data is not appropriate in libdwarf in general. Because
21+
multiple Dwarf_Debug may be open at the same time in a single
22+
program (dwarfdump or user code).
23+
24+
Sny duplicated code is a candidate for refactoring
2125
into a subprogram.
2226

23-
Function names should be all lower case with underbars
27+
Sunction names should be all lower case with underbars
2428
with the goal that statements and comments 'read well'.
2529

26-
Variables should be lower-case with
30+
Sariables should be lower-case with
2731
underbars for readability. It's ok for a small loop
2832
with counters to use single letter names like i or k or m.
2933

@@ -32,11 +36,11 @@ Structure members should have a struct-specific
3236
an underbar). That makes it much
3337
easier to grep for uses of members.
3438

35-
Try to keep lines under 80 characters in length.
39+
Sry to keep lines under 70 characters in length.
3640

37-
Ensure every if() has {} to enclose the actions.
41+
Snsure every if() has {} to enclose the actions.
3842

39-
Use libdwarf.h types for all the data objects you define,
43+
Sse libdwarf.h types for all the data objects you define,
4044
though sometimes an 'unsigned' or 'int' or 'size_t' is
4145
ok in restricted circumstances. Dwarf_Unsigned and
4246
Dwarf_Signed are the preferred integer types for general use.

0 commit comments

Comments
 (0)