[gtk-osx] Patch CFStringGetCStringPtr blunder in gio.
- From: John Ralls <jralls src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-osx] Patch CFStringGetCStringPtr blunder in gio.
- Date: Thu, 26 Oct 2017 19:50:42 +0000 (UTC)
commit f333bb9b866bc0cbfaff0eb9d665ddac0f2f7877
Author: John Ralls <jralls ceridwen us>
Date: Fri Oct 13 14:12:48 2017 -0700
Patch CFStringGetCStringPtr blunder in gio.
modulesets-stable/gtk-osx.modules | 2 +
...ack-to-CFStringGetCSTring-if-CFStringGetC.patch | 116 ++++++++++++++++++++
2 files changed, 118 insertions(+), 0 deletions(-)
---
diff --git a/modulesets-stable/gtk-osx.modules b/modulesets-stable/gtk-osx.modules
index 800b964..fa52834 100644
--- a/modulesets-stable/gtk-osx.modules
+++ b/modulesets-stable/gtk-osx.modules
@@ -80,6 +80,8 @@
<branch module="glib/2.52/glib-2.52.2.tar.xz" version="2.52.2"
hash="sha256:f00e5d9e2a2948b1da25fcba734a6b7a40f556de8bc9f528a53f6569969ac5d0">
<patch file="https://git.gnome.org/browse/gtk-osx/plain/patches/glib-gint64-long-long.patch"
strip="1"/>
+ <!-- Fix should be in glib-2.54.2 -->
+ <patch
file='https://git.gnome.org/browse/gtk-osx/plain/patches/glib-2.52-Fallback-to-CFStringGetCSTring-if-CFStringGetC.patch"
strip="1"/>
</branch>
<dependencies>
<dep package="libffi"/>
diff --git a/patches/glib-2.52-Fallback-to-CFStringGetCSTring-if-CFStringGetC.patch
b/patches/glib-2.52-Fallback-to-CFStringGetCSTring-if-CFStringGetC.patch
new file mode 100644
index 0000000..5155813
--- /dev/null
+++ b/patches/glib-2.52-Fallback-to-CFStringGetCSTring-if-CFStringGetC.patch
@@ -0,0 +1,116 @@
+From d5a9ce69c46a907af8ed3af0020d2a409faa3751 Mon Sep 17 00:00:00 2001
+From: John Ralls <jralls ceridwen us>
+Date: Fri, 13 Oct 2017 13:45:01 -0700
+Subject: [PATCH] [MacOS] Fallback to CFStringGetCSTring if
+ CFStringGetCStringPtr fails.
+
+---
+ gio/gosxappinfo.c | 34 ++++++++++++++++++++++++++++++++--
+ gio/gosxcontenttype.c | 34 ++++++++++++++++++++++++++++++++--
+ 2 files changed, 64 insertions(+), 4 deletions(-)
+
+diff --git a/gio/gosxappinfo.c b/gio/gosxappinfo.c
+index b24b6ff..7c2b402 100644
+--- a/gio/gosxappinfo.c
++++ b/gio/gosxappinfo.c
+@@ -175,14 +175,44 @@ static gchar *
+ create_cstr_from_cfstring (CFStringRef str)
+ {
+ const gchar *cstr;
++ CFIndex length = CFStringGetLength (str);
++ char *buffer = NULL;
+
+ if (str == NULL)
+ return NULL;
+
+ cstr = CFStringGetCStringPtr (str, kCFStringEncodingUTF8);
++ /* CFStringGetCStringPtr returns "NULL if the internal storage of
++ * theString does not allow [a pointer] to be returned efficiently".
++ * (Apple's docs don't say what that means). In that case we must
++ * use CFStringGetCString as a fallback.
++ */
++ if (cstr != NULL)
++ {
++ CFRelease (str);
++ return g_strdup (cstr);
++ }
++
++ buffer = g_malloc0 (length + 1);
++ /* Start off with a buffer size sufficient for the most likely case
++ * that the CFString is ASCII so the UTF8 representation will be 1
++ * byte per code point. Keep trying up to 4 bytes per code point,
++ * the max allowed by RFC3629.
++ */
++ for (int i = 1; i <= 4; ++i)
++ {
++ if (CFStringGetCString (str, buffer, length, kCFStringEncodingUTF8))
++ {
++ CFRelease (str);
++ return buffer;
++ }
++ length += length;
++ buffer = g_realloc (buffer, length + 1);
++ }
++
++ g_free (buffer);
+ CFRelease (str);
+-
+- return g_strdup (cstr);
++ return NULL;
+ }
+
+ static char *
+diff --git a/gio/gosxcontenttype.c b/gio/gosxcontenttype.c
+index 485f5bf..c046d9e 100644
+--- a/gio/gosxcontenttype.c
++++ b/gio/gosxcontenttype.c
+@@ -53,14 +53,44 @@ static gchar *
+ create_cstr_from_cfstring (CFStringRef str)
+ {
+ const gchar *cstr;
++ CFIndex length = CFStringGetLength (str);
++ char *buffer = NULL;
+
+ if (str == NULL)
+ return NULL;
+
+ cstr = CFStringGetCStringPtr (str, kCFStringEncodingUTF8);
++ /* CFStringGetCStringPtr returns "NULL if the internal storage of
++ * theString does not allow [a pointer] to be returned efficiently".
++ * (Apple's docs don't say what that means). In that case we must
++ * use CFStringGetCString as a fallback.
++ */
++ if (cstr != NULL)
++ {
++ CFRelease (str);
++ return g_strdup (cstr);
++ }
++
++ buffer = g_malloc0 (length + 1);
++ /* Start off with a buffer size sufficient for the most likely case
++ * that the CFString is ASCII so the UTF8 representation will be 1
++ * byte per code point. Keep trying up to 4 bytes per code point,
++ * the max allowed by RFC3629.
++ */
++ for (int i = 1; i <= 4; ++i)
++ {
++ if (CFStringGetCString (str, buffer, length, kCFStringEncodingUTF8))
++ {
++ CFRelease (str);
++ return buffer;
++ }
++ length += length;
++ buffer = g_realloc (buffer, length + 1);
++ }
++
++ g_free (buffer);
+ CFRelease (str);
+-
+- return g_strdup (cstr);
++ return NULL;
+ }
+
+ /*< internal >
+--
+2.2.2
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]