[HACKERS] MemSetLoop ignoring the 'val' parameter

2012-10-08 Thread Andres Freund
Hi,

#define MemSetLoop(start, val, len) \
do \
{ \
long * _start = (long *) (start); \
long * _stop = (long *) ((char *) _start + (Size) (len)); \
\
while (_start  _stop) \
*_start++ = 0; \
} while (0)

The 'val' parameter is ignored.

Currently it doesn't matter because MemSetLoop is only used with a 0 parameter 
and only so in mcxt.c but it looks like it should be fixed anyway.

Andres
-- 
 Andres Freund http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] MemSetLoop ignoring the 'val' parameter

2012-10-08 Thread Andres Freund
On Monday, October 08, 2012 10:39:27 PM Andres Freund wrote:
 The 'val' parameter is ignored.
Trivial patch attached.
-- 
 Andres Freund http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services
From a4056e1110961c64b56d61a88c0d472c58a80579 Mon Sep 17 00:00:00 2001
From: Andres Freund and...@anarazel.de
Date: Mon, 8 Oct 2012 22:55:14 +0200
Subject: [PATCH] Fix MemSetLoop to not ignore the val parameter

This typo didn't have any bad consequences as the only in-core callsite passes
in 0 which is the value that was assigned instead of val anyway.
---
 src/include/c.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/include/c.h b/src/include/c.h
index 925d961..8c3ca8c 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -689,7 +689,7 @@ typedef NameData *Name;
 		long * _stop = (long *) ((char *) _start + (Size) (len)); \
 	\
 		while (_start  _stop) \
-			*_start++ = 0; \
+			*_start++ = val; \
 	} while (0)
 
 
-- 
1.7.12.289.g0ce9864.dirty


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] MemSetLoop ignoring the 'val' parameter

2012-10-08 Thread Tom Lane
Andres Freund and...@2ndquadrant.com writes:
 The 'val' parameter is ignored.

This is not broken.  Read the comments for MemSetTest.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] MemSetLoop ignoring the 'val' parameter

2012-10-08 Thread Andres Freund
On Tuesday, October 09, 2012 12:56:16 AM Tom Lane wrote:
 Andres Freund and...@2ndquadrant.com writes:
  The 'val' parameter is ignored.
 
 This is not broken.  Read the comments for MemSetTest.
Ah. I was surprised about that already. The comment says that val has to be 
constant though, not that it has to be zero. In my understanding 1 is constant 
as well. Also, why do we even pass in a 'val' parameter in that case?

Feeling a little slow here...

Andres
-- 
 Andres Freund http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] MemSetLoop ignoring the 'val' parameter

2012-10-08 Thread Tom Lane
Andres Freund and...@2ndquadrant.com writes:
 On Tuesday, October 09, 2012 12:56:16 AM Tom Lane wrote:
 Andres Freund and...@2ndquadrant.com writes:
 The 'val' parameter is ignored.

 This is not broken.  Read the comments for MemSetTest.

 Ah. I was surprised about that already. The comment says that val has to be 
 constant though, not that it has to be zero. In my understanding 1 is 
 constant 
 as well. Also, why do we even pass in a 'val' parameter in that case?

Well, first off, the callers should not be aware of the detail that
MemSetTest insists on a val of zero, so they have to pass val even
though it's unused by the current implementation of MemSetLoop.

The callers are responsible for not passing a volatile value there, but
it's hard to dodge that problem given that we're dealing with macros;
if the value changes on repeat evaluation we're screwed anyway.

However, nonvolatile is not constant.  For instance, it's perfectly
fine to pass MemSetTest/Loop a variable for the val that is sometimes
zero and sometimes not.  If we changed the coding as you suggest, the
compiler would probably generate less efficient code since it wouldn't
realize (unless it was quite smart) that MemSetLoop is always filling
with zeroes.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers