Patchset to make __func__ more visible

Volker Lendecke Volker.Lendecke at SerNet.DE
Fri Nov 1 06:11:56 MDT 2013


Hi!

Attached find 2 patches that fix faulty DEBUG statements in
one case by using __func__. I would like to see more use of
this throughout our code, so I added another patch putting a
hint into README.Coding.

Please review & push!

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From ba8f8336cc097fa5ecb55f885e4d6598f6032249 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 1 Nov 2013 11:55:43 +0000
Subject: [PATCH 1/2] smbd: Fix DEBUG in do_break_to_none

The name of this function has changed, but the DEBUG statements have
not been adapted. This is the case in a lot of our code. With __func__
this problem goes away: __func__ is C99, and we also use it already.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/oplock.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index b5d6b54..312855d 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -644,13 +644,12 @@ static void do_break_to_none(struct tevent_context *ctx,
 
 	lck = get_existing_share_mode_lock(talloc_tos(), state->id);
 	if (lck == NULL) {
-		DEBUG(1, ("release_level_2_oplocks_on_change: failed to lock "
-			  "share mode entry for file %s.\n",
-			  file_id_string_tos(&state->id)));
+		DEBUG(1, ("%s: failed to lock share mode entry for file %s.\n",
+			  __func__, file_id_string_tos(&state->id)));
 		goto done;
 	}
 
-	DEBUG(10,("release_level_2_oplocks_on_change: num_share_modes = %d\n", 
+	DEBUG(10,("%s: num_share_modes = %d\n", __func__,
 		  lck->data->num_share_modes ));
 
 	for(i = 0; i < lck->data->num_share_modes; i++) {
@@ -672,8 +671,7 @@ static void do_break_to_none(struct tevent_context *ctx,
 		 * NO_OPLOCK states. JRA.
 		 */
 
-		DEBUG(10,("release_level_2_oplocks_on_change: "
-			  "share_entry[%i]->op_type == %d\n",
+		DEBUG(10,("%s: share_entry[%i]->op_type == %d\n", __func__,
 			  i, share_entry->op_type ));
 
 		if (share_entry->op_type == NO_OPLOCK) {
@@ -682,9 +680,9 @@ static void do_break_to_none(struct tevent_context *ctx,
 
 		/* Paranoia .... */
 		if (EXCLUSIVE_OPLOCK_TYPE(share_entry->op_type)) {
-			DEBUG(0,("release_level_2_oplocks_on_change: PANIC. "
+			DEBUG(0,("%s: PANIC. "
 				 "share mode entry %d is an exlusive "
-				 "oplock !\n", i ));
+				 "oplock !\n", __func__, i ));
 			TALLOC_FREE(lck);
 			abort();
 		}
-- 
1.8.1.2


From f3b8912bd1c56b847f237b4b3a0f1b6083b2de58 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 1 Nov 2013 12:04:38 +0000
Subject: [PATCH 2/2] README.Coding: Add __func__

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 README.Coding | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/README.Coding b/README.Coding
index 956a733..107856e 100644
--- a/README.Coding
+++ b/README.Coding
@@ -377,3 +377,17 @@ do not use them in new code.
 
 The only exception is the test code that depends repeated use of calls
 like CHECK_STATUS, CHECK_VAL and others.
+
+
+Function names in DEBUG statements
+----------------------------------
+
+Many DEBUG statements contain the name of the function they appear in. This is
+not a good idea, as this is prone to bitrot. Function names change, code
+moves, but the DEBUG statements are not adapted. Use %s and __func__ for this:
+
+Bad Example:
+	DEBUG(0, ("strstr_m: src malloc fail\n"));
+
+Good Example:
+	DEBUG(0, ("%s: src malloc fail\n", __func__));
-- 
1.8.1.2



More information about the samba-technical mailing list