From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Dhruva Krishnamurthy Newsgroups: gmane.emacs.devel Subject: Re: Build segfaults when loading image.el Date: Mon, 23 Dec 2019 14:43:55 -0800 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000004a8923059a66c5e5" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="202038"; mail-complaints-to="usenet@blaine.gmane.org" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Dec 23 23:45:24 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ijWS3-000qND-Ce for ged-emacs-devel@m.gmane.org; Mon, 23 Dec 2019 23:45:23 +0100 Original-Received: from localhost ([::1]:33950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ijWS2-0008DD-3G for ged-emacs-devel@m.gmane.org; Mon, 23 Dec 2019 17:45:22 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37069) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ijWRI-0007Yq-Vv for emacs-devel@gnu.org; Mon, 23 Dec 2019 17:44:38 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ijWRH-0000Bi-Ie for emacs-devel@gnu.org; Mon, 23 Dec 2019 17:44:36 -0500 Original-Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:45104) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ijWRH-00007q-Ca for emacs-devel@gnu.org; Mon, 23 Dec 2019 17:44:35 -0500 Original-Received: by mail-ot1-x341.google.com with SMTP id 59so23887531otp.12 for ; Mon, 23 Dec 2019 14:44:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=skp+NxXqmvCIj1dkdgjSYsO4qmuvZqzqIhWjuRqzQiI=; b=ePzvZYvLvgFy2H8gzFk3qIUA840UFVKWC3Y8SeltGxGgIDhy98Sa3Nb8djOi0iupET 1PqHNictGaYEsV3Xa0BEd48CLqiXot4aDcrD0SCZZ9GUKDL9LSvEbEc/v2ygUG3eEldU XzlVCXEQjC1oZedb8gUw3TPPBnQ/Pt85sR8vcWVzy8nPaSj4eWcbq93JjQt2lo8ZLhAK MFSwSBrawPHfoBbcLe9MLXMxkS81H5TEH5gbXe6utW2claLa2S6pr4ZxVeiOh8WQtSMa sorF4P6xDNKuyP67e+s9TK8bGqPdCo0WFvwPSD7imEO4V47gnTMRIc85MplmD5CI5PFA PAcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=skp+NxXqmvCIj1dkdgjSYsO4qmuvZqzqIhWjuRqzQiI=; b=BrAXH8L42FohMBx3wrG8fNiw12M5Mz0+1vNMH7bM4XKGh0kR7UEB/HsBDjjsBsXqwJ /2UWk5nbzTsAK4iwS7UI8UP1N3A93Q+oiltcE8w4aHAUARZnRIEy8ZIkulkUQjkluSxZ B0bOX3XFD+g6poxF/u4yLrtnlXR5A2dWA619r+BelUIS5/hujGA3kXkjeTdoM8ngEnon XJatjFvv/Rzs+zKvGKCeJXi87eQ1xUmEDEQLuph99MzDHGvisv2gaavPn+j7HLeqTlFp slwWmszZyi0KvPJnpsxGIL+pcuQYPVGmARD9fiWOB1qjOCJomkYbsKpqu9bi2nqpmpFR t5Zg== X-Gm-Message-State: APjAAAUnWF56RvFJ6UASXl5K+HFlxNsvkYhbkrk14qjZA77nbf+4yOy6 xf3/zzbcDW3GUeXMotblJLcZoXsKlz4jsq8ZoYlw3YNikBA= X-Google-Smtp-Source: APXvYqwasp6KCL1qPEZiCEDWtRULUV6Hqooo9s70CWA/COVVxDjdBo0fBKu9rBc9WPpHQJBVy9A1yZLJf5FcQ9/hxuI= X-Received: by 2002:a05:6830:4b9:: with SMTP id l25mr36040645otd.266.1577141070889; Mon, 23 Dec 2019 14:44:30 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::341 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:243595 Archived-At: --0000000000004a8923059a66c5e5 Content-Type: text/plain; charset="UTF-8" Missed providing other details: # Build host env $ uname -a Darwin C02V341YHTD8 19.2.0 Darwin Kernel Version 19.2.0: Sat Nov 9 03:47:04 PST 2019; root:xnu-6153.61.1~20/RELEASE_X86_64 x86_64 i386 MacBookPro14,3 Darwin # Configure options $ configure CC=clang --with-imagemagick # ImageMagic details $ MagickWand-config --cflags --ldflags -Xpreprocessor -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -Xpreprocessor -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/local/Cellar/imagemagick/7.0.9-10/include/ImageMagick-7 -L/usr/local/Cellar/imagemagick/7.0.9-10/lib -lMagickWand-7.Q16HDRI -lMagickCore-7.Q16HDRI On Mon, Dec 23, 2019 at 1:59 PM Dhruva Krishnamurthy wrote: > Loading image.el segfaults when ImageMagick is enabled on MacOS (do not > have access to other platforms) since image magic environment is not > initialized yet. The following patch on HEAD fixes the crash by > initializing it before use. > > -dhruva > > diff --git a/src/image.c b/src/image.c > index 70d932f9ed..50d90ccb55 100644 > --- a/src/image.c > +++ b/src/image.c > @@ -8603,6 +8603,20 @@ #define DrawRectangle DrawRectangleGif > MagickPixelPacket *); > #endif > > +/* Initialize the ImageMagick environment if not initialized. */ > + > +static void > +imagemagick_initialize(void) > +{ > + /* Initialize the ImageMagick environment. */ > + static bool imagemagick_initialized; > + if (!imagemagick_initialized) > + { > + MagickWandGenesis(); > + imagemagick_initialized = !!IsMagickWandInstantiated(); > + } > +} > + > /* Log ImageMagick error message. > Useful when an ImageMagick function returns the status `MagickFalse'. > */ > > @@ -8876,12 +8890,7 @@ imagemagick_load_image (struct frame *f, struct > image *img, > char *filename_hint = NULL; > > /* Initialize the ImageMagick environment. */ > - static bool imagemagick_initialized; > - if (!imagemagick_initialized) > - { > - imagemagick_initialized = true; > - MagickWandGenesis (); > - } > + imagemagick_initialize(); > > /* Handle image index for image types who can contain more than one > image. > Interface :index is same as for GIF. First we "ping" the image to > see how > @@ -9290,6 +9299,9 @@ DEFUN ("imagemagick-types", Fimagemagick_types, > Simagemagick_types, 0, 0, 0, > char **imtypes; > size_t i; > > + /* Initialize the ImageMagick environment. */ > + imagemagick_initialize(); > + > ex = AcquireExceptionInfo (); > imtypes = GetMagickList ("*", &numf, ex); > DestroyExceptionInfo (ex); > > > --0000000000004a8923059a66c5e5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Missed provi= ding other details:

