Skip to content

Commit 392c08b

Browse files
committed
Use Int32 for the flags, write a complete empty struct at the end.
1 parent 418e767 commit 392c08b

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

src/runtime/methodwrapper.cs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,19 @@ public MethodWrapper(Type type, string name) {
3131

3232
IntPtr fp = Interop.GetThunk(type.GetMethod(name));
3333

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-
4534
// Allocate and initialize a PyMethodDef structure to represent
4635
// the managed method, then create a PyCFunction.
4736

4837
mdef = Runtime.PyMem_Malloc(4 * IntPtr.Size);
49-
Marshal.WriteIntPtr(mdef, sp);
38+
Marshal.WriteIntPtr(mdef, Marshal.StringToHGlobalAnsi(name));
5039
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
5241
Marshal.WriteIntPtr(mdef, (3 * IntPtr.Size), IntPtr.Zero);
5342
ptr = Runtime.PyCFunction_NewEx(mdef, IntPtr.Zero, IntPtr.Zero);
5443
}
5544

5645
public IntPtr Call(IntPtr args, IntPtr kw) {
5746
return Runtime.PyCFunction_Call(ptr, args, kw);
5847
}
59-
60-
6148
}
62-
63-
64-
}
65-
49+
}

src/runtime/typemanager.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,14 @@ internal static IntPtr CreateMetaType(Type impl) {
306306
IntPtr mdef = Runtime.PyMem_Malloc(5 * IntPtr.Size);
307307
Marshal.WriteIntPtr(mdef, Marshal.StringToHGlobalAnsi("__instancecheck__"));
308308
Marshal.WriteIntPtr(mdef, (1 * IntPtr.Size), fp);
309-
Marshal.WriteIntPtr(mdef, (2 * IntPtr.Size), (IntPtr)0x0001); // METH_VARARGS
309+
Marshal.WriteInt32(mdef, (2 * IntPtr.Size), 0x0001);
310310
Marshal.WriteIntPtr(mdef, (3 * IntPtr.Size), IntPtr.Zero);
311+
312+
// Write empty sentinel struct
311313
Marshal.WriteIntPtr(mdef, (4 * IntPtr.Size), IntPtr.Zero);
314+
Marshal.WriteIntPtr(mdef, (5 * IntPtr.Size), IntPtr.Zero);
315+
Marshal.WriteIntPtr(mdef, (6 * IntPtr.Size), IntPtr.Zero);
316+
Marshal.WriteIntPtr(mdef, (7 * IntPtr.Size), IntPtr.Zero);
312317

313318
Marshal.WriteIntPtr(type, TypeOffset.tp_methods, mdef);
314319

0 commit comments

Comments
 (0)