On Sat, Jun 21, 2008 at 11:10 AM, chromatic <[EMAIL PROTECTED]> wrote:
> On Friday 20 June 2008 10:53:55 Andrew Johnson wrote:
>
>> I'm concluding that these warnings are due to incorrect casting inside of
>> packfile.c.
>>
>> In both cases, the code generating the warnings looks like this:
>>
>>         munmap(PARROT_const_cast(opcode_t *, pf->src), pf->size);
>>
>> pf->src is a const opcode_t* and the purpose of the PARROT_const_cast is to
>> drop the const. The first argument to munmap() is a void* on Linux and Mac,
>> but a char* on Solaris;  I tried globally defining the feature-test macros
>> _POSIX_C_SOURCE or _XPG4_2, but these are supposed to be an all-or-nothing
>> choice, and in both cases they broke the build elsewhere.
>>
>> In C any pointer auto-converts to a void*, but has to be cast to any other
>> pointer type such as a char*. If we change the above casts to void* the
>> warning on Solaris goes away. I have checked this on Linux and it builds
>> fine.  Hence the attached patch to packfile.c
>
> This sounds reasonable.  I'd like to hear results from trying to compile with
> a C++ compiler though.  NotFound, any luck?

The goal of the PARROT_const_cast macro is to do the const-dropping
casting (given that is almost impossible to completely get rid of all
of them) in the safer and less annoying (for the people building and
searching errors, not for the writer) possible way. To accomplish that
goal, when compiling with C++ is mappped to a c++ const_cast, and
because of that the type converted to can only differ to the argument
type in constness and volatileness.

In several cases the desired conversion is to void *, but that is not
problem because after dropping the const the conversion to void * is
done automatically without warnings.

In corner cases like this, the only solution I see is to explicitly
cast to (void *) the result of PARROT_const_cast, like this:

         munmap( (void *)PARROT_const_cast(opcode_t *, pf->src), pf->size);

I think that the goal is good enough to justify the need to use such
ugly casts occasionally.

Can't write a fixed patch at this moment, I will send it later today.

-- 
Salu2

Reply via email to