mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
Snapshot of debugging code (does NOT pass pre-commit checks).
This commit is contained in:
parent
8ea1b8cda7
commit
1d4f9ff263
@ -184,6 +184,7 @@ extern "C" inline PyObject *pybind11_meta_getattro(PyObject *obj, PyObject *name
|
|||||||
extern "C" inline PyObject *pybind11_meta_call(PyObject *type, PyObject *args, PyObject *kwargs) {
|
extern "C" inline PyObject *pybind11_meta_call(PyObject *type, PyObject *args, PyObject *kwargs) {
|
||||||
|
|
||||||
// use the default metaclass call to create/initialize the object
|
// use the default metaclass call to create/initialize the object
|
||||||
|
printf("\nLOOOK %s:%d\n", __FILE__, __LINE__); fflush(stdout);
|
||||||
PyObject *self = PyType_Type.tp_call(type, args, kwargs);
|
PyObject *self = PyType_Type.tp_call(type, args, kwargs);
|
||||||
if (self == nullptr) {
|
if (self == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -366,7 +367,10 @@ inline PyObject *make_new_instance(PyTypeObject *type) {
|
|||||||
/// Instance creation function for all pybind11 types. It only allocates space for the
|
/// Instance creation function for all pybind11 types. It only allocates space for the
|
||||||
/// C++ object, but doesn't call the constructor -- an `__init__` function must do that.
|
/// C++ object, but doesn't call the constructor -- an `__init__` function must do that.
|
||||||
extern "C" inline PyObject *pybind11_object_new(PyTypeObject *type, PyObject *, PyObject *) {
|
extern "C" inline PyObject *pybind11_object_new(PyTypeObject *type, PyObject *, PyObject *) {
|
||||||
return make_new_instance(type);
|
printf("\nLOOOK [pybind11_object_new (called via tp_new) %s:%d\n", __FILE__, __LINE__); fflush(stdout);
|
||||||
|
PyObject *retval = make_new_instance(type);
|
||||||
|
printf("\nLOOOK ]pybind11_object_new (called via tp_new) %s:%d\n", __FILE__, __LINE__); fflush(stdout);
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An `__init__` function constructs the C++ object. Users should provide at least one
|
/// An `__init__` function constructs the C++ object. Users should provide at least one
|
||||||
|
@ -104,14 +104,16 @@ all_type_info_get_cache(PyTypeObject *type);
|
|||||||
|
|
||||||
// Populates a just-created cache entry.
|
// Populates a just-created cache entry.
|
||||||
PYBIND11_NOINLINE void all_type_info_populate(PyTypeObject *t, std::vector<type_info *> &bases) {
|
PYBIND11_NOINLINE void all_type_info_populate(PyTypeObject *t, std::vector<type_info *> &bases) {
|
||||||
|
printf("\nLOOOK all_type_info_populate[ %s:%d\n", __FILE__, __LINE__); fflush(stdout);
|
||||||
std::vector<PyTypeObject *> check;
|
std::vector<PyTypeObject *> check;
|
||||||
for (handle parent : reinterpret_borrow<tuple>(t->tp_bases)) {
|
for (handle parent : reinterpret_borrow<tuple>(t->tp_bases)) {
|
||||||
check.push_back((PyTypeObject *) parent.ptr());
|
check.push_back((PyTypeObject *) parent.ptr());
|
||||||
}
|
}
|
||||||
|
printf("\nLOOOK:REG:POP tp_name=%s check.size()=%lu %s:%d\n", t->tp_name, (unsigned long) check.size(), __FILE__, __LINE__); fflush(stdout);
|
||||||
|
|
||||||
auto const &type_dict = get_internals().registered_types_py;
|
auto const &type_dict = get_internals().registered_types_py;
|
||||||
for (size_t i = 0; i < check.size(); i++) {
|
for (size_t i = 0; i < check.size(); i++) {
|
||||||
auto *type = check[i];
|
PyTypeObject *type = check[i];
|
||||||
// Ignore Python2 old-style class super type:
|
// Ignore Python2 old-style class super type:
|
||||||
if (!PyType_Check((PyObject *) type)) {
|
if (!PyType_Check((PyObject *) type)) {
|
||||||
continue;
|
continue;
|
||||||
@ -119,23 +121,25 @@ PYBIND11_NOINLINE void all_type_info_populate(PyTypeObject *t, std::vector<type_
|
|||||||
|
|
||||||
// Check `type` in the current set of registered python types:
|
// Check `type` in the current set of registered python types:
|
||||||
auto it = type_dict.find(type);
|
auto it = type_dict.find(type);
|
||||||
|
printf("\nLOOOK type_dict.find(type) tp_name=%s found=%s %s:%d\n", type->tp_name, (it != type_dict.end() ? "yes" : "no"), __FILE__, __LINE__); fflush(stdout);
|
||||||
if (it != type_dict.end()) {
|
if (it != type_dict.end()) {
|
||||||
// We found a cache entry for it, so it's either pybind-registered or has pre-computed
|
// We found a cache entry for it, so it's either pybind-registered or has pre-computed
|
||||||
// pybind bases, but we have to make sure we haven't already seen the type(s) before:
|
// pybind bases, but we have to make sure we haven't already seen the type(s) before:
|
||||||
// we want to follow Python/virtual C++ rules that there should only be one instance of
|
// we want to follow Python/virtual C++ rules that there should only be one instance of
|
||||||
// a common base.
|
// a common base.
|
||||||
for (auto *tinfo : it->second) {
|
for (type_info *tinfo : it->second) {
|
||||||
// NB: Could use a second set here, rather than doing a linear search, but since
|
// NB: Could use a second set here, rather than doing a linear search, but since
|
||||||
// having a large number of immediate pybind11-registered types seems fairly
|
// having a large number of immediate pybind11-registered types seems fairly
|
||||||
// unlikely, that probably isn't worthwhile.
|
// unlikely, that probably isn't worthwhile.
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (auto *known : bases) {
|
for (type_info *known : bases) {
|
||||||
if (known == tinfo) {
|
if (known == tinfo) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
printf("\nLOOOK:REG:ADD bases.push_back(tinfo) %s %s:%d\n", tinfo->cpptype->name(), __FILE__, __LINE__); fflush(stdout);
|
||||||
bases.push_back(tinfo);
|
bases.push_back(tinfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,6 +158,7 @@ PYBIND11_NOINLINE void all_type_info_populate(PyTypeObject *t, std::vector<type_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printf("\nLOOOK all_type_info_populate] %s:%d\n", __FILE__, __LINE__); fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -260,7 +265,14 @@ struct value_and_holder {
|
|||||||
value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
|
value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
|
||||||
: inst{i}, index{index}, type{type},
|
: inst{i}, index{index}, type{type},
|
||||||
vh{inst->simple_layout ? inst->simple_value_holder
|
vh{inst->simple_layout ? inst->simple_value_holder
|
||||||
: &inst->nonsimple.values_and_holders[vpos]} {}
|
: &inst->nonsimple.values_and_holders[vpos]} {
|
||||||
|
if (type && type->cpptype) {
|
||||||
|
const char *nm = type->cpptype->name();
|
||||||
|
if (strcmp(nm, "N32test_python_multiple_inheritance7CppBaseE") == 0 || strcmp(nm, "N32test_python_multiple_inheritance7CppDrvdE") == 0) {
|
||||||
|
printf("\nLOOOK %s value_and_holder ctor %s:%d\n", nm, __FILE__, __LINE__); fflush(stdout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Default constructor (used to signal a value-and-holder not found by get_value_and_holder())
|
// Default constructor (used to signal a value-and-holder not found by get_value_and_holder())
|
||||||
value_and_holder() = default;
|
value_and_holder() = default;
|
||||||
@ -286,11 +298,18 @@ struct value_and_holder {
|
|||||||
}
|
}
|
||||||
// NOLINTNEXTLINE(readability-make-member-function-const)
|
// NOLINTNEXTLINE(readability-make-member-function-const)
|
||||||
void set_holder_constructed(bool v = true) {
|
void set_holder_constructed(bool v = true) {
|
||||||
|
//printf("\nLOOOK set_holder_constructed inst=%lu %s %s:%d\n", reinterpret_cast<unsigned long>(inst), type->cpptype->name(), __FILE__, __LINE__); fflush(stdout);
|
||||||
|
if (strcmp("N32test_python_multiple_inheritance7CppBaseE", type->cpptype->name()) == 0) {
|
||||||
|
//long *BAD = nullptr; *BAD = 101;
|
||||||
|
}
|
||||||
if (inst->simple_layout) {
|
if (inst->simple_layout) {
|
||||||
|
//printf("\nLOOOK %s set_holder_constructed simple_layout %s:%d\n", type->cpptype->name(), __FILE__, __LINE__); fflush(stdout);
|
||||||
inst->simple_holder_constructed = v;
|
inst->simple_holder_constructed = v;
|
||||||
} else if (v) {
|
} else if (v) {
|
||||||
|
//printf("\nLOOOK %s set_holder_constructed v %s:%d\n", type->cpptype->name(), __FILE__, __LINE__); fflush(stdout);
|
||||||
inst->nonsimple.status[index] |= instance::status_holder_constructed;
|
inst->nonsimple.status[index] |= instance::status_holder_constructed;
|
||||||
} else {
|
} else {
|
||||||
|
//printf("\nLOOOK %s set_holder_constructed not v %s:%d\n", type->cpptype->name(), __FILE__, __LINE__); fflush(stdout);
|
||||||
inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_holder_constructed;
|
inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_holder_constructed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1142,8 +1142,10 @@ protected:
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (overloads->is_constructor && !self_value_and_holder.holder_constructed()) {
|
if (overloads->is_constructor && !self_value_and_holder.holder_constructed()) {
|
||||||
|
printf("\nLOOOK %s BEFORE self_value_and_holder.type->init_instance %s:%d\n", self_value_and_holder.type->cpptype->name(), __FILE__, __LINE__); fflush(stdout);
|
||||||
auto *pi = reinterpret_cast<instance *>(parent.ptr());
|
auto *pi = reinterpret_cast<instance *>(parent.ptr());
|
||||||
self_value_and_holder.type->init_instance(pi, nullptr);
|
self_value_and_holder.type->init_instance(pi, nullptr);
|
||||||
|
printf("\nLOOOK %s AFTER self_value_and_holder.type->init_instance %s:%d\n", self_value_and_holder.type->cpptype->name(), __FILE__, __LINE__); fflush(stdout);
|
||||||
}
|
}
|
||||||
return result.ptr();
|
return result.ptr();
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,28 @@ class PC(m.CppBase):
|
|||||||
|
|
||||||
class PPCCInit(PC, m.CppDrvd):
|
class PPCCInit(PC, m.CppDrvd):
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
|
print("\nLOOOK PPCCInit PC", flush=True)
|
||||||
PC.__init__(self, value)
|
PC.__init__(self, value)
|
||||||
|
print("\nLOOOK PPCCInit CppDrvd", flush=True)
|
||||||
m.CppDrvd.__init__(self, value + 1)
|
m.CppDrvd.__init__(self, value + 1)
|
||||||
|
print("\nLOOOK PPCCInit Done", flush=True)
|
||||||
|
|
||||||
|
|
||||||
|
def NOtest_PC_AAA():
|
||||||
|
print("\nLOOOK BEFORE PC(11) AAA", flush=True)
|
||||||
|
d = PC(11)
|
||||||
|
print("\nLOOOK AFTER PC(11) AAA", flush=True)
|
||||||
|
assert d.get_base_value() == 11
|
||||||
|
d.reset_base_value(13)
|
||||||
|
assert d.get_base_value() == 13
|
||||||
|
|
||||||
|
|
||||||
# Moving this test after test_PC() changes the behavior!
|
# Moving this test after test_PC() changes the behavior!
|
||||||
def test_PPCCInit():
|
def test_PPCCInit_BBB():
|
||||||
|
print("\nLOOOK BEFORE PPCCInit(11) BBB", flush=True)
|
||||||
d = PPCCInit(11)
|
d = PPCCInit(11)
|
||||||
|
print("\nLOOOK AFTER PPCCInit(11) BBB", flush=True)
|
||||||
|
print("\nLOOOK", flush=True)
|
||||||
assert d.get_drvd_value() == 36
|
assert d.get_drvd_value() == 36
|
||||||
d.reset_drvd_value(55)
|
d.reset_drvd_value(55)
|
||||||
assert d.get_drvd_value() == 55
|
assert d.get_drvd_value() == 55
|
||||||
@ -31,8 +46,29 @@ def test_PPCCInit():
|
|||||||
assert d.get_base_value_from_drvd() == 30
|
assert d.get_base_value_from_drvd() == 30
|
||||||
|
|
||||||
|
|
||||||
def test_PC():
|
def NOtest_PC_CCC():
|
||||||
|
print("\nLOOOK BEFORE PC(11) CCC", flush=True)
|
||||||
d = PC(11)
|
d = PC(11)
|
||||||
|
print("\nLOOOK AFTER PC(11) CCC", flush=True)
|
||||||
assert d.get_base_value() == 11
|
assert d.get_base_value() == 11
|
||||||
d.reset_base_value(13)
|
d.reset_base_value(13)
|
||||||
assert d.get_base_value() == 13
|
assert d.get_base_value() == 13
|
||||||
|
|
||||||
|
# Moving this test after test_PC() changes the behavior!
|
||||||
|
def NOtest_PPCCInit_DDD():
|
||||||
|
print("\nLOOOK BEFORE PPCCInit(11) DDD", flush=True)
|
||||||
|
d = PPCCInit(11)
|
||||||
|
print("\nLOOOK AFTER PPCCInit(11) DDD", flush=True)
|
||||||
|
print("\nLOOOK", flush=True)
|
||||||
|
assert d.get_drvd_value() == 36
|
||||||
|
d.reset_drvd_value(55)
|
||||||
|
assert d.get_drvd_value() == 55
|
||||||
|
|
||||||
|
assert d.get_base_value() == 12
|
||||||
|
assert d.get_base_value_from_drvd() == 12
|
||||||
|
d.reset_base_value(20)
|
||||||
|
assert d.get_base_value() == 20
|
||||||
|
assert d.get_base_value_from_drvd() == 20
|
||||||
|
d.reset_base_value_from_drvd(30)
|
||||||
|
assert d.get_base_value() == 30
|
||||||
|
assert d.get_base_value_from_drvd() == 30
|
||||||
|
Loading…
Reference in New Issue
Block a user