@@ -50,7 +50,10 @@ internal void AddMethod(MethodBase m) {
50
50
//====================================================================
51
51
52
52
internal static MethodInfo MatchSignature ( MethodInfo [ ] mi , Type [ ] tp ) {
53
- int count = tp . Length ;
53
+ if ( tp == null ) {
54
+ return null ;
55
+ }
56
+ int count = tp . Length ;
54
57
for ( int i = 0 ; i < mi . Length ; i ++ ) {
55
58
ParameterInfo [ ] pi = mi [ i ] . GetParameters ( ) ;
56
59
if ( pi . Length != count ) {
@@ -92,51 +95,54 @@ internal static MethodInfo MatchParameters(MethodInfo[] mi, Type[] tp) {
92
95
}
93
96
94
97
95
- //====================================================================
96
- // Given a sequence of MethodInfo and two sequences of type parameters,
97
- // return the MethodInfo that matches the signature and the closed generic.
98
- //====================================================================
99
-
100
- internal static MethodInfo MatchSignatureAndParameters ( MethodInfo [ ] mi , Type [ ] genericTp , Type [ ] sigTp )
101
- {
102
- int genericCount = genericTp . Length ;
103
- int signatureCount = sigTp . Length ;
104
- for ( int i = 0 ; i < mi . Length ; i ++ )
105
- {
106
- if ( ! mi [ i ] . IsGenericMethodDefinition )
107
- {
108
- continue ;
109
- }
110
- Type [ ] genericArgs = mi [ i ] . GetGenericArguments ( ) ;
111
- if ( genericArgs . Length != genericCount )
112
- {
113
- continue ;
114
- }
115
- ParameterInfo [ ] pi = mi [ i ] . GetParameters ( ) ;
116
- if ( pi . Length != signatureCount )
117
- {
118
- continue ;
119
- }
120
- for ( int n = 0 ; n < pi . Length ; n ++ )
121
- {
122
- if ( sigTp [ n ] != pi [ n ] . ParameterType )
123
- {
124
- break ;
125
- }
126
- if ( n == ( pi . Length - 1 ) )
127
- {
128
- MethodInfo match = mi [ i ] ;
129
- if ( match . IsGenericMethodDefinition )
130
- {
131
- Type [ ] typeArgs = match . GetGenericArguments ( ) ;
132
- return match . MakeGenericMethod ( genericTp ) ;
133
- }
134
- return match ;
135
- }
136
- }
137
- }
138
- return null ;
139
- }
98
+ //====================================================================
99
+ // Given a sequence of MethodInfo and two sequences of type parameters,
100
+ // return the MethodInfo that matches the signature and the closed generic.
101
+ //====================================================================
102
+
103
+ internal static MethodInfo MatchSignatureAndParameters ( MethodInfo [ ] mi , Type [ ] genericTp , Type [ ] sigTp )
104
+ {
105
+ if ( ( genericTp == null ) || ( sigTp == null ) ) {
106
+ return null ;
107
+ }
108
+ int genericCount = genericTp . Length ;
109
+ int signatureCount = sigTp . Length ;
110
+ for ( int i = 0 ; i < mi . Length ; i ++ )
111
+ {
112
+ if ( ! mi [ i ] . IsGenericMethodDefinition )
113
+ {
114
+ continue ;
115
+ }
116
+ Type [ ] genericArgs = mi [ i ] . GetGenericArguments ( ) ;
117
+ if ( genericArgs . Length != genericCount )
118
+ {
119
+ continue ;
120
+ }
121
+ ParameterInfo [ ] pi = mi [ i ] . GetParameters ( ) ;
122
+ if ( pi . Length != signatureCount )
123
+ {
124
+ continue ;
125
+ }
126
+ for ( int n = 0 ; n < pi . Length ; n ++ )
127
+ {
128
+ if ( sigTp [ n ] != pi [ n ] . ParameterType )
129
+ {
130
+ break ;
131
+ }
132
+ if ( n == ( pi . Length - 1 ) )
133
+ {
134
+ MethodInfo match = mi [ i ] ;
135
+ if ( match . IsGenericMethodDefinition )
136
+ {
137
+ Type [ ] typeArgs = match . GetGenericArguments ( ) ;
138
+ return match . MakeGenericMethod ( genericTp ) ;
139
+ }
140
+ return match ;
141
+ }
142
+ }
143
+ }
144
+ return null ;
145
+ }
140
146
141
147
142
148
//====================================================================
@@ -239,9 +245,10 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
239
245
else {
240
246
_methods = GetMethods ( ) ;
241
247
}
242
-
248
+ Type type ;
243
249
for ( int i = 0 ; i < _methods . Length ; i ++ ) {
244
250
MethodBase mi = _methods [ i ] ;
251
+
245
252
if ( mi . IsGenericMethod ) { isGeneric = true ; }
246
253
ParameterInfo [ ] pi = mi . GetParameters ( ) ;
247
254
int clrnargs = pi . Length ;
@@ -275,19 +282,41 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
275
282
276
283
for ( int n = 0 ; n < clrnargs ; n ++ ) {
277
284
IntPtr op ;
278
- if ( n < pynargs )
279
- {
280
- if ( arrayStart == n )
281
- {
285
+ if ( n < pynargs ) {
286
+ if ( arrayStart == n ) {
282
287
// map remaining Python arguments to a tuple since
283
288
// the managed function accepts it - hopefully :]
284
289
op = Runtime . PyTuple_GetSlice ( args , arrayStart , pynargs ) ;
285
290
}
286
- else
287
- {
291
+ else {
288
292
op = Runtime . PyTuple_GetItem ( args , n ) ;
289
293
}
290
- Type type = pi [ n ] . ParameterType ;
294
+
295
+ // this logic below handles cases when multiple overloading methods
296
+ // are ambiguous, hence comparison between Python and CLR types
297
+ // is necessary
298
+ type = null ;
299
+
300
+ if ( _methods . Length > 1 ) {
301
+ IntPtr pyoptype = IntPtr . Zero ;
302
+ pyoptype = Runtime . PyObject_Type ( op ) ;
303
+ Exceptions . Clear ( ) ;
304
+ if ( pyoptype != IntPtr . Zero ) { }
305
+ type = Converter . GetTypeByAlias ( pyoptype ) ;
306
+ Runtime . Decref ( pyoptype ) ;
307
+ }
308
+
309
+
310
+ if ( type != null ) {
311
+ if ( pi [ n ] . ParameterType != type ) {
312
+ margs = null ;
313
+ break ;
314
+ }
315
+ }
316
+ else {
317
+ type = pi [ n ] . ParameterType ;
318
+ }
319
+
291
320
if ( pi [ n ] . IsOut || type . IsByRef )
292
321
{
293
322
outs ++ ;
@@ -348,7 +377,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
348
377
MethodInfo mi = MethodBinder . MatchParameters ( methodinfo , types ) ;
349
378
return Bind ( inst , args , kw , mi , null ) ;
350
379
}
351
- return null ;
380
+ return null ;
352
381
}
353
382
354
383
internal virtual IntPtr Invoke ( IntPtr inst , IntPtr args , IntPtr kw ) {
0 commit comments