# Build host env
$ un= ame -a
Darwin C02V341YHTD8 19.2.0 Darwin = Kernel Version 19.2.0: Sat Nov =C2=A09 03:47:04 PST 2019; root:xnu-6153.61.= 1~20/RELEASE_X86_64 x86_64 i386 MacBookPro14,3 Darwin

# Configure options
$ configure CC=3Dclang --with-i= magemagick

# ImageMagic details
$ MagickW= and-config --cflags --ldflags
-Xpreproces= sor -fopenmp -DMAGICKCORE_HDRI_ENABLE=3D1 -DMAGICKCORE_QUANTUM_DEPTH=3D16 -= Xpreprocessor -fopenmp -DMAGICKCORE_HDRI_ENABLE=3D1 -DMAGICKCORE_QUANTUM_DE= PTH=3D16 -I/usr/local/Cellar/imagemagick/7.0.9-10/include/ImageMagick-7
-L/usr/local/Cellar/imagemagick/7.0.9-10/lib= -lMagickWand-7.Q16HDRI -lMagickCore-7.Q16HDRI


On Mon, Dec 23, 2019 at 1:59 PM Dhr= uva Krishnamurthy <dhruvakm@gmail.= com> wrote:
L= oading image.el segfaults when ImageMagick is enabled on MacOS (do not have= access to other platforms) since image magic environment is not initialize= d yet. The following patch on HEAD fixes the crash by initializing it befor= e use.

-dhruva

diff --git a/src/imag= e.c b/src/image.c
index 70d932f9ed..50d90= ccb55 100644
--- a/src/image.c
+++ b/src/image.c
@@ -8603,6 +8603,20 @@ #define DrawRectangle DrawRectangleGif
=C2=A0 =C2=A0 =C2=A0MagickPixelPacket *);
=C2= =A0#endif
=C2=A0
+/* Initialize the ImageMagick environment if not initialized. = =C2=A0*/
+
+static void
+imagemagick_initialize(= void)
+{
+ =C2=A0/* Initialize the ImageMagick environment. =C2=A0*/
+ =C2=A0static bool imagemagick_initialized;
+ =C2=A0if (!imagemagick_initialized)
+ =C2=A0 =C2=A0{
+ = =C2=A0 =C2=A0 =C2=A0MagickWandGenesis();
= + =C2=A0 =C2=A0 =C2=A0imagemagick_initialized =3D !!IsMagickWandInstantiate= d();
+ =C2=A0 =C2=A0}
+}
+
=C2=A0/* Log ImageMagick error message.
=C2=A0 =C2=A0 Useful when an ImageMagick function returns the s= tatus `MagickFalse'. =C2=A0*/
=C2=A0<= /div>
@@ -8876,12 +8890,7 @@ imagemagick_load_i= mage (struct frame *f, struct image *img,
=C2=A0 =C2=A0char *filename_hint =3D NULL;
=C2=A0
=C2=A0 =C2=A0/* Initialize the = ImageMagick environment. =C2=A0*/
- =C2= =A0static bool imagemagick_initialized;
-= =C2=A0if (!imagemagick_initialized)
- = =C2=A0 =C2=A0{
- =C2=A0 =C2=A0 =C2=A0imag= emagick_initialized =3D true;
- =C2=A0 = =C2=A0 =C2=A0MagickWandGenesis ();
- =C2= =A0 =C2=A0}
+ =C2=A0imagemagick_initializ= e();
=C2=A0
=C2=A0 =C2=A0/* Handle image index for image types who can contain mor= e than one image.
=C2=A0 =C2=A0 =C2=A0 In= terface :index is same as for GIF.=C2=A0 First we "ping" the imag= e to see how
@@ -9290,6 +9299,9 @@ DEFUN = ("imagemagick-types", Fimagemagick_types, Simagemagick_types, 0, = 0, 0,
=C2=A0 =C2=A0char **imtypes;
<= div class=3D"gmail_default">=C2=A0 =C2=A0size_t i;
=C2=A0
+ =C2=A0/* Initialize th= e ImageMagick environment. =C2=A0*/
+ =C2= =A0imagemagick_initialize();
+
=C2=A0 =C2=A0ex =3D AcquireExceptionInfo ();
<= div class=3D"gmail_default">=C2=A0 =C2=A0imtypes =3D GetMagickList ("*= ", &numf, ex);
=C2=A0 =C2=A0Dest= royExceptionInfo (ex);


--0000000000004a8923059a66c5e5--