postgres-extension.rs
postgres-extension.rs copied to clipboard
Datum
Need to figure out a good story here. A datum is simply a pointer stored as a uint
. Then casted to an appropriate type (in C). Text, for example, is allocated onto the heap using the custom pg_malloc
allocator that allocates memory in contexts (regions). This enables it to easily clean up after a misbehaving extension, for example, in one whole swoop, instead of keeping track of a bunch of independent allocations that could never be freed.
Ideally, one could simply do:
Datum::new("foobar");
Datum::new(5i);
Datum::new(true);
Postgres has the concept of:
- Pass by-value using a fixed length.
- Pass by-reference using a fixed length.
- Pass by-reference using a variable length.
Looking through the source, I noticed that Datum.val
defaults to 0
. Should this be updated to make use of the new non-zero numeric types?