The embedded 40250 script layer needs its own interpreter on five platforms. 2.7 is end-of-life, so nothing can be fetched from the target SDKs and the source is vendored (official 2.7.18 tarball, trimmed to 25MB; Lib/ stays for step 3's python27.zip). cpython-2.7.18/CMakeLists.txt builds one `mtpython` static library from exactly the 133 objects the reference libpython2.7.a contains, off by default behind -DMTGODOT_EMBED_PYTHON=ON. The source list and the built-in module table (config/config.c, 39 entries) are shared; pyconfig.h is a probe result and is not, so each platform keeps its own under config/<platform>/, regenerated by tools/py_embed/gen_pyconfig.sh and checked against the shared table. Three vendor patches, documented in docs/THIRD-PARTY.md: configure/configure.ac learn arm64 on macOS, and posixmodule.c undefines the process-control calls it hard-defines past pyconfig.h when building for iOS. macOS (ctest python.embed: every builtin imports, codecs and pickle work off the vendored Lib/), Android arm64 and iOS arm64 build. Linux needs a Linux host and Windows needs a MinGW-vs-MSVC decision; both are noted for step 4. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
import signal
|
|
import weakref
|
|
|
|
from functools import wraps
|
|
|
|
__unittest = True
|
|
|
|
|
|
class _InterruptHandler(object):
|
|
def __init__(self, default_handler):
|
|
self.called = False
|
|
self.original_handler = default_handler
|
|
if isinstance(default_handler, (int, long)):
|
|
if default_handler == signal.SIG_DFL:
|
|
# Pretend it's signal.default_int_handler instead.
|
|
default_handler = signal.default_int_handler
|
|
elif default_handler == signal.SIG_IGN:
|
|
# Not quite the same thing as SIG_IGN, but the closest we
|
|
# can make it: do nothing.
|
|
def default_handler(unused_signum, unused_frame):
|
|
pass
|
|
else:
|
|
raise TypeError("expected SIGINT signal handler to be "
|
|
"signal.SIG_IGN, signal.SIG_DFL, or a "
|
|
"callable object")
|
|
self.default_handler = default_handler
|
|
|
|
def __call__(self, signum, frame):
|
|
installed_handler = signal.getsignal(signal.SIGINT)
|
|
if installed_handler is not self:
|
|
# if we aren't the installed handler, then delegate immediately
|
|
# to the default handler
|
|
self.default_handler(signum, frame)
|
|
|
|
if self.called:
|
|
self.default_handler(signum, frame)
|
|
self.called = True
|
|
for result in _results.keys():
|
|
result.stop()
|
|
|
|
_results = weakref.WeakKeyDictionary()
|
|
def registerResult(result):
|
|
_results[result] = 1
|
|
|
|
def removeResult(result):
|
|
return bool(_results.pop(result, None))
|
|
|
|
_interrupt_handler = None
|
|
def installHandler():
|
|
global _interrupt_handler
|
|
if _interrupt_handler is None:
|
|
default_handler = signal.getsignal(signal.SIGINT)
|
|
_interrupt_handler = _InterruptHandler(default_handler)
|
|
signal.signal(signal.SIGINT, _interrupt_handler)
|
|
|
|
|
|
def removeHandler(method=None):
|
|
if method is not None:
|
|
@wraps(method)
|
|
def inner(*args, **kwargs):
|
|
initial = signal.getsignal(signal.SIGINT)
|
|
removeHandler()
|
|
try:
|
|
return method(*args, **kwargs)
|
|
finally:
|
|
signal.signal(signal.SIGINT, initial)
|
|
return inner
|
|
|
|
global _interrupt_handler
|
|
if _interrupt_handler is not None:
|
|
signal.signal(signal.SIGINT, _interrupt_handler.original_handler)
|