@@ -31,35 +31,19 @@ public MethodWrapper(Type type, string name) {
31
31
32
32
IntPtr fp = Interop . GetThunk ( type . GetMethod ( name ) ) ;
33
33
34
- // XXX - here we create a Python string object, then take the
35
- // char * of the internal string to pass to our methoddef
36
- // structure. Its a hack, and the name is leaked!
37
- #if ( PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 )
38
- IntPtr ps = Runtime . PyBytes_FromString ( name ) ;
39
- IntPtr sp = Runtime . PyBytes_AS_STRING ( ps ) ;
40
- #else
41
- IntPtr ps = Runtime . PyString_FromString ( name ) ;
42
- IntPtr sp = Runtime . PyString_AS_STRING ( ps ) ;
43
- #endif
44
-
45
34
// Allocate and initialize a PyMethodDef structure to represent
46
35
// the managed method, then create a PyCFunction.
47
36
48
37
mdef = Runtime . PyMem_Malloc ( 4 * IntPtr . Size ) ;
49
- Marshal . WriteIntPtr ( mdef , sp ) ;
38
+ Marshal . WriteIntPtr ( mdef , Marshal . StringToHGlobalAnsi ( name ) ) ;
50
39
Marshal . WriteIntPtr ( mdef , ( 1 * IntPtr . Size ) , fp ) ;
51
- Marshal . WriteIntPtr ( mdef , ( 2 * IntPtr . Size ) , ( IntPtr ) 0x0003 ) ; // METH_VARARGS | METH_KEYWORDS
40
+ Marshal . WriteInt32 ( mdef , ( 2 * IntPtr . Size ) , 0x0003 ) ; // METH_VARARGS | METH_KEYWORDS
52
41
Marshal . WriteIntPtr ( mdef , ( 3 * IntPtr . Size ) , IntPtr . Zero ) ;
53
42
ptr = Runtime . PyCFunction_NewEx ( mdef , IntPtr . Zero , IntPtr . Zero ) ;
54
43
}
55
44
56
45
public IntPtr Call ( IntPtr args , IntPtr kw ) {
57
46
return Runtime . PyCFunction_Call ( ptr , args , kw ) ;
58
47
}
59
-
60
-
61
48
}
62
-
63
-
64
- }
65
-
49
+ }
0 commit comments