Skip to content

Commit a141b40

Browse files
committed
checkpoint
1 parent ac992c8 commit a141b40

File tree

14 files changed

+759
-810
lines changed

14 files changed

+759
-810
lines changed

pythonnet/pythonnet.build

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0"?>
2+
<project name="Python for .NET" default="build-2.0" basedir=".">
3+
4+
<property name="project.name" value="pythonnet"/>
5+
6+
7+
<target name="build-1.0">
8+
<property name="project.version" value="1.0.0"/>
9+
<echo message="Building ${project.name}-${project.version}"/>
10+
</target>
11+
12+
<target name="build-2.0">
13+
<property name="project.version" value="2.0.0"/>
14+
<echo message="Building ${project.name}-${project.version}"/>
15+
</target>
16+
17+
<target name="test">
18+
19+
</target>
20+
21+
22+
<target name="console" depends="runtime" >
23+
<csc target="exe" output="python.exe" >
24+
<references>
25+
<include name="python.runtime.dll" />
26+
</references>
27+
<sources>
28+
<include name="src/console/*.cs" />
29+
</sources>
30+
</csc>
31+
</target>
32+
33+
<target name="runtime">
34+
<csc target="library" output="python.runtime.dll" unsafe="true">
35+
<sources>
36+
<include name="src/runtime/*.cs" />
37+
</sources>
38+
</csc>
39+
</target>
40+
41+
<target name="testdll">
42+
<csc target="library" output="python.test.dll">
43+
<references>
44+
<include name="python.runtime.dll" />
45+
</references>
46+
<sources>
47+
<include name="src/testing/*.cs" />
48+
</sources>
49+
</csc>
50+
</target>
51+
52+
<target name="oldmodule">
53+
<ilasm target="dll" output="CLR.dll">
54+
<sources>
55+
<include name="src/runtime/oldmodule.il" />
56+
</sources>
57+
</csc>
58+
</target>
59+
60+
<target name="clrmodule">
61+
<ilasm target="dll" output="clr.dll">
62+
<sources>
63+
<include name="src/runtime/clrmodule.il" />
64+
</sources>
65+
</csc>
66+
</target>
67+
68+
69+
<target name="dist">
70+
71+
</target>
72+
73+
</project>

