[glib/resources.msvc: 12/13] glib-compile-resources: Fix code generation for MSVC builds
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/resources.msvc: 12/13] glib-compile-resources: Fix code generation for MSVC builds
- Date: Wed, 5 Dec 2018 08:18:18 +0000 (UTC)
commit 4501807d7319726a620841cafbab705a21c378dc
Author: Chun-wei Fan <fanc999 yahoo com tw>
Date: Thu Nov 29 16:12:26 2018 +0800
glib-compile-resources: Fix code generation for MSVC builds
glib-compile-resources was updated to generate octal byte
representation in a string, but unfortunately this breaks the build
on Visual Studio when the generated string sequence exceeds 65535
characters, which is the imposed limit on Visual Studio compilers.
To make things work on Visual Studio builds and to not slow down things
on other compilers, generate a code path for Visual Studio an array of
octal byte representations, as well as a code path for other compilers
that use the new string representation of octal values, and let the
compiler take the appropriate code path when compiling the
generated code.
Fixes issue #1580.
gio/glib-compile-resources.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/gio/glib-compile-resources.c b/gio/glib-compile-resources.c
index 7e318b254..2c421b6a4 100644
--- a/gio/glib-compile-resources.c
+++ b/gio/glib-compile-resources.c
@@ -1086,9 +1086,33 @@ main (int argc, char **argv)
"#else\n"
"# define SECTION\n"
"#endif\n"
- "\n"
+ "\n",
+ c_name_no_underscores);
+
+ /* For Visual Studio builds: Avoid surpassing the 65535-character limit for a string, GitLab issue
#1580 */
+ g_fprintf (file, "#ifdef _MSC_VER\n");
+ g_fprintf (file,
+ "static const SECTION union { const guint8 data[%"G_GSIZE_FORMAT"]; const double alignment; void
* const ptr;} %s_resource_data = { {\n",
+ data_size + 1 /* nul terminator */, c_name);
+
+ for (i = 0; i < data_size; i++)
+ {
+ if (i % 16 == 0)
+ g_fprintf (file, " ");
+ g_fprintf (file, "0%3.3o", (int)data[i]);
+ if (i != data_size - 1)
+ g_fprintf (file, ", ");
+ if (i % 16 == 15 || i == data_size - 1)
+ g_fprintf (file, "\n");
+ }
+
+ g_fprintf (file, "} };\n");
+
+ /* For other compilers, use the long string approach */
+ g_fprintf (file, "#else /* _MSC_VER */\n");
+ g_fprintf (file,
"static const SECTION union { const guint8 data[%"G_GSIZE_FORMAT"]; const double alignment;
void * const ptr;} %s_resource_data = {\n \"",
- c_name_no_underscores, data_size + 1 /* nul terminator */, c_name);
+ data_size + 1 /* nul terminator */, c_name);
for (i = 0; i < data_size; i++) {
g_fprintf (file, "\\%3.3o", (int)data[i]);
@@ -1097,6 +1121,7 @@ main (int argc, char **argv)
}
g_fprintf (file, "\" };\n");
+ g_fprintf (file, "#endif /* !_MSC_VER */\n");
g_fprintf (file,
"\n"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]