Skip to content

Commit beffbb4

Browse files
committed
checkpoint
1 parent 067ea8e commit beffbb4

File tree

8 files changed

+104
-10
lines changed

8 files changed

+104
-10
lines changed

pythonnet/src/runtime/assemblymanager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal class AssemblyManager {
3030
static ResolveEventHandler rhandler;
3131
static Dictionary<string, int> probed;
3232
static List<Assembly> assemblies;
33-
static List<string> pypath;
33+
internal static List<string> pypath;
3434

3535
private AssemblyManager() {}
3636

pythonnet/src/runtime/clrobject.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ internal CLRObject(Object ob, IntPtr tp) : base() {
3838
this.pyHandle = py;
3939
this.gcHandle = gc;
4040
inst = ob;
41-
42-
//DebugUtil.DumpInst(py);
43-
4441
}
4542

4643

pythonnet/src/runtime/importhook.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal class ImportHook {
2222
static IntPtr py_import;
2323
static ModuleObject root;
2424
static MethodWrapper hook;
25+
static ClrModule clr;
2526
static int preload;
2627

2728
//===================================================================
@@ -45,7 +46,9 @@ internal static void Initialize() {
4546

4647
root = new ModuleObject("");
4748
Runtime.PyDict_SetItemString(dict, "CLR", root.pyHandle);
48-
Runtime.PyDict_SetItemString(dict, "clr", root.pyHandle);
49+
50+
clr = new ClrModule("clr");
51+
Runtime.PyDict_SetItemString(dict, "clr", clr.pyHandle);
4952
preload = -1;
5053
}
5154

@@ -99,11 +102,16 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) {
99102

100103
string mod_name = Runtime.GetManagedString(py_mod_name);
101104

102-
if (mod_name == "CLR" || mod_name == "clr") {
105+
if (mod_name == "CLR") {
103106
Runtime.Incref(root.pyHandle);
104107
return root.pyHandle;
105108
}
106109

110+
if (mod_name == "clr") {
111+
Runtime.Incref(clr.pyHandle);
112+
return clr.pyHandle;
113+
}
114+
107115
string realname = mod_name;
108116
if (mod_name.StartsWith("CLR.")) {
109117
realname = mod_name.Substring(4);

pythonnet/src/runtime/interop.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ public PythonMethodAttribute() {}
3030

3131
[Serializable()]
3232
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Delegate)]
33-
internal class ModuleMethodAttribute : Attribute {
34-
public ModuleMethodAttribute() {}
33+
internal class ModuleFunctionAttribute : Attribute {
34+
public ModuleFunctionAttribute() {}
35+
}
36+
37+
[Serializable()]
38+
[AttributeUsage(AttributeTargets.Property)]
39+
internal class ModulePropertyAttribute : Attribute {
40+
public ModulePropertyAttribute() {}
3541
}
3642

3743

pythonnet/src/runtime/methodbinder.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
187187
int count = pi.Length;
188188
int outs = 0;
189189

190+
191+
// if ((nargs > count) && (pi[count].ParameterType.IsArray)) {
192+
// // See if we can map to a params signature
193+
194+
// }
195+
190196
if ( nargs == count ) {
191197
Object[] margs = new Object[count];
192198

@@ -219,7 +225,6 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
219225

220226
return new Binding(mi, target, margs, outs);
221227
}
222-
223228
}
224229
return null;
225230
}

pythonnet/src/runtime/moduleobject.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ internal class ModuleObject : ExtensionType {
2525

2626
Dictionary<string, ManagedType> cache;
2727
internal string moduleName;
28+
internal IntPtr dict;
2829
string _namespace;
2930
static bool hacked;
30-
IntPtr dict;
31+
3132

3233
public ModuleObject(string name) : base() {
3334
moduleName = (name == String.Empty) ? "CLR" : name;
@@ -254,6 +255,8 @@ public static IntPtr tp_repr(IntPtr ob) {
254255
return Runtime.PyString_FromString(s);
255256
}
256257

258+
259+
257260
}
258261

259262

pythonnet/src/testing/methodtest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,34 @@ public Type[] TestNullArrayConversion(Type [] v) {
7979
return v;
8080
}
8181

82+
public static string[] TestStringParamsArg(params string[] args) {
83+
return args;
84+
}
85+
86+
public static object[] TestObjectParamsArg(params object[] args) {
87+
return args;
88+
}
89+
90+
public static int[] TestValueParamsArg(params int[] args) {
91+
return args;
92+
}
93+
94+
public static int[] TestOneArgWithParams(string s, params int[] args) {
95+
return args;
96+
}
97+
98+
public static int[] TestTwoArgWithParams(string s, string x,
99+
params int[] args) {
100+
return args;
101+
}
102+
103+
public static int[] TestOverloadedParams(string v, params int[] args) {
104+
return args;
105+
}
106+
107+
public static int[] TestOverloadedParams(int v, int[] args) {
108+
return args;
109+
}
82110

83111
public static bool TestStringOutParams (string s, out string s1) {
84112
s1 = "output string";
@@ -128,6 +156,8 @@ public static void TestVoidSingleRefParam (ref int i) {
128156
i = 42;
129157
}
130158

159+
160+
131161
// overload selection test support
132162

133163
public static bool Overloaded(bool v) {

pythonnet/src/tests/test_method.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,51 @@ def testNullArrayConversion(self):
243243
self.failUnless(r == None)
244244

245245

246+
def testStringParamsArgs(self):
247+
"""Test use of string params."""
248+
result = MethodTest.TestStringParamsArg('one', 'two', 'three')
249+
self.failUnless(len(result) == 3)
250+
self.failUnless(result[0] == 'one')
251+
self.failUnless(result[1] == 'two')
252+
self.failUnless(result[2] == 'three')
253+
254+
result = MethodTest.TestStringParamsArg(['one', 'two', 'three'])
255+
self.failUnless(len(result) == 3)
256+
self.failUnless(result[0] == 'one')
257+
self.failUnless(result[1] == 'two')
258+
self.failUnless(result[2] == 'three')
259+
260+
261+
def testObjectParamsArgs(self):
262+
"""Test use of object params."""
263+
result = MethodTest.TestObjectParamsArg('one', 'two', 'three')
264+
self.failUnless(len(result) == 3)
265+
self.failUnless(result[0] == 'one')
266+
self.failUnless(result[1] == 'two')
267+
self.failUnless(result[2] == 'three')
268+
269+
result = MethodTest.TestObjectParamsArg(['one', 'two', 'three'])
270+
self.failUnless(len(result) == 3)
271+
self.failUnless(result[0] == 'one')
272+
self.failUnless(result[1] == 'two')
273+
self.failUnless(result[2] == 'three')
274+
275+
276+
def testValueParamsArgs(self):
277+
"""Test use of value type params."""
278+
result = MethodTest.TestValueParamsArg(1, 2, 3)
279+
self.failUnless(len(result) == 3)
280+
self.failUnless(result[0] == 1)
281+
self.failUnless(result[1] == 2)
282+
self.failUnless(result[2] == 3)
283+
284+
result = MethodTest.TestValueParamsArg([1, 2, 3])
285+
self.failUnless(len(result) == 3)
286+
self.failUnless(result[0] == 1)
287+
self.failUnless(result[1] == 2)
288+
self.failUnless(result[2] == 3)
289+
290+
246291
def testStringOutParams(self):
247292
"""Test use of string out-parameters."""
248293
result = MethodTest.TestStringOutParams("hi", "there")

0 commit comments

Comments
 (0)