Re: currawong is not a happy animal

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: currawong is not a happy animal
Date: 2014-01-17 20:11:38
Message-ID: 52D98E7A.9060409@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 01/17/2014 02:54 PM, Alvaro Herrera wrote:
> Tom Lane escribió:
>> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>>> Not quite out of the woods yet. We're getting this regression failure on
>>> Windows/MSVC (see
>>> <http://www.pgbuildfarm.org/cgi-bin/show_log.pl?nm=bowerbird&dt=2014-01-17%2018%3A20%3A35>):
>>> SELECT test_shm_mq(32768, (select string_agg(chr(32+(random()*96)::int), '') from generate_series(1,400)), 10000, 1);
>>> ! ERROR: queue size must be at least 472262143 bytes
>> It looks like this is computing a bogus value:
>>
>> const Size shm_mq_minimum_size =
>> MAXALIGN(offsetof(shm_mq, mq_ring)) + MAXIMUM_ALIGNOF;
>>
>> I seem to recall that we've previously found that you have to write
>>
>> MAXALIGN(offsetof(shm_mq, mq_ring[0])) + MAXIMUM_ALIGNOF;
>>
>> to keep MSVC happy with a reference to an array member in offsetof.
> Hmm, this seems to contradict what's documented at the definition of
> FLEXIBLE_ARRAY_MEMBER:
>
> /* Define to nothing if C supports flexible array members, and to 1 if it does
> not. That way, with a declaration like `struct s { int n; double
> d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99
> compilers. When computing the size of such an object, don't use 'sizeof
> (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)'
> instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with
> MSVC and with C++ compilers. */
> #define FLEXIBLE_ARRAY_MEMBER /**/
>
>

Well, there's a bunch of these in the source:

[andrew(at)emma pg_head]$ grep -r offsetof.*\\[0 src/backend
src/backend/access/nbtree/nbtutils.c: size = offsetof(BTVacInfo,
vacuums[0]);
src/backend/utils/adt/geo_ops.c: size = offsetof(PATH, p[0])
+sizeof(path->p[0]) * npts;
src/backend/utils/adt/geo_ops.c: if (npts <= 0 || npts >= (int32)
((INT_MAX - offsetof(PATH, p[0])) / sizeof(Point)))
src/backend/utils/adt/geo_ops.c: size = offsetof(PATH, p[0])
+sizeof(path->p[0]) * npts;
src/backend/utils/adt/geo_ops.c: size = offsetof(POLYGON, p[0])
+sizeof(poly->p[0]) * npts;
src/backend/utils/adt/geo_ops.c: if (npts <= 0 || npts >= (int32)
((INT_MAX - offsetof(POLYGON, p[0])) / sizeof(Point)))
src/backend/utils/adt/geo_ops.c: size = offsetof(POLYGON, p[0])
+sizeof(poly->p[0]) * npts;
src/backend/utils/adt/geo_ops.c: size = offsetof(PATH, p[0])
+base_size;
src/backend/utils/adt/geo_ops.c: size = offsetof(POLYGON, p[0])
+sizeof(poly->p[0]) * path->npts;
src/backend/utils/adt/geo_ops.c: size = offsetof(POLYGON, p[0])
+sizeof(poly->p[0]) * 4;
src/backend/utils/adt/geo_ops.c: size = offsetof(PATH, p[0])
+sizeof(path->p[0]) * poly->npts;
src/backend/utils/adt/geo_ops.c: size = offsetof(POLYGON, p[0])
+base_size;
src/backend/postmaster/pgstat.c: len =
offsetof(PgStat_MsgTabstat, m_entry[0]) +
src/backend/postmaster/pgstat.c: pgstat_send(&msg,
offsetof(PgStat_MsgFuncstat, m_entry[0]) +
src/backend/postmaster/pgstat.c: pgstat_send(&msg,
offsetof(PgStat_MsgFuncstat, m_entry[0]) +
src/backend/postmaster/pgstat.c: len =
offsetof(PgStat_MsgTabpurge, m_tableid[0])
src/backend/postmaster/pgstat.c: len =
offsetof(PgStat_MsgTabpurge, m_tableid[0])
src/backend/postmaster/pgstat.c: len =
offsetof(PgStat_MsgFuncpurge, m_functionid[0])
src/backend/postmaster/pgstat.c: len =
offsetof(PgStat_MsgFuncpurge, m_functionid[0])
src/backend/postmaster/pgstat.c: len =
offsetof(PgStat_MsgTabpurge, m_tableid[0]) +sizeof(Oid);

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2014-01-17 20:15:21 Re: currawong is not a happy animal
Previous Message Alvaro Herrera 2014-01-17 19:54:37 Re: currawong is not a happy animal