]> git.puffer.fish Git - mirror/frr.git/commitdiff
tools, doc: update checkpatch for u_int_*
authorQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 19 Mar 2018 16:35:48 +0000 (12:35 -0400)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 27 Mar 2018 19:00:23 +0000 (15:00 -0400)
* 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>
doc/developer/workflow.rst
tools/checkpatch.pl
tools/convert-fixedwidth.sh [new file with mode: 0755]

index ff66007f8da35ddba658ddd64192be048f58f393..0114a6ddbd04dad8d87be0e28ed9243b6b1331c8 100644 (file)
@@ -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
 ^^^^^^^^^^
 
index a85d811c96a0559361748d28b1be95b68db0c4e8..e66be1875fa97d3a3f7665a87bc86380be47087d 100755 (executable)
@@ -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 (executable)
index 0000000..bb6011e
--- /dev/null
@@ -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