Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
344 changes: 332 additions & 12 deletions python_tests/test_memo_immutable.py

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/dbzero/bindings/python/PyHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>
#include <dbzero/bindings/python/collections/PyTuple.hpp>
#include <dbzero/bindings/python/Memo.hpp>
#include <dbzero/bindings/python/embedded/EmbeddedObject.hpp>
#include <dbzero/object_model/object/Object.hpp>
#include <dbzero/object_model/class/ClassFactory.hpp>
#include <dbzero/object_model/class/Class.hpp>
Expand Down Expand Up @@ -72,6 +73,9 @@ namespace db0::python

template <> std::int64_t getPyHashImpl<TypeId::MEMO_IMMUTABLE_OBJECT>(db0::swine_ptr<Fixture> &, PyObject *key)
{
if (PyEmbeddedMemo_Check(key)) {
return getEmbeddedMemoUniqueAddress(key).getValue();
}
auto &obj = reinterpret_cast<MemoImmutableObject*>(key)->ext();
if (!obj.hasInstance()) {
THROWF(db0::InputException) << "Memo immutable object is not initialized" << THROWF_END;
Expand Down
20 changes: 12 additions & 8 deletions src/dbzero/bindings/python/PyInternalAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "PyInternalAPI.hpp"
#include "PyToolkit.hpp"
#include "Memo.hpp"
#include <dbzero/bindings/python/embedded/EmbeddedObject.hpp>
#include <dbzero/object_model/class/ClassFactory.hpp>
#include <dbzero/object_model/class/Class.hpp>
#include <dbzero/object_model/object/Object.hpp>
Expand Down Expand Up @@ -141,21 +142,22 @@ namespace db0::python
auto addr = object_id.m_address;
if (storage_class == db0::object_model::StorageClass::OBJECT_REF) {
auto &class_factory = db0::object_model::getClassFactory(*fixture);
// FIXME: this may be sped up if unloading object is avoided
auto result = PyToolkit::tryUnloadObject(fixture, addr, class_factory, nullptr, addr.getInstanceId());
// Keep exists() non-throwing for deleted root objects. Embedded-address fetch
// resolution is handled by fetchObject(); existence checks for embedded UUIDs
// are not part of this feature slice.
auto result = PyToolkit::tryUnloadObject(fixture, addr.getAddress(), class_factory, nullptr, addr.getInstanceId());
if (!result.get()) {
return false;
}

// validate type if requested
auto &memo = reinterpret_cast<MemoObject*>(result.get())->ext();
if (py_expected_type) {
// in other cases the type must match the actual object type
auto expected_class = class_factory.tryGetExistingType(py_expected_type);
if (!expected_class) {
return false;
}
if (memo.getType() != *expected_class) {
if (PyToolkit::getMemoType(result.get()) != *expected_class) {
return false;
}
}
Expand Down Expand Up @@ -189,18 +191,17 @@ namespace db0::python
// in other cases the type must match the actual object type
auto expected_class = class_factory.getOrCreateType(py_expected_type);
// honor class-specific access flags (e.g. type-level no_cache)
auto result = PyToolkit::unloadObject(fixture, addr, class_factory, nullptr, addr.getInstanceId(),
auto result = PyToolkit::unloadAnyObject(fixture, addr.getAddress(), class_factory, nullptr, addr.getInstanceId(),
expected_class->getInstanceFlags()
);
auto &memo = reinterpret_cast<MemoObject*>(result.get())->ext();
// NOTE: base types should be accepted
if (!memo.getType().isBaseClass(*expected_class)) {
if (!PyToolkit::getMemoType(result.get()).isBaseClass(*expected_class)) {
THROWF(db0::InputException) << "Object type mismatch";
}
return result;
} else {
// unload without type validation
return PyToolkit::unloadObject(fixture, addr, class_factory, py_expected_type, addr.getInstanceId());
return PyToolkit::unloadAnyObject(fixture, addr.getAddress(), class_factory, py_expected_type, addr.getInstanceId());
}
} else if (storage_class == db0::object_model::StorageClass::DB0_CLASS) {
auto &class_factory = db0::object_model::getClassFactory(*fixture);
Expand Down Expand Up @@ -677,6 +678,9 @@ namespace db0::python

PyObject *tryGetAddress(PyObject *py_obj)
{
if (PyEmbeddedMemo_Check(py_obj)) {
return PyLong_FromUnsignedLongLong(getEmbeddedMemoAddress(py_obj).getValue());
}
if (PyAnyMemo_Check(py_obj)) {
return PyLong_FromUnsignedLongLong(
reinterpret_cast<MemoAnyObject*>(py_obj)->ext().getAddress().getValue()
Expand Down
Loading
Loading