runtime.Panic: mv error/Stringer to printany

This commit is contained in:
xushiwei
2024-07-28 20:31:48 +08:00
parent 0d468e0df4
commit 54964629fe
2 changed files with 4 additions and 10 deletions

View File

@@ -96,6 +96,10 @@ func printany(i any) {
print(v)
case string:
print(v)
case error:
print(v.Error())
case interface{ String() string }:
print(v.String())
default:
printanycustomtype(i)
}

View File

@@ -47,12 +47,6 @@ func Recover() (ret any) {
// Panic panics with a value.
func Panic(v any) {
switch e := v.(type) {
case error:
v = e.Error()
case interface{ String() string }:
v = e.String()
}
ptr := c.Malloc(unsafe.Sizeof(v))
*(*any)(ptr) = v
excepKey.Set(ptr)
@@ -91,10 +85,6 @@ func TracePanic(v any) {
}
/*
func unpackEface(i any) *eface {
return (*eface)(unsafe.Pointer(&i))
}
func stringTracef(fp c.FilePtr, format *c.Char, s String) {
cs := c.Alloca(uintptr(s.len) + 1)
c.Fprintf(fp, format, CStrCopy(cs, s))