@@ -226,7 +226,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
226226 int pynargs = Runtime . PyTuple_Size ( args ) ;
227227 object arg ;
228228 bool isGeneric = false ;
229-
229+ ArrayList defaultArgList = null ;
230230 if ( info != null ) {
231231 _methods = ( MethodBase [ ] ) Array . CreateInstance (
232232 typeof ( MethodBase ) , 1
@@ -247,7 +247,17 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
247247 int outs = 0 ;
248248
249249 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+ }
251261 } else if ( ( pynargs > clrnargs ) && ( clrnargs > 0 ) &&
252262 ( pi [ clrnargs - 1 ] . ParameterType . IsArray ) ) {
253263 // The last argument of the mananged functions seems to
@@ -262,30 +272,43 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
262272
263273 for ( int n = 0 ; n < clrnargs ; n ++ ) {
264274 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 ;
282306 }
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 ] ;
287311 }
288- margs [ n ] = arg ;
289312 }
290313
291314 if ( margs == null ) {
0 commit comments