diff options
| author | 2021-08-29 15:41:41 +0100 | |
|---|---|---|
| committer | 2021-08-29 16:41:41 +0200 | |
| commit | ed462245730bd7832019bd43e0bc1c9d1c055e8e (patch) | |
| tree | 1caad78ea6aabf5ea93c93a8ade97176b4889500 /vendor/modernc.org/libc/mem.go | |
| parent | Mention fixup (#167) (diff) | |
| download | gotosocial-ed462245730bd7832019bd43e0bc1c9d1c055e8e.tar.xz | |
Add SQLite support, fix un-thread-safe DB caches, small performance f… (#172)
* Add SQLite support, fix un-thread-safe DB caches, small performance fixes
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* add SQLite licenses to README
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* appease the linter, and fix my dumbass-ery
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* make requested changes
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* add back comment
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
Diffstat (limited to 'vendor/modernc.org/libc/mem.go')
| -rw-r--r-- | vendor/modernc.org/libc/mem.go | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/vendor/modernc.org/libc/mem.go b/vendor/modernc.org/libc/mem.go new file mode 100644 index 000000000..23c2ec060 --- /dev/null +++ b/vendor/modernc.org/libc/mem.go @@ -0,0 +1,117 @@ +// Copyright 2021 The Libc Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !libc.membrk,!libc.memgrind + +package libc // import "modernc.org/libc" + +import ( + "modernc.org/libc/errno" + "modernc.org/libc/sys/types" + "modernc.org/memory" +) + +const memgrind = false + +var ( + allocator memory.Allocator +) + +// void *malloc(size_t size); +func Xmalloc(t *TLS, n types.Size_t) uintptr { + if n == 0 { + return 0 + } + + allocMu.Lock() + + defer allocMu.Unlock() + + p, err := allocator.UintptrMalloc(int(n)) + if err != nil { + t.setErrno(errno.ENOMEM) + return 0 + } + + return p +} + +// void *calloc(size_t nmemb, size_t size); +func Xcalloc(t *TLS, n, size types.Size_t) uintptr { + rq := int(n * size) + if rq == 0 { + return 0 + } + + allocMu.Lock() + + defer allocMu.Unlock() + + p, err := allocator.UintptrCalloc(int(n * size)) + if err != nil { + t.setErrno(errno.ENOMEM) + return 0 + } + + return p +} + +// void *realloc(void *ptr, size_t size); +func Xrealloc(t *TLS, ptr uintptr, size types.Size_t) uintptr { + allocMu.Lock() + + defer allocMu.Unlock() + + p, err := allocator.UintptrRealloc(ptr, int(size)) + if err != nil { + t.setErrno(errno.ENOMEM) + return 0 + } + + return p +} + +// void free(void *ptr); +func Xfree(t *TLS, p uintptr) { + if p == 0 { + return + } + + allocMu.Lock() + + defer allocMu.Unlock() + + allocator.UintptrFree(p) +} + +func UsableSize(p uintptr) types.Size_t { + allocMu.Lock() + + defer allocMu.Unlock() + + return types.Size_t(memory.UintptrUsableSize(p)) +} + +// MemAuditStart locks the memory allocator, initializes and enables memory +// auditing. Finaly it unlocks the memory allocator. +// +// Some memory handling errors, like double free or freeing of unallocated +// memory, will panic when memory auditing is enabled. +// +// This memory auditing functionality has to be enabled using the libc.memgrind +// build tag. +// +// It is intended only for debug/test builds. It slows down memory allocation +// routines and it has additional memory costs. +func MemAuditStart() {} + +// MemAuditReport locks the memory allocator, reports memory leaks, if any. +// Finally it disables memory auditing and unlocks the memory allocator. +// +// This memory auditing functionality has to be enabled using the libc.memgrind +// build tag. +// +// It is intended only for debug/test builds. It slows down memory allocation +// routines and it has additional memory costs. +func MemAuditReport() error { return nil } |
