# New Ticket Created by  Bruce Gray 
# Please include the string:  [perl #19232]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=19232 >


In parrot.h (revision 1.45 2002-08-07), macros were defined 
to eliminate warnings during pointer conversions. See:
        http://rt.perl.org/rt2/Ticket/Display.html?id=16019

The definition of the macros is controlled by the first line of this block:
        #if (INTVAL_SIZE == PTR_SIZE) && (UINTVAL_SIZE == PTR_SIZE)
        #  define INTVAL2PTR(any,d)    (any)(d)
        #  define UINTVAL2PTR(any,d)    (any)(d)
        #else
        #  if PTR_SIZE == LONG_SIZE
        #    define INTVAL2PTR(any,d)    (any)(unsigned long)(d)
        #    define UINTVAL2PTR(any,d)    (any)(unsigned long)(d)
        #  else
        #    define INTVAL2PTR(any,d)    (any)(unsigned int)(d)
        #    define UINTVAL2PTR(any,d)    (any)(unsigned int)(d)
        #  endif
        #endif
        #define PTR2INTVAL(p)    INTVAL2PTR(INTVAL,p)
        #define PTR2UINTVAL(p)    UINTVAL2PTR(UINTVAL,p)
--snip--
        #define D2FPTR(x) UINTVAL2PTR(funcptr_t, PTR2UINTVAL(x))
        #define F2DPTR(x) UINTVAL2PTR(void *, PTR2UINTVAL((funcptr_t) x))

I cannot find a definition for UINTVAL_SIZE anywhere. Being 
undefined, it evaluates to 0, and so the #if always fails. 
This means that some systems have been getting the wrong 
macro definitions.

It would not be difficult to add Configure tests to define 
UINTVAL_SIZE, but I think that it is not really needed. 
Instead, the attached patch just changes the first line to:
        #if PTR_SIZE == INTVAL_SIZE
( Is there any platform for which sizeof(signed foo) <> 
sizeof(unsigned foo)? Would the C spec even allow it? If so, 
I will be glad to write the Configure tests. )

I feel confident that this simpler change is the Right 
Thing, but it could uncover other bugs, and I have no 
esoteric platforms to test it on. Here is a summary of the 
patch's effect on different platforms:

1) PTR_SIZE <> INTVAL_SIZE
No change.

2) PTR_SIZE == INTVAL_SIZE == LONG_SIZE (x86 Linux and Win32)
Intermediate casts to (unsigned long) removed, i.e.
        (any)(unsigned long)(d)
becomes
        (any)(d)

3) PTR_SIZE == INTVAL_SIZE <> LONG_SIZE
Intermediate casts to (unsigned int) removed, i.e.
        (any)(unsigned int)(d)
becomes
        (any)(d)


Under MS VC++ for .Net, this patch changes the results of 
none of the tests; it only stops the "UINTVAL_SIZE is not 
defined as a preprocessor macro" warnings that are given 
with the -Wall option.

-- 
Hope this helps,
Bruce Gray



-- attachment  1 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/45713/35845/cf2db0/UINTVAL_SIZE.patch

Index: include/parrot/parrot.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/parrot.h,v
retrieving revision 1.58
diff -u -r1.58 parrot.h
--- include/parrot/parrot.h     12 Dec 2002 20:13:35 -0000      1.58
+++ include/parrot/parrot.h     17 Dec 2002 22:26:21 -0000
@@ -112,7 +112,7 @@
     explicitly Configured in) which do limits checks?
     A. D. Aug. 6, 2002.
 */
-#if (INTVAL_SIZE == PTR_SIZE) && (UINTVAL_SIZE == PTR_SIZE)
+#if PTR_SIZE == INTVAL_SIZE
 #  define INTVAL2PTR(any,d)    (any)(d)
 #  define UINTVAL2PTR(any,d)    (any)(d)
 #else

Reply via email to