From bde905af5b11e3e34bc1f5d4846d7767f7197236 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 21 May 2024 23:24:47 -0400 Subject: all: document legacy //go:linkname for modules with ≥20,000 dependents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For #67401. Change-Id: Icc10ede72547d8020c0ba45e89d954822a4b2455 Reviewed-on: https://go-review.googlesource.com/c/go/+/587218 Auto-Submit: Russ Cox Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI --- src/encoding/json/encode.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/encoding/json/encode.go') diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index bd55c7caf0..cb28feb279 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -24,6 +24,7 @@ import ( "sync" "unicode" "unicode/utf8" + _ "unsafe" // for linkname ) // Marshal returns the JSON encoding of v. @@ -591,6 +592,16 @@ func stringEncoder(e *encodeState, v reflect.Value, opts encOpts) { } // isValidNumber reports whether s is a valid JSON number literal. +// +// isValidNumber should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/bytedance/sonic +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname isValidNumber func isValidNumber(s string) bool { // This function implements the JSON numbers grammar. // See https://tools.ietf.org/html/rfc7159#section-6 @@ -1045,6 +1056,16 @@ type field struct { // typeFields returns a list of fields that JSON should recognize for the given type. // The algorithm is breadth-first search over the set of structs to include - the top struct // and then any reachable anonymous structs. +// +// typeFields should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/bytedance/sonic +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname typeFields func typeFields(t reflect.Type) structFields { // Anonymous fields to explore at the current level and the next. current := []field{} -- cgit v1.3