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
2 changes: 1 addition & 1 deletion dbzero/dbzero/dbzero.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def load_dynamic(name, path):

def __bootstrap__():
global __bootstrap__, __loader__, __file__
paths = [os.path.join(os.path.split(__file__)[0]), "/src/dev/build/release", "/usr/local/lib/python3/dist-packages/dbzero/"]
paths = [os.path.join(os.path.split(__file__)[0]), "/src/dev/build/debug", "/usr/local/lib/python3/dist-packages/dbzero/"]
__file__ = None
for path in paths:
if os.path.isdir(path):
Expand Down
3 changes: 2 additions & 1 deletion run_memcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export G_DEBUG=gc-friendly
#valgrind -v --tool=memcheck --leak-check=no --num-callers=250 --log-file=valgrind.log python3 -m pytest -m 'not integration_test' -m 'not stress_test' -c pytest.ini --capture=no "$@"
#valgrind -v --tool=memcheck --leak-check=no --num-callers=250 --log-file=valgrind.log python3 -m pytest -m 'stress_test' -c pytest.ini --capture=no "$@"
#valgrind -v --tool=memcheck --leak-check=full --num-callers=40 --log-file=valgrind.log python3 -m samples.explore --path='/src/zorch/app-data'
valgrind -v --tool=memcheck --leak-check=no --num-callers=250 --log-file=valgrind.log python3 -m pytest -m 'stress_test' -k='test_no_cache_allocator_issue' -c pytest.ini --capture=no "$@"
#valgrind -v --tool=memcheck --leak-check=no --num-callers=250 --log-file=valgrind.log python3 -m pytest -m 'stress_test' -k='test_no_cache_allocator_issue' -c pytest.ini --capture=no "$@"
valgrind -v --tool=memcheck --leak-check=no --num-callers=250 --log-file=valgrind.log python3 -m pytest -k='test_base_lock_usage_does_not_exceed_limits' -c pytest.ini --capture=no "$@"
14 changes: 7 additions & 7 deletions src/dbzero/bindings/python/shared_py_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
namespace db0::python

{

template <typename MemoImplT>
void incExtRefImpl(PyObject *py_object) {
// increment reference count for memo objects
reinterpret_cast<const MemoImplT*>(py_object)->ext().addExtRef();
}

template <typename MemoImplT>
void decExtRef(PyObject *py_object) {
void decExtRefImpl(PyObject *py_object) {
// decrement reference count for memo objects
reinterpret_cast<const MemoImplT*>(py_object)->ext().removeExtRef();
}

template <typename MemoImplT>
unsigned int getExtRefcount(PyObject *py_object, unsigned int default_count) {
unsigned int getExtRefcountImpl(PyObject *py_object, unsigned int default_count) {
// return reference count for memo objects
return reinterpret_cast<const MemoImplT*>(py_object)->ext().getExtRefs();
}
Expand All @@ -36,18 +36,18 @@ namespace db0::python
void decExtRef(PyObject *py_object)
{
if (PyMemo_Check<MemoObject>(py_object)) {
decExtRef<MemoObject>(py_object);
decExtRefImpl<MemoObject>(py_object);
} else if (PyMemo_Check<MemoImmutableObject>(py_object)) {
decExtRef<MemoImmutableObject>(py_object);
decExtRefImpl<MemoImmutableObject>(py_object);
}
}

unsigned int getExtRefcount(PyObject *py_object, unsigned int default_count)
{
if (PyMemo_Check<MemoObject>(py_object)) {
return getExtRefcount<MemoObject>(py_object, default_count);
return getExtRefcountImpl<MemoObject>(py_object, default_count);
} else if (PyMemo_Check<MemoImmutableObject>(py_object)) {
return getExtRefcount<MemoImmutableObject>(py_object, default_count);
return getExtRefcountImpl<MemoImmutableObject>(py_object, default_count);
}

// for non-memo objects, return the default count
Expand Down
68 changes: 36 additions & 32 deletions src/dbzero/bindings/python/shared_py_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#include <Python.h>
#include <iostream>
#include <thread>

// extended inc-ref, handles additional ref-counter for memo objects
// Extended inc-ref, handles additional ref-counter for memo objects
// must dec-ref with PyEXT_DECREF
#define PyEXT_INCREF(ptr) db0::python::incExtRef(ptr)
#define PyEXT_DECREF(ptr) db0::python::decExtRef(ptr)
Expand All @@ -20,15 +21,17 @@ namespace db0::python

{

// incRef / decRef with a special handling for memo objects
void incExtRef(PyObject *);
void decExtRef(PyObject *);
unsigned int getExtRefcount(PyObject *, unsigned int default_count = 0);
unsigned int getExtRefcount(PyObject *, unsigned int default_count);

// @tparam ExtRef flag indicating if should be counted as an "external" reference
template <typename T, bool ExtRef = false> class shared_py_object
{
public:
using self_t = shared_py_object<T, ExtRef>;
static constexpr bool hasExtRefs = ExtRef;

inline shared_py_object() = default;
inline shared_py_object(T py_object, bool incref = true)
: m_py_object(py_object)
Expand All @@ -39,7 +42,7 @@ namespace db0::python
}
if constexpr (ExtRef) {
PyEXT_INCREF(py_object);
}
}
}
}

Expand All @@ -48,13 +51,15 @@ namespace db0::python
shared_py_object(shared_py_object<T, true> &&other)
: m_py_object(other.m_py_object)
{
static_assert(!ExtRef, "Member only available for non-ExtRef conversion");
static_assert(other.hasExtRefs, "Source object must have ExtRef");
if (m_py_object) {
PyEXT_DECREF(m_py_object);
}
other.m_py_object = nullptr;
}

shared_py_object(const shared_py_object &other)
shared_py_object(const self_t &other)
: m_py_object(other.m_py_object)
{
if (m_py_object) {
Expand All @@ -64,21 +69,15 @@ namespace db0::python
}
}
}

shared_py_object(shared_py_object &&other)
shared_py_object(self_t &&other)
: m_py_object(other.m_py_object)
{
other.m_py_object = nullptr;
}

inline ~shared_py_object()
{
if (m_py_object) {
if constexpr (ExtRef) {
PyEXT_DECREF(m_py_object);
}
Py_DECREF(m_py_object);
}
inline ~shared_py_object() {
this->_destruct();
}

inline T get() const {
Expand Down Expand Up @@ -113,19 +112,19 @@ namespace db0::python
}
m_py_object = nullptr;
return result;
}
}

