mdup.pyx: New support for mLib's glorious `mdup' function.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 3 Oct 2009 23:34:39 +0000 (00:34 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 3 Oct 2009 23:34:39 +0000 (00:34 +0100)
MANIFEST.in
defs.pxi
mLib.pyx
mdup.pyx [new file with mode: 0644]
setup.py

index ba67515..17e28c4 100644 (file)
@@ -1,7 +1,7 @@
 include COPYING
 include mLib.pyx defs.pxi utils.pyx
 include codec.pyx.in grim.h atom.h array.h atom-base.c array.c Makefile
-include lbuf.pyx pkbuf.pyx mapping.pyx
+include lbuf.pyx pkbuf.pyx mapping.pyx mdup.pyx
 include atom.pyx crc32.pyx report.pyx sym.pyx assoc.pyx unihash.pyx
 include sel-base.pyx sel-file.pyx sel-timer.pyx conn.pyx
 include bres.pyx selbuf.pyx selpk.pyx sig.pyx ident.pyx
index a09130c..2dd50b7 100644 (file)
--- a/defs.pxi
+++ b/defs.pxi
@@ -414,6 +414,12 @@ cdef extern from 'mLib/fdpass.h':
   int fdpass_send(int sock, int fd, void *p, size_t sz)
   int fdpass_recv(int sock, int *fd, void *p, size_t sz)
 
+cdef extern from 'mLib/mdup.h':
+  ctypedef struct mdup_fd:
+    int cur
+    int want
+  int _mdup "mdup"(mdup_fd *v, size_t n)
+
 #----- Daemon utilities -----------------------------------------------------
 
 cdef extern from 'mLib/daemonize.h':
index 2b25fcd..5b1f5a7 100644 (file)
--- a/mLib.pyx
+++ b/mLib.pyx
@@ -66,6 +66,7 @@ include 'report.pyx'
 
 include 'fwatch.pyx'
 include 'fdutils.pyx'
+include 'mdup.pyx'
 
 # --- Other useful stuff ---
 
diff --git a/mdup.pyx b/mdup.pyx
new file mode 100644 (file)
index 0000000..24cd995
--- /dev/null
+++ b/mdup.pyx
@@ -0,0 +1,45 @@
+# -*-pyrex-*-
+#
+# $Id$
+#
+# File descriptor juggling
+#
+# (c) 2009 Straylight/Edgeware
+#
+
+#----- Licensing notice -----------------------------------------------------
+#
+# This file is part of the Python interface to mLib.
+#
+# mLib/Python is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# mLib/Python is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with mLib/Python; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+def mdup(v):
+  cdef mdup_fd *vv
+  cdef size_t n
+  cdef int i
+  cdef int rc
+
+  n = len(v)
+  vv = <mdup_fd *>xmalloc(n * PSIZEOF(vv))
+  for 0 <= i < n:
+    vv[i].cur, vv[i].want = v[i]
+  rc = _mdup(vv, n)
+  for 0 <= i < n:
+    v[i] = vv[i].cur, vv[i].want
+  if rc < 0:
+    _oserror()
+  return v
+
+#----- That's all, folks ----------------------------------------------------
index d4b8cfa..d59471f 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -36,7 +36,7 @@ def uniquify(l):
   return o
 
 libconfig('catacomb', '2.1.0')
-libconfig('mLib', '2.0.3')
+libconfig('mLib', '2.1.0')
 
 def needs_update_p(target, sources):
   if not path.exists(target): return True