@@ -226,7 +226,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
226
226
int pynargs = Runtime . PyTuple_Size ( args ) ;
227
227
object arg ;
228
228
bool isGeneric = false ;
229
-
229
+ ArrayList defaultArgList = null ;
230
230
if ( info != null ) {
231
231
_methods = ( MethodBase [ ] ) Array . CreateInstance (
232
232
typeof ( MethodBase ) , 1
@@ -247,7 +247,17 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
247
247
int outs = 0 ;
248
248
249
249
if ( pynargs == clrnargs ) {
250
- match = true ;
250
+ match = true ;
251
+ } else if ( pynargs < clrnargs ) {
252
+ match = true ;
253
+ defaultArgList = new ArrayList ( ) ;
254
+ for ( int v = pynargs ; v < clrnargs ; v ++ )
255
+ {
256
+ if ( pi [ v ] . DefaultValue == DBNull . Value )
257
+ match = false ;
258
+ else
259
+ defaultArgList . Add ( ( object ) pi [ v ] . DefaultValue ) ;
260
+ }
251
261
} else if ( ( pynargs > clrnargs ) && ( clrnargs > 0 ) &&
252
262
( pi [ clrnargs - 1 ] . ParameterType . IsArray ) ) {
253
263
// The last argument of the mananged functions seems to
@@ -262,30 +272,43 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
262
272
263
273
for ( int n = 0 ; n < clrnargs ; n ++ ) {
264
274
IntPtr op ;
265
- if ( arrayStart == n ) {
266
- // map remaining Python arguments to a tuple since
267
- // the managed function accepts it - hopefully :]
268
- op = Runtime . PyTuple_GetSlice ( args , arrayStart , pynargs ) ;
269
- }
270
- else {
271
- op = Runtime . PyTuple_GetItem ( args , n ) ;
272
- }
273
- Type type = pi [ n ] . ParameterType ;
274
- if ( pi [ n ] . IsOut || type . IsByRef ) {
275
- outs ++ ;
276
- }
277
-
278
- if ( ! Converter . ToManaged ( op , type , out arg , false ) ) {
279
- Exceptions . Clear ( ) ;
280
- margs = null ;
281
- break ;
275
+ if ( n < pynargs )
276
+ {
277
+ if ( arrayStart == n )
278
+ {
279
+ // map remaining Python arguments to a tuple since
280
+ // the managed function accepts it - hopefully :]
281
+ op = Runtime . PyTuple_GetSlice ( args , arrayStart , pynargs ) ;
282
+ }
283
+ else
284
+ {
285
+ op = Runtime . PyTuple_GetItem ( args , n ) ;
286
+ }
287
+ Type type = pi [ n ] . ParameterType ;
288
+ if ( pi [ n ] . IsOut || type . IsByRef )
289
+ {
290
+ outs ++ ;
291
+ }
292
+
293
+ if ( ! Converter . ToManaged ( op , type , out arg , false ) )
294
+ {
295
+ Exceptions . Clear ( ) ;
296
+ margs = null ;
297
+ break ;
298
+ }
299
+ if ( arrayStart == n )
300
+ {
301
+ // GetSlice() creates a new reference but GetItem()
302
+ // returns only a borrow reference.
303
+ Runtime . Decref ( op ) ;
304
+ }
305
+ margs [ n ] = arg ;
282
306
}
283
- if ( arrayStart == n ) {
284
- // GetSlice() creates a new reference but GetItem()
285
- // returns only a borrow reference.
286
- Runtime . Decref ( op ) ;
307
+ else
308
+ {
309
+ if ( defaultArgList != null )
310
+ margs [ n ] = defaultArgList [ n - pynargs ] ;
287
311
}
288
- margs [ n ] = arg ;
289
312
}
290
313
291
314
if ( margs == null ) {
0 commit comments