inline bool operator==(const shared_py_object &other) const {
inline bool operator==(const self_t &other) const {
return m_py_object == other.m_py_object;
}

inline bool operator!=(const shared_py_object &other) const {
inline bool operator!=(const self_t &other) const {
return m_py_object != other.m_py_object;
}

shared_py_object<T, ExtRef> &operator=(const shared_py_object &other)
self_t &operator=(const self_t &other)
{
this->~shared_py_object();
this->_destruct();
m_py_object = other.m_py_object;
if (m_py_object) {
Py_INCREF(m_py_object);
Expand All @@ -135,29 +134,34 @@ namespace db0::python
}
return *this;
}

shared_py_object<T, ExtRef> &operator=(shared_py_object &&other)
self_t &operator=(self_t &&other)
{
this->~shared_py_object();
this->_destruct();
m_py_object = other.m_py_object;
other.m_py_object = nullptr;
return *this;
}

void reset()
{
this->_destruct();
m_py_object = nullptr;
}

private:
friend class shared_py_object<T, !ExtRef>;
T m_py_object = nullptr;

void _destruct()
{
if (m_py_object) {
if constexpr (ExtRef) {
PyEXT_DECREF(m_py_object);
}
Py_DECREF(m_py_object);
m_py_object = nullptr;
Py_DECREF(m_py_object);
}
}

private:
friend class shared_py_object<T, !ExtRef>;
T m_py_object = nullptr;
};

// PyTypeObject specialization
Expand Down Expand Up @@ -241,7 +245,7 @@ namespace db0::python
template <typename T, typename K> shared_py_object<T> shared_py_cast(shared_py_object<K> &&obj) {
return shared_py_object<T>(static_cast<T>(obj.steal()), false);
}

}

namespace std
Expand Down
2 changes: 1 addition & 1 deletion src/dbzero/core/collections/vector/v_bvector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@ DB0_PACKED_END
return super_t::measureMembers();
}
}

template <typename PtrT>
template <typename buf_t>
std::size_t o_bvector<PtrT>::safeSizeOf(buf_t buf)
Expand Down
37 changes: 24 additions & 13 deletions src/dbzero/core/utils/FlagSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ DB0_PACKED_BEGIN
}
}

// Value constructor
explicit FlagSet(store_t value)
// only set flags that are allowed
: m_flags(value & FlagSetLimits<enum_t>::all())
{}

bool operator[](enum_t flag) const {
return test(flag);
}
Expand Down Expand Up @@ -134,27 +128,27 @@ DB0_PACKED_BEGIN
}

FlagSet operator&(EnumT flag) const {
return FlagSet(m_flags & static_cast<store_t>(flag));
return FlagSet::fromValue(m_flags & static_cast<store_t>(flag));
}

FlagSet operator&(const FlagSet &other) const {
return FlagSet(m_flags & other.m_flags);
return FlagSet::fromValue(m_flags & other.m_flags);
}

FlagSet operator|(EnumT flag) const {
return FlagSet(m_flags | static_cast<store_t>(flag));
return FlagSet::fromValue(m_flags | static_cast<store_t>(flag));
}

FlagSet operator|(const FlagSet &other) const {
return FlagSet(m_flags | other.m_flags);
return FlagSet::fromValue(m_flags | other.m_flags);
}

FlagSet operator^(const FlagSet &other) const {
return FlagSet(m_flags ^ other);
return FlagSet::fromValue(m_flags ^ other.m_flags);
}

FlagSet operator~() const {
return FlagSet(~m_flags);
return FlagSet::fromValue(~m_flags);
}

bool operator==(const FlagSet &other) const {
Expand All @@ -165,6 +159,14 @@ DB0_PACKED_BEGIN
return m_flags != other.m_flags;
}

void operator+=(EnumT flag) {
set(flag);
}

void operator-=(EnumT flag) {
clear(flag);
}

/**
* Unpack flags into vector of specific type (can be std::string)
* @tparam T unpacked type
Expand All @@ -191,11 +193,20 @@ DB0_PACKED_BEGIN
* @return
*/
static constexpr FlagSet all() {
return FlagSet(FlagSetLimits<enum_t>::all());
return FlagSet::fromValue(FlagSetLimits<enum_t>::all());
}

static FlagSet fromValue(store_t value) {
return FlagSet(value);
}

private:
store_t m_flags = 0;

FlagSet(store_t flags)
: m_flags(flags)
{
}
};
DB0_PACKED_END

Expand Down
Loading