go malloc 源码

  • 2022-07-15
  • 浏览 (1268)

golang malloc 代码

文件路径:/misc/cgo/errors/testdata/malloc.go

// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Test that C.malloc does not return nil.

package main

// #include <stdlib.h>
import "C"

import (
	"fmt"
	"runtime"
)

func main() {
	var size C.size_t
	size--

	// The Dragonfly libc succeeds when asked to allocate
	// 0xffffffffffffffff bytes, so pass a different value that
	// causes it to fail.
	if runtime.GOOS == "dragonfly" {
		size = C.size_t(0x7fffffff << (32 * (^uintptr(0) >> 63)))
	}

	p := C.malloc(size)
	if p == nil {
		fmt.Println("malloc: C.malloc returned nil")
		// Just exit normally--the test script expects this
		// program to crash, so exiting normally indicates failure.
	}
}

相关信息

go 源码目录

相关文章

go err1 源码

go err2 源码

go err4 源码

go issue11097a 源码

go issue11097b 源码

go issue14669 源码

go issue18452 源码

go issue18889 源码

go issue28069 源码

go issue28721 源码

0  赞