Skip to content

Commit

Permalink
[cppyy] Sync load_cpp_backend with upsteam backend
Browse files Browse the repository at this point in the history
Reverts commit 834f8f3 to hopefully get rid of a patch.

Sync the `load_cpp_backend` function with upsteam as an alternative
and more sustainable solution to the problem.
  • Loading branch information
guitargeek committed Feb 5, 2025
1 parent 8435a18 commit 15acfec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,34 @@
'ensure_precompiled_header' # build precompiled header as necessary
]

import os, sys, ctypes, subprocess, sysconfig, warnings
import ctypes
import os
import platform
import re
import subprocess
import sys
import sysconfig
import warnings

if 'win32' in sys.platform:
soext = '.dll'
else:
soext = '.so'

soabi = sysconfig.get_config_var("SOABI")
soext2 = sysconfig.get_config_var("EXT_SUFFIX")
if not soext2:
soext2 = sysconfig.get_config_var("SO")


def _load_helper(bkname):
# normal load, allowing for user overrides of LD_LIBRARY_PATH
try:
return ctypes.CDLL(bkname, ctypes.RTLD_GLOBAL)
except OSError:
pass
errors = set()

# failed ... try absolute path
# needed on MacOS12 with soversion
# normal load, allowing for user overrides of LD_LIBRARY_PATH
try:
libpath = os.path.dirname(os.path.dirname(__file__))
return ctypes.CDLL(os.path.join(libpath, bkname), ctypes.RTLD_GLOBAL)
except OSError:
pass
return ctypes.CDLL(bkname, ctypes.RTLD_GLOBAL), errors
except OSError as e:
errors.add(str(e))

# failed ... load dependencies explicitly
try:
Expand All @@ -47,11 +51,11 @@ def _load_helper(bkname):
if dep == 'libCling': ldtype = ctypes.RTLD_LOCAL
ctypes.CDLL(fpath, ldtype)
break
return ctypes.CDLL(os.path.join(pkgpath, 'lib', bkname), ctypes.RTLD_GLOBAL)
except OSError:
pass
return ctypes.CDLL(os.path.join(pkgpath, 'lib', bkname), ctypes.RTLD_GLOBAL), errors
except OSError as e:
errors.add(str(e))

return None
return None, errors


_precompiled_header_ensured = False
Expand All @@ -61,22 +65,29 @@ def load_cpp_backend():
# distribution as there are too many varieties; create it now if needed
ensure_precompiled_header()

altbkname = None
names = list()
try:
bkname = os.environ['CPPYY_BACKEND_LIBRARY']
if bkname.rfind(soext) < 0:
bkname += soext
names.append(bkname)
except KeyError:
bkname = 'libcppyy_backend'+soext
names.append('libcppyy_backend'+soext)
if soabi:
altbkname = 'libcppyy_backend.'+soabi+soext
names.append('libcppyy_backend.'+soabi+soext)
if soext2:
names.append('libcppyy_backend'+soext2)

c = _load_helper(bkname)
if not c and altbkname is not None:
c = _load_helper(altbkname)
err = set()
for name in names:
c, err2 = _load_helper(name)
if c:
break
err = err.union(err2)

if not c:
raise RuntimeError("could not load cppyy_backend library")
raise RuntimeError("could not load cppyy_backend library, details:\n%s" %
'\n'.join([' '+x for x in err]))

return c

Expand Down
32 changes: 0 additions & 32 deletions bindings/pyroot/cppyy/patches/mac12soversion.patch

This file was deleted.

0 comments on commit 15acfec

Please sign in to comment.