Re: [PATCH] Fix ouside scope t_ctid (ItemPointerData)

Поиск
Список
Период
Сортировка
От Mark Dilger
Тема Re: [PATCH] Fix ouside scope t_ctid (ItemPointerData)
Дата
Msg-id 14C3304F-CCC8-4825-9536-A2B47D598C54@enterprisedb.com
обсуждение исходный текст
Ответ на Re: [PATCH] Fix ouside scope t_ctid (ItemPointerData)  (Ranier Vilela <ranier.vf@gmail.com>)
Ответы Re: [PATCH] Fix ouside scope t_ctid (ItemPointerData)  (Ranier Vilela <ranier.vf@gmail.com>)
Список pgsql-hackers

> On May 14, 2020, at 11:34 AM, Ranier Vilela <ranier.vf@gmail.com> wrote:
>
> Certainly.
> In the same file you can find the appropriate use of the API.
> ItemPointerSet(&heapTuple->t_self, blkno, offnum);

It took a couple reads through your patch to figure out what you were trying to accomplish, and I think you are
uncomfortablewith assigning one ItemPointerData variable from another.    ItemPointerData is just a struct with three
int16variables.  To make a standalone program that has the same structure without depending on any postgres headers,
I'musing "short int" instead of "int16" and structs "TwoData" and "ThreeData" that are analogous to BlockIdData and
OffsetNumber.

#include <stdio.h>

typedef struct TwoData {
    short int a;
    short int b;
} TwoData;

typedef struct ThreeData {
    TwoData left;
    short int right;
} ThreeData;

int main(int argc, char **argv)
{
    ThreeData x = { { 5, 10 }, 15 };
    ThreeData y = x;
    x.left.a = 0;
    x.left.b = 1;
    x.right = 2;

    printf("y = { { %d, %d }, %d }\n",
        y.left.a, y.left.b, y.right);

    return 0;
}

If you compile and run this, you'll notice it outputs:

y = { { 5, 10 }, 15 }

and not the { { 0, 1}, 2 } that you would expect if y were merely pointing at x.

—
Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company






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

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: SEQUENCE values (duplicated) in some corner cases when crashhappens
Следующее
От: Ranier Vilela
Дата:
Сообщение: Re: [PATCH] Fix ouside scope t_ctid (ItemPointerData)