@@ -63,7 +63,7 @@ internal void SetItem(IntPtr inst, IntPtr args) {
63
63
}
64
64
65
65
internal bool NeedsDefaultArgs ( IntPtr args ) {
66
- int pynargs = Runtime . PyTuple_Size ( args ) - 1 ;
66
+ int pynargs = Runtime . PyTuple_Size ( args ) ;
67
67
var methods = SetterBinder . GetMethods ( ) ;
68
68
if ( methods . Length == 0 )
69
69
return false ;
@@ -72,7 +72,7 @@ internal bool NeedsDefaultArgs(IntPtr args){
72
72
ParameterInfo [ ] pi = mi . GetParameters ( ) ;
73
73
// need to subtract one for the value
74
74
int clrnargs = pi . Length - 1 ;
75
- if ( pynargs == clrnargs )
75
+ if ( pynargs == clrnargs || pynargs > clrnargs )
76
76
return false ;
77
77
78
78
for ( int v = pynargs ; v < clrnargs ; v ++ ) {
@@ -82,34 +82,30 @@ internal bool NeedsDefaultArgs(IntPtr args){
82
82
return true ;
83
83
}
84
84
85
+ /// <summary>
86
+ /// This will return default arguments a new instance of a tuple. The size
87
+ /// of the tuple will indicate the number of default arguments.
88
+ /// </summary>
89
+ /// <param name="args">This is pointing to the tuple args passed in</param>
90
+ /// <returns>a new instance of the tuple containing the default args</returns>
85
91
internal IntPtr GetDefaultArgs ( IntPtr args ) {
86
- //IntPtr real = Runtime.PyTuple_New(i + 1);
87
- int pynargs = Runtime . PyTuple_Size ( args ) - 1 ;
92
+
93
+ // if we don't need default args return empty tuple
94
+ if ( ! NeedsDefaultArgs ( args ) )
95
+ return Runtime . PyTuple_New ( 0 ) ;
96
+ int pynargs = Runtime . PyTuple_Size ( args ) ;
97
+
98
+ // Get the default arg tuple
88
99
var methods = SetterBinder . GetMethods ( ) ;
89
- IntPtr defaultArgs ;
90
- if ( methods . Length == 0 ) {
91
- defaultArgs = Runtime . PyTuple_New ( 0 ) ;
92
- return defaultArgs ;
93
- }
94
100
MethodBase mi = methods [ 0 ] ;
95
101
ParameterInfo [ ] pi = mi . GetParameters ( ) ;
96
102
int clrnargs = pi . Length - 1 ;
97
- if ( pynargs == clrnargs || pynargs > clrnargs ) {
98
- defaultArgs = Runtime . PyTuple_New ( 0 ) ;
99
- return defaultArgs ;
100
- }
101
-
102
- defaultArgs = Runtime . PyTuple_New ( clrnargs - pynargs ) ;
103
+ IntPtr defaultArgs = Runtime . PyTuple_New ( clrnargs - pynargs ) ;
103
104
for ( int i = 0 ; i < ( clrnargs - pynargs ) ; i ++ ) {
104
- // Here we own the reference to the Python value, and we
105
- // give the ownership to the arg tuple.
106
105
if ( pi [ i + pynargs ] . DefaultValue == DBNull . Value )
107
106
continue ;
108
107
else {
109
108
IntPtr arg = Converter . ToPython ( pi [ i + pynargs ] . DefaultValue , pi [ i + pynargs ] . ParameterType ) ;
110
- Type type = typeof ( String ) ;
111
- Object arg2 ;
112
- Converter . ToManaged ( arg , type , out arg2 , false ) ;
113
109
Runtime . PyTuple_SetItem ( defaultArgs , i , arg ) ;
114
110
}
115
111
}
0 commit comments