diff --git a/src/borg/_item.c b/src/borg/_item.c deleted file mode 100644 index c5c78c4074..0000000000 --- a/src/borg/_item.c +++ /dev/null @@ -1,41 +0,0 @@ -#include "Python.h" - -/* - * This is not quite as dark magic as it looks. We just convert the address of (pointer to) - * a PyObject into a bytes object in _wrap_object, and convert these bytes back to the - * pointer to the original object. - * - * This mainly looks a bit confusing due to our mental special-casing of "char*" from other - * pointers. - * - * The big upside to this is that this neither does *any* serialization (beyond creating tiny - * bytes objects as "stand-ins"), nor has to copy the entire object that's passed around. - */ - -static PyObject * -_object_to_optr(PyObject *obj) -{ - /* - * Create a temporary reference to the object being passed around so it does not vanish. - * Note that we never decref this one in _unwrap_object, since we just transfer that reference - * there, i.e. there is an elided "Py_INCREF(x); Py_DECREF(x)". - * Since the reference is transferred, calls to _wrap_object and _unwrap_object must be symmetric. - */ - Py_INCREF(obj); - return PyBytes_FromStringAndSize((const char*) &obj, sizeof(void*)); -} - -static PyObject * -_optr_to_object(PyObject *bytes) -{ - if(!PyBytes_Check(bytes)) { - PyErr_SetString(PyExc_TypeError, "Cannot unwrap non-bytes object"); - return NULL; - } - if(PyBytes_Size(bytes) != sizeof(void*)) { - PyErr_SetString(PyExc_TypeError, "Invalid length of bytes object"); - return NULL; - } - PyObject *object = * (PyObject **) PyBytes_AsString(bytes); - return object; -} diff --git a/src/borg/item.pyi b/src/borg/item.pyi index 5f63eda377..33baf21665 100644 --- a/src/borg/item.pyi +++ b/src/borg/item.pyi @@ -128,9 +128,6 @@ class Item(PropDict): def _is_type(self, typetest: Callable) -> bool: ... @classmethod def create_deleted(self, path) -> Item: ... - @classmethod - def from_optr(self, optr: Any) -> Item: ... - def to_optr(self) -> Any: ... @property def atime(self) -> int: ... @atime.setter diff --git a/src/borg/item.pyx b/src/borg/item.pyx index 482a14e001..bec41404ae 100644 --- a/src/borg/item.pyx +++ b/src/borg/item.pyx @@ -12,11 +12,6 @@ from .helpers.msgpack import timestamp_to_int, int_to_timestamp, Timestamp from .helpers.time import OutputTimestamp, safe_timestamp -cdef extern from "_item.c": - object _object_to_optr(object obj) - object _optr_to_object(object bytes) - - @@ -337,25 +332,6 @@ cdef class Item(PropDict): setattr(self, attr, size) return size - def to_optr(self): - """ - Return an "object pointer" (optr), an opaque bag of bytes. - The return value is effectively a reference to this object - that can be passed exactly once to Item.from_optr to get this - object back. - - to_optr/from_optr must be used symmetrically, - don't call from_optr multiple times. - - This object can't be deallocated after a call to to_optr() - until from_optr() is called. - """ - return _object_to_optr(self) - - @classmethod - def from_optr(self, optr): - return _optr_to_object(optr) - @classmethod def create_deleted(cls, path): return cls(deleted=True, chunks=[], mode=0, path=path) diff --git a/src/borg/testsuite/item_test.py b/src/borg/testsuite/item_test.py index 9c6a5b796c..c795430fb3 100644 --- a/src/borg/testsuite/item_test.py +++ b/src/borg/testsuite/item_test.py @@ -152,11 +152,6 @@ def test_item_file_size_no_chunks(): assert item.get_size() == 0 -def test_item_optr(): - item = Item() - assert Item.from_optr(item.to_optr()) is item - - @pytest.mark.parametrize( "chunk_a, chunk_b, chunks_equal", [