summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-kv/v2/format/abi.go
diff options
context:
space:
mode:
authorLibravatar kim <grufwub@gmail.com>2025-08-09 16:23:00 +0200
committerLibravatar tobi <kipvandenbos@noreply.codeberg.org>2025-08-09 16:23:00 +0200
commit7af9117e0dc73f83995a32f11158cffdbaf5307c (patch)
tree8295b880a2b20306febbd0330de1f51a03533bb0 /vendor/codeberg.org/gruf/go-kv/v2/format/abi.go
parentchore: github/README update release month (#4359) (diff)
downloadgotosocial-7af9117e0dc73f83995a32f11158cffdbaf5307c.tar.xz
[feature + performance] add JSON logging format (#4355)
# Description Adds JSON logging as an optional alternative log output format. In the process this moves our log formatting itself into a separate subpkg to make it more easily modular, and improves caller name getting with some calling function name caching. ## Checklist - [x] I/we have read the [GoToSocial contribution guidelines](https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CONTRIBUTING.md). - [x] I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat. - [x] I/we have not leveraged AI to create the proposed changes. - [x] I/we have performed a self-review of added code. - [x] I/we have written code that is legible and maintainable by others. - [x] I/we have commented the added code, particularly in hard-to-understand areas. - [x] I/we have made any necessary changes to documentation. - [ ] I/we have added tests that cover new code. - [x] I/we have run tests and they pass locally with the changes. - [x] I/we have run `go fmt ./...` and `golangci-lint run`. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4355 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-kv/v2/format/abi.go')
-rw-r--r--vendor/codeberg.org/gruf/go-kv/v2/format/abi.go45
1 files changed, 23 insertions, 22 deletions
diff --git a/vendor/codeberg.org/gruf/go-kv/v2/format/abi.go b/vendor/codeberg.org/gruf/go-kv/v2/format/abi.go
index 815660a5e..b68d3cb73 100644
--- a/vendor/codeberg.org/gruf/go-kv/v2/format/abi.go
+++ b/vendor/codeberg.org/gruf/go-kv/v2/format/abi.go
@@ -1,4 +1,4 @@
-//go:build go1.24 && !go1.25
+//go:build go1.24 && !go1.26
package format
@@ -39,26 +39,36 @@ type abi_EmptyInterface struct {
Data unsafe.Pointer
}
+// abi_NonEmptyInterface is a copy of the memory layout of abi.NonEmptyInterface{},
+// which is to say also the memory layout of any interface containing method(s).
+//
+// see: go/src/internal/abi/iface.go on 1.25+
+// see: go/src/reflect/value.go on 1.24
+type abi_NonEmptyInterface struct {
+ ITab uintptr
+ Data unsafe.Pointer
+}
+
// see: go/src/internal/abi/type.go Type.Kind()
func abi_Type_Kind(t reflect.Type) uint8 {
- iface := (*reflect_nonEmptyInterface)(unsafe.Pointer(&t))
- atype := (*abi_Type)(unsafe.Pointer(iface.word))
+ iface := (*abi_NonEmptyInterface)(unsafe.Pointer(&t))
+ atype := (*abi_Type)(unsafe.Pointer(iface.Data))
return atype.Kind_ & abi_KindMask
}
// see: go/src/internal/abi/type.go Type.IfaceIndir()
func abi_Type_IfaceIndir(t reflect.Type) bool {
- iface := (*reflect_nonEmptyInterface)(unsafe.Pointer(&t))
- atype := (*abi_Type)(unsafe.Pointer(iface.word))
+ iface := (*abi_NonEmptyInterface)(unsafe.Pointer(&t))
+ atype := (*abi_Type)(unsafe.Pointer(iface.Data))
return atype.Kind_&abi_KindDirectIface == 0
}
-// pack_iface packs a new reflect.nonEmptyInterface{} using shielded itab
-// pointer and data (word) pointer, returning a pointer for caller casting.
+// pack_iface packs a new reflect.nonEmptyInterface{} using shielded
+// itab and data pointer, returning a pointer for caller casting.
func pack_iface(itab uintptr, word unsafe.Pointer) unsafe.Pointer {
- return unsafe.Pointer(&reflect_nonEmptyInterface{
- itab: itab,
- word: word,
+ return unsafe.Pointer(&abi_NonEmptyInterface{
+ ITab: itab,
+ Data: word,
})
}
@@ -68,8 +78,8 @@ func pack_iface(itab uintptr, word unsafe.Pointer) unsafe.Pointer {
// this is useful for later calls to pack_iface for known type.
func get_iface_ITab[I any](t reflect.Type) uintptr {
s := reflect.New(t).Elem().Interface().(I)
- i := (*reflect_nonEmptyInterface)(unsafe.Pointer(&s))
- return i.itab
+ i := (*abi_NonEmptyInterface)(unsafe.Pointer(&s))
+ return i.ITab
}
// unpack_eface returns the .Data portion of an abi.EmptyInterface{}.
@@ -162,15 +172,6 @@ func reflect_map_elem_flags(elemType reflect.Type) reflect_flag {
return reflect_flag(abi_Type_Kind(elemType))
}
-// reflect_nonEmptyInterface is a copy of the memory layout of reflect.nonEmptyInterface,
-// which is also to say the memory layout of any non-empty (i.e. w/ method) interface.
-//
-// see: go/src/reflect/value.go
-type reflect_nonEmptyInterface struct {
- itab uintptr
- word unsafe.Pointer
-}
-
// reflect_Value is a copy of the memory layout of reflect.Value{}.
//
// see: go/src/reflect/value.go
@@ -190,7 +191,7 @@ func init() {
// as the reflect.nonEmptyInterface{}, which itself will be a pointer
// to the actual abi.Type{} that this reflect.Type{} is wrapping.
func reflect_type_data(t reflect.Type) unsafe.Pointer {
- return (*reflect_nonEmptyInterface)(unsafe.Pointer(&t)).word
+ return (*abi_NonEmptyInterface)(unsafe.Pointer(&t)).Data
}
// build_reflect_value manually builds a reflect.Value{} by setting the internal field members.