Re: building pg 8.0.1 with gcc-4.0.1: MemSet problems on SPARC?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: building pg 8.0.1 with gcc-4.0.1: MemSet problems on SPARC?
Дата
Msg-id 3168.1121697358@sss.pgh.pa.us
обсуждение исходный текст
Ответ на building pg 8.0.1 with gcc-4.0.1: MemSet problems on SPARC?  (Andrew Morrow <andrew.c.morrow@gmail.com>)
Список pgsql-ports
Andrew Morrow <andrew.c.morrow@gmail.com> writes:
> I am no language laywer, so I don't know for certain what is going on
> here, but it does seem to be that one of the following must be true:
> 1) There is something illegal/undefined about the address argument to
> memset in the original version, due to the int32 * and char * casts.

I think you are absolutely right --- the cast to int32* allows the
compiler to assume that the pointer is word-aligned, and even casting
it back to char * or void * at the memset call wouldn't really undo
the damage.  So really, correct coding of the macro should be along
the lines of

{               void   *_vstart = (void *)(start); \
                int     _val = (val); \
                Size    _len = (len); \
\
                if ((((long) _vstart) & INT_ALIGN_MASK) == 0 && \
                        (_len & INT_ALIGN_MASK) == 0 && \
                        _val == 0 && \
                        _len <= MEMSET_LOOP_LIMIT) \
                { \
                        int32 * _start = (int32 *) (_vstart); \
                        int32 * _stop = (int32 *) ((char *) _start + _len); \
                        while (_start < _stop) \
                                *_start++ = 0; \
                } \
                else \
                        memset(_vstart, _val, _len); \
        } while (0)

Interesting that we have not seen this before.

            regards, tom lane

В списке pgsql-ports по дате отправления:

Предыдущее
От: Andrew Morrow
Дата:
Сообщение: building pg 8.0.1 with gcc-4.0.1: MemSet problems on SPARC?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: building pg 8.0.1 with gcc-4.0.1: MemSet problems on SPARC?