mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 13:15:12 +00:00
Revert "Snapshot of debugging code (does NOT pass pre-commit checks)."
This reverts commit 1d4f9ff263
.
This commit is contained in:
parent
1d4f9ff263
commit
775aab5722
@ -184,7 +184,6 @@ extern "C" inline PyObject *pybind11_meta_getattro(PyObject *obj, PyObject *name
|
||||
extern "C" inline PyObject *pybind11_meta_call(PyObject *type, PyObject *args, PyObject *kwargs) {
|
||||
|
||||
// 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);
|
||||
if (self == nullptr) {
|
||||
return nullptr;
|
||||
@ -367,10 +366,7 @@ inline PyObject *make_new_instance(PyTypeObject *type) {
|
||||
/// 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.
|
||||
extern "C" inline PyObject *pybind11_object_new(PyTypeObject *type, PyObject *, PyObject *) {
|
||||
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;
|
||||
return make_new_instance(type);
|
||||
}
|
||||
|
||||
/// An `__init__` function constructs the C++ object. Users should provide at least one
|
||||
|
@ -104,16 +104,14 @@ all_type_info_get_cache(PyTypeObject *type);
|
||||
|
||||
// Populates a just-created cache entry.
|
||||
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;
|
||||
for (handle parent : reinterpret_borrow<tuple>(t->tp_bases)) {
|
||||
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;
|
||||
for (size_t i = 0; i < check.size(); i++) {
|
||||
PyTypeObject *type = check[i];
|
||||
auto *type = check[i];
|
||||
// Ignore Python2 old-style class super type:
|
||||
if (!PyType_Check((PyObject *) type)) {
|
||||
continue;
|
||||
@ -121,25 +119,23 @@ printf("\nLOOOK:REG:POP tp_name=%s check.size()=%lu %s:%d\n", t->tp_name, (unsig
|
||||
|
||||
// Check `type` in the current set of registered python types:
|
||||
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()) {
|
||||
// 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:
|
||||
// we want to follow Python/virtual C++ rules that there should only be one instance of
|
||||
// a common base.
|
||||
for (type_info *tinfo : it->second) {
|
||||
for (auto *tinfo : it->second) {
|
||||
// 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
|
||||
// unlikely, that probably isn't worthwhile.
|
||||
bool found = false;
|
||||
for (type_info *known : bases) {
|
||||
for (auto *known : bases) {
|
||||
if (known == tinfo) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -158,7 +154,6 @@ printf("\nLOOOK:REG:ADD bases.push_back(tinfo) %s %s:%d\n", tinfo->cpptype->name
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\nLOOOK all_type_info_populate] %s:%d\n", __FILE__, __LINE__); fflush(stdout);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -265,14 +260,7 @@ struct value_and_holder {
|
||||
value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
|
||||
: inst{i}, index{index}, type{type},
|
||||
vh{inst->simple_layout ? inst->simple_value_holder
|
||||
: &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);
|
||||
}
|
||||
}
|
||||
}
|
||||
: &inst->nonsimple.values_and_holders[vpos]} {}
|
||||
|
||||
// Default constructor (used to signal a value-and-holder not found by get_value_and_holder())
|
||||
value_and_holder() = default;
|
||||
@ -298,18 +286,11 @@ printf("\nLOOOK %s value_and_holder ctor %s:%d\n", nm, __FILE__, __LINE__); fflu
|
||||
}
|
||||
// NOLINTNEXTLINE(readability-make-member-function-const)
|
||||
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) {
|
||||
//printf("\nLOOOK %s set_holder_constructed simple_layout %s:%d\n", type->cpptype->name(), __FILE__, __LINE__); fflush(stdout);
|
||||
inst->simple_holder_constructed = 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;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
@ -1142,10 +1142,8 @@ protected:
|
||||
return nullptr;
|
||||
}
|
||||
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());
|
||||
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();
|
||||
}
|
||||
|
@ -10,28 +10,13 @@ class PC(m.CppBase):
|
||||
|
||||
class PPCCInit(PC, m.CppDrvd):
|
||||
def __init__(self, value):
|
||||
print("\nLOOOK PPCCInit PC", flush=True)
|
||||
PC.__init__(self, value)
|
||||
print("\nLOOOK PPCCInit CppDrvd", flush=True)
|
||||
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!
|
||||
def test_PPCCInit_BBB():
|
||||
print("\nLOOOK BEFORE PPCCInit(11) BBB", flush=True)
|
||||
def test_PPCCInit():
|
||||
d = PPCCInit(11)
|
||||
print("\nLOOOK AFTER PPCCInit(11) BBB", flush=True)
|
||||
print("\nLOOOK", flush=True)
|
||||
assert d.get_drvd_value() == 36
|
||||
d.reset_drvd_value(55)
|
||||
assert d.get_drvd_value() == 55
|
||||
@ -46,29 +31,8 @@ def test_PPCCInit_BBB():
|
||||
assert d.get_base_value_from_drvd() == 30
|
||||
|
||||
|
||||
def NOtest_PC_CCC():
|
||||
print("\nLOOOK BEFORE PC(11) CCC", flush=True)
|
||||
def test_PC():
|
||||
d = PC(11)
|
||||
print("\nLOOOK AFTER PC(11) CCC", 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!
|
||||
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