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: Tue, 24 Dec 2019 07:38:54 -0800 Message-ID: References: <550d1942-f29c-4801-356d-a8c4b3b77ea4@cs.ucla.edu> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000034a81a059a74f3fe" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="155496"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel@gnu.org To: Paul Eggert Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Dec 24 16:40:05 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 1ijmHz-000eJA-7E for ged-emacs-devel@m.gmane.org; Tue, 24 Dec 2019 16:40:03 +0100 Original-Received: from localhost ([::1]:39954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ijmHy-0001qD-3Z for ged-emacs-devel@m.gmane.org; Tue, 24 Dec 2019 10:40:02 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33260) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ijmHV-0001RE-9N for emacs-devel@gnu.org; Tue, 24 Dec 2019 10:39:34 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ijmHT-0000fR-QD for emacs-devel@gnu.org; Tue, 24 Dec 2019 10:39:33 -0500 Original-Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:41663) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ijmHT-0000f0-Kq for emacs-devel@gnu.org; Tue, 24 Dec 2019 10:39:31 -0500 Original-Received: by mail-ot1-x344.google.com with SMTP id r27so26715577otc.8 for ; Tue, 24 Dec 2019 07:39:31 -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 :cc; bh=35Vnyuoe7BoJoAe2dDqSr3r/cs4jEHgrXpGn9lwn060=; b=dnstyUxxuZ3ICyhCtNOT0aSu//S3rFo3esesM4oqTROTkVlTxq+n1XSyDdQK28GJn4 ZjETHozd6EvwpOJFHAXy9HiW+JkmwnjKROIMQvtwea516UAacoy+u2OovBo5inYPup/W +Pe6ddtRqbthxizpXhdDpdhq9gddK96vSDxNg/IU8DW9y3ZwAuJMDz1ymyanI1ErRVhy PQRIh2fNVMAxTp4tXlPoKRK8k3n28qm5Hnv1Ueng9dCMPfvYV7WaDsALS9cAWF1Da48f F4ord8m1Pj/DQ6RaJnuNmOvZiYBN2VCwTNlZmBMtbjsPOMWlSr+5RTbvS9RbzV+jhEJk E0iQ== 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:cc; bh=35Vnyuoe7BoJoAe2dDqSr3r/cs4jEHgrXpGn9lwn060=; b=NCrp2xoqQ4Gayb9tz9qX5vzGBdZ9QNKxAFG844R184h3xbjp/DTC9odIF3vQhLyXtu HP32IUT0CaF5F+py25s/1tygPcA/HlXjT0ogLQtOauOF+YY0RfSyWz0VyZMNkBYWZ9UJ Qpv15cjoU6/Pgq2KEOm+Q+YYHn3sx9xnqPheXCjpqN/6Ag3WKZrdV+Zr0hrbKd4gQRhX cJ4ZkVAmdYgv+aUZRnEeQyb76MLmscFD5kFrVDZkMEL40KbArjkF5bv2vPG9K1p1ckM7 0jt4/cBxsoZSLGo/tMOd8K7XD1Z+qU6kCRub3LEQJ7Tc/llNZzWCiALxzfoL8t2zXwZZ lJlQ== X-Gm-Message-State: APjAAAV5On2uDtYsq2oJqZltZK7WBQCLgnBLqK7i2U7mPFwhbjsH+gu3 rVbFT/vYG/r9/nem0YMYIH3tmHEqvQ7DvrUSFS0= X-Google-Smtp-Source: APXvYqwFu//pshfEByGYHylz7S/bQjnC3nUnAFrtNSsYSLtYLcpTqRR9oAwfiPPVE+SbaLoG9p1CB3qxjhLFQzQc0Os= X-Received: by 2002:a05:6830:1715:: with SMTP id 21mr40330924otk.67.1577201970750; Tue, 24 Dec 2019 07:39:30 -0800 (PST) In-Reply-To: <550d1942-f29c-4801-356d-a8c4b3b77ea4@cs.ucla.edu> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::344 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:243612 Archived-At: --00000000000034a81a059a74f3fe Content-Type: text/plain; charset="UTF-8" On further reading the ImageMagick source, I would that the calls to 'MagickWandGenesis' protect themselves against redundant repeat calls. Hence, there is no need to protect it using a static variable. The following patch is a minimal fix. Link to source: https://github.com/ImageMagick/ImageMagick/blob/f775a5cf27a95c42bb6d19b50f4869db265fdaa9/MagickWand/magick-wand.c#L1001 -dhruva commit 23236f26d2f5839f2fdb7022039dcf102dcf3a3b Author: Dhruva Krishnamurthy Date: Mon Dec 23 14:49:51 2019 -0800 Initialize ImageMagick runtime environment before use diff --git a/src/image.c b/src/image.c index 70d932f9ed..75c31cad57 100644 --- a/src/image.c +++ b/src/image.c @@ -8875,13 +8875,8 @@ imagemagick_load_image (struct frame *f, struct image *img, char hint_buffer[MaxTextExtent]; char *filename_hint = NULL; - /* Initialize the ImageMagick environment. */ - static bool imagemagick_initialized; - if (!imagemagick_initialized) - { - imagemagick_initialized = true; - MagickWandGenesis (); - } + /* Initialize the ImageMagick environment if not initialized. */ + MagickWandGenesis (); /* 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 +9285,9 @@ DEFUN ("imagemagick-types", Fimagemagick_types, Simagemagick_types, 0, 0, 0, char **imtypes; size_t i; + /* Initialize the ImageMagick environment if not initialized. */ + MagickWandGenesis (); + ex = AcquireExceptionInfo (); imtypes = GetMagickList ("*", &numf, ex); DestroyExceptionInfo (ex); On Mon, Dec 23, 2019 at 6:51 PM Paul Eggert wrote: > On 12/23/19 6:09 PM, Dhruva Krishnamurthy wrote: > > I still feel the original patch calling into IsMagickWandInstantiated() > was > > more correct > > Not sure I follow, but anyway any change along those lines would be more > experimental, whereas the emacs-27 branch is for bug-fixing and is > maintained > more conservatively. > > PS. I didn't notice the "!!IsMagickWandInstantiated();" part of your > patch; if I > had, I would have omitted it from the emacs-27 branch and would have said > why. > --00000000000034a81a059a74f3fe Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On further r= eading the ImageMagick source, I would that the calls to 'MagickWandGen= esis' protect themselves against redundant repeat calls. Hence, there i= s no need to protect it using a static variable. The following patch is a m= inimal fix.


