From 90b29e186576d2682c024b0f0b90c6ad98e824d7 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Wed, 19 Jan 2022 17:01:25 +0100 Subject: [PATCH] cmd/cgo: use size_t instead of __SIZE_TYPE__ __SIZE_TYPE__ is a GCC type which has been superseded by size_t -define in stddef.h- since ISO C99. cmd/cgo already uses size_t in many places, but still generates several files using __SIZE_TYPES__, most notably the _cgo_export.h. This change replaces all __SIZE_TYPES__ occurrences with size_t. Updates #36233 Change-Id: Id8a99b5d7763caab9333eab9b585e78249a37415 Reviewed-on: https://go-review.googlesource.com/c/go/+/379474 Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Reviewed-by: Tobias Klauser --- src/cmd/cgo/out.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index e0803866c80..8ead173e64d 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -57,18 +57,19 @@ func (p *Package) writeDefs() { fflg.Close() // Write C main file for using gcc to resolve imports. + fmt.Fprintf(fm, "#include \n") // For size_t below. fmt.Fprintf(fm, "int main() { return 0; }\n") if *importRuntimeCgo { - fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*) __attribute__((unused)), void *a __attribute__((unused)), int c __attribute__((unused)), __SIZE_TYPE__ ctxt __attribute__((unused))) { }\n") - fmt.Fprintf(fm, "__SIZE_TYPE__ _cgo_wait_runtime_init_done(void) { return 0; }\n") - fmt.Fprintf(fm, "void _cgo_release_context(__SIZE_TYPE__ ctxt __attribute__((unused))) { }\n") + fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*) __attribute__((unused)), void *a __attribute__((unused)), int c __attribute__((unused)), size_t ctxt __attribute__((unused))) { }\n") + fmt.Fprintf(fm, "size_t _cgo_wait_runtime_init_done(void) { return 0; }\n") + fmt.Fprintf(fm, "void _cgo_release_context(size_t ctxt __attribute__((unused))) { }\n") fmt.Fprintf(fm, "char* _cgo_topofstack(void) { return (char*)0; }\n") } else { // If we're not importing runtime/cgo, we *are* runtime/cgo, // which provides these functions. We just need a prototype. - fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*), void *a, int c, __SIZE_TYPE__ ctxt);\n") - fmt.Fprintf(fm, "__SIZE_TYPE__ _cgo_wait_runtime_init_done(void);\n") - fmt.Fprintf(fm, "void _cgo_release_context(__SIZE_TYPE__);\n") + fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*), void *a, int c, size_t ctxt);\n") + fmt.Fprintf(fm, "size_t _cgo_wait_runtime_init_done(void);\n") + fmt.Fprintf(fm, "void _cgo_release_context(size_t);\n") } fmt.Fprintf(fm, "void _cgo_allocate(void *a __attribute__((unused)), int c __attribute__((unused))) { }\n") fmt.Fprintf(fm, "void _cgo_panic(void *a __attribute__((unused)), int c __attribute__((unused))) { }\n") @@ -886,9 +887,9 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) { fmt.Fprintf(fgcc, "#pragma GCC diagnostic ignored \"-Wpragmas\"\n") fmt.Fprintf(fgcc, "#pragma GCC diagnostic ignored \"-Waddress-of-packed-member\"\n") - fmt.Fprintf(fgcc, "extern void crosscall2(void (*fn)(void *), void *, int, __SIZE_TYPE__);\n") - fmt.Fprintf(fgcc, "extern __SIZE_TYPE__ _cgo_wait_runtime_init_done(void);\n") - fmt.Fprintf(fgcc, "extern void _cgo_release_context(__SIZE_TYPE__);\n\n") + fmt.Fprintf(fgcc, "extern void crosscall2(void (*fn)(void *), void *, int, size_t);\n") + fmt.Fprintf(fgcc, "extern size_t _cgo_wait_runtime_init_done(void);\n") + fmt.Fprintf(fgcc, "extern void _cgo_release_context(size_t);\n\n") fmt.Fprintf(fgcc, "extern char* _cgo_topofstack(void);") fmt.Fprintf(fgcc, "%s\n", tsanProlog) fmt.Fprintf(fgcc, "%s\n", msanProlog) @@ -992,7 +993,7 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) { fmt.Fprintf(fgcc, "\nCGO_NO_SANITIZE_THREAD") fmt.Fprintf(fgcc, "\n%s\n", s) fmt.Fprintf(fgcc, "{\n") - fmt.Fprintf(fgcc, "\t__SIZE_TYPE__ _cgo_ctxt = _cgo_wait_runtime_init_done();\n") + fmt.Fprintf(fgcc, "\tsize_t _cgo_ctxt = _cgo_wait_runtime_init_done();\n") // The results part of the argument structure must be // initialized to 0 so the write barriers generated by // the assignments to these fields in Go are safe. @@ -1561,7 +1562,7 @@ var msanProlog = noMsanProlog const builtinProlog = ` #line 1 "cgo-builtin-prolog" -#include /* for ptrdiff_t and size_t below */ +#include /* Define intgo when compiling with GCC. */ typedef ptrdiff_t intgo; @@ -1845,7 +1846,7 @@ void localCgoCheckResult(Eface val) { const builtinExportProlog = ` #line 1 "cgo-builtin-export-prolog" -#include /* for ptrdiff_t below */ +#include #ifndef GO_CGO_EXPORT_PROLOGUE_H #define GO_CGO_EXPORT_PROLOGUE_H @@ -1891,7 +1892,7 @@ typedef long long GoInt64; typedef unsigned long long GoUint64; typedef GoIntGOINTBITS GoInt; typedef GoUintGOINTBITS GoUint; -typedef __SIZE_TYPE__ GoUintptr; +typedef size_t GoUintptr; typedef float GoFloat32; typedef double GoFloat64; typedef float _Complex GoComplex64; @@ -1941,5 +1942,5 @@ static void GoInit(void) { runtime_iscgo = 1; } -extern __SIZE_TYPE__ _cgo_wait_runtime_init_done(void) __attribute__ ((weak)); +extern size_t _cgo_wait_runtime_init_done(void) __attribute__ ((weak)); `