Re: Refactor: allow pg_strncoll(), etc., to accept -1 length for NUL-terminated cstrings.
Jeff Davis <pgsql@j-davis.com>
From: Jeff Davis <pgsql@j-davis.com>
To: pgsql-hackers@postgresql.org
Date: 2024-09-21T00:28:51Z
Lists: pgsql-hackers
Attachments
- v4-0007-Use-method-table-for-collation.patch (text/x-patch) patch v4-0007
- v4-0006-Allow-length-1-for-NUL-terminated-input-to-pg_str.patch (text/x-patch) patch v4-0006
- v4-0005-invalidation.patch (text/x-patch) patch v4-0005
- v4-0004-resource-owners.patch (text/x-patch) patch v4-0004
- v4-0003-CollationCacheContext.patch (text/x-patch) patch v4-0003
- v4-0002-create_pg_locale.patch (text/x-patch) patch v4-0002
- v4-0001-Tighten-up-make_libc_collator-and-make_icu_collat.patch (text/x-patch) patch v4-0001
On Thu, 2024-08-22 at 11:00 -0700, Jeff Davis wrote: > Like ICU, allow -1 length to mean that the input string is NUL- > terminated for pg_strncoll(), pg_strnxfrm(), and > pg_strnxfrm_prefix(). To better illustrate the direction I'm going, I roughly implemented some patches that implement collation using a table of methods rather than lots branching based on the provider. This more cleanly separates the API for a provider, which will enable us to use a hook to create a custom provider with arbitrary methods, that may have nothing to do with ICU or libc. Or, we could go so far as to implement a "CREATE LOCALE PROVIDER" that would provide the methods using a handler function, and "datlocprovider" would be an OID rather than a char. From a practical perspective, I expect that extensions would use this to lock down the version of a particular provider rather than implement a completely arbitrary one. But the API is good for either case, and offers quite a bit of code cleanup. There are quite a few loose ends, of course: * There is still a lot of branching on the provider for DDL and catalog access. I'm not sure if we will ever eliminate all of this, or if we would even want to. * I haven't done anything with get_collation_actual_version(). Perhaps that should be a method, too, but it requires some extra thought if we want this to be useful for "multilib" (having multiple versions of a provider library at once). * I didn't add methods for formatting.c yet. * initdb -- should it offer a way to preload a library and then use that for the provider? * I need to allow an arbitrary per-provider context, rather than the current union designed for the existing providers. Again, the patches are rough and there's a lot of code churn. I'd like some feedback on whether people generally like the direction this is going. If so I will clean up the patch series into smaller, more reviewable chunks. Regards, Jeff Davis
Commits
-
Don't accept length of -1 in pg_locale.h APIs.
- 6d22c67c3bf5 19 (unreleased) landed
-
Allow length=-1 for NUL-terminated input to pg_strncoll(), etc.
- ac30021356e7 18.0 landed