Compare commits
2 commits
bf8557798a
...
c2877c8053
| Author | SHA1 | Date | |
|---|---|---|---|
| c2877c8053 | |||
| a81430991c |
2 changed files with 16 additions and 10 deletions
|
|
@ -16,7 +16,7 @@ endif()
|
||||||
|
|
||||||
# Add include directories
|
# Add include directories
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/deps)
|
include_directories(${CMAKE_SOURCE_DIR}/deps)
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/deps/libtcod)
|
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/deps/libtcod)
|
||||||
|
|
||||||
# Python includes: use different paths for Windows vs Linux
|
# Python includes: use different paths for Windows vs Linux
|
||||||
if(MCRF_CROSS_WINDOWS)
|
if(MCRF_CROSS_WINDOWS)
|
||||||
|
|
@ -29,7 +29,7 @@ if(MCRF_CROSS_WINDOWS)
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/deps/cpython/PC) # For other Windows-specific headers
|
include_directories(${CMAKE_SOURCE_DIR}/deps/cpython/PC) # For other Windows-specific headers
|
||||||
# Also include SFML and libtcod Windows headers
|
# Also include SFML and libtcod Windows headers
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/__lib_windows/sfml/include)
|
include_directories(${CMAKE_SOURCE_DIR}/__lib_windows/sfml/include)
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/__lib_windows/libtcod/include)
|
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/__lib_windows/libtcod/include)
|
||||||
else()
|
else()
|
||||||
# Native builds (Linux/Windows): use existing Python setup
|
# Native builds (Linux/Windows): use existing Python setup
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/deps/cpython)
|
include_directories(${CMAKE_SOURCE_DIR}/deps/cpython)
|
||||||
|
|
|
||||||
|
|
@ -37,14 +37,16 @@ void PythonObjectCache::registerObject(uint64_t serial, PyObject* weakref) {
|
||||||
PyObject* PythonObjectCache::lookup(uint64_t serial) {
|
PyObject* PythonObjectCache::lookup(uint64_t serial) {
|
||||||
if (serial == 0) return nullptr;
|
if (serial == 0) return nullptr;
|
||||||
|
|
||||||
// No mutex needed for read - GIL protects PyWeakref_GetObject
|
// No mutex needed for read - GIL protects PyWeakref_GetRef
|
||||||
auto it = cache.find(serial);
|
auto it = cache.find(serial);
|
||||||
if (it != cache.end()) {
|
if (it != cache.end()) {
|
||||||
PyObject* obj = PyWeakref_GetObject(it->second);
|
PyObject* obj = nullptr;
|
||||||
if (obj && obj != Py_None) {
|
int result = PyWeakref_GetRef(it->second, &obj);
|
||||||
Py_INCREF(obj);
|
if (result == 1 && obj) {
|
||||||
|
// obj is already a strong reference from PyWeakref_GetRef
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
// result == 0: dead reference, result == -1: error
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
@ -65,11 +67,15 @@ void PythonObjectCache::cleanup() {
|
||||||
|
|
||||||
auto it = cache.begin();
|
auto it = cache.begin();
|
||||||
while (it != cache.end()) {
|
while (it != cache.end()) {
|
||||||
PyObject* obj = PyWeakref_GetObject(it->second);
|
PyObject* obj = nullptr;
|
||||||
if (!obj || obj == Py_None) {
|
int result = PyWeakref_GetRef(it->second, &obj);
|
||||||
|
if (result <= 0) {
|
||||||
|
// Dead reference or error - remove from cache
|
||||||
Py_DECREF(it->second);
|
Py_DECREF(it->second);
|
||||||
it = cache.erase(it);
|
it = cache.erase(it);
|
||||||
} else {
|
} else {
|
||||||
|
// Still alive - release the strong reference we obtained
|
||||||
|
Py_DECREF(obj);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue