Skip to content

Add utils/datum.h bindings + generic_agg example#2341

Merged
eeeebbbbrrrr merged 1 commit into
pgcentralfoundation:developfrom
isdaniel:feat/bind-utils-datum-h
Jun 25, 2026
Merged

Add utils/datum.h bindings + generic_agg example#2341
eeeebbbbrrrr merged 1 commit into
pgcentralfoundation:developfrom
isdaniel:feat/bind-utils-datum-h

Conversation

@isdaniel

@isdaniel isdaniel commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Motivation

These are the canonical, type-length-aware way to copy/compare a Datum when the concrete type is only known at runtime (anyelement, polymorphic aggregates, generic state). Today an extension author has to hand-redeclare them extern "C" — easy to get subtly wrong (typLen is C int, not int16) and missing pgrx's #[pg_guard], so a palloc OOM longjmp becomes UB.

What this does

  • Add #include "utils/datum.h" to all seven wrappers (pg13pg19).
  • Add pgrx-examples/generic_agg: a polymorphic count_changes(anyelement) aggregate that needs datumCopy (keep a by-ref value alive across transition calls) + datumIsEqual (byte-compare type-erased values), with #[pg_test]s covering text/numeric (by-ref), int4 (by-value), NULL, and empty input.

@eeeebbbbrrrr

Copy link
Copy Markdown
Contributor

I put up the same fix for the flaky tests in #2342, so if you'll remove it from this PR I'd appreciate it.

@isdaniel
isdaniel force-pushed the feat/bind-utils-datum-h branch from fc6c0a4 to e0a3c30 Compare June 25, 2026 14:20
@isdaniel

isdaniel commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Hi @eeeebbbbrrrr noted, I already removed that commit from my branch, and also change the PR comment as well

@eeeebbbbrrrr
eeeebbbbrrrr merged commit 14ccc0e into pgcentralfoundation:develop Jun 25, 2026
30 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants