Convert *GetDatum() and DatumGet*() macros to inline functions

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Convert *GetDatum() and DatumGet*() macros to inline functions
Дата
Msg-id 8528fb7e-0aa2-6b54-85fb-0c0886dbd6ed@enterprisedb.com
обсуждение исходный текст
Ответы Re: Convert *GetDatum() and DatumGet*() macros to inline functions  (Aleksander Alekseev <aleksander@timescale.com>)
Список pgsql-hackers
I once wrote code like this:

     char *oid = get_from_somewhere();
     ...

     values[i++] = ObjectIdGetDatum(oid);

This compiles cleanly and even appears to work in practice, except of 
course it doesn't.

The FooGetDatum() macros just cast whatever you give it to Datum, 
without checking whether the input was really foo.

To address this, I converted these macros to inline functions, which 
enables type checking of the input argument.  For symmetry, I also 
converted the corresponding DatumGetFoo() macros (but those are less 
likely to cover mistakes, since the input argument is always Datum). 
This is patch 0002.

(I left some of the DatumGet... of the varlena types in fmgr.h as 
macros.  These ultimately map to functions that do type checking, so 
there would be little more to be learnt from that.  But we could do 
those for consistency as well.)

This whole thing threw up a bunch of compiler warnings and errors, which 
revealed a number of existing misuses.  These are fixed in patch 0001. 
These include

- using FooGetDatum on things that are already Datum,

- using DatumGetPointer on things that are already pointers,

- using PG_RETURN_TYPE on things that are Datum,

- using PG_RETURN_TYPE of the wrong type,

and others, including my personal favorite:

- using PointerGetDatum where DatumGetPointer should be used.

(AFAICT, unlike my initial example, I don't think any of those would 
cause wrong behavior.)
Вложения

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [PATCH] Add native windows on arm64 support
Следующее
От: Andres Freund
Дата:
Сообщение: Re: CI and test improvements