Issue #1263 resolved

PyPy support broken

Anonymous created an issue

From PyPy:

lib-python/2.7/socket.py:

class _fileobject(object):
    """Faux file object attached to a socket object."""

    default_bufsize = 8192
    name = "<socket>"

    __slots__ = ["mode", "bufsize", "softspace",
                 # "closed" is a property, see below
                 "_sock", "_rbufsize", "_wbufsize", "_rbuf", "_wbuf", "_wbuf_len",
                 "_close"]

    def __init__(self, sock, mode='rb', bufsize=-1, close=False):
        # Note that a few libraries (like eventlet) poke at the
        # private implementation of socket.py, passing custom
        # objects to _fileobject().  These libraries need the
        # following fix for use on PyPy: the custom objects need
        # methods _reuse() and _drop() that maintains an explicit
        # reference counter, starting at 0.  When it drops back to
        # zero, close() must be called.
        sock._reuse()
        ....

CherryPy wsgiserver2 makes calls to socket._fileobject() passing objects that do not support _reuse() and _drop().

PyPy support has been broken since PyPy removed checks on their end: https://bitbucket.org/pypy/pypy/commits/867a673cccfb7bab3c4a5982137061fa2a085e0b

Comments (9)

  1. Joel Rivera

    Sylvain Hellegouarch are you having the same error? I have test the change and it did worked. The patch just mocks the sock parameter.

    Before the patch:

    [PyPy 2.2.1 with GCC 4.7.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    And now for something completely different: ``<fijal> I love pypy''
    >>>> import cherrypy.wsgiserver
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "cherrypy/wsgiserver/__init__.py", line 11, in <module>
        from wsgiserver2 import *
      File "cherrypy/wsgiserver/wsgiserver2.py", line 100, in <module>
        _fileobject_uses_str_type = isinstance(socket._fileobject(None)._rbuf, basestring)
      File "/home/joe/pypy-2.2.1-src/lib-python/2.7/socket.py", line 300, in __init__
        sock._reuse()
    AttributeError: 'NoneType' object has no attribute '_reuse'
    >>>> 
    

    After the patch:

    [PyPy 2.2.1 with GCC 4.7.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    And now for something completely different: ``A random quote''
    >>>> import cherrypy.wsgiserver
    >>>> 
    
  2. Joel Rivera

    Change the socket parameter that is used on the internals of the socket interface, those were suppose to be used with the "real" socket which is an attribute (_sock) of the high level socket interface socket.socket.

    This was a particular issue for pypy, who was actually using the real socket interface.

    Fix issue #1263

    → <<cset 4f2ef8d67ae1>>

  3. Log in to comment