Thread: fix windows contrib compile warnings for redefined macros

fix windows contrib compile warnings for redefined macros

From
Andrew Dunstan
Date:
This patch fixes contrib so that it compiles under windows without
warnings about redefines for min, max, V_UNKNOWN and IDIGNORE

cheers

andrew
Index: intarray/_int.h
===================================================================
RCS file: /home/cvsmirror/pgsql/contrib/intarray/_int.h,v
retrieving revision 1.3
diff -c -r1.3 _int.h
*** intarray/_int.h    4 Aug 2003 00:43:10 -0000    1.3
--- intarray/_int.h    21 Oct 2004 17:31:18 -0000
***************
*** 14,21 ****
--- 14,25 ----
  /* number ranges for compression */
  #define MAXNUMRANGE 100

+ #ifndef max
  #define max(a,b)        ((a) >    (b) ? (a) : (b))
+ #endif
+ #ifndef min
  #define min(a,b)        ((a) <= (b) ? (a) : (b))
+ #endif
  #define abs(a)            ((a) <    (0) ? -(a) : (a))

  /* dimension of array */
Index: tsearch2/gistidx.h
===================================================================
RCS file: /home/cvsmirror/pgsql/contrib/tsearch2/gistidx.h,v
retrieving revision 1.1
diff -c -r1.1 gistidx.h
*** tsearch2/gistidx.h    21 Jul 2003 10:26:26 -0000    1.1
--- tsearch2/gistidx.h    21 Oct 2004 17:31:22 -0000
***************
*** 34,40 ****
--- 34,42 ----
  #define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )

  #define abs(a)            ((a) <    (0) ? -(a) : (a))
+ #ifndef min
  #define min(a,b)            ((a) <    (b) ? (a) : (b))
+ #endif
  #define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
  #define HASH(sign, val) SETBIT((sign), HASHVAL(val))

Index: tsearch2/rewrite.c
===================================================================
RCS file: /home/cvsmirror/pgsql/contrib/tsearch2/rewrite.c,v
retrieving revision 1.3
diff -c -r1.3 rewrite.c
*** tsearch2/rewrite.c    28 Aug 2003 12:23:24 -0000    1.3
--- tsearch2/rewrite.c    21 Oct 2004 17:31:22 -0000
***************
*** 174,179 ****
--- 174,182 ----
      return plaintree(clean_NOT_intree(root), len);
  }

+ #ifdef V_UNKNOWN
+ #undef V_UNKNOWN
+ #endif
  #define V_UNKNOWN    0
  #define V_TRUE        1
  #define V_FALSE        2
Index: tsearch2/wparser_def.c
===================================================================
RCS file: /home/cvsmirror/pgsql/contrib/tsearch2/wparser_def.c,v
retrieving revision 1.10
diff -c -r1.10 wparser_def.c
*** tsearch2/wparser_def.c    29 Aug 2004 05:06:39 -0000    1.10
--- tsearch2/wparser_def.c    21 Oct 2004 17:31:23 -0000
***************
*** 76,86 ****
  #define ENDPUNCTOKEN(x) ( (x)==12 )


! #define IDIGNORE(x) ( (x)==13 || (x)==14 || (x)==12 || (x)==23 )
  #define HLIDIGNORE(x) ( (x)==5 || (x)==13 || (x)==15 || (x)==16 || (x)==17 )
  #define HTMLHLIDIGNORE(x) ( (x)==5 || (x)==15 || (x)==16 || (x)==17 )
  #define NONWORDTOKEN(x) ( (x)==12 || HLIDIGNORE(x) )
! #define NOENDTOKEN(x)    ( NONWORDTOKEN(x) || (x)==7 || (x)==8 || (x)==20 || (x)==21 || (x)==22 || IDIGNORE(x) )

  typedef struct
  {
--- 76,86 ----
  #define ENDPUNCTOKEN(x) ( (x)==12 )


! #define TS_IDIGNORE(x) ( (x)==13 || (x)==14 || (x)==12 || (x)==23 )
  #define HLIDIGNORE(x) ( (x)==5 || (x)==13 || (x)==15 || (x)==16 || (x)==17 )
  #define HTMLHLIDIGNORE(x) ( (x)==5 || (x)==15 || (x)==16 || (x)==17 )
  #define NONWORDTOKEN(x) ( (x)==12 || HLIDIGNORE(x) )
! #define NOENDTOKEN(x)    ( NONWORDTOKEN(x) || (x)==7 || (x)==8 || (x)==20 || (x)==21 || (x)==22 || TS_IDIGNORE(x) )

  typedef struct
  {

Re: fix windows contrib compile warnings for redefined macros

From
Tom Lane
Date:
Andrew Dunstan <andrew@dunslane.net> writes:
> This patch fixes contrib so that it compiles under windows without
> warnings about redefines for min, max, V_UNKNOWN and IDIGNORE

Surely this is wrong.  You might be able to assume that Windows'
definitions for min/max are the same as what this code is expecting,
but it's a lot bigger stretch to assume that for the other ones.
(Does tsearch2 still *work* after you change it this way??)

The right thing for the min/max macros is to get rid of them anyway,
and use the Min/Max macros from c.h.

            regards, tom lane

Re: fix windows contrib compile warnings for redefined

From
Andrew Dunstan
Date:

Tom Lane wrote:

>Andrew Dunstan <andrew@dunslane.net> writes:
>
>
>>This patch fixes contrib so that it compiles under windows without
>>warnings about redefines for min, max, V_UNKNOWN and IDIGNORE
>>
>>
>
>Surely this is wrong.  You might be able to assume that Windows'
>definitions for min/max are the same as what this code is expecting,
>
>

I checked and they are, fairly much character for character I think.

>but it's a lot bigger stretch to assume that for the other ones.
>
>

I didn't. In one case (IDIGNORE) I changed the name of the macro to
avoid the conflict, and in the other (V_UKNOWN) I removed the Windows
def which has no applicability in that context (the Windows version
comes from oleauto.h).  Both of these cases occur in .c files and have
no effects outside these files.

>(Does tsearch2 still *work* after you change it this way??)
>
>

I don't know, because (as you know) tsearch2 is currently busted at the
link stage on Windows, and I don't know how to fix it - I was hoping
someone would have jumped on that by now. But by analysis it should not
have changed the behaviour at all.

>The right thing for the min/max macros is to get rid of them anyway,
>and use the Min/Max macros from c.h.
>
>

That's a fair point. I'll look at that.

cheers

andrew


Re: fix windows contrib compile warnings for redefined macros

From
Tom Lane
Date:
Andrew Dunstan <andrew@dunslane.net> writes:
>> The right thing for the min/max macros is to get rid of them anyway,
>> and use the Min/Max macros from c.h.

> That's a fair point. I'll look at that.

Actually I'm in the middle of doing that myself, so don't worry about
it.

            regards, tom lane

Re: fix windows contrib compile warnings for redefined

From
Tom Lane
Date:
Andrew Dunstan <andrew@dunslane.net> writes:
> I didn't. In one case (IDIGNORE) I changed the name of the macro to
> avoid the conflict, and in the other (V_UKNOWN) I removed the Windows
> def which has no applicability in that context (the Windows version
> comes from oleauto.h).  Both of these cases occur in .c files and have
> no effects outside these files.

I hadn't checked closely enough --- you're right these are ok.
Patch applied (and yes, tsearch2 does still work for me...)

            regards, tom lane