From 83891ed63e15cf44f4d1cb8bf7286441c34111d6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 25 Jan 2023 09:13:00 +0530 Subject: [PATCH] Code to get the memory address of a SharedMemory object --- src/calibre/utils/shm.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/calibre/utils/shm.py b/src/calibre/utils/shm.py index abb083c75a..6857b18a44 100644 --- a/src/calibre/utils/shm.py +++ b/src/calibre/utils/shm.py @@ -132,6 +132,15 @@ class SharedMemory: self._size = size + @property + def memory_address(self) -> int: + import ctypes + obj = ctypes.py_object(self.mmap) + address = ctypes.c_void_p() + length = ctypes.c_ssize_t() + ctypes.pythonapi.PyObject_AsReadBuffer(obj, ctypes.byref(address), ctypes.byref(length)) + return address.value + def read(self, sz: int = 0) -> bytes: if sz <= 0: sz = self.size