diff options
-rw-r--r-- | doc/developer/workflow.rst | 29 | ||||
-rwxr-xr-x | tools/checkpatch.pl | 13 | ||||
-rwxr-xr-x | tools/convert-fixedwidth.sh | 44 |
3 files changed, 86 insertions, 0 deletions
diff --git a/doc/developer/workflow.rst b/doc/developer/workflow.rst index ff66007f8..0114a6ddb 100644 --- a/doc/developer/workflow.rst +++ b/doc/developer/workflow.rst @@ -496,6 +496,35 @@ For GNU coding style, use ``indent`` with the following invocation: 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 ^^^^^^^^^^ diff --git a/tools/checkpatch.pl b/tools/checkpatch.pl index a85d811c9..e66be1875 100755 --- a/tools/checkpatch.pl +++ b/tools/checkpatch.pl @@ -6357,6 +6357,19 @@ sub process { "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 diff --git a/tools/convert-fixedwidth.sh b/tools/convert-fixedwidth.sh new file mode 100755 index 000000000..bb6011edd --- /dev/null +++ b/tools/convert-fixedwidth.sh @@ -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 |