[pypy-commit] pypy issue1430: add State to module

mattip noreply at buildbot.pypy.org
Thu May 1 23:02:19 CEST 2014


Author: mattip <matti.picus at gmail.com>
Branch: issue1430
Changeset: r71152:841653d07ec4
Date: 2014-05-02 00:01 +0300
http://bitbucket.org/pypy/pypy/changeset/841653d07ec4/

Log:	add State to module

diff --git a/pypy/module/_socket/__init__.py b/pypy/module/_socket/__init__.py
--- a/pypy/module/_socket/__init__.py
+++ b/pypy/module/_socket/__init__.py
@@ -17,7 +17,8 @@
     def startup(self, space):
         from rpython.rlib.rsocket import rsocket_startup
         rsocket_startup()
-        space.socket_gethostbyxxx_lock = space.allocate_lock()
+        from pypy.module._socket.interp_func import State
+        space.fromcache(State).alloc_lock(space)
 
     def buildloaders(cls):
         from rpython.rlib import rsocket
diff --git a/pypy/module/_socket/interp_func.py b/pypy/module/_socket/interp_func.py
--- a/pypy/module/_socket/interp_func.py
+++ b/pypy/module/_socket/interp_func.py
@@ -43,7 +43,8 @@
     for a host.  The host argument is a string giving a host name or IP number.
     """
     try:
-        res = rsocket.gethostbyname_ex(host, space.socket_gethostbyxxx_lock)
+        lock = space.fromcache(State).gethostbyxxx_lock
+        res = rsocket.gethostbyname_ex(host, lock)
     except SocketError, e:
         raise converted_error(space, e)
     return common_wrapgethost(space, res)
@@ -56,7 +57,8 @@
     for a host.  The host argument is a string giving a host name or IP number.
     """
     try:
-        res = rsocket.gethostbyaddr(host, space.socket_gethostbyxxx_lock)
+        lock = space.fromcache(State).gethostbyxxx_lock
+        res = rsocket.gethostbyaddr(host, lock)
     except SocketError, e:
         raise converted_error(space, e)
     return common_wrapgethost(space, res)
@@ -310,3 +312,11 @@
             raise OperationError(space.w_ValueError,
                                  space.wrap('Timeout value out of range'))
     rsocket.setdefaulttimeout(timeout)
+
+class State(object):
+    def __init__(self, space):
+        self.gethostbyxxx_lock = None
+
+    def alloc_lock(self, space):
+        self.gethostbyxxx_lock = space.allocate_lock()
+


More information about the pypy-commit mailing list