aboutsummaryrefslogtreecommitdiffstats
path: root/src/image.c
diff options
context:
space:
mode:
authorPaul Eggert2019-07-10 12:37:55 -0700
committerPaul Eggert2019-07-10 12:41:13 -0700
commit40cd6278ba965f3a9fcdddc568eb9ee7c69cf899 (patch)
tree518c326c713350312b170a016bc145920bddb0f3 /src/image.c
parent83ed722c8d9d4d9d4143062584b89f79f3b8104a (diff)
downloademacs-40cd6278ba965f3a9fcdddc568eb9ee7c69cf899.tar.gz
emacs-40cd6278ba965f3a9fcdddc568eb9ee7c69cf899.zip
Avoid functions deprecated in librsvg 2.45.1
* src/image.c (init_svg_functions) [WINDOWSNT]: Load the pre-2.32 or 2.32 functions, depending on LIBRSVG_CHECK_VERSION. (svg_load_image): In librsvg 2.32 or later, use g_memory_input_stream_new_from_data, g_file_new_for_path and rsvg_handle_new_from_stream_sync rather than the deprecated-in-2.45 rsvg_handle_write and rsvg_handle_close. From a patch by YAMAMOTO Mitsuharu (Bug#35548#11).
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c82
1 files changed, 54 insertions, 28 deletions
diff --git a/src/image.c b/src/image.c
index e898a7364a8..3695342232d 100644
--- a/src/image.c
+++ b/src/image.c
@@ -9300,14 +9300,23 @@ svg_image_p (Lisp_Object object)
9300# endif 9300# endif
9301 9301
9302/* SVG library functions. */ 9302/* SVG library functions. */
9303# if LIBRSVG_CHECK_VERSION (2, 32, 0)
9304DEF_DLL_FN (GFile *, g_file_new_for_path, (char const *));
9305DEF_DLL_FN (GInputStream *, g_memory_input_stream_new_from_data,
9306 (void const *, gssize, GDestroyNotify));
9307DEF_DLL_FN (RsvgHandle *, rsvg_handle_new_from_stream_sync,
9308 (GInputStream *, GFile *, RsvgHandleFlags, GCancellable *,
9309 GError **error));
9310# else
9303DEF_DLL_FN (RsvgHandle *, rsvg_handle_new, (void)); 9311DEF_DLL_FN (RsvgHandle *, rsvg_handle_new, (void));
9304DEF_DLL_FN (void, rsvg_handle_get_dimensions, 9312DEF_DLL_FN (void, rsvg_handle_set_base_uri, (RsvgHandle *, const char *));
9305 (RsvgHandle *, RsvgDimensionData *));
9306DEF_DLL_FN (gboolean, rsvg_handle_write, 9313DEF_DLL_FN (gboolean, rsvg_handle_write,
9307 (RsvgHandle *, const guchar *, gsize, GError **)); 9314 (RsvgHandle *, const guchar *, gsize, GError **));
9308DEF_DLL_FN (gboolean, rsvg_handle_close, (RsvgHandle *, GError **)); 9315DEF_DLL_FN (gboolean, rsvg_handle_close, (RsvgHandle *, GError **));
9316#endif
9317DEF_DLL_FN (void, rsvg_handle_get_dimensions,
9318 (RsvgHandle *, RsvgDimensionData *));
9309DEF_DLL_FN (GdkPixbuf *, rsvg_handle_get_pixbuf, (RsvgHandle *)); 9319DEF_DLL_FN (GdkPixbuf *, rsvg_handle_get_pixbuf, (RsvgHandle *));
9310DEF_DLL_FN (void, rsvg_handle_set_base_uri, (RsvgHandle *, const char *));
9311 9320
9312DEF_DLL_FN (int, gdk_pixbuf_get_width, (const GdkPixbuf *)); 9321DEF_DLL_FN (int, gdk_pixbuf_get_width, (const GdkPixbuf *));
9313DEF_DLL_FN (int, gdk_pixbuf_get_height, (const GdkPixbuf *)); 9322DEF_DLL_FN (int, gdk_pixbuf_get_height, (const GdkPixbuf *));
@@ -9340,12 +9349,18 @@ init_svg_functions (void)
9340 return 0; 9349 return 0;
9341 } 9350 }
9342 9351
9352#if LIBRSVG_CHECK_VERSION (2, 32, 0)
9353 LOAD_DLL_FN (glib, g_file_new_for_path);
9354 LOAD_DLL_FN (glib, g_memory_input_stream_new_from_data);
9355 LOAD_DLL_FN (library, rsvg_handle_new_from_stream_sync);
9356#else
9343 LOAD_DLL_FN (library, rsvg_handle_new); 9357 LOAD_DLL_FN (library, rsvg_handle_new);
9344 LOAD_DLL_FN (library, rsvg_handle_get_dimensions); 9358 LOAD_DLL_FN (library, rsvg_handle_set_base_uri);
9345 LOAD_DLL_FN (library, rsvg_handle_write); 9359 LOAD_DLL_FN (library, rsvg_handle_write);
9346 LOAD_DLL_FN (library, rsvg_handle_close); 9360 LOAD_DLL_FN (library, rsvg_handle_close);
9361#endif
9362 LOAD_DLL_FN (library, rsvg_handle_get_dimensions);
9347 LOAD_DLL_FN (library, rsvg_handle_get_pixbuf); 9363 LOAD_DLL_FN (library, rsvg_handle_get_pixbuf);
9348 LOAD_DLL_FN (library, rsvg_handle_set_base_uri);
9349 9364
9350 LOAD_DLL_FN (gdklib, gdk_pixbuf_get_width); 9365 LOAD_DLL_FN (gdklib, gdk_pixbuf_get_width);
9351 LOAD_DLL_FN (gdklib, gdk_pixbuf_get_height); 9366 LOAD_DLL_FN (gdklib, gdk_pixbuf_get_height);
@@ -9379,12 +9394,18 @@ init_svg_functions (void)
9379# undef g_clear_error 9394# undef g_clear_error
9380# undef g_object_unref 9395# undef g_object_unref
9381# undef g_type_init 9396# undef g_type_init
9382# undef rsvg_handle_close
9383# undef rsvg_handle_get_dimensions 9397# undef rsvg_handle_get_dimensions
9384# undef rsvg_handle_get_pixbuf 9398# undef rsvg_handle_get_pixbuf
9385# undef rsvg_handle_new 9399# if LIBRSVG_CHECK_VERSION (2, 32, 0)
9386# undef rsvg_handle_set_base_uri 9400# undef g_file_new_for_path
9387# undef rsvg_handle_write 9401# undef g_memory_input_stream_new_from_data
9402# undef rsvg_handle_new_from_stream_sync
9403# else
9404# undef rsvg_handle_close
9405# undef rsvg_handle_new
9406# undef rsvg_handle_set_base_uri
9407# undef rsvg_handle_write
9408# endif
9388 9409
9389# define gdk_pixbuf_get_bits_per_sample fn_gdk_pixbuf_get_bits_per_sample 9410# define gdk_pixbuf_get_bits_per_sample fn_gdk_pixbuf_get_bits_per_sample
9390# define gdk_pixbuf_get_colorspace fn_gdk_pixbuf_get_colorspace 9411# define gdk_pixbuf_get_colorspace fn_gdk_pixbuf_get_colorspace
@@ -9399,12 +9420,19 @@ init_svg_functions (void)
9399# if ! GLIB_CHECK_VERSION (2, 36, 0) 9420# if ! GLIB_CHECK_VERSION (2, 36, 0)
9400# define g_type_init fn_g_type_init 9421# define g_type_init fn_g_type_init
9401# endif 9422# endif
9402# define rsvg_handle_close fn_rsvg_handle_close
9403# define rsvg_handle_get_dimensions fn_rsvg_handle_get_dimensions 9423# define rsvg_handle_get_dimensions fn_rsvg_handle_get_dimensions
9404# define rsvg_handle_get_pixbuf fn_rsvg_handle_get_pixbuf 9424# define rsvg_handle_get_pixbuf fn_rsvg_handle_get_pixbuf
9405# define rsvg_handle_new fn_rsvg_handle_new 9425# if LIBRSVG_CHECK_VERSION (2, 32, 0)
9406# define rsvg_handle_set_base_uri fn_rsvg_handle_set_base_uri 9426# define g_file_new_for_path fn_g_file_new_for_path
9407# define rsvg_handle_write fn_rsvg_handle_write 9427# define g_memory_input_stream_new_from_data \
9428 fn_g_memory_input_stream_new_from_data
9429# define rsvg_handle_new_from_stream_sync fn_rsvg_handle_new_from_stream_sync
9430# else
9431# define rsvg_handle_close fn_rsvg_handle_close
9432# define rsvg_handle_new fn_rsvg_handle_new
9433# define rsvg_handle_set_base_uri fn_rsvg_handle_set_base_uri
9434# define rsvg_handle_write fn_rsvg_handle_write
9435# endif
9408 9436
9409# endif /* !WINDOWSNT */ 9437# endif /* !WINDOWSNT */
9410 9438
@@ -9489,6 +9517,18 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
9489 g_type_init (); 9517 g_type_init ();
9490#endif 9518#endif
9491 9519
9520#if LIBRSVG_CHECK_VERSION (2, 32, 0)
9521 GInputStream *input_stream
9522 = g_memory_input_stream_new_from_data (contents, size, NULL);
9523 GFile *base_file = filename ? g_file_new_for_path (filename) : NULL;
9524 rsvg_handle = rsvg_handle_new_from_stream_sync (input_stream, base_file,
9525 RSVG_HANDLE_FLAGS_NONE,
9526 NULL, &err);
9527 if (base_file)
9528 g_object_unref (base_file);
9529 g_object_unref (input_stream);
9530 if (err) goto rsvg_error;
9531#else
9492 /* Make a handle to a new rsvg object. */ 9532 /* Make a handle to a new rsvg object. */
9493 rsvg_handle = rsvg_handle_new (); 9533 rsvg_handle = rsvg_handle_new ();
9494 9534
@@ -9498,17 +9538,6 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
9498 if (filename) 9538 if (filename)
9499 rsvg_handle_set_base_uri (rsvg_handle, filename); 9539 rsvg_handle_set_base_uri (rsvg_handle, filename);
9500 9540
9501 /* Suppress GCC deprecation warnings starting in librsvg 2.45.1 for
9502 rsvg_handle_write and rsvg_handle_close. FIXME: Use functions
9503 like rsvg_handle_new_from_gfile_sync on newer librsvg versions,
9504 and remove this hack. */
9505 #if GNUC_PREREQ (4, 6, 0)
9506 #pragma GCC diagnostic push
9507 #endif
9508 #if LIBRSVG_CHECK_VERSION (2, 45, 1) && GNUC_PREREQ (4, 2, 0)
9509 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
9510 #endif
9511
9512 /* Parse the contents argument and fill in the rsvg_handle. */ 9541 /* Parse the contents argument and fill in the rsvg_handle. */
9513 rsvg_handle_write (rsvg_handle, (unsigned char *) contents, size, &err); 9542 rsvg_handle_write (rsvg_handle, (unsigned char *) contents, size, &err);
9514 if (err) goto rsvg_error; 9543 if (err) goto rsvg_error;
@@ -9517,10 +9546,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
9517 for further writes. */ 9546 for further writes. */
9518 rsvg_handle_close (rsvg_handle, &err); 9547 rsvg_handle_close (rsvg_handle, &err);
9519 if (err) goto rsvg_error; 9548 if (err) goto rsvg_error;
9520 9549#endif
9521 #if GNUC_PREREQ (4, 6, 0)
9522 #pragma GCC diagnostic pop
9523 #endif
9524 9550
9525 rsvg_handle_get_dimensions (rsvg_handle, &dimension_data); 9551 rsvg_handle_get_dimensions (rsvg_handle, &dimension_data);
9526 if (! check_image_size (f, dimension_data.width, dimension_data.height)) 9552 if (! check_image_size (f, dimension_data.width, dimension_data.height))