-d= hruva

commit 23236f26d2f5839f2fdb7022039d= cf102dcf3a3b
Author: Dhruva Krishnamurthy= <dhruvakm@gmail.com>
=
Date: =C2=A0 Mon Dec 23 14:49:51 2019 -0800

=C2= =A0 =C2=A0 Initialize ImageMagick runtime environment before use

diff --git a= /src/image.c b/src/image.c
index 70d932f9= ed..75c31cad57 100644
--- a/src/image.c
+++ b/src/image.c
@@ -8875,13 +8875,8 @@ imagemagick_load_image (struct frame *f, s= truct image *img,
=C2=A0 =C2=A0char hint_= buffer[MaxTextExtent];
=C2=A0 =C2=A0char = *filename_hint =3D NULL;
=C2=A0
- =C2=A0/* Initialize the ImageMagick environment.= =C2=A0*/
- =C2=A0static bool imagemagick= _initialized;
- =C2=A0if (!imagemagick_in= itialized)
- =C2=A0 =C2=A0{
- =C2=A0 =C2=A0 =C2=A0imagemagick_initialized =3D true= ;
- =C2=A0 =C2=A0 =C2=A0MagickWandGenesis= ();
- =C2=A0 =C2=A0}
+ =C2=A0/* Initialize the ImageMagick environment if not ini= tialized. */
+ =C2=A0MagickWandGenesis ()= ;
=C2=A0
=C2=A0 =C2=A0/* Handle image index for image types who can contain more t= han one image.
=C2=A0 =C2=A0 =C2=A0 Inter= face :index is same as for GIF.=C2=A0 First we "ping" the image t= o see how
@@ -9290,6 +9285,9 @@ DEFUN (&q= uot;imagemagick-types", Fimagemagick_types, Simagemagick_types, 0, 0, = 0,
=C2=A0 =C2=A0char **imtypes;
=C2=A0 =C2=A0size_t i;
=C2=A0
+ =C2=A0/* Initialize the I= mageMagick environment if not initialized. */
+ =C2=A0MagickWandGenesis ();
+
=C2=A0 =C2=A0ex =3D AcquireExceptionInfo ();<= /div>
=C2=A0 =C2=A0imtypes =3D GetMagickList (&= quot;*", &numf, ex);
=C2=A0 =C2= =A0DestroyExceptionInfo (ex);

<= /div>
O= n Mon, Dec 23, 2019 at 6:51 PM Paul Eggert <eggert@cs.ucla.edu> wrote:
On 12= /23/19 6:09 PM, Dhruva Krishnamurthy wrote:
> I still feel the original patch calling into IsMagickWandInstantiated(= ) was
> more correct

Not sure I follow, but anyway any change along those lines would be more experimental, whereas the emacs-27 branch is for bug-fixing and is maintain= ed
more conservatively.

PS. I didn't notice the "!!IsMagickWandInstantiated();" part = of your patch; if I
had, I would have omitted it from the emacs-27 branch and would have said w= hy.
--00000000000034a81a059a74f3fe--