Re: notmuch and "mute" -- useful to anyone?
[notmuch-archives.git] / 06 / 9c51317e3a9f020e3d83b27af957c56afff1f3
1 Return-Path: <teythoon@jade-hamburg.de>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 868DB431FAF\r
6         for <notmuch@notmuchmail.org>; Thu, 30 May 2013 05:26:44 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id i+1BCzKjDItp for <notmuch@notmuchmail.org>;\r
16         Thu, 30 May 2013 05:26:36 -0700 (PDT)\r
17 Received: from mail.cryptobitch.de (cryptobitch.de [88.198.7.68])\r
18         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 224E5431FAE\r
21         for <notmuch@notmuchmail.org>; Thu, 30 May 2013 05:26:35 -0700 (PDT)\r
22 Received: from mail.jade-hamburg.de (mail.jade-hamburg.de [85.183.11.228])\r
23         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
24         (No client certificate requested)\r
25         by mail.cryptobitch.de (Postfix) with ESMTPSA id 1D44F64C63D\r
26         for <notmuch@notmuchmail.org>; Thu, 30 May 2013 14:26:16 +0200 (CEST)\r
27 Received: by mail.jade-hamburg.de (Postfix, from userid 401)\r
28         id 5FAE6DF28B; Thu, 30 May 2013 14:26:14 +0200 (CEST)\r
29 Received: from thinkbox.jade-hamburg.de (cryptobitch.de [88.198.7.68])\r
30         (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
31         (No client certificate requested) (Authenticated sender: teythoon)\r
32         by mail.jade-hamburg.de (Postfix) with ESMTPSA id 8B725DF28B;\r
33         Thu, 30 May 2013 14:26:10 +0200 (CEST)\r
34 Received: from teythoon by thinkbox.jade-hamburg.de with local (Exim 4.80)\r
35         (envelope-from <teythoon@thinkbox.jade-hamburg.de>)\r
36         id 1Ui1vl-0003KD-2H; Thu, 30 May 2013 14:26:09 +0200\r
37 Content-Type: multipart/signed; protocol="application/pgp-signature";\r
38         micalg="pgp-sha256"; boundary="===============4092482392989916922=="\r
39 MIME-Version: 1.0\r
40 Content-Disposition: inline\r
41 From: Justus Winter <4winter@informatik.uni-hamburg.de>\r
42 User-Agent: alot/0.3.4\r
43 To: Julian Berman <Julian@GrayVines.com>,  notmuch@notmuchmail.org\r
44 References: <1369540418-94177-1-git-send-email-Julian@GrayVines.com>\r
45 In-Reply-To: <1369540418-94177-1-git-send-email-Julian@GrayVines.com>\r
46 Message-ID: <20130530122608.20099.26290@thinkbox.jade-hamburg.de>\r
47 Subject: Re: [PATCH] Fix shared library loading in Python bindings.\r
48 Date: Thu, 30 May 2013 14:26:08 +0200\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Thu, 30 May 2013 12:26:44 -0000\r
62 \r
63 --===============4092482392989916922==\r
64 Content-Type: text/plain; charset="utf-8"\r
65 MIME-Version: 1.0\r
66 Content-Transfer-Encoding: quoted-printable\r
67 \r
68 Hi Julian :)\r
69 \r
70 Quoting Julian Berman (2013-05-26 05:53:38)\r
71 > Specifically, fixes loading on OS X, where libnotmuch will be\r
72 > a dylib.:\r
73 > ---\r
74 >  bindings/python/notmuch/globals.py | 3 ++-\r
75 >  1 file changed, 2 insertions(+), 1 deletion(-)\r
76 > =\r
77 \r
78 > diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch=\r
79 /globals.py\r
80 > index c7632c3..5e08e73 100644\r
81 > --- a/bindings/python/notmuch/globals.py\r
82 > +++ b/bindings/python/notmuch/globals.py\r
83 > @@ -18,11 +18,12 @@ Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>\r
84 >  """\r
85 >  =\r
86 \r
87 >  from ctypes import CDLL, Structure, POINTER\r
88 > +from ctypes.util import find_library\r
89 >  =\r
90 \r
91 >  #-----------------------------------------------------------------------=\r
92 ------\r
93 >  #package-global instance of the notmuch library\r
94 >  try:\r
95 > -    nmlib =3D CDLL("libnotmuch.so.3")\r
96 > +    nmlib =3D CDLL(find_library("libnotmuch"))\r
97 \r
98 Does this work for you on Darwin? On my box (Debian/Linux) I have to\r
99 use "notmuch" instead of "libnotmuch" to get anything from\r
100 find_library:\r
101 \r
102 In [5]: print ctypes.util.find_library("notmuch")\r
103 libnotmuch.so.3\r
104 \r
105 In [6]: print ctypes.util.find_library("libnotmuch")\r
106 None\r
107 \r
108 Then again, find_library is different for every architecture under the\r
109 sun...\r
110 \r
111 >  except:\r
112 >      raise ImportError("Could not find shared 'notmuch' library.")\r
113 \r
114 I'm leaning towards declining the patch in it's current form. If the\r
115 bindings do not work on OS X, we need to find another solution. There\r
116 are two reasons for this:\r
117 \r
118 1. find_library was once used, but was removed since it is (has?) been\r
119 problematic wrt to LD_LIBRARY_PATH usage:\r
120 \r
121 % git show f378f458\r
122 commit f378f45893bb4263402008b2abd8aab522901fb6\r
123 Author: Cedric Cabessa <ced@ryick.net>\r
124 Date:   Mon Apr 5 03:03:51 2010 +0200\r
125 \r
126     find_library does not read LD_LIBRARY_PATH, but CDLL does.\r
127 \r
128 diff --git a/cnotmuch/globals.py b/cnotmuch/globals.py\r
129 index ef2686f..fa20ae8 100644\r
130 --- a/cnotmuch/globals.py\r
131 +++ b/cnotmuch/globals.py\r
132 @@ -3,17 +3,17 @@ from ctypes.util import find_library\r
133  =\r
134 \r
135  #-------------------------------------------------------------------------=\r
136 ----\r
137  #package-global instance of the notmuch library\r
138 -#TODO: lazy load this on first access?\r
139 -so =3D find_library('notmuch')\r
140 -if so is None:\r
141 -  raise ImportError("Could not find shared 'notmuch' library.")\r
142 -nmlib =3D CDLL(so)\r
143 +try:\r
144 +    nmlib =3D CDLL("libnotmuch.so.1")\r
145 +except:\r
146 +    raise ImportError("Could not find shared 'notmuch' library.")\r
147 [...]\r
148 \r
149 As a heavy LD_LIBRARY_PATH user I don't want to break this. So I tried\r
150 to test whether find_library now respects LD_LIBRARY_PATH or not:\r
151 \r
152 teythoon@thinkbox ~ % echo $LD_LIBRARY_PATH\r
153 /home/teythoon/.local/lib\r
154 teythoon@thinkbox ~ % strace -e trace=3Dopen python -c 'import ctypes; ctyp=\r
155 es.CDLL("libnotmuch.so.3")' 2>&1 | grep notmuch\r
156 open("/home/teythoon/.local/lib/libnotmuch.so.3", O_RDONLY) =3D 3\r
157 \r
158 That's how it's done now and indeed it finds my libnotmuch.\r
159 \r
160 teythoon@thinkbox ~ % strace -f -e trace=3Dstat,open python -c 'import ctyp=\r
161 es.util; ctypes.util.find_library("notmuch")' 2>&1 | grep notmuch\r
162 \r
163 Nothing. Funny. Let's see:\r
164 \r
165 teythoon@thinkbox ~ % strace -f -e trace=3Dfork,execve,clone python -c 'imp=\r
166 ort ctypes.util; print ctypes.util.find_library("notmuch")'\r
167 execve("/usr/bin/python", ["python", "-c", "import ctypes.util; print ctype=\r
168 s"...], [/* 63 vars */]) =3D 0\r
169 clone(Process 12000 attached\r
170 child_stack=3D0, flags=3DCLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, c=\r
171 hild_tidptr=3D0x7f0734a649d0) =3D 12000\r
172 [pid 12000] execve("/bin/sh", ["sh", "-c", "/sbin/ldconfig -p 2>/dev/null"]=\r
173 , [/* 63 vars */]) =3D 0\r
174 [pid 12000] clone(Process 12001 attached\r
175 child_stack=3D0, flags=3DCLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, c=\r
176 hild_tidptr=3D0x7f119d5479d0) =3D 12001\r
177 [pid 12001] execve("/sbin/ldconfig", ["/sbin/ldconfig", "-p"], [/* 63 vars =\r
178 */]) =3D 0\r
179 Process 12001 detached\r
180 [pid 12000] --- SIGCHLD (Child exited) @ 0 (0) ---\r
181 Process 12000 detached\r
182 --- SIGCHLD (Child exited) @ 0 (0) ---\r
183 libnotmuch.so.3\r
184 \r
185 So it also prints libnotmuch.so.3, but only because the version\r
186 installed from the Debian archive is also libnotmuch.so.3:\r
187 \r
188 teythoon@thinkbox ~ % /sbin/ldconfig -p | grep notmuch\r
189         libnotmuch.so.3 (libc6,x86-64) =3D> /usr/lib/libnotmuch.so.3\r
190 \r
191 So I guess *if* I had a libnotmuch.so.2 in my ldconfig(8) cache (-p\r
192 prints the cache), find_library would have returned libnotmuch.so.2\r
193 and not my libnotmuch.so.3. So your patch would most likely break this\r
194 kind of setup.\r
195 \r
196 2. Uh. I actually looked at /usr/lib/python2.7/ctypes/util.py and I\r
197 almost got eye cancer from just looking briefly at it... The\r
198 implementation of find_library differs for various operating systems\r
199 and most (all?) of them use fork/exec some program (even gcc in some\r
200 cases) to look up the libraries. I'd like to avoid this if possible,\r
201 maybe even if this means handling OS X as a special case in our\r
202 bindings. For reference, our current solution does not require any\r
203 fork/exec calls:\r
204 \r
205 teythoon@thinkbox ~ % strace -f -e trace=3Dexecve,fork,clone python -c 'imp=\r
206 ort ctypes; ctypes.CDLL("libnotmuch.so.3")' =\r
207 \r
208 execve("/usr/bin/python", ["python", "-c", "import ctypes; ctypes.CDLL(\"li=\r
209 bn"...], [/* 63 vars */]) =3D 0\r
210 \r
211 Thoughts anyone?\r
212 \r
213 Cheers,\r
214 Justus\r
215 \r
216 --===============4092482392989916922==\r
217 MIME-Version: 1.0\r
218 Content-Transfer-Encoding: 7bit\r
219 Content-Description: signature\r
220 Content-Type: application/pgp-signature; name="signature.asc"; charset="us-ascii"\r
221 \r
222 -----BEGIN PGP SIGNATURE-----\r
223 Version: GnuPG v1.4.12 (GNU/Linux)\r
224 \r
225 iQIcBAABCAAGBQJRp0VcAAoJENMeiILK3jZYJwMP/R4VQYUmEDFYHX7xuiLL4zoC\r
226 r+afAVY4OE2u2c9bncT54QairXuDGlLs8wmpDwkfZeiZ1N8OXeEwDlcMZYZ8BpQD\r
227 /5LW0Gcf4u91UIsQ6t3wQLj6slvnMEQmLgyWbHpZIjFMbi/sMF7akJ+Ov/eZf0Si\r
228 /9ZTrXteoUWw7kw9NhIqyxRC9/WHB9TwSdCVj7QPRBxK78B3+OxoX7DIp40QB3eZ\r
229 MPiaOWRqV/6PrEmM1CxIRAEb5EoNB5LdgMM+0Ip6DtoEoKGbt3E7BbBk//tVTtaZ\r
230 OYTCDEDtUfv0bfKL/VHVyihFZDJjDN1H+VgJZ4Sai3rjME1k/HphT/ZiBSO8b995\r
231 tpsc3yBB76kWEnHd1wf6DFJTLiKDwhm46V9WeNZiZ9auUm4RfcHozejPIooog9Bo\r
232 +qubc9r7FhZpV7qrh9+PfS5MPf7qXb+Q5BpZMU30Cqksy1BwrPtmWJ6dDqucI+pR\r
233 /9LxMTxfm8Qub8Fy811nOuG8vcKuL0GxvN/cSM2oqgceDiTXqwCWDO6y3jO3+HBf\r
234 yChjoPioIdxfsyRv3UWjxVI0am3lkN0lKHp7tUbCxank9Yaj1yW/DOQhvpt5pNLe\r
235 NvuNfYPG+Gk0IIsdOWM+R7EBkkPZmnMGdIJ+fsKPxgFZegeYJRP0FejHtw/HoWhG\r
236 R9uuna4ewRUTTFnhxxLU\r
237 =IPQn\r
238 -----END PGP SIGNATURE-----\r
239 \r
240 --===============4092482392989916922==--\r