mirror of
https://github.com/FRRouting/frr.git
synced 2025-04-30 13:37:17 +02:00
tools, doc: update checkpatch for u_int_*
* Checkpatch.pl now checks for nonstandard integral types * Add shell script to replace all nonstandard types with their standard counterparts in C source files * Document usage of types, mention conversion script Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
parent
2d6e6d36d7
commit
28ac5a0381
|
@ -496,6 +496,35 @@ For GNU coding style, use ``indent`` with the following invocation:
|
||||||
|
|
||||||
indent -nut -nfc1 file_for_submission.c
|
indent -nut -nfc1 file_for_submission.c
|
||||||
|
|
||||||
|
|
||||||
|
Historically, FRR used fixed-width integral types that do not exist in any
|
||||||
|
standard but were defined by most platforms at some point. Officially these
|
||||||
|
types are not guaranteed to exist. Therefore, please use the fixed-width
|
||||||
|
integral types introduced in the C99 standard when contributing new code to
|
||||||
|
FRR. If you need to convert a large amount of code to use the correct types,
|
||||||
|
there is a shell script in :file:`tools/convert-fixedwidth.sh` that will do the
|
||||||
|
necessary replacements.
|
||||||
|
|
||||||
|
+-----------+--------------------------+
|
||||||
|
| Incorrect | Correct |
|
||||||
|
+===========+==========================+
|
||||||
|
| u_int8_t | uint8_t |
|
||||||
|
+-----------+--------------------------+
|
||||||
|
| u_int16_t | uint16_t |
|
||||||
|
+-----------+--------------------------+
|
||||||
|
| u_int32_t | uint32_t |
|
||||||
|
+-----------+--------------------------+
|
||||||
|
| u_int64_t | uint64_t |
|
||||||
|
+-----------+--------------------------+
|
||||||
|
| u_char | uint8_t or unsigned char |
|
||||||
|
+-----------+--------------------------+
|
||||||
|
| u_short | unsigned short |
|
||||||
|
+-----------+--------------------------+
|
||||||
|
| u_int | unsigned int |
|
||||||
|
+-----------+--------------------------+
|
||||||
|
| u_long | unsigned long |
|
||||||
|
+-----------+--------------------------+
|
||||||
|
|
||||||
Exceptions
|
Exceptions
|
||||||
^^^^^^^^^^
|
^^^^^^^^^^
|
||||||
|
|
||||||
|
|
|
@ -6357,6 +6357,19 @@ sub process {
|
||||||
"unknown module license " . $extracted_string . "\n" . $herecurr);
|
"unknown module license " . $extracted_string . "\n" . $herecurr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# check for usage of nonstandard fixed-width integral types
|
||||||
|
if ($line =~ /u_int8_t/ ||
|
||||||
|
$line =~ /u_int32_t/ ||
|
||||||
|
$line =~ /u_int16_t/ ||
|
||||||
|
$line =~ /u_int64_t/ ||
|
||||||
|
$line =~ /[^a-z_]u_char[^a-z_]/ ||
|
||||||
|
$line =~ /[^a-z_]u_short[^a-z_]/ ||
|
||||||
|
$line =~ /[^a-z_]u_int[^a-z_]/ ||
|
||||||
|
$line =~ /[^a-z_]u_long[^a-z_]/) {
|
||||||
|
ERROR("NONSTANDARD_INTEGRAL_TYPES",
|
||||||
|
"Please, no nonstandard integer types in new code.\n" . $herecurr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# If we have no input at all, then there is nothing to report on
|
# If we have no input at all, then there is nothing to report on
|
||||||
|
|
44
tools/convert-fixedwidth.sh
Executable file
44
tools/convert-fixedwidth.sh
Executable file
|
@ -0,0 +1,44 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# This script converts nonstandard fixed-width integer types found in FRR to
|
||||||
|
# C99 standard types.
|
||||||
|
USAGE="./$(basename "$0")"
|
||||||
|
USAGE+=$' <src-path> -- convert nonstandard fixed-width integer types found in FRR to C99 standard types\n'
|
||||||
|
USAGE+=$'<src-path> - a directory containing C source, or a C source file\n'
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
printf "%s" "$USAGE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
FRRTREE=$1
|
||||||
|
|
||||||
|
if [[ -d $FRRTREE ]]; then
|
||||||
|
SOURCES=$(find $FRRTREE -type f -name '*.[ch]')
|
||||||
|
elif [[ -f $FRRTREE ]]; then
|
||||||
|
SOURCES="$FRRTREE"
|
||||||
|
SOURCES+=$'\n'
|
||||||
|
else
|
||||||
|
printf "%s" "$USAGE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "%s" "$SOURCES" | while read line ; do
|
||||||
|
printf "Processing $line "
|
||||||
|
sed -i -e 's/u_int\([0-9]\{1,3\}\)_t/uint\1_t/g' $line
|
||||||
|
printf "."
|
||||||
|
sed -i -e 's/\([^a-z_]\)u_char\([^a-z_]\|$\)/\1uint8_t\2/g' $line
|
||||||
|
printf "."
|
||||||
|
sed -i -e 's/\([^a-z_]\)u_short\([^a-z_]\|$\)/\1unsigned short\2/g' $line
|
||||||
|
printf "."
|
||||||
|
sed -i -e 's/\([^a-z_]\)u_int\([^a-z_]\|$\)/\1unsigned int\2/g' $line
|
||||||
|
printf "."
|
||||||
|
sed -i -e 's/\([^a-z_]\)u_long\([^a-z_]\|$\)/\1unsigned long\2/g' $line
|
||||||
|
printf "."
|
||||||
|
sed -i -e 's/^u_char /uint8_t /g' $line
|
||||||
|
printf "."
|
||||||
|
sed -i -e 's/^u_short /unsigned short /g' $line
|
||||||
|
printf "."
|
||||||
|
sed -i -e 's/^u_int /unsigned int /g' $line
|
||||||
|
printf "."
|
||||||
|
sed -i -e 's/^u_long /unsigned long /g' $line
|
||||||
|
printf ".\n"
|
||||||
|
done
|
Loading…
Reference in a new issue