[PATCH 2 of 2 chg-port] osutil: implement pure version of recvfds() for PyPy
Sean Farley
sean at farley.io
Sat Dec 19 12:37:11 CST 2015
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.
More information about the Mercurial-devel
mailing list