Skip to content

Commit b976620

Browse files
committed
chore: remove useless package for python engine
1 parent c9dadf0 commit b976620

File tree

3 files changed

+46
-56
lines changed

3 files changed

+46
-56
lines changed

src/legacy/main/PythonHelper.cpp

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "utils/Utils.h"
1515

1616
#include <Python.h>
17-
#include <detours.h>
1817
#include <engine/TimeTaskSystem.h>
1918
#include <filesystem>
2019
#include <toml.h>
@@ -267,51 +266,52 @@ int executePipCommand(std::string cmd) {
267266
//
268267
// Attention! When CPython is upgraded, this fix must be re-adapted or removed!!
269268
//
270-
namespace FixPython310Stdin {
271-
// Hard coded function address
272-
const uintptr_t create_stdio_func_base_offset = 0xCE0F4;
273-
274-
create_stdio_func_type create_stdio_original = nullptr;
275-
276-
PyObject* create_stdio_hooked(
277-
const PyConfig* config,
278-
PyObject* io,
279-
int fd,
280-
int write_mode,
281-
const char* name,
282-
const wchar_t* encoding,
283-
const wchar_t* errors
284-
) {
285-
if (fd == 0) {
286-
Py_RETURN_NONE;
287-
}
288-
return create_stdio_original(config, io, fd, write_mode, name, encoding, errors);
289-
}
290-
291-
bool patchPython310CreateStdio() {
292-
if (create_stdio_original == nullptr) {
293-
HMODULE hModule = GetModuleHandleW(L"python310.dll");
294-
if (hModule == NULL) return false;
295-
create_stdio_original = (create_stdio_func_type)(void*)(((uintptr_t)hModule) + create_stdio_func_base_offset);
296-
}
297-
298-
DetourRestoreAfterWith();
299-
if (DetourTransactionBegin() != NO_ERROR) return false;
300-
else if (DetourUpdateThread(GetCurrentThread()) != NO_ERROR) return false;
301-
else if (DetourAttach((PVOID*)&create_stdio_original, create_stdio_hooked) != NO_ERROR) return false;
302-
else if (DetourTransactionCommit() != NO_ERROR) return false;
303-
return true;
304-
}
305-
306-
bool unpatchPython310CreateStdio() {
307-
if (DetourTransactionBegin() != NO_ERROR) return false;
308-
else if (DetourUpdateThread(GetCurrentThread()) != NO_ERROR) return false;
309-
else if (DetourDetach((PVOID*)&create_stdio_original, create_stdio_hooked) != NO_ERROR) return false;
310-
else if (DetourTransactionCommit() != NO_ERROR) return false;
311-
return true;
312-
}
313-
314-
} // namespace FixPython310Stdin
269+
// namespace FixPython310Stdin {
270+
// // Hard coded function address
271+
// const uintptr_t create_stdio_func_base_offset = 0xCE0F4;
272+
273+
// create_stdio_func_type create_stdio_original = nullptr;
274+
275+
// PyObject* create_stdio_hooked(
276+
// const PyConfig* config,
277+
// PyObject* io,
278+
// int fd,
279+
// int write_mode,
280+
// const char* name,
281+
// const wchar_t* encoding,
282+
// const wchar_t* errors
283+
// ) {
284+
// if (fd == 0) {
285+
// Py_RETURN_NONE;
286+
// }
287+
// return create_stdio_original(config, io, fd, write_mode, name, encoding, errors);
288+
// }
289+
290+
// bool patchPython310CreateStdio() {
291+
// if (create_stdio_original == nullptr) {
292+
// HMODULE hModule = GetModuleHandleW(L"python310.dll");
293+
// if (hModule == NULL) return false;
294+
// create_stdio_original = (create_stdio_func_type)(void*)(((uintptr_t)hModule) +
295+
// create_stdio_func_base_offset);
296+
// }
297+
298+
// DetourRestoreAfterWith();
299+
// if (DetourTransactionBegin() != NO_ERROR) return false;
300+
// else if (DetourUpdateThread(GetCurrentThread()) != NO_ERROR) return false;
301+
// else if (DetourAttach((PVOID*)&create_stdio_original, create_stdio_hooked) != NO_ERROR) return false;
302+
// else if (DetourTransactionCommit() != NO_ERROR) return false;
303+
// return true;
304+
// }
305+
306+
// bool unpatchPython310CreateStdio() {
307+
// if (DetourTransactionBegin() != NO_ERROR) return false;
308+
// else if (DetourUpdateThread(GetCurrentThread()) != NO_ERROR) return false;
309+
// else if (DetourDetach((PVOID*)&create_stdio_original, create_stdio_hooked) != NO_ERROR) return false;
310+
// else if (DetourTransactionCommit() != NO_ERROR) return false;
311+
// return true;
312+
// }
313+
314+
// } // namespace FixPython310Stdin
315315

316316
} // namespace PythonHelper
317317

src/lse/Entry.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ void initializeLegacyStuff() {
9898
InitSafeGuardRecord();
9999
EconomySystem::init();
100100
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
101-
// This fix is used for Python3.10's bug:
102-
// The thread will freeze when creating a new engine while another thread is blocking to read stdin
103-
// Side effects: sys.stdin cannot be used after this patch.
104-
// More info to see: https://github.com/python/cpython/issues/83526
105-
//
106-
// Attention! When CPython is upgraded, this fix must be re-adapted or removed!!
107-
//
108-
PythonHelper::FixPython310Stdin::patchPython310CreateStdio();
109101
PythonHelper::initPythonRuntime();
110102
#endif
111103

xmake.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ elseif is_config("backend", "quickjs") then
2828

2929
elseif is_config("backend", "python") then
3030
add_requires("scriptx main", {configs={backend="Python"}})
31-
add_requires("microsoft-detours")
3231

3332
elseif is_config("backend", "nodejs") then
3433
add_requires("scriptx main", {configs={backend="V8"}})
@@ -102,7 +101,6 @@ target("legacy-script-engine")
102101
"LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON"
103102
)
104103
set_basename("legacy-script-engine-python")
105-
add_packages("microsoft-detours")
106104

107105
elseif is_config("backend", "nodejs") then
108106
add_defines(

0 commit comments

Comments
 (0)