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>
35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
#pragma once
|
|
#include "Common.h"
|
|
#include "Python.h"
|
|
|
|
// Singleton keyboard state object
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
} PyKeyboardObject;
|
|
|
|
class PyKeyboard
|
|
{
|
|
public:
|
|
// Python getters - query real-time keyboard state via SFML
|
|
static PyObject* get_shift(PyObject* self, void* closure);
|
|
static PyObject* get_ctrl(PyObject* self, void* closure);
|
|
static PyObject* get_alt(PyObject* self, void* closure);
|
|
static PyObject* get_system(PyObject* self, void* closure);
|
|
|
|
static PyObject* repr(PyObject* obj);
|
|
static PyGetSetDef getsetters[];
|
|
};
|
|
|
|
namespace mcrfpydef {
|
|
inline PyTypeObject PyKeyboardType = {
|
|
.ob_base = {.ob_base = {.ob_refcnt = 1, .ob_type = NULL}, .ob_size = 0},
|
|
.tp_name = "mcrfpy.Keyboard",
|
|
.tp_basicsize = sizeof(PyKeyboardObject),
|
|
.tp_itemsize = 0,
|
|
.tp_repr = PyKeyboard::repr,
|
|
.tp_flags = Py_TPFLAGS_DEFAULT,
|
|
.tp_doc = PyDoc_STR("Keyboard state singleton for checking modifier keys"),
|
|
.tp_getset = PyKeyboard::getsetters,
|
|
.tp_new = PyType_GenericNew,
|
|
};
|
|
}
|