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) print(v)
case string: case string:
print(v) print(v)
case error:
print(v.Error())
case interface{ String() string }:
print(v.String())
default: default:
printanycustomtype(i) printanycustomtype(i)
} }

View File

@@ -47,12 +47,6 @@ func Recover() (ret any) {
// Panic panics with a value. // Panic panics with a value.
func Panic(v any) { 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)) ptr := c.Malloc(unsafe.Sizeof(v))
*(*any)(ptr) = v *(*any)(ptr) = v
excepKey.Set(ptr) 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) { func stringTracef(fp c.FilePtr, format *c.Char, s String) {
cs := c.Alloca(uintptr(s.len) + 1) cs := c.Alloca(uintptr(s.len) + 1)
c.Fprintf(fp, format, CStrCopy(cs, s)) c.Fprintf(fp, format, CStrCopy(cs, s))