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

Commite2efdda

Browse files
author
dse
committed
Implicit assembly loading optimization.
1 parent307f1dd commite2efdda

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
88
##[unreleased][]
99

1010
###Added
11+
- Optimized implicit assembly loading on module import, PythonEngine.ImplicitAssemblyLoading event added.
1112
- Added support for embedding python into dotnet core 2.0 (NetCoreApp2.0)
1213
- Added new build system (pythonnet.15.sln) based on dotnetcore-sdk/xplat(crossplatform msbuild).
1314
Currently there two side-by-side build systems that produces the same output (net40) from the same sources.

‎src/runtime/assemblymanager.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ public static Assembly LoadAssembly(string name)
196196
Assemblyassembly=null;
197197
try
198198
{
199+
varimportEvent=newImplicitAssemblyLoadingEventArgs(name);
200+
if(importEvent.SkipAssemblyLoad)
201+
{
202+
returnnull;
203+
}
204+
205+
PythonEngine.RaiseAssemblyAsModuleImportingEvent(importEvent);
206+
199207
assembly=Assembly.Load(name);
200208
}
201209
catch(Exception)
@@ -419,12 +427,15 @@ public static List<string> GetNames(string nsname)
419427
{
420428
foreach(Assemblyainnamespaces[nsname].Keys)
421429
{
422-
Type[]types=a.GetTypes();
430+
Type[]types=a.IsDynamic?a.GetTypes():a.GetExportedTypes();
423431
foreach(Typetintypes)
424432
{
425433
if((t.Namespace??"")==nsname)
426434
{
427-
names.Add(t.Name);
435+
if(!t.IsNested)
436+
{
437+
names.Add(t.Name);
438+
}
428439
}
429440
}
430441
}

‎src/runtime/pythonengine.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
usingSystem;
1+
usingSystem;
22
usingSystem.Collections.Generic;
33
usingSystem.IO;
44
usingSystem.Linq;
@@ -130,6 +130,11 @@ public static string Compiler
130130
get{returnMarshal.PtrToStringAnsi(Runtime.Py_GetCompiler());}
131131
}
132132

133+
/// <summary>
134+
/// Fires when python engines importing module and probably tries to load an assembly.
135+
/// </summary>
136+
publicstaticeventEventHandler<ImplicitAssemblyLoadingEventArgs>ImplicitAssemblyLoading;
137+
133138
publicstaticintRunSimpleString(stringcode)
134139
{
135140
returnRuntime.PyRun_SimpleString(code);
@@ -526,6 +531,29 @@ internal static PyObject RunString(string code, IntPtr? globals, IntPtr? locals,
526531
}
527532
}
528533
}
534+
535+
internalstaticvoidRaiseAssemblyAsModuleImportingEvent(ImplicitAssemblyLoadingEventArgse)
536+
{
537+
ImplicitAssemblyLoading?.Invoke(null,e);
538+
}
539+
}
540+
541+
publicclassImplicitAssemblyLoadingEventArgs:EventArgs
542+
{
543+
publicImplicitAssemblyLoadingEventArgs(stringmoduleName)
544+
{
545+
ModuleName=moduleName;
546+
}
547+
548+
/// <summary>
549+
/// The name of the module to import that is probably assembly name.
550+
/// </summary>
551+
publicstringModuleName{get;}
552+
553+
/// <summary>
554+
/// Set it to true, if you know that <see cref="ModuleName"/> is not an assembly to import.
555+
/// </summary>
556+
publicboolSkipAssemblyLoad{get;set;}
529557
}
530558

531559
publicenumRunFlagType

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp