1 Return-Path: <tomi.ollila@iki.fi>
\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 99689431FBC
\r
6 for <notmuch@notmuchmail.org>; Thu, 30 May 2013 09:06:55 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 S8n+lLFKrtT0 for <notmuch@notmuchmail.org>;
\r
16 Thu, 30 May 2013 09:06:47 -0700 (PDT)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 85B7D431FAE
\r
19 for <notmuch@notmuchmail.org>; Thu, 30 May 2013 09:06:47 -0700 (PDT)
\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])
\r
21 by guru.guru-group.fi (Postfix) with ESMTP id 475A8100093;
\r
22 Thu, 30 May 2013 19:06:43 +0300 (EEST)
\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
24 To: Justus Winter <4winter@informatik.uni-hamburg.de>,
\r
25 Julian Berman <Julian@GrayVines.com>, notmuch@notmuchmail.org
\r
26 Subject: Re: [PATCH] Fix shared library loading in Python bindings.
\r
27 In-Reply-To: <20130530122608.20099.26290@thinkbox.jade-hamburg.de>
\r
28 References: <1369540418-94177-1-git-send-email-Julian@GrayVines.com>
\r
29 <20130530122608.20099.26290@thinkbox.jade-hamburg.de>
\r
30 User-Agent: Notmuch/0.15.2+115~g12cf6af (http://notmuchmail.org) Emacs/24.3.1
\r
31 (x86_64-unknown-linux-gnu)
\r
32 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
33 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
34 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
35 Date: Thu, 30 May 2013 19:06:42 +0300
\r
36 Message-ID: <m28v2wcuzx.fsf@guru.guru-group.fi>
\r
38 Content-Type: text/plain
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.13
\r
42 List-Id: "Use and development of the notmuch mail system."
\r
43 <notmuch.notmuchmail.org>
\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
47 List-Post: <mailto:notmuch@notmuchmail.org>
\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
51 X-List-Received-Date: Thu, 30 May 2013 16:06:55 -0000
\r
53 On Thu, May 30 2013, Justus Winter <4winter@informatik.uni-hamburg.de> wrote:
\r
57 > Quoting Julian Berman (2013-05-26 05:53:38)
\r
58 >> Specifically, fixes loading on OS X, where libnotmuch will be
\r
61 >> bindings/python/notmuch/globals.py | 3 ++-
\r
62 >> 1 file changed, 2 insertions(+), 1 deletion(-)
\r
64 >> diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
\r
65 >> index c7632c3..5e08e73 100644
\r
66 >> --- a/bindings/python/notmuch/globals.py
\r
67 >> +++ b/bindings/python/notmuch/globals.py
\r
68 >> @@ -18,11 +18,12 @@ Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
\r
71 >> from ctypes import CDLL, Structure, POINTER
\r
72 >> +from ctypes.util import find_library
\r
74 >> #-----------------------------------------------------------------------------
\r
75 >> #package-global instance of the notmuch library
\r
77 >> - nmlib = CDLL("libnotmuch.so.3")
\r
78 >> + nmlib = CDLL(find_library("libnotmuch"))
\r
80 > Does this work for you on Darwin? On my box (Debian/Linux) I have to
\r
81 > use "notmuch" instead of "libnotmuch" to get anything from
\r
84 > In [5]: print ctypes.util.find_library("notmuch")
\r
87 > In [6]: print ctypes.util.find_library("libnotmuch")
\r
90 > Then again, find_library is different for every architecture under the
\r
94 >> raise ImportError("Could not find shared 'notmuch' library.")
\r
96 > I'm leaning towards declining the patch in it's current form. If the
\r
97 > bindings do not work on OS X, we need to find another solution. There
\r
98 > are two reasons for this:
\r
100 > 1. find_library was once used, but was removed since it is (has?) been
\r
101 > problematic wrt to LD_LIBRARY_PATH usage:
\r
103 > % git show f378f458
\r
104 > commit f378f45893bb4263402008b2abd8aab522901fb6
\r
105 > Author: Cedric Cabessa <ced@ryick.net>
\r
106 > Date: Mon Apr 5 03:03:51 2010 +0200
\r
108 > find_library does not read LD_LIBRARY_PATH, but CDLL does.
\r
110 > diff --git a/cnotmuch/globals.py b/cnotmuch/globals.py
\r
111 > index ef2686f..fa20ae8 100644
\r
112 > --- a/cnotmuch/globals.py
\r
113 > +++ b/cnotmuch/globals.py
\r
114 > @@ -3,17 +3,17 @@ from ctypes.util import find_library
\r
116 > #-----------------------------------------------------------------------------
\r
117 > #package-global instance of the notmuch library
\r
118 > -#TODO: lazy load this on first access?
\r
119 > -so = find_library('notmuch')
\r
121 > - raise ImportError("Could not find shared 'notmuch' library.")
\r
122 > -nmlib = CDLL(so)
\r
124 > + nmlib = CDLL("libnotmuch.so.1")
\r
126 > + raise ImportError("Could not find shared 'notmuch' library.")
\r
129 > As a heavy LD_LIBRARY_PATH user I don't want to break this. So I tried
\r
130 > to test whether find_library now respects LD_LIBRARY_PATH or not:
\r
132 > teythoon@thinkbox ~ % echo $LD_LIBRARY_PATH
\r
133 > /home/teythoon/.local/lib
\r
134 > teythoon@thinkbox ~ % strace -e trace=open python -c 'import ctypes; ctypes.CDLL("libnotmuch.so.3")' 2>&1 | grep notmuch
\r
135 > open("/home/teythoon/.local/lib/libnotmuch.so.3", O_RDONLY) = 3
\r
137 > That's how it's done now and indeed it finds my libnotmuch.
\r
139 > teythoon@thinkbox ~ % strace -f -e trace=stat,open python -c 'import ctypes.util; ctypes.util.find_library("notmuch")' 2>&1 | grep notmuch
\r
141 > Nothing. Funny. Let's see:
\r
143 > teythoon@thinkbox ~ % strace -f -e trace=fork,execve,clone python -c 'import ctypes.util; print ctypes.util.find_library("notmuch")'
\r
144 > execve("/usr/bin/python", ["python", "-c", "import ctypes.util; print ctypes"...], [/* 63 vars */]) = 0
\r
145 > clone(Process 12000 attached
\r
146 > child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f0734a649d0) = 12000
\r
147 > [pid 12000] execve("/bin/sh", ["sh", "-c", "/sbin/ldconfig -p 2>/dev/null"], [/* 63 vars */]) = 0
\r
148 > [pid 12000] clone(Process 12001 attached
\r
149 > child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f119d5479d0) = 12001
\r
150 > [pid 12001] execve("/sbin/ldconfig", ["/sbin/ldconfig", "-p"], [/* 63 vars */]) = 0
\r
151 > Process 12001 detached
\r
152 > [pid 12000] --- SIGCHLD (Child exited) @ 0 (0) ---
\r
153 > Process 12000 detached
\r
154 > --- SIGCHLD (Child exited) @ 0 (0) ---
\r
157 > So it also prints libnotmuch.so.3, but only because the version
\r
158 > installed from the Debian archive is also libnotmuch.so.3:
\r
160 > teythoon@thinkbox ~ % /sbin/ldconfig -p | grep notmuch
\r
161 > libnotmuch.so.3 (libc6,x86-64) => /usr/lib/libnotmuch.so.3
\r
163 > So I guess *if* I had a libnotmuch.so.2 in my ldconfig(8) cache (-p
\r
164 > prints the cache), find_library would have returned libnotmuch.so.2
\r
165 > and not my libnotmuch.so.3. So your patch would most likely break this
\r
168 > 2. Uh. I actually looked at /usr/lib/python2.7/ctypes/util.py and I
\r
169 > almost got eye cancer from just looking briefly at it... The
\r
170 > implementation of find_library differs for various operating systems
\r
171 > and most (all?) of them use fork/exec some program (even gcc in some
\r
172 > cases) to look up the libraries. I'd like to avoid this if possible,
\r
173 > maybe even if this means handling OS X as a special case in our
\r
174 > bindings. For reference, our current solution does not require any
\r
177 > teythoon@thinkbox ~ % strace -f -e trace=execve,fork,clone python -c 'import ctypes; ctypes.CDLL("libnotmuch.so.3")'
\r
178 > execve("/usr/bin/python", ["python", "-c", "import ctypes; ctypes.CDLL(\"libn"...], [/* 63 vars */]) = 0
\r
184 >>> from ctypes import CDLL
\r
185 >>> x = CDLL("foobnar.so")
\r
186 Traceback (most recent call last):
\r
187 File "<stdin>", line 1, in <module>
\r
188 File "/usr/lib/python2.6/ctypes/__init__.py", line 353, in __init__
\r
189 self._handle = _dlopen(self._name, mode)
\r
190 OSError: foobnar.so: cannot open shared object file: No such file or
\r
193 Looked into /usr/lib/python2.6/ctypes/__init__.py -- _dlopen() uses
\r
194 dlopen() from _ctypes module, which is in
\r
195 /usr/lib/python2.6/lib-dynload/_ctypes.so
\r
197 I'd guess this does pretty much the same as dlopen(3) does in Linux
\r
198 (or Mac -- whatever it does there)
\r
200 Could something like
\r
203 nmlib = CDLL("libnotmuch.so.3")
\r
206 nmlib = CDLL("something_macosx_understands")
\r
208 ImportError("Could not find shared 'notmuch' library.")
\r
213 Just before sending this email I came up with this page:
\r
215 https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/dlopen.3.html
\r
217 The 'SEARCHING' section has quite a few words how the file is found.
\r