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

Commitdaa2901

Browse files
committed
attempt to fix PyScopeTest.TestThread() reading stale value from res in Python 2.7 x64
1 parent39b2347 commitdaa2901

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

‎src/embed_tests/TestPyScope.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
usingSystem;
2+
usingSystem.Threading;
23
usingNUnit.Framework;
34
usingPython.Runtime;
45

@@ -337,9 +338,12 @@ public void TestThread()
337338
//add function to the scope
338339
//can be call many times, more efficient than ast
339340
ps.Exec(
341+
"import clr\n"+
342+
"from System.Threading import Thread\n"+
340343
"def update():\n"+
341344
" global res, th_cnt\n"+
342345
" res += bb + 1\n"+
346+
" Thread.MemoryBarrier()\n"+
343347
" th_cnt += 1\n"
344348
);
345349
}
@@ -364,8 +368,9 @@ public void TestThread()
364368
{
365369
cnt=ps.Get<int>("th_cnt");
366370
}
367-
System.Threading.Thread.Sleep(10);
371+
Thread.Sleep(10);
368372
}
373+
Thread.MemoryBarrier();
369374
using(Py.GIL())
370375
{
371376
varresult=ps.Get<int>("res");

‎src/runtime/assemblymanager.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ public static List<string> GetNames(string nsname)
452452
/// looking in the currently loaded assemblies for the named
453453
/// type. Returns null if the named type cannot be found.
454454
/// </summary>
455+
[Obsolete("Use LookupTypes and handle name conflicts")]
455456
publicstaticTypeLookupType(stringqname)
456457
{
457458
foreach(Assemblyassemblyinassemblies)
@@ -465,6 +466,14 @@ public static Type LookupType(string qname)
465466
returnnull;
466467
}
467468

469+
/// <summary>
470+
/// Returns the <see cref="Type"/> objects for the given qualified name,
471+
/// looking in the currently loaded assemblies for the named
472+
/// type.
473+
/// </summary>
474+
publicstaticIEnumerable<Type>LookupTypes(stringqualifiedName)
475+
=>assemblies.Select(assembly=>assembly.GetType(qualifiedName)).Where(type=>type!=null);
476+
468477
internalstaticType[]GetTypes(Assemblya)
469478
{
470479
if(a.IsDynamic)
@@ -492,4 +501,4 @@ internal static Type[] GetTypes(Assembly a)
492501
}
493502
}
494503
}
495-
}
504+
}

‎src/runtime/moduleobject.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
usingSystem;
22
usingSystem.Collections.Generic;
3+
usingSystem.Linq;
34
usingSystem.IO;
45
usingSystem.Reflection;
56
usingSystem.Runtime.InteropServices;
@@ -105,13 +106,9 @@ public ManagedType GetAttribute(string name, bool guess)
105106
// Look for a type in the current namespace. Note that this
106107
// includes types, delegates, enums, interfaces and structs.
107108
// Only public namespace members are exposed to Python.
108-
type=AssemblyManager.LookupType(qname);
109+
type=AssemblyManager.LookupTypes(qname).FirstOrDefault(t=>t.IsPublic);
109110
if(type!=null)
110111
{
111-
if(!type.IsPublic)
112-
{
113-
returnnull;
114-
}
115112
c=ClassManager.GetClass(type);
116113
StoreAttribute(name,c);
117114
returnc;
@@ -131,13 +128,9 @@ public ManagedType GetAttribute(string name, bool guess)
131128
returnm;
132129
}
133130

134-
type=AssemblyManager.LookupType(qname);
131+
type=AssemblyManager.LookupTypes(qname).FirstOrDefault(t=>t.IsPublic);
135132
if(type!=null)
136133
{
137-
if(!type.IsPublic)
138-
{
139-
returnnull;
140-
}
141134
c=ClassManager.GetClass(type);
142135
StoreAttribute(name,c);
143136
returnc;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp