[PATCH 2 of 2 chg-port] osutil: implement pure version of recvfds() for PyPy

Yuya Nishihara yuya at tcha.org
Sun Dec 20 03:18:24 CST 2015


On Sat, 19 Dec 2015 10:37:11 -0800, Sean Farley wrote:
> 
> Yuya Nishihara <yuya at tcha.org> writes:
> 
> > # HG changeset patch
> > # User Yuya Nishihara <yuya at tcha.org>
> > # Date 1450363989 -32400
> > #      Thu Dec 17 23:53:09 2015 +0900
> > # Node ID 9726608c61dd53832c821d8bb9ce15b8aa268466
> > # Parent  076525f412e74c913f72ff52034aa7ea046af74b
> > osutil: implement pure version of recvfds() for PyPy
> >
> > This is less portable than the C version, but PyPy can't load CPython
> > extensions. So for now, this will be used on PyPy.
> >
> > I've tested it on Linux amd64 and Mac OS X.
> >
> > diff --git a/mercurial/pure/osutil.py b/mercurial/pure/osutil.py
> > --- a/mercurial/pure/osutil.py
> > +++ b/mercurial/pure/osutil.py
> > @@ -7,8 +7,12 @@
> >  
> >  from __future__ import absolute_import
> >  
> > +import ctypes
> > +import ctypes.util
> >  import os
> > +import socket
> >  import stat as statmod
> > +import sys
> >  
> >  def _mode_to_kind(mode):
> >      if statmod.S_ISREG(mode):
> > @@ -59,8 +63,87 @@ def listdir(path, stat=False, skip=None)
> >  
> >  if os.name != 'nt':
> >      posixfile = open
> > +
> > +    _SCM_RIGHTS = 0x01
> > +    _socklen_t = ctypes.c_uint
> > +
> > +    if sys.platform == 'linux2':
> > +        # socket.h says "the type should be socklen_t but the definition of
> > +        # the kernel is incompatible with this."
> > +        _cmsg_len_t = ctypes.c_size_t
> > +        _msg_controllen_t = ctypes.c_size_t
> > +        _msg_iovlen_t = ctypes.c_size_t
> > +    else:
> > +        _cmsg_len_t = _socklen_t
> > +        _msg_controllen_t = _socklen_t
> > +        _msg_iovlen_t = ctypes.c_int
> 
> I think we usually write the above without the else clause:
> 
>     _cmsg_len_t = _socklen_t
>     _msg_controllen_t = _socklen_t
>     _msg_iovlen_t = ctypes.c_int
>     if sys.platform == 'linux2':
>         # socket.h says "the type should be socklen_t but the definition of
>         # the kernel is incompatible with this."
>         _cmsg_len_t = ctypes.c_size_t
>         _msg_controllen_t = ctypes.c_size_t
>         _msg_iovlen_t = ctypes.c_size_t
> 
> But that's a minor nit. Otherwise, both these patches look good to me.

Thanks. I personally prefer if-else, but that isn't big issue. If I coded it
on BSD and found Linux problem later, I would do like your suggestion.

Please feel free to change it in flight.


More information about the Mercurial-devel mailing list