public inbox for [email protected]
help / color / mirror / Atom feedFrom: Peter Eisentraut <[email protected]>
To: pgsql-hackers <[email protected]>
Subject: Collation version tracking for macOS
Date: Mon, 14 Feb 2022 10:00:27 +0100
Message-ID: <[email protected]> (raw)
During development, I have been using the attached patch to simulate
libc collation versions on macOS. It just uses the internal major OS
version number. I don't know to what the extend the libc locales on
macOS are maintained or updated at all, so I don't know what practical
effect this would have. Again, it's mainly for development. If there
is interest from others, I think we could add this, maybe disabled by
default, or we just keep it in the mailing list archives for interested
parties.
From 5e6f1a94a839981755f0380960511e60aba2b8d2 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Tue, 1 Feb 2022 16:07:29 +0100
Subject: [PATCH] Collation version tracking for macOS
---
src/backend/utils/adt/pg_locale.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index 871a710967..f8e57ee236 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -74,6 +74,10 @@
#include <gnu/libc-version.h>
#endif
+#ifdef __APPLE__
+#include <sys/sysctl.h>
+#endif
+
#ifdef WIN32
#include <shlwapi.h>
#endif
@@ -1696,6 +1700,28 @@ get_collation_actual_version(char collprovider, const char *collcollate)
else
ereport(ERROR,
(errmsg("could not load locale \"%s\"", collcollate)));
+#elif defined(__APPLE__)
+ /*
+ * The POSIX-level locales on macOS are mostly useless for real work,
+ * and they also don't appear to change much or at all. However, at
+ * least for development it is useful to have some version tracking
+ * mechanism on this platform. For lack of better ideas, we just
+ * record the internal major operating system version.
+ */
+ {
+ char str[256];
+ size_t len = sizeof(str);
+ char *p;
+
+ if (sysctlbyname("kern.osrelease", str, &len, NULL, 0) != 0)
+ ereport(ERROR,
+ (errmsg("could not get OS release: %m")));
+ /* value is three numbers like "12.3.4", we take only the first one */
+ p = strchr(str, '.');
+ if (p)
+ *p = '\0';
+ collversion = pstrdup(str);
+ }
#elif defined(WIN32) && _WIN32_WINNT >= 0x0600
/*
* If we are targeting Windows Vista and above, we can ask for a name
--
2.35.1
Attachments:
[text/plain] 0001-Collation-version-tracking-for-macOS.patch (1.7K, ../[email protected]/2-0001-Collation-version-tracking-for-macOS.patch)
download | inline diff:
From 5e6f1a94a839981755f0380960511e60aba2b8d2 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Tue, 1 Feb 2022 16:07:29 +0100
Subject: [PATCH] Collation version tracking for macOS
---
src/backend/utils/adt/pg_locale.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index 871a710967..f8e57ee236 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -74,6 +74,10 @@
#include <gnu/libc-version.h>
#endif
+#ifdef __APPLE__
+#include <sys/sysctl.h>
+#endif
+
#ifdef WIN32
#include <shlwapi.h>
#endif
@@ -1696,6 +1700,28 @@ get_collation_actual_version(char collprovider, const char *collcollate)
else
ereport(ERROR,
(errmsg("could not load locale \"%s\"", collcollate)));
+#elif defined(__APPLE__)
+ /*
+ * The POSIX-level locales on macOS are mostly useless for real work,
+ * and they also don't appear to change much or at all. However, at
+ * least for development it is useful to have some version tracking
+ * mechanism on this platform. For lack of better ideas, we just
+ * record the internal major operating system version.
+ */
+ {
+ char str[256];
+ size_t len = sizeof(str);
+ char *p;
+
+ if (sysctlbyname("kern.osrelease", str, &len, NULL, 0) != 0)
+ ereport(ERROR,
+ (errmsg("could not get OS release: %m")));
+ /* value is three numbers like "12.3.4", we take only the first one */
+ p = strchr(str, '.');
+ if (p)
+ *p = '\0';
+ collversion = pstrdup(str);
+ }
#elif defined(WIN32) && _WIN32_WINNT >= 0x0600
/*
* If we are targeting Windows Vista and above, we can ask for a name
--
2.35.1
view thread (81+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: Collation version tracking for macOS
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox