summaryrefslogtreecommitdiff
path: root/vendor/modernc.org/libc/memgrind.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/modernc.org/libc/memgrind.go')
-rw-r--r--vendor/modernc.org/libc/memgrind.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/vendor/modernc.org/libc/memgrind.go b/vendor/modernc.org/libc/memgrind.go
index ccf5d8a3e..d525fa293 100644
--- a/vendor/modernc.org/libc/memgrind.go
+++ b/vendor/modernc.org/libc/memgrind.go
@@ -77,7 +77,9 @@ func Xmalloc(t *TLS, size types.Size_t) uintptr {
trc("t=%v size=%v, (%v:)", t, size, origin(2))
}
if size == 0 {
- return 0
+ // malloc(0) should return unique pointers
+ // (often expected and gnulib replaces malloc if malloc(0) returns 0)
+ size = 1
}
allocMu.Lock()
@@ -113,18 +115,18 @@ func Xmalloc(t *TLS, size types.Size_t) uintptr {
// void *calloc(size_t nmemb, size_t size);
func Xcalloc(t *TLS, n, size types.Size_t) uintptr {
if __ccgo_strace {
- trc("t=%v size=%v, (%v:)", t, size, origin(2))
+ trc("t=%v n=%v size=%v, (%v:)", t, n, size, origin(2))
}
rq := int(n * size)
if rq == 0 {
- return 0
+ rq = 1
}
allocMu.Lock()
defer allocMu.Unlock()
- p, err := allocator.UintptrCalloc(int(n * size))
+ p, err := allocator.UintptrCalloc(rq)
// if dmesgs {
// dmesg("%v: %v -> %#x, %v", origin(1), n*size, p, err)
// }
@@ -269,6 +271,10 @@ func UsableSize(p uintptr) types.Size_t {
return types.Size_t(memory.UintptrUsableSize(p))
}
+func Xmalloc_usable_size(tls *TLS, p uintptr) (r Tsize_t) {
+ return UsableSize(p)
+}
+
type MemAllocatorStat struct {
Allocs int
Bytes int