mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-08 21:25:32 +02:00
Using fcntl() based fallocate on darwin doesnt work with file descriptors returned by shm_open
This commit is contained in:
@@ -82,7 +82,10 @@ class SharedMemory:
|
||||
self._name = name
|
||||
try:
|
||||
if flags & os.O_CREAT and size:
|
||||
os.posix_fallocate(self._fd, 0, size)
|
||||
if hasattr(os, 'posix_fallocate'):
|
||||
os.posix_fallocate(self._fd, 0, size)
|
||||
else:
|
||||
os.ftruncate(self._fd, size)
|
||||
self.stats = os.fstat(self._fd)
|
||||
size = self.stats.st_size
|
||||
self._mmap = mmap.mmap(self._fd, size, access=mmap.ACCESS_READ if readonly else mmap.ACCESS_WRITE)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
package shm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func Fallocate_simple(fd int, size int64) (err error) {
|
||||
store := &syscall.Fstore_t{
|
||||
Flags: syscall.F_ALLOCATEALL,
|
||||
Posmode: syscall.F_PEOFPOSMODE,
|
||||
Offset: 0,
|
||||
Length: size,
|
||||
}
|
||||
|
||||
for {
|
||||
if _, _, err = syscall.Syscall(syscall.SYS_FCNTL, uintptr(fd), syscall.F_PREALLOCATE, uintptr(unsafe.Pointer(store))); !errors.Is(err, unix.EINTR) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
//go:build !darwin && !linux
|
||||
//go:build !linux
|
||||
|
||||
package shm
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
var _ = fmt.Print
|
||||
|
||||
func TestSHM(t *testing.T) {
|
||||
force_use_of_fallocate = runtime.GOOS == "darwin" || runtime.GOOS == "linux"
|
||||
force_use_of_fallocate = runtime.GOOS == "linux"
|
||||
defer func() { force_use_of_fallocate = false }()
|
||||
data := make([]byte, 13347)
|
||||
_, _ = rand.Read(data)
|
||||
|
||||
Reference in New Issue
Block a user