Migrate static PyTypeObject to inline, delete PyTypeCache workarounds

All 27 PyTypeObject declarations in namespace mcrfpydef headers changed
from `static` to `inline` (C++17), ensuring a single global instance
across translation units. This fixes the root cause of stale-type-pointer
segfaults where only the McRFPy_API.cpp copy was PyType_Ready'd.

Replaced ~20 PyTypeCache call sites and 2 PyRAII::PyTypeRef lookups with
direct &mcrfpydef::Type references. Deleted PyTypeCache.h/.cpp,
PyObjectUtils.h, and PyRAII.h (all were workarounds for the static bug).

228/228 tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-02-16 20:58:09 -05:00
commit bb72040396
37 changed files with 74 additions and 600 deletions

View file

@ -1,7 +1,6 @@
#include "PyTexture.h"
#include "McRFPy_API.h"
#include "McRFPy_Doc.h"
#include "PyTypeCache.h"
#include <cmath>
#include <algorithm>
@ -93,13 +92,8 @@ sf::Sprite PyTexture::sprite(int index, sf::Vector2f pos, sf::Vector2f s)
PyObject* PyTexture::pyObject()
{
PyTypeObject* type = PyTypeCache::Texture();
if (!type) {
PyErr_SetString(PyExc_RuntimeError, "Failed to get Texture type from cache");
return NULL;
}
PyTypeObject* type = &mcrfpydef::PyTextureType;
PyObject* obj = PyTexture::pynew(type, Py_None, Py_None);
// PyTypeCache returns borrowed reference — no DECREF needed
if (!obj) {
return NULL;
@ -275,12 +269,7 @@ PyObject* PyTexture::composite(PyObject* cls, PyObject* args, PyObject* kwds)
std::vector<sf::Image> images;
unsigned int tex_w = 0, tex_h = 0;
// Use PyTypeCache for reliable, leak-free isinstance check
PyTypeObject* texture_type = PyTypeCache::Texture();
if (!texture_type) {
PyErr_SetString(PyExc_RuntimeError, "Failed to get Texture type from cache");
return NULL;
}
PyTypeObject* texture_type = &mcrfpydef::PyTextureType;
for (Py_ssize_t i = 0; i < count; i++) {
PyObject* item = PyList_GetItem(layers_list, i);
@ -311,7 +300,6 @@ PyObject* PyTexture::composite(PyObject* cls, PyObject* args, PyObject* kwds)
}
images.push_back(std::move(img));
}
// PyTypeCache returns borrowed reference — no DECREF needed
// Alpha-composite all layers bottom-to-top
sf::Image result;