From patchwork Fri Jun 19 07:29:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 486592 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1F1961401AB for ; Fri, 19 Jun 2015 17:29:31 +1000 (AEST) Received: from localhost ([::1]:56591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5qju-0002d9-OT for incoming@patchwork.ozlabs.org; Fri, 19 Jun 2015 03:29:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5qjf-0002MI-HH for qemu-devel@nongnu.org; Fri, 19 Jun 2015 03:29:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5qjc-00014O-6F for qemu-devel@nongnu.org; Fri, 19 Jun 2015 03:29:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37197) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5qjb-000142-VF for qemu-devel@nongnu.org; Fri, 19 Jun 2015 03:29:08 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 76ED93897B3; Fri, 19 Jun 2015 07:29:07 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-30.ams2.redhat.com [10.36.112.30]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5J7T4bv017934; Fri, 19 Jun 2015 03:29:05 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 19 Jun 2015 09:29:04 +0200 Message-Id: <1434698944-3331-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Andreas Faerber , Eduardo Habkost , Markus Armbruster Subject: [Qemu-devel] [PATCH] CODING_STYLE: update line length and mixed declaration rules X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 1) Line lengths above 80 characters do exist. They are rare, but they happen from time to time. An ignored rule is worse than an exception to the rule, so do the latter. 2) Mixed declarations also do exist at the top of #ifdef blocks. Remark on this particular usage and suggest an alternative. Cc: Andreas Faerber Cc: Markus Armbruster Cc: Eduardo Habkost Signed-off-by: Paolo Bonzini --- CODING_STYLE | 21 ++++++++++++++++----- scripts/checkpatch.pl | 9 ++++++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CODING_STYLE b/CODING_STYLE index d46cfa5..d013cb8 100644 --- a/CODING_STYLE +++ b/CODING_STYLE @@ -31,7 +31,11 @@ Do not leave whitespace dangling off the ends of lines. 2. Line width -Lines are 80 characters; not longer. +Lines should be 80 characters; try not to make them longer. + +Sometimes it is hard to do, especially when dealing with QEMU subsystems +that use long function or symbol names. Even in that case, do not make +lines _much_ longer than 80 characters. Rationale: - Some people like to tile their 24" screens with a 6x4 matrix of 80x24 @@ -39,6 +43,8 @@ Rationale: let them keep doing it. - Code and especially patches is much more readable if limited to a sane line length. Eighty is traditional. + - The four-space indentation makes the most common excuse ("But look + at all that white space on the left!") moot. - It is the QEMU coding style. 3. Naming @@ -87,10 +93,15 @@ Furthermore, it is the QEMU coding style. 5. Declarations -Mixed declarations (interleaving statements and declarations within blocks) -are not allowed; declarations should be at the beginning of blocks. In other -words, the code should not generate warnings if using GCC's --Wdeclaration-after-statement option. +Mixed declarations (interleaving statements and declarations within +blocks) are generally not allowed; declarations should be at the beginning +of blocks. + +Every now and then, an exception is made for declarations inside a +#ifdef or #ifndef block: if the code looks nicer, such declarations can +be placed at the top of the block even if there are statements above. +On the other hand, however, it's often best to move that #ifdef/#ifndef +block to a separate function altogether. 6. Conditional statements diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 7f0aae9..f4e7050 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1470,10 +1470,13 @@ sub process { if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && $rawline !~ /^.\s*\*\s*\@$Ident\s/ && !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ || - $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) && - $length > 80) + $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/)) { - WARN("line over 80 characters\n" . $herecurr); + if ($length > 90) { + ERROR("line over 90 characters\n" . $herecurr); + } if ($length > 80) { + WARN("line over 80 characters\n" . $herecurr); + } } # check for spaces before a quoted newline