Load dynamic library for python library
Casey Deccio
casey at deccio.net
Fri Feb 8 22:20:13 UTC 2019
> On Feb 7, 2019, at 8:05 PM, Joshua Root <jmr at macports.org <mailto:jmr at macports.org>> wrote:
>
> On 2019-2-8 13:59 , Casey Deccio wrote:
>>
>>
>>> On Feb 7, 2019, at 7:03 PM, Joshua Root <jmr at macports.org <mailto:jmr at macports.org>> wrote:
>>>
>>> BTW Gmail decided my reply was spam; sending only to the list this time
>>> so Casey might actually see it...
>>
>> Much appreciated :)
>>
>>> On 2019-2-8 13:00 , Joshua Root wrote:
>>>>
>>>> Ctypes uses dlopen behind the scenes, and if you look at dlopen's man
>>>> page, it only searches a small set of fallback paths when the full path
>>>> to the library is not supplied, most of which are controlled by
>>>> environment variables. So I would say that py-libnacl should be passing
>>>> the full path to libnacl to ctypes.cdll.LoadLibrary.
>>
>> Thanks for the feedback! I figured it should have that path provided somehow. So, should an issue/pull request be filed with the py-libnacl port then? Where is the right place for the path to be provided?
>
> The call is in libnacl/__init__.py. I'd patch in a placeholder and use
> reinplace to insert the value of $prefix.
Thanks! So would it be better for the patch to try first the hard-coded location (i.e., hardcoded with ${prefix}) then via relative name/search or just the hardcoded?
That is,
$ git diff
diff --git a/libnacl/__init__.py b/libnacl/__init__.py
index 1b037ac..c2c321a 100644
--- a/libnacl/__init__.py
+++ b/libnacl/__init__.py
@@ -34,7 +34,7 @@ def _get_nacl():
raise OSError(msg)
elif sys.platform.startswith('darwin'):
try:
- return ctypes.cdll.LoadLibrary('libsodium.dylib')
+ return ctypes.cdll.LoadLibrary(os.path.join('@@PREFIX@@', 'libsodium.dylib'))
except OSError:
pass
try:
vs.
$ git diff
diff --git a/libnacl/__init__.py b/libnacl/__init__.py
index 1b037ac..648f885 100644
--- a/libnacl/__init__.py
+++ b/libnacl/__init__.py
@@ -37,6 +37,10 @@ def _get_nacl():
return ctypes.cdll.LoadLibrary('libsodium.dylib')
except OSError:
pass
+ try:
+ return ctypes.cdll.LoadLibrary(os.path.join('@@PREFIX@@', 'libsodium.dylib'))
+ except OSError:
+ pass
try:
libidx = __file__.find('lib')
if libidx > 0:
Casey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macports.org/pipermail/macports-dev/attachments/20190208/315e4148/attachment-0001.html>
More information about the macports-dev
mailing list