From: | Florian Pflug <fgp(at)phlo(dot)org> |
---|---|
To: | Andres Freund <andres(at)2ndquadrant(dot)com> |
Cc: | Robert Haas <robertmhaas(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: same-address mappings vs. relative pointers |
Date: | 2013-12-11 11:37:56 |
Message-ID: | 981FAEAC-4AEB-4F39-B4F8-725D1BFA1D52@phlo.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Dec11, 2013, at 11:47 , Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> On 2013-12-11 11:42:25 +0100, Florian Pflug wrote:
>> On Dec5, 2013, at 15:44 , Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
>>> There might be some ugly compiler dependent magic we could do. Depending
>>> on how we decide to declare offsets. Like (very, very roughly)
>>>
>>> #define relptr(type, struct_name, varname) union struct_name##_##varname{ \
>>> type relptr_type; \
>>> Offset relptr_off;
>>> }
>>>
>>> And then, for accessing have:
>>> #define relptr_access(seg, off) \
>>> typeof(off.relptr_type)* (((char *)seg->base_address) + off.relptr_off)
>>>
>>> But boy, that's ugly.
>>
>> Well, uglyness we can live with, especially if it's less ugly than the
>> alternatives. But I'm afraid is also unportable - typeof() is a GCC
>> extension, not a part of ANSI C, no?
>
> Yes (although there's C11 stuff to do equivalent stuff afair) - I was
> thinking of only doing it for compilers we support that dark magic for
> and fall back to returning a void* for the others. We'll probably miss a
> cast or two required on !gcc that way, but it's still likely to be less
> error prone.
Would it? For this to catch type mismatches, you'd both need to develop
on a typeof-supporting compiler *and* don't cast the result of relptr_access().
But you can't really do that, because the code will then fail on compilers
which don't support typeof()...
What we could do, I guess, is to pass the type to relptr_access() and to
relptr(), and let the compiler verify that they are the same.
Something like
#define relptr(type) union { \
type relptr_type; \
Offset relptr_off; \
}
#define relptr_access(type, seg, rptr) \
(type)( \
(rptr.relptr_type - (type)0), \
((char*)seg->base_address) + rptr.relptr_off \
)
And, yes, ouch ;-)
best regards,
Florian Pflug
From | Date | Subject | |
---|---|---|---|
Next Message | Andres Freund | 2013-12-11 11:49:35 | Re: same-address mappings vs. relative pointers |
Previous Message | Dev Kumkar | 2013-12-11 11:25:07 | Re: Case sensitivity |