X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fglib-compile-resources.c;h=60ccdbf81623091f7bb080b662751923cc47f0df;hb=a60402374ac62bf99a22f84f0801d5513b12fd66;hp=bf88334b1d0b217c7a740dfe61f15c8f941f5297;hpb=c269d2d422d5a0be99f0fcf71762db547481031b;p=platform%2Fupstream%2Fglib.git diff --git a/gio/glib-compile-resources.c b/gio/glib-compile-resources.c index bf88334..60ccdbf 100644 --- a/gio/glib-compile-resources.c +++ b/gio/glib-compile-resources.c @@ -483,7 +483,7 @@ end_element (GMarkupParseContext *context, } g_free (data->content); - data->content_size = g_memory_output_stream_get_size (G_MEMORY_OUTPUT_STREAM (out)); + data->content_size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (out)); data->content = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (out)); g_object_unref (compressor); @@ -725,6 +725,7 @@ main (int argc, char **argv) gboolean generate_header = FALSE; gboolean manual_register = FALSE; gboolean internal = FALSE; + gboolean external_data = FALSE; gboolean generate_dependencies = FALSE; gboolean generate_phony_targets = FALSE; char *dependency_file = NULL; @@ -744,6 +745,7 @@ main (int argc, char **argv) { "generate-phony-targets", 0, 0, G_OPTION_ARG_NONE, &generate_phony_targets, N_("Include phony targets in the generated dependency file"), NULL }, { "manual-register", 0, 0, G_OPTION_ARG_NONE, &manual_register, N_("Don’t automatically create and register resource"), NULL }, { "internal", 0, 0, G_OPTION_ARG_NONE, &internal, N_("Don’t export functions; declare them G_GNUC_INTERNAL"), NULL }, + { "external-data", 0, 0, G_OPTION_ARG_NONE, &external_data, N_("Don’t embed resource data in the C file; assume it's linked externally instead"), NULL }, { "c-name", 0, 0, G_OPTION_ARG_STRING, &c_name, N_("C identifier name used for the generated source code"), NULL }, { NULL } }; @@ -1086,31 +1088,63 @@ main (int argc, char **argv) "#else\n" "# define SECTION\n" "#endif\n" - "\n" - "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, c_name); - - for (i = 0; i < data_size; i++) { - if (i % 8 == 0) - g_fprintf (file, " "); - g_fprintf (file, "0x%2.2x", (int)data[i]); - if (i != data_size - 1) - g_fprintf (file, ", "); - if ((i % 8 == 7) || (i == data_size - 1)) - g_fprintf (file, "\n"); - } + "\n", + c_name_no_underscores); + + if (external_data) + { + g_fprintf (file, + "extern const SECTION union { const guint8 data[%"G_GSIZE_FORMAT"]; const double alignment; void * const ptr;} %s_resource_data;" + "\n", + data_size, c_name); + } + else + { + /* 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 \"", + data_size + 1 /* nul terminator */, c_name); - g_fprintf (file, "} };\n"); + for (i = 0; i < data_size; i++) + { + g_fprintf (file, "\\%3.3o", (int)data[i]); + if (i % 16 == 15) + g_fprintf (file, "\"\n \""); + } + + g_fprintf (file, "\" };\n"); + g_fprintf (file, "#endif /* !_MSC_VER */\n"); + } g_fprintf (file, "\n" - "static GStaticResource static_resource = { %s_resource_data.data, sizeof (%s_resource_data.data), NULL, NULL, NULL };\n" + "static GStaticResource static_resource = { %s_resource_data.data, sizeof (%s_resource_data.data)%s, NULL, NULL, NULL };\n" "%s GResource *%s_get_resource (void);\n" "GResource *%s_get_resource (void)\n" "{\n" " return g_static_resource_get_resource (&static_resource);\n" "}\n", - c_name, c_name, linkage, c_name, c_name); + c_name, c_name, (external_data ? "" : " - 1 /* nul terminator */"), linkage, c_name, c_name); if (manual_register)