Skip to content

Commit

Permalink
remove LD_PRELOAD workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
tonybaloney committed Sep 19, 2024
1 parent 3d94d12 commit 51ae8ae
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@
"remoteUser": "root",
"remoteEnv": {
"Python3_ROOT_DIR": "/usr/local/python/current",
"LD_PRELOAD": "/usr/local/python/current/lib/libpython3.12.so.1.0"
}
}
1 change: 0 additions & 1 deletion .github/workflows/dotnet-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ jobs:
working-directory: src
env:
PYTHON_VERSION: ${{ steps.installpython.outputs.python-version }}
LD_PRELOAD: /opt/hostedtoolcache/Python/${{ steps.installpython.outputs.python-version }}/x64/lib/libpython3.so

- name: Upload test results
uses: actions/upload-artifact@v4
Expand Down
14 changes: 14 additions & 0 deletions src/CSnakes.Runtime/CPython/Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,24 @@ public CPythonAPI(string pythonLibraryPath, Version version)
}
}

const int RTLD_LAZY=0x1;
const int RTLD_NOW=0x2;
const int RTLD_LOCAL=0x4;
const int RTLD_GLOBAL=0x8;

[LibraryImport("/usr/lib/x86_64-linux-gnu/libdl.so.2", StringMarshalling = StringMarshalling.Utf8)]
private static partial nint dlopen(string path, int flags);


private static IntPtr DllImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{
if (libraryName == PythonLibraryName)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)){
// TODO: find how to load libdl.so without hardcoding the path
return dlopen(pythonLibraryPath!, RTLD_NOW | RTLD_GLOBAL);
}

return NativeLibrary.Load(pythonLibraryPath!, assembly, null);
}
return NativeLibrary.Load(libraryName, assembly, searchPath);
Expand Down
2 changes: 2 additions & 0 deletions src/Integration.Tests/BufferTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using CSnakes.Runtime.Python;
using Xunit;

namespace Integration.Tests;

public class BufferTests : IntegrationTestBase
{
[Fact]
[Trait("requires", "numpy")]
public void TestBoolBuffer()
{
var testModule = Env.TestBuffer();
Expand Down

0 comments on commit 51ae8ae

Please sign in to comment.