Patchwork [STABLE] osutil: do not abort loading pure module just because libc has no recvmsg()

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 3, 2016, 2:16 p.m.
Message ID <7b55244664ad678b5940.1454509006@mimosa>
Download mbox | patch
Permalink /patch/12951/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 3, 2016, 2:16 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1454507247 -32400
#      Wed Feb 03 22:47:27 2016 +0900
# Branch stable
# Node ID 7b55244664ad678b594087e29f4d33fecdb7d4a9
# Parent  ae78af2ef11009409a3ca73a7b230404ae3ae321
osutil: do not abort loading pure module just because libc has no recvmsg()

On Solaris, recvmsg() is provided by libsocket.so. We could try hard to look
for the library which provides 'recvmsg' symbol, but it would make little sense
now since recvfds() won't work anyway on Solaris. So this patch just disables
_recvmsg() on such platforms.

Thanks to FUJIWARA Katsunori for spotting this problem.
Matt Mackall - Feb. 3, 2016, 8:22 p.m.
On Wed, 2016-02-03 at 23:16 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1454507247 -32400
> #      Wed Feb 03 22:47:27 2016 +0900
> # Branch stable
> # Node ID 7b55244664ad678b594087e29f4d33fecdb7d4a9
> # Parent  ae78af2ef11009409a3ca73a7b230404ae3ae321
> osutil: do not abort loading pure module just because libc has no recvmsg()

Queued for stable, thanks.

-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/mercurial/pure/osutil.py b/mercurial/pure/osutil.py
--- a/mercurial/pure/osutil.py
+++ b/mercurial/pure/osutil.py
@@ -104,9 +104,15 @@  if os.name != 'nt':
         ]
 
     _libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
-    _recvmsg = _libc.recvmsg
-    _recvmsg.restype = getattr(ctypes, 'c_ssize_t', ctypes.c_long)
-    _recvmsg.argtypes = (ctypes.c_int, ctypes.POINTER(_msghdr), ctypes.c_int)
+    _recvmsg = getattr(_libc, 'recvmsg', None)
+    if _recvmsg:
+        _recvmsg.restype = getattr(ctypes, 'c_ssize_t', ctypes.c_long)
+        _recvmsg.argtypes = (ctypes.c_int, ctypes.POINTER(_msghdr),
+                             ctypes.c_int)
+    else:
+        # recvmsg isn't always provided by libc; such systems are unsupported
+        def _recvmsg(sockfd, msg, flags):
+            raise NotImplementedError('unsupported platform')
 
     def _CMSG_FIRSTHDR(msgh):
         if msgh.msg_controllen < ctypes.sizeof(_cmsghdr):