@@ -114,6 +114,60 @@ internal static int ArgPrecedence(Type t) {
114114 }
115115
116116
117+ internal static MethodInfo MatchByTypeSig ( MethodInfo [ ] msig ,
118+ IntPtr psig ) {
119+ IntPtr args = psig ;
120+ bool free = false ;
121+
122+ if ( ! Runtime . PyTuple_Check ( psig ) ) {
123+ args = Runtime . PyTuple_New ( 1 ) ;
124+ Runtime . Incref ( psig ) ;
125+ Runtime . PyTuple_SetItem ( args , 0 , psig ) ;
126+ free = true ;
127+ }
128+
129+ int plen = Runtime . PyTuple_Size ( args ) ;
130+ MethodInfo match = null ;
131+
132+ // XXX: what about out args, etc.?
133+
134+ for ( int i = 0 ; i < msig . Length ; i ++ ) {
135+ ParameterInfo [ ] pi = msig [ i ] . GetParameters ( ) ;
136+ if ( pi . Length != plen ) {
137+ continue ;
138+ }
139+ bool matched = true ;
140+ for ( int n = 0 ; n < pi . Length ; n ++ ) {
141+ IntPtr p = Runtime . PyTuple_GetItem ( args , n ) ;
142+ if ( p == IntPtr . Zero ) {
143+ Exceptions . Clear ( ) ;
144+ break ;
145+ }
146+ ClassBase c = ManagedType . GetManagedObject ( p ) as ClassBase ;
147+ Type t = ( c != null ) ? c . type :
148+ Converter . GetTypeByAlias ( p ) ;
149+
150+ if ( t == null ) {
151+ break ;
152+ }
153+ if ( t != pi [ n ] . ParameterType ) {
154+ matched = false ;
155+ break ;
156+ }
157+ }
158+ if ( matched ) {
159+ match = msig [ i ] ;
160+ break ;
161+ }
162+ }
163+
164+ if ( free ) {
165+ Runtime . Decref ( args ) ;
166+ }
167+
168+ return match ;
169+ }
170+
117171
118172 //====================================================================
119173 // Bind the given Python instance and arguments to a particular method
@@ -122,12 +176,26 @@ internal static int ArgPrecedence(Type t) {
122176 //====================================================================
123177
124178 internal Binding Bind ( IntPtr inst , IntPtr args , IntPtr kw ) {
179+ return this . Bind ( inst , args , kw , null ) ;
180+ }
181+
182+ internal Binding Bind ( IntPtr inst , IntPtr args , IntPtr kw ,
183+ MethodBase info ) {
125184 // loop to find match, return invoker w/ or /wo error
185+ MethodBase [ ] _methods = null ;
126186 int nargs = Runtime . PyTuple_Size ( args ) ;
127187 object arg ;
128188
129- MethodBase [ ] _methods = GetMethods ( ) ;
130-
189+ if ( info != null ) {
190+ _methods = ( MethodBase [ ] ) Array . CreateInstance (
191+ typeof ( MethodBase ) , 1
192+ ) ;
193+ _methods . SetValue ( info , 0 ) ;
194+ }
195+ else {
196+ _methods = GetMethods ( ) ;
197+ }
198+
131199 for ( int i = 0 ; i < _methods . Length ; i ++ ) {
132200 MethodBase mi = _methods [ i ] ;
133201 ParameterInfo [ ] pi = mi . GetParameters ( ) ;
@@ -171,9 +239,14 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw) {
171239 return null ;
172240 }
173241
174-
175242 internal virtual IntPtr Invoke ( IntPtr inst , IntPtr args , IntPtr kw ) {
176- Binding binding = this . Bind ( inst , args , kw ) ;
243+ return this . Invoke ( inst , args , kw , null ) ;
244+
245+ }
246+
247+ internal virtual IntPtr Invoke ( IntPtr inst , IntPtr args , IntPtr kw ,
248+ MethodBase info ) {
249+ Binding binding = this . Bind ( inst , args , kw , info ) ;
177250 Object result ;
178251
179252 if ( binding == null ) {
0 commit comments