mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Source changes for compilation
These are the commits from https://github.com/ahgamut/cpython/tree/cosmo_py36 squashed for simplicity. Also included is the pyconfig.h used for compilation. The pyconfig.h has to be changed manually in case Cosmopolitan gets new features.
This commit is contained in:
parent
0c4c56ff39
commit
5ef64dbcdb
82 changed files with 2009 additions and 424 deletions
40
third_party/python/Lib/_threading_local.py
vendored
40
third_party/python/Lib/_threading_local.py
vendored
|
@ -143,15 +143,17 @@ __all__ = ["local"]
|
|||
# then, so problems introduced by fiddling the order of imports here won't
|
||||
# manifest.
|
||||
|
||||
|
||||
class _localimpl:
|
||||
"""A class managing thread-local dicts"""
|
||||
__slots__ = 'key', 'dicts', 'localargs', 'locallock', '__weakref__'
|
||||
|
||||
__slots__ = "key", "dicts", "localargs", "locallock", "__weakref__"
|
||||
|
||||
def __init__(self):
|
||||
# The key used in the Thread objects' attribute dicts.
|
||||
# We keep it a string for speed but make it unlikely to clash with
|
||||
# a "real" attribute.
|
||||
self.key = '_threading_local._localimpl.' + str(id(self))
|
||||
self.key = "_threading_local._localimpl." + str(id(self))
|
||||
# { id(Thread) -> (ref(Thread), thread-local dict) }
|
||||
self.dicts = {}
|
||||
|
||||
|
@ -167,11 +169,13 @@ class _localimpl:
|
|||
key = self.key
|
||||
thread = current_thread()
|
||||
idt = id(thread)
|
||||
|
||||
def local_deleted(_, key=key):
|
||||
# When the localimpl is deleted, remove the thread attribute.
|
||||
thread = wrthread()
|
||||
if thread is not None:
|
||||
del thread.__dict__[key]
|
||||
|
||||
def thread_deleted(_, idt=idt):
|
||||
# When the thread is deleted, remove the local dict.
|
||||
# Note that this is suboptimal if the thread object gets
|
||||
|
@ -180,6 +184,7 @@ class _localimpl:
|
|||
local = wrlocal()
|
||||
if local is not None:
|
||||
dct = local.dicts.pop(idt)
|
||||
|
||||
wrlocal = ref(self, local_deleted)
|
||||
wrthread = ref(thread, thread_deleted)
|
||||
thread.__dict__[key] = wrlocal
|
||||
|
@ -189,7 +194,7 @@ class _localimpl:
|
|||
|
||||
@contextmanager
|
||||
def _patch(self):
|
||||
impl = object.__getattribute__(self, '_local__impl')
|
||||
impl = object.__getattribute__(self, "_local__impl")
|
||||
try:
|
||||
dct = impl.get_dict()
|
||||
except KeyError:
|
||||
|
@ -197,12 +202,20 @@ def _patch(self):
|
|||
args, kw = impl.localargs
|
||||
self.__init__(*args, **kw)
|
||||
with impl.locallock:
|
||||
object.__setattr__(self, '__dict__', dct)
|
||||
object.__setattr__(self, "__dict__", dct)
|
||||
yield
|
||||
|
||||
|
||||
class DummyList(list):
|
||||
def pop(self, index=-1):
|
||||
try:
|
||||
return super.pop(index)
|
||||
except IndexError as e:
|
||||
return None
|
||||
|
||||
|
||||
class local:
|
||||
__slots__ = '_local__impl', '__dict__'
|
||||
__slots__ = "_local__impl", "__dict__"
|
||||
|
||||
def __new__(cls, *args, **kw):
|
||||
if (args or kw) and (cls.__init__ is object.__init__):
|
||||
|
@ -211,11 +224,12 @@ class local:
|
|||
impl = _localimpl()
|
||||
impl.localargs = (args, kw)
|
||||
impl.locallock = RLock()
|
||||
object.__setattr__(self, '_local__impl', impl)
|
||||
stack = DummyList()
|
||||
object.__setattr__(self, "_local__impl", impl)
|
||||
# We need to create the thread dict in anticipation of
|
||||
# __init__ being called, to make sure we don't call it
|
||||
# again ourselves.
|
||||
impl.create_dict()
|
||||
impl.create_dict()["stack"] = stack
|
||||
return self
|
||||
|
||||
def __getattribute__(self, name):
|
||||
|
@ -223,18 +237,18 @@ class local:
|
|||
return object.__getattribute__(self, name)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name == '__dict__':
|
||||
if name == "__dict__":
|
||||
raise AttributeError(
|
||||
"%r object attribute '__dict__' is read-only"
|
||||
% self.__class__.__name__)
|
||||
"%r object attribute '__dict__' is read-only" % self.__class__.__name__
|
||||
)
|
||||
with _patch(self):
|
||||
return object.__setattr__(self, name, value)
|
||||
|
||||
def __delattr__(self, name):
|
||||
if name == '__dict__':
|
||||
if name == "__dict__":
|
||||
raise AttributeError(
|
||||
"%r object attribute '__dict__' is read-only"
|
||||
% self.__class__.__name__)
|
||||
"%r object attribute '__dict__' is read-only" % self.__class__.__name__
|
||||
)
|
||||
with _patch(self):
|
||||
return object.__delattr__(self, name)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue