Fix GridView.grid property and add sanitizer stress test
- Implement GridView.grid getter: reconstruct shared_ptr<UIGrid> from aliasing grid_data pointer, use PythonObjectCache for identity preservation (view.grid is grid == True) - Add sanitizer stress test exercising entity lifecycle, behavior stepping, GridView lifecycle, FOV dedup, and spatial hash churn - Add GridView.grid identity test Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4b13e5f5db
commit
86f8e596b0
3 changed files with 215 additions and 2 deletions
|
|
@ -426,8 +426,35 @@ PyObject* UIGridView::repr(PyUIGridViewObject* self)
|
|||
PyObject* UIGridView::get_grid(PyUIGridViewObject* self, void* closure)
|
||||
{
|
||||
if (!self->data->grid_data) Py_RETURN_NONE;
|
||||
// TODO: return the Grid wrapper for grid_data
|
||||
Py_RETURN_NONE;
|
||||
|
||||
// grid_data is an aliasing shared_ptr into a UIGrid (GridData is a base of UIGrid).
|
||||
// Reconstruct shared_ptr<UIGrid> to return the proper Python wrapper.
|
||||
auto grid_ptr = static_cast<UIGrid*>(self->data->grid_data.get());
|
||||
auto grid_as_uigrid = std::shared_ptr<UIGrid>(
|
||||
self->data->grid_data, grid_ptr);
|
||||
|
||||
// Check cache via UIDrawable::serial_number
|
||||
if (grid_ptr->serial_number != 0) {
|
||||
PyObject* cached = PythonObjectCache::getInstance().lookup(grid_ptr->serial_number);
|
||||
if (cached) return cached;
|
||||
}
|
||||
|
||||
auto grid_type = &mcrfpydef::PyUIGridType;
|
||||
auto pyGrid = (PyUIGridObject*)grid_type->tp_alloc(grid_type, 0);
|
||||
if (!pyGrid) return PyErr_NoMemory();
|
||||
|
||||
pyGrid->data = grid_as_uigrid;
|
||||
pyGrid->weakreflist = NULL;
|
||||
|
||||
if (grid_ptr->serial_number == 0) {
|
||||
grid_ptr->serial_number = PythonObjectCache::getInstance().assignSerial();
|
||||
}
|
||||
PyObject* weakref = PyWeakref_NewRef((PyObject*)pyGrid, NULL);
|
||||
if (weakref) {
|
||||
PythonObjectCache::getInstance().registerObject(grid_ptr->serial_number, weakref);
|
||||
Py_DECREF(weakref);
|
||||
}
|
||||
return (PyObject*)pyGrid;
|
||||
}
|
||||
|
||||
int UIGridView::set_grid(PyUIGridViewObject* self, PyObject* value, void* closure)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue