Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 107d22f

Browse files
committed
debugging
1 parent bafbe25 commit 107d22f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/embed_tests/TestTypeManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ public static void TestNativeCode()
2929
[Test]
3030
public static void TestMemoryMapping()
3131
{
32+
System.Console.WriteLine("TestMemoryMapping");
3233
Assert.That(() => { var _ = TypeManager.CreateMemoryMapper(); }, Throws.Nothing);
3334
var mapper = TypeManager.CreateMemoryMapper();
3435

36+
System.Console.WriteLine("TestMemoryMapping 1");
3537
// Allocate a read-write page.
3638
int len = 12;
3739
var page = mapper.MapWriteable(len);
3840
Assert.That(() => { Marshal.WriteInt64(page, 17); }, Throws.Nothing);
3941
Assert.That(Marshal.ReadInt64(page), Is.EqualTo(17));
4042

43+
System.Console.WriteLine("TestMemoryMapping 2");
4144
// Mark it read-execute. We can still read, haven't changed any values.
4245
mapper.SetReadExec(page, len);
4346
Assert.That(Marshal.ReadInt64(page), Is.EqualTo(17));
@@ -54,10 +57,13 @@ public static void TestMemoryMapping()
5457
// We can't use compiler flags because we compile with MONO_LINUX
5558
// while running on the Microsoft .NET Core during continuous
5659
// integration tests.
60+
System.Console.WriteLine("TestMemoryMapping 3");
5761
if (System.Type.GetType ("Mono.Runtime") != null)
5862
{
5963
// Mono throws NRE instead of AccessViolationException for some reason.
6064
Assert.That(() => { Marshal.WriteInt64(page, 73); }, Throws.TypeOf<System.NullReferenceException>());
65+
66+
System.Console.WriteLine("TestMemoryMapping 4");
6167
Assert.That(Marshal.ReadInt64(page), Is.EqualTo(17));
6268
}
6369
}

src/runtime/classbase.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ public static IntPtr tp_str(IntPtr ob)
233233
}
234234
try
235235
{
236+
Console.WriteLine("classbase tp_str");
236237
//As per python doc:
237238
//The return value must be a string object. If a class defines __repr__() but not __str__(),
238239
//then __repr__() is also used when an “informal” string representation of instances of that
@@ -245,25 +246,32 @@ public static IntPtr tp_str(IntPtr ob)
245246
var instType = co.inst.GetType();
246247
foreach (var method in instType.GetMethods())
247248
{
248-
249+
Console.WriteLine("classbase tp_str in loop");
249250
//TODO this could probably be done more cleanly with Linq
250251
if (!method.IsPublic) continue; //skip private/protected methods
251252
if (method.Name != "ToString") continue; //only look for ToString
252253
if (method.DeclaringType == typeof(object)) continue; //ignore default from object
253254
if (method.GetParameters().Length != 0) continue; //ignore Formatter overload of ToString
254255

256+
Console.WriteLine("classbase tp_str in loop end");
257+
255258
//match! something other than object provides a parameter-less overload of ToString
256259
return Runtime.PyString_FromString(co.inst.ToString());
257260
}
258261

262+
Console.WriteLine("classbase tp_str after loop");
263+
259264
//If the object defines __repr__, call it.
260265
System.Reflection.MethodInfo reprMethodInfo = instType.GetMethod("__repr__");
261266
if (reprMethodInfo != null && reprMethodInfo.IsPublic)
262267
{
268+
Console.WriteLine("classbase tp_str has __repr__");
263269
var reprString = reprMethodInfo.Invoke(co.inst, null) as string;
264270
return Runtime.PyString_FromString(reprString);
265271
}
266272

273+
Console.WriteLine("classbase tp_str fallback");
274+
267275
//otherwise fallback to object's ToString() implementation
268276
return Runtime.PyString_FromString(co.inst.ToString());
269277

@@ -288,6 +296,7 @@ public static IntPtr tp_repr(IntPtr ob)
288296
}
289297
try
290298
{
299+
Console.WriteLine("classbase tp_repr");
291300
//if __repr__ is defined, use it
292301
var instType = co.inst.GetType();
293302
System.Reflection.MethodInfo methodInfo = instType.GetMethod("__repr__");
@@ -297,6 +306,8 @@ public static IntPtr tp_repr(IntPtr ob)
297306
return Runtime.PyString_FromString(reprString);
298307
}
299308

309+
Console.WriteLine("classbase tp_repr fallback");
310+
300311
//otherwise use the standard object.__repr__(inst)
301312
IntPtr args = Runtime.PyTuple_New(1);
302313
Runtime.PyTuple_SetItem(args, 0, ob);

0 commit comments

Comments
 (0)