Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
/pythonnetPublic archive
forked frompythonnet/pythonnet

Commit0185bcb

Browse files
committed
Make the code compile with ILibPython
1 parente61dd72 commit0185bcb

File tree

7 files changed

+83
-819
lines changed

7 files changed

+83
-819
lines changed

‎Python.Runtime.Native/AssemblyInfo.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
usingSystem;
2+
usingSystem.Runtime.CompilerServices;
3+
4+
[assembly:CLSCompliant(true)]
5+
[assembly:InternalsVisibleTo("Python.Test.Embed")]
6+
[assembly:InternalsVisibleTo("Python.Runtime")]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
usingSystem;
2+
usingSystem.Reflection;
3+
usingSystem.Runtime.Loader;
4+
5+
namespacePython.Runtime.Platform
6+
{
7+
classInternalLoadContext:AssemblyLoadContext
8+
{
9+
protectedoverrideAssemblyLoad(AssemblyNamename)=>null;
10+
11+
protectedoverrideIntPtrLoadUnmanagedDll(stringname)
12+
{
13+
if(name=="__Internal")
14+
{
15+
varloader=LibraryLoader.Get(OperatingSystemType.Linux);
16+
returnloader.Load(null);
17+
}
18+
19+
returnIntPtr.Zero;
20+
}
21+
22+
publicstaticAssemblyLoadContextInstance{get;}=newInternalLoadContext();
23+
}
24+
}

‎Python.Runtime/platform/LibraryLoader.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ class LinuxLoader : ILibraryLoader
4040

4141
publicIntPtrLoad(stringdllToLoad)
4242
{
43-
varfilename=$"lib{dllToLoad}.so";
43+
stringfilename;
44+
if(dllToLoad!=null)
45+
{
46+
filename=$"lib{dllToLoad}.so";
47+
}
48+
else
49+
{
50+
filename=null;
51+
}
4452
ClearError();
4553
varres=dlopen(filename,RTLD_NOW|RTLD_GLOBAL);
4654
if(res==IntPtr.Zero)
@@ -111,7 +119,15 @@ class DarwinLoader : ILibraryLoader
111119

112120
publicIntPtrLoad(stringdllToLoad)
113121
{
114-
varfilename=$"lib{dllToLoad}.dylib";
122+
stringfilename;
123+
if(dllToLoad!=null)
124+
{
125+
filename=$"lib{dllToLoad}.dylib";
126+
}
127+
else
128+
{
129+
filename=null;
130+
}
115131
ClearError();
116132
varres=dlopen(filename,RTLD_NOW|RTLD_GLOBAL);
117133
if(res==IntPtr.Zero)

‎Python.Runtime/pythonengine.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
usingSystem.Runtime.CompilerServices;
2+
usingSystem.Runtime.Loader;
13
usingSystem;
24
usingSystem.Collections.Generic;
35
usingSystem.IO;
46
usingSystem.Linq;
57
usingSystem.Reflection;
68
usingSystem.Runtime.InteropServices;
9+
usingPython.Runtime.Native;
710

811
namespacePython.Runtime
912
{
@@ -254,10 +257,17 @@ static void OnDomainUnload(object _, EventArgs __)
254257
/// CPython interpreter process - this bootstraps the managed runtime
255258
/// when it is imported by the CLR extension module.
256259
/// </summary>
257-
publicstaticintInternalInitialize(intsize,IntPtrdata)
260+
publicstaticintInternalInitialize(IntPtrdata,intsize)
258261
{
262+
263+
259264
try
260265
{
266+
// Console.WriteLine("Before Initialize");
267+
// Console.Out.Flush();
268+
269+
// Python.Runtime.Platform.InternalLoadContext.Instance.EnterContextualReflection();
270+
261271
Initialize(setSysArgv:false);
262272

263273
// Trickery - when the import hook is installed into an already
@@ -277,6 +287,9 @@ public static int InternalInitialize(int size, IntPtr data)
277287
// still doesn't work if you use the interactive interpreter,
278288
// since there is no line info to get the import line ;(
279289

290+
// Console.WriteLine("Initialized");
291+
// Console.Out.Flush();
292+
280293
stringcode=
281294
"import traceback\n"+
282295
"for item in traceback.extract_stack():\n"+
@@ -290,13 +303,23 @@ public static int InternalInitialize(int size, IntPtr data)
290303
" break\n";
291304

292305
PythonEngine.Exec(code);
306+
307+
// Console.WriteLine("Exec'd traceback hack");
308+
// Console.Out.Flush();
309+
293310
return0;
294311
}
295312
catch(PythonExceptione)
296313
{
297314
e.Restore();
298315
return-1;
299316
}
317+
catch(Exceptione)
318+
{
319+
// Console.Error.WriteLine(e.ToString());
320+
// Console.Error.Write(e.StackTrace);
321+
return-2;
322+
}
300323
}
301324

302325
/// <summary>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp