chiark / gitweb /
Release 1.0.5.
[mLib-python] / defs.pxi
index a09130cc22528937052ea6ce60555dc9a80decc5..e7086b7972a532112ef28467085c11a1d5961e18 100644 (file)
--- a/defs.pxi
+++ b/defs.pxi
@@ -1,31 +1,30 @@
-# -*-pyrex-*-
-#
-# $Id$
-#
-# Basic definitions, used all over
-#
-# (c) 2005 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.
-
-#----- C library ------------------------------------------------------------
+### -*-pyrex-*-
+###
+### Basic definitions, used all over
+###
+### (c) 2005 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.
+
+###--------------------------------------------------------------------------
+### C library.
 
 cdef extern from 'errno.h':
   int errno
@@ -44,7 +43,8 @@ cdef extern from 'string.h':
   char *strerror(int err)
   size_t strlen(char *p)
 
-#----- Unix interface -------------------------------------------------------
+###--------------------------------------------------------------------------
+### Unix interface.
 
 cdef extern from 'sys/types.h':
   pass
@@ -84,7 +84,8 @@ cdef extern from 'netdb.h':
     char *h_addr
   int h_errno
 
-#----- Python ---------------------------------------------------------------
+###--------------------------------------------------------------------------
+### Python.
 
 cdef extern from 'Python.h':
 
@@ -105,7 +106,8 @@ cdef extern from 'Python.h':
   void Py_INCREF(PyObject *obj)
   void Py_DECREF(PyObject *obj)
 
-#----- mLib basic stuff -----------------------------------------------------
+###--------------------------------------------------------------------------
+### mLib basic stuff.
 
 cdef extern from 'mLib/alloc.h':
   char *xstrdup(char *p)
@@ -122,12 +124,14 @@ cdef extern from 'mLib/dstr.h':
   void DCREATE(dstr *d)
   void dstr_destroy(dstr *d)
 
-#----- CRC32 ----------------------------------------------------------------
+###--------------------------------------------------------------------------
+### CRC32.
 
 cdef extern from 'mLib/crc32.h':
   uint32 c_crc32 "crc32" (uint32 a, void *p, int sz)
 
-#----- Universal hashing ----------------------------------------------------
+###--------------------------------------------------------------------------
+### Universal hashing.
 
 cdef extern from 'mLib/unihash.h':
   ctypedef struct unihash_info:
@@ -137,7 +141,8 @@ cdef extern from 'mLib/unihash.h':
   uint32 unihash_hash(unihash_info *i, uint32 a, void *p, int sz)
   unihash_info unihash_global
 
-#----- Symbol tables --------------------------------------------------------
+###--------------------------------------------------------------------------
+### Symbol tables.
 
 cdef extern from 'mLib/sym.h':
   ctypedef struct sym_table:
@@ -155,7 +160,8 @@ cdef extern from 'mLib/sym.h':
   void sym_mkiter(sym_iter *i, sym_table *t)
   void *sym_next(sym_iter *i)
 
-#----- String utilities -----------------------------------------------------
+###--------------------------------------------------------------------------
+### String utilities.
 
 cdef extern from 'mLib/str.h':
   enum:
@@ -169,7 +175,8 @@ cdef extern from 'mLib/str.h':
 cdef extern from 'mLib/versioncmp.h':
   int _versioncmp "versioncmp"(char *va, char *vb)
 
-#----- Form-urlencoding functions -------------------------------------------
+###--------------------------------------------------------------------------
+### Form-urlencoding functions.
 
 cdef extern from 'mLib/url.h':
   struct url_ectx:
@@ -186,12 +193,12 @@ cdef extern from 'mLib/url.h':
   void url_initdec(url_dctx *ctx, char *p)
   int url_dec(url_dctx *ctx, dstr *n, dstr *v)
 
-#----- Atom stuff -----------------------------------------------------------
-
-# --- Atoms ---
-#
-# Partly written in `real' C.
+###--------------------------------------------------------------------------
+### Atom stuff.
 
+## Atoms.
+##
+## Partly written in `real' C.
 cdef extern from 'atom.h':
   ctypedef struct atom:
     pass
@@ -208,8 +215,7 @@ cdef extern from 'atom.h':
   atom *ATOM_A(obj)
   PyTypeObject atom_pytype
 
-# --- Association tables ---
-
+## Association tables.
 cdef extern from 'mLib/assoc.h':
   ctypedef struct assoc_table:
     pass
@@ -225,14 +231,16 @@ cdef extern from 'mLib/assoc.h':
   void assoc_mkiter(assoc_iter *i, assoc_table *t)
   void *assoc_next(assoc_iter *i)
 
-#----- Double-ended arrays --------------------------------------------------
+###--------------------------------------------------------------------------
+### Double-ended arrays.
 
 cdef extern from 'array.h':
   void da_pysetup()
   PyTypeObject da_pytype
   PyTypeObject daiter_pytype
 
-#----- Line buffer ----------------------------------------------------------
+###--------------------------------------------------------------------------
+### Line buffer.
 
 cdef extern from 'mLib/lbuf.h':
   cdef struct lbuf:
@@ -250,10 +258,11 @@ cdef extern from 'mLib/lbuf.h':
   void lbuf_enable(lbuf *b)
   void lbuf_disable(lbuf *b)
   void lbuf_init(lbuf *b,
-                void (*func)(char *s, size_t len, void *arg), void *arg)
+                 void (*func)(char *s, size_t len, void *arg), void *arg)
   void lbuf_destroy(lbuf *b)
 
-#----- Packet buffer --------------------------------------------------------
+###--------------------------------------------------------------------------
+### Packet buffer.
 
 cdef extern from 'mLib/pkbuf.h':
   ctypedef struct pkbuf:
@@ -266,15 +275,15 @@ cdef extern from 'mLib/pkbuf.h':
   size_t pkbuf_free(pkbuf *pk, unsigned char **p)
   void pkbuf_want(pkbuf *pk, size_t sz)
   void pkbuf_init(pkbuf *b,
-                 void (*func)(unsigned char *s, size_t len,
-                              pkbuf *pk, size_t *keep, void *arg),
-                 void *arg)
+                  void (*func)(unsigned char *s, size_t len,
+                               pkbuf *pk, size_t *keep, void *arg),
+                  void *arg)
   void pkbuf_destroy(pkbuf *b)
 
-#----- Select stuff ---------------------------------------------------------
-
-# --- Basics ---
+###--------------------------------------------------------------------------
+### Select stuff.
 
+## Basics.
 cdef extern from 'mLib/sel.h':
   ctypedef struct sel_state:
     pass
@@ -288,41 +297,38 @@ cdef extern from 'mLib/sel.h':
     _SEL_EXC "SEL_EXC"
   void sel_init(sel_state *s)
   void sel_initfile(sel_state *s, sel_file *f, int fd, unsigned mode,
-                   void (*func)(int fd, unsigned mode, void *arg),
-                   void *arg)
+                    void (*func)(int fd, unsigned mode, void *arg),
+                    void *arg)
   void sel_force(sel_file *f)
   void sel_addfile(sel_file *f)
   void sel_rmfile(sel_file *f)
   void sel_addtimer(sel_state *s, sel_timer *t, timeval *tv,
-                   void (*func)(timeval *tv, void *arg),
-                   void *arg)
+                    void (*func)(timeval *tv, void *arg),
+                    void *arg)
   void sel_rmtimer(sel_timer *t)
   int sel_select(sel_state *s) except *
 
-# --- Non-blocking connection ---
-
+### Non-blocking connection.
 cdef extern from 'mLib/conn.h':
   ctypedef struct conn:
     pass
   int conn_fd(conn *c, sel_state *s, int fd,
-             void (*func)(int fd, void *arg), void *arg)
+              void (*func)(int fd, void *arg), void *arg)
   void conn_kill(conn *c)
 
-# --- Background name resolver ---
-
+## Background name resolver.
 cdef extern from 'mLib/bres.h':
   ctypedef struct bres_client:
     pass
   void bres_byname(bres_client *r, char *name,
-                  void (*func)(hostent *h, void *arg), void *arg)
+                   void (*func)(hostent *h, void *arg), void *arg)
   void bres_byaddr(bres_client *r, in_addr addr,
-                  void (*func)(hostent *h, void *arg), void *arg)
+                   void (*func)(hostent *h, void *arg), void *arg)
   void bres_abort(bres_client *r)
   void bres_exec(char *null)
   void bres_init(sel_state *s)
 
-# --- In-band signal handling ---
-
+## In-band signal handling.
 cdef extern from 'mLib/sig.h':
   ctypedef struct sig:
     pass
@@ -330,8 +336,7 @@ cdef extern from 'mLib/sig.h':
   void sig_remove(sig *s)
   void sig_init(sel_state *s)
 
-# --- Line buffer ---
-
+## Line buffer.
 cdef extern from 'mLib/selbuf.h':
   ctypedef struct selbuf:
     sel_file reader
@@ -340,11 +345,10 @@ cdef extern from 'mLib/selbuf.h':
   void selbuf_disable(selbuf *b)
   void selbuf_setsize(selbuf *b, size_t sz)
   void selbuf_init(selbuf *b, sel_state *s, int fd,
-                  void (*func)(char *s, size_t len, void *arg), void *arg)
+                   void (*func)(char *s, size_t len, void *arg), void *arg)
   void selbuf_destroy(selbuf *b)
 
-# --- Packet buffer ---
-
+## Packet buffer.
 cdef extern from 'mLib/selpk.h':
   ctypedef struct selpk:
     sel_file reader
@@ -353,13 +357,12 @@ cdef extern from 'mLib/selpk.h':
   void selpk_disable(selpk *b)
   void selpk_want(selpk *b, size_t sz)
   void selpk_init(selpk *b, sel_state *s, int fd,
-                 void (*func)(unsigned char *p, size_t n,
-                              pkbuf *pk, size_t *keep, void *arg),
-                 void *arg)
+                  void (*func)(unsigned char *p, size_t n,
+                               pkbuf *pk, size_t *keep, void *arg),
+                  void *arg)
   void selpk_destroy(selpk *b)
 
-# --- Ident client ---
-
+## Ident client.
 cdef extern from 'mLib/ident.h':
   ctypedef struct ident_request:
     pass
@@ -379,12 +382,13 @@ cdef extern from 'mLib/ident.h':
     int type
     ident_u u
   void ident(ident_request *rq, sel_state *s,
-            sockaddr_in *local, sockaddr_in *remote,
-            void (*func)(ident_reply *r, void *arg),
-            void *arg)
+             sockaddr_in *local, sockaddr_in *remote,
+             void (*func)(ident_reply *r, void *arg),
+             void *arg)
   void ident_abort(ident_request *rq)
 
-#----- Error reporting ------------------------------------------------------
+###--------------------------------------------------------------------------
+### Error reporting.
 
 cdef extern from 'mLib/quis.h':
   void _ego "ego"(char *prog)
@@ -393,7 +397,8 @@ cdef extern from 'mLib/quis.h':
 cdef extern from 'mLib/report.h':
   void _moan "moan"(char *f, char *msg)
 
-#----- File comparison ------------------------------------------------------
+###--------------------------------------------------------------------------
+### File comparison.
 
 cdef extern from 'mLib/fwatch.h':
   ctypedef struct fwatch:
@@ -403,26 +408,35 @@ cdef extern from 'mLib/fwatch.h':
   int fwatch_update(fwatch *f, char *name)
   int fwatch_updatefd(fwatch *f, int fd)
 
-#----- File descriptor hacking ----------------------------------------------
+###--------------------------------------------------------------------------
+### File descriptor hacking.
 
 cdef extern from 'mLib/fdflags.h':
   int _fdflags "fdflags"(int fd,
-                        unsigned fbic, unsigned fxor,
-                        unsigned fdbic, unsigned fdxor)
+                         unsigned fbic, unsigned fxor,
+                         unsigned fdbic, unsigned fdxor)
 
 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)
 
-#----- Daemon utilities -----------------------------------------------------
+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':
   int _daemonize "daemonize"()
   void _detachtty "detachtty"()
 
-#----- Internal utilities ---------------------------------------------------
+###--------------------------------------------------------------------------
+### Internal utilities.
 
 cdef extern from 'grim.h':
   int PSIZEOF(void *x)
 
-#----- That's all, folks ----------------------------------------------------
+###----- That's all, folks --------------------------------------------------