pythonnet/src/runtime/assemblymanager.cs

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ namespace Python.Runtime {
2424

2525
internal class AssemblyManager {
2626

27+
static Dictionary<string, Dictionary<Assembly, string>> namespaces;
28+
static Dictionary<string, Dictionary<string, string>> generics;
2729
static AssemblyLoadEventHandler lhandler;
2830
static ResolveEventHandler rhandler;
29-
static Dictionary<string, string> snames;
30-
static Dictionary<string, Dictionary<Assembly, string>> namespaces;
3131
static Dictionary<string, int> probed;
3232
static List<Assembly> assemblies;
3333
static List<string> pypath;
@@ -42,11 +42,10 @@ private AssemblyManager() {}
4242
//===================================================================
4343

4444
internal static void Initialize() {
45-
snames = new Dictionary<string, string>();
46-
4745
namespaces = new
4846
Dictionary<string, Dictionary<Assembly, string>>(32);
4947
probed = new Dictionary<string, int>(32);
48+
generics = new Dictionary<string, Dictionary<string, string>>();
5049
assemblies = new List<Assembly>(16);
5150
pypath = new List<string>(16);
5251

@@ -114,32 +113,6 @@ static Assembly ResolveHandler(Object ob, ResolveEventArgs args){
114113
}
115114

116115

117-
//===================================================================
118-
// Certain kinds of names (such as the names of generic types) are
119-
// mangled so we need to perform mapping from human-friendly names
120-
// to inhumane names. Given a friendly name, this method will either
121-
// return the associated inhumane name or the original name with no
122-
// changes if there is no mapping for that name.
123-
//===================================================================
124-
125-
static string ConvertSpecialName(string name) {
126-
if (snames.ContainsKey(name)) {
127-
return snames[name];
128-
}
129-
return name;
130-
}
131-
132-
static void AddSpecialName(string nice, string ugly) {
133-
if (!snames.ContainsKey(nice)) {
134-
snames.Add(nice, ugly);
135-
}
136-
else {
137-
//Console.WriteLine("dup: {0} : {1}", nice, ugly);
138-
}
139-
140-
}
141-
142-
143116
//===================================================================
144117
// We __really__ want to avoid using Python objects or APIs when
145118
// probing for assemblies to load, since our ResolveHandler may be
@@ -211,7 +184,9 @@ static string FindAssembly(string name) {
211184
public static Assembly LoadAssembly(string name) {
212185
Assembly assembly = null;
213186
try {
187+
#pragma warning disable 618
214188
assembly = Assembly.LoadWithPartialName(name);
189+
#pragma warning restore 618
215190
}
216191
catch {
217192
}
@@ -272,11 +247,7 @@ static void ScanAssembly(Assembly assembly) {
272247

273248
// A couple of things we want to do here: first, we want to
274249
// gather a list of all of the namespaces contributed to by
275-
// the assembly. Since we have to rifle through all of the
276-
// types in the assembly anyway, we also build up a running
277-
// list of 'odd names' like generic names so that we can map
278-
// them appropriately later while still being lazy about
279-
// type lookup and instantiation.
250+
// the assembly.
280251

281252
Type[] types = assembly.GetTypes();
282253
for (int i = 0; i < types.Length; i++) {
@@ -300,12 +271,35 @@ static void ScanAssembly(Assembly assembly) {
300271
}
301272

302273
if (t.IsGenericTypeDefinition) {
303-
string qname = t.FullName;
304-
int tick = qname.IndexOf('`');
305-
if (tick != -1) {
306-
AddSpecialName(qname.Substring(0, tick), qname);
307-
}
274+
GenericManager.Register(t);
275+
// Dictionary<string, string> map = null;
276+
// generics.TryGetValue(t.Namespace, out map);
277+
// if (map == null) {
278+
// map = new Dictionary<string, string>();
279+
// generics[t.Namespace] = map;
280+
// }
281+
// string bname = t.Name;
282+
// string mapped = null;
283+
// int tick = bname.IndexOf("`");
284+
// if (tick > -1) {
285+
// bname = bname.Substring(0, tick);
286+
// }
287+
// map.TryGetValue(bname, out mapped);
288+
// if (mapped == null) {
289+
// map[bname] = t.Name;
290+
// }
308291
}
292+
293+
// if (t.IsGenericTypeDefinition) {
294+
// List<string> snames = null;
295+
// special.TryGetValue(t.Namespace, out snames);
296+
// if (snames == null) {
297+
// snames = new List<string>(8);
298+
// special[t.Namespace] = snames;
299+
// }
300+
// snames.Add(t.Name);
301+
// }
302+
309303

310304
}
311305
}
@@ -326,16 +320,23 @@ public static bool IsValidNamespace(string name) {
326320
//===================================================================
327321

328322
public static List<string> GetNames(string nsname) {
329-
List<string> names = new List<string>(32);
330323
Dictionary<string, int> seen = new Dictionary<string, int>();
324+
List<string> names = new List<string>(8);
325+
326+
List<string> g = GenericManager.GetGenericBaseNames(nsname);
327+
if (g != null) {
328+
foreach (string n in g) {
329+
names.Add(n);
330+
}
331+
}
331332

332333
if (namespaces.ContainsKey(nsname)) {
333334
foreach (Assembly a in namespaces[nsname].Keys) {
334335
Type[] types = a.GetTypes();
335336
for (int i = 0; i < types.Length; i++) {
336337
Type t = types[i];
337338
if (t.Namespace == nsname) {
338-
names.Add(ConvertSpecialName(t.Name));
339+
names.Add(t.Name);
339340
}
340341
}
341342
}
@@ -349,7 +350,6 @@ public static List<string> GetNames(string nsname) {
349350
}
350351
}
351352
}
352-
names.Sort(); // ensure that non-generics come first!
353353
return names;
354354
}
355355

@@ -359,13 +359,10 @@ public static List<string> GetNames(string nsname) {
359359
// type. Returns null if the named type cannot be found.
360360
//===================================================================
361361

362-
// funny names: generics,
363-
364362
public static Type LookupType(string qname) {
365-
string name = ConvertSpecialName(qname);
366363
for (int i = 0; i < assemblies.Count; i++) {
367364
Assembly assembly = (Assembly)assemblies[i];
368-
Type type = assembly.GetType(name);
365+
Type type = assembly.GetType(qname);
369366
if (type != null) {
370367
return type;
371368
}

pythonnet/src/runtime/genericmethod.cs

Lines changed: 0 additions & 61 deletions
This file was deleted.

pythonnet/src/runtime/generictype.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,35 @@ public override IntPtr type_subscript(IntPtr idx) {
6161
"type is not a generic type definition"
6262
);
6363
}
64+
65+
// This is a little tricky, because an instance of GenericType
66+
// may represent either a specific generic type, or act as an
67+
// alias for one or more generic types with the same base name.
68+
6469
if (this.type.ContainsGenericParameters) {
65-
Type t = this.type.MakeGenericType(types);
66-
ManagedType c = (ManagedType)ClassManager.GetClass(t);
67-
Runtime.Incref(c.pyHandle);
68-
return c.pyHandle;
70+
Type[] args = this.type.GetGenericArguments();
71+
Type target = null;
72+
73+
if (args.Length == types.Length) {
74+
target = this.type;
75+
}
76+
else {
77+
foreach (Type t in
78+
GenericManager.GenericsForType(this.type)) {
79+
if (t.GetGenericArguments().Length == types.Length) {
80+
target = t;
81+
break;
82+
}
83+
}
84+
}
85+
86+
if (target != null) {
87+
Type t = target.MakeGenericType(types);
88+
ManagedType c = (ManagedType)ClassManager.GetClass(t);
89+
Runtime.Incref(c.pyHandle);
90+
return c.pyHandle;
91+
}
92+
return Exceptions.RaiseTypeError("no type matches params");
6993
}
7094

7195
return Exceptions.RaiseTypeError("unsubscriptable object");

pythonnet/src/runtime/importhook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) {
166166

167167
for (int i = 0; i < names.Length; i++) {
168168
string name = names[i];
169-
ManagedType mt = tail.GetAttribute(name);
169+
ManagedType mt = tail.GetAttribute(name, true);
170170
if (!(mt is ModuleObject)) {
171171
string error = String.Format("No module named {0}", name);
172172
Exceptions.SetError(Exceptions.ImportError, error);

0 commit comments

Comments
 (0)