ia64/xen-unstable

changeset 7939:e60115657823

Remove all unnecessary uses of keyword arguments, to reduce complexity. In
many places we were supporting keywords for calling the methods here, and never
using that feature (especially where all the arguments were compulsory anyway)
and in some places we were even accepting positional and keyword arguments, and
not actually taking any arguments to the method at all!

Fix the permission parsing string in xspy_set_permissions -- this would have
blown up horribly if anyone were actually calling this code.

Fix the documentation comments to include the transaction handle throughout.

Have the self parameter to all the methods be an XsHandle, not a PyObject, to
avoid casting.

Remove unused pyvalue_int and pyvalue_str.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Mon Nov 21 12:34:37 2005 +0100 (2005-11-21)
parents aad88a902892
children 2cfded7de82f
files tools/python/xen/lowlevel/xs/xs.c
line diff
     1.1 --- a/tools/python/xen/lowlevel/xs/xs.c	Sat Nov 19 10:37:14 2005 +0100
     1.2 +++ b/tools/python/xen/lowlevel/xs/xs.c	Mon Nov 21 12:34:37 2005 +0100
     1.3 @@ -51,47 +51,35 @@ typedef struct XsHandle {
     1.4      PyObject *watches;
     1.5  } XsHandle;
     1.6  
     1.7 -static inline struct xs_handle *xshandle(PyObject *self)
     1.8 +static inline struct xs_handle *xshandle(XsHandle *self)
     1.9  {
    1.10 -    struct xs_handle *xh = ((XsHandle*)self)->xh;
    1.11 +    struct xs_handle *xh = self->xh;
    1.12      if (!xh)
    1.13          PyErr_SetString(PyExc_RuntimeError, "invalid xenstore daemon handle");
    1.14      return xh;
    1.15  }
    1.16  
    1.17 -static inline PyObject *pyvalue_int(int val) {
    1.18 -    return (val
    1.19 -            ? PyInt_FromLong(val)
    1.20 -            : PyErr_SetFromErrno(PyExc_RuntimeError));
    1.21 -}
    1.22 -
    1.23 -static inline PyObject *pyvalue_str(char *val) {
    1.24 -    return (val
    1.25 -            ? PyString_FromString(val)
    1.26 -            : PyErr_SetFromErrno(PyExc_RuntimeError));
    1.27 -}
    1.28 -
    1.29  static void remove_watch(XsHandle *xsh, PyObject *token);
    1.30  
    1.31  static PyObject *none(bool result);
    1.32  
    1.33 -static int parse_transaction_path(PyObject *self, PyObject *args,
    1.34 -                                  PyObject *kwds,
    1.35 +static int parse_transaction_path(XsHandle *self, PyObject *args,
    1.36                                    struct xs_handle **xh,
    1.37                                    struct xs_transaction_handle **th,
    1.38                                    char **path);
    1.39  
    1.40  
    1.41 -#define xspy_read_doc "\n"			\
    1.42 -	"Read data from a path.\n"		\
    1.43 -	" path [string]: xenstore path\n"	\
    1.44 -	"\n"					\
    1.45 -	"Returns: [string] data read.\n"	\
    1.46 -	"         None if key doesn't exist.\n"	\
    1.47 -	"Raises RuntimeError on error.\n"	\
    1.48 +#define xspy_read_doc "\n"                              \
    1.49 +	"Read data from a path.\n"                      \
    1.50 +	" transaction [string]: transaction handle\n"	\
    1.51 +	" path [string]:        xenstore path\n"	\
    1.52 +	"\n"                                            \
    1.53 +	"Returns: [string] data read.\n"                \
    1.54 +	"         None if key doesn't exist.\n"         \
    1.55 +	"Raises RuntimeError on error.\n"               \
    1.56  	"\n"
    1.57  
    1.58 -static PyObject *xspy_read(PyObject *self, PyObject *args, PyObject *kwds)
    1.59 +static PyObject *xspy_read(XsHandle *self, PyObject *args)
    1.60  {
    1.61      struct xs_handle *xh;
    1.62      struct xs_transaction_handle *th;
    1.63 @@ -100,7 +88,7 @@ static PyObject *xspy_read(PyObject *sel
    1.64      char *xsval;
    1.65      unsigned int xsval_n;
    1.66  
    1.67 -    if (!parse_transaction_path(self, args, kwds, &xh, &th, &path))
    1.68 +    if (!parse_transaction_path(self, args, &xh, &th, &path))
    1.69          return NULL;
    1.70  
    1.71      Py_BEGIN_ALLOW_THREADS
    1.72 @@ -119,6 +107,7 @@ static PyObject *xspy_read(PyObject *sel
    1.73  
    1.74  #define xspy_write_doc "\n"					\
    1.75  	"Write data to a path.\n"				\
    1.76 +	" transaction [string]: transaction handle\n"           \
    1.77  	" path   [string] : xenstore path to write to\n."	\
    1.78  	" data   [string] : data to write.\n"			\
    1.79  	"\n"							\
    1.80 @@ -126,24 +115,20 @@ static PyObject *xspy_read(PyObject *sel
    1.81  	"Raises RuntimeError on error.\n"			\
    1.82  	"\n"
    1.83  
    1.84 -static PyObject *xspy_write(PyObject *self, PyObject *args, PyObject *kwds)
    1.85 +static PyObject *xspy_write(XsHandle *self, PyObject *args)
    1.86  {
    1.87 -    static char *kwd_spec[] = { "transaction", "path", "data", NULL };
    1.88      static char *arg_spec = "sss#";
    1.89 -    char *path = NULL;
    1.90 -    char *data = NULL;
    1.91 -    int data_n = 0;
    1.92 -
    1.93      struct xs_handle *xh = xshandle(self);
    1.94 -    bool result;
    1.95 -
    1.96      struct xs_transaction_handle *th;
    1.97      char *thstr;
    1.98 +    char *path;
    1.99 +    char *data;
   1.100 +    int data_n;
   1.101 +    bool result;
   1.102  
   1.103      if (!xh)
   1.104          return NULL;
   1.105 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   1.106 -                                     &thstr, &path, &data, &data_n))
   1.107 +    if (!PyArg_ParseTuple(args, arg_spec, &thstr, &path, &data, &data_n))
   1.108          return NULL;
   1.109  
   1.110      th = (struct xs_transaction_handle *)strtoul(thstr, NULL, 16);
   1.111 @@ -158,14 +143,15 @@ static PyObject *xspy_write(PyObject *se
   1.112  
   1.113  #define xspy_ls_doc "\n"					\
   1.114  	"List a directory.\n"					\
   1.115 -	" path [string]: path to list.\n"			\
   1.116 +	" transaction [string]: transaction handle\n"           \
   1.117 +	" path [string]:        path to list.\n"                \
   1.118  	"\n"							\
   1.119  	"Returns: [string array] list of subdirectory names.\n"	\
   1.120  	"         None if key doesn't exist.\n"			\
   1.121  	"Raises RuntimeError on error.\n"			\
   1.122  	"\n"
   1.123  
   1.124 -static PyObject *xspy_ls(PyObject *self, PyObject *args, PyObject *kwds)
   1.125 +static PyObject *xspy_ls(XsHandle *self, PyObject *args)
   1.126  {
   1.127      struct xs_handle *xh;
   1.128      struct xs_transaction_handle *th;
   1.129 @@ -174,7 +160,7 @@ static PyObject *xspy_ls(PyObject *self,
   1.130      char **xsval;
   1.131      int xsval_n;
   1.132  
   1.133 -    if (!parse_transaction_path(self, args, kwds, &xh, &th, &path))
   1.134 +    if (!parse_transaction_path(self, args, &xh, &th, &path))
   1.135          return NULL;
   1.136  
   1.137      Py_BEGIN_ALLOW_THREADS
   1.138 @@ -203,7 +189,7 @@ static PyObject *xspy_ls(PyObject *self,
   1.139  	"Raises RuntimeError on error.\n"			\
   1.140  	"\n"
   1.141  
   1.142 -static PyObject *xspy_mkdir(PyObject *self, PyObject *args, PyObject *kwds)
   1.143 +static PyObject *xspy_mkdir(XsHandle *self, PyObject *args)
   1.144  {
   1.145      struct xs_handle *xh;
   1.146      struct xs_transaction_handle *th;
   1.147 @@ -211,7 +197,7 @@ static PyObject *xspy_mkdir(PyObject *se
   1.148  
   1.149      bool result;
   1.150  
   1.151 -    if (!parse_transaction_path(self, args, kwds, &xh, &th, &path))
   1.152 +    if (!parse_transaction_path(self, args, &xh, &th, &path))
   1.153          return NULL;
   1.154  
   1.155      Py_BEGIN_ALLOW_THREADS
   1.156 @@ -222,15 +208,16 @@ static PyObject *xspy_mkdir(PyObject *se
   1.157  }
   1.158  
   1.159  
   1.160 -#define xspy_rm_doc "\n"			\
   1.161 -	"Remove a path.\n"			\
   1.162 -	" path [string] : path to remove\n"	\
   1.163 -	"\n"					\
   1.164 -	"Returns None on success.\n"		\
   1.165 -	"Raises RuntimeError on error.\n"	\
   1.166 +#define xspy_rm_doc "\n"                                \
   1.167 +	"Remove a path.\n"                              \
   1.168 +	" transaction [string]: transaction handle\n"	\
   1.169 +	" path [string] : path to remove\n"             \
   1.170 +	"\n"                                            \
   1.171 +	"Returns None on success.\n"                    \
   1.172 +	"Raises RuntimeError on error.\n"               \
   1.173  	"\n"
   1.174  
   1.175 -static PyObject *xspy_rm(PyObject *self, PyObject *args, PyObject *kwds)
   1.176 +static PyObject *xspy_rm(XsHandle *self, PyObject *args)
   1.177  {
   1.178      struct xs_handle *xh;
   1.179      struct xs_transaction_handle *th;
   1.180 @@ -238,7 +225,7 @@ static PyObject *xspy_rm(PyObject *self,
   1.181  
   1.182      bool result;
   1.183  
   1.184 -    if (!parse_transaction_path(self, args, kwds, &xh, &th, &path))
   1.185 +    if (!parse_transaction_path(self, args, &xh, &th, &path))
   1.186          return NULL;
   1.187  
   1.188      Py_BEGIN_ALLOW_THREADS
   1.189 @@ -249,18 +236,17 @@ static PyObject *xspy_rm(PyObject *self,
   1.190  }
   1.191  
   1.192  
   1.193 -#define xspy_get_permissions_doc "\n"		\
   1.194 -	"Get the permissions for a path\n"	\
   1.195 -	" path [string]: xenstore path.\n"	\
   1.196 -	"\n"					\
   1.197 -	"Returns: permissions array.\n"		\
   1.198 -	"Raises RuntimeError on error.\n"	\
   1.199 +#define xspy_get_permissions_doc "\n"                   \
   1.200 +	"Get the permissions for a path\n"              \
   1.201 +	" transaction [string]: transaction handle\n"	\
   1.202 +	" path [string]:        xenstore path.\n"       \
   1.203 +	"\n"                                            \
   1.204 +	"Returns: permissions array.\n"                 \
   1.205 +	"Raises RuntimeError on error.\n"               \
   1.206  	"\n"
   1.207  
   1.208 -static PyObject *xspy_get_permissions(PyObject *self, PyObject *args,
   1.209 -                                      PyObject *kwds)
   1.210 +static PyObject *xspy_get_permissions(XsHandle *self, PyObject *args)
   1.211  {
   1.212 -    static char *kwd_spec[] = { "transaction", "path", NULL };
   1.213      static char *arg_spec = "ss";
   1.214      char *path = NULL;
   1.215  
   1.216 @@ -274,8 +260,7 @@ static PyObject *xspy_get_permissions(Py
   1.217  
   1.218      if (!xh)
   1.219          return NULL;
   1.220 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   1.221 -                                     &thstr, &path))
   1.222 +    if (!PyArg_ParseTuple(args, arg_spec, &thstr, &path))
   1.223          return NULL;
   1.224  
   1.225      th = (struct xs_transaction_handle *)strtoul(thstr, NULL, 16);
   1.226 @@ -303,39 +288,35 @@ static PyObject *xspy_get_permissions(Py
   1.227      }
   1.228  }
   1.229  
   1.230 -#define xspy_set_permissions_doc "\n"		\
   1.231 -	"Set the permissions for a path\n"	\
   1.232 -	" path  [string] : xenstore path.\n"	\
   1.233 -	" perms          : permissions.\n"	\
   1.234 -	"\n"					\
   1.235 -	"Returns None on success.\n"		\
   1.236 -	"Raises RuntimeError on error.\n"	\
   1.237 +#define xspy_set_permissions_doc "\n"                   \
   1.238 +	"Set the permissions for a path\n"              \
   1.239 +	" transaction [string]: transaction handle\n"	\
   1.240 +	" path  [string]      : xenstore path.\n"	\
   1.241 +	" perms               : permissions.\n"         \
   1.242 +	"\n"                                            \
   1.243 +	"Returns None on success.\n"                    \
   1.244 +	"Raises RuntimeError on error.\n"               \
   1.245  	"\n"
   1.246  
   1.247 -static PyObject *xspy_set_permissions(PyObject *self, PyObject *args,
   1.248 -                                      PyObject *kwds)
   1.249 +static PyObject *xspy_set_permissions(XsHandle *self, PyObject *args)
   1.250  {
   1.251 -    static char *kwd_spec[] = { "transaction", "path", "perms", NULL };
   1.252 -    static char *arg_spec = "ssO";
   1.253 -    char *path = NULL;
   1.254 -    PyObject *perms = NULL;
   1.255 +    char *path;
   1.256 +    PyObject *perms;
   1.257      static char *perm_names[] = { "dom", "read", "write", NULL };
   1.258 -    static char *perm_spec = "i|iiii";
   1.259 +    static char *perm_spec = "i|ii";
   1.260  
   1.261      struct xs_handle *xh = xshandle(self);
   1.262      int i, result;
   1.263      struct xs_permissions *xsperms = NULL;
   1.264 -    int xsperms_n = 0;
   1.265 +    int xsperms_n;
   1.266      PyObject *tuple0 = NULL;
   1.267 -    PyObject *val = NULL;
   1.268  
   1.269      struct xs_transaction_handle *th;
   1.270      char *thstr;
   1.271  
   1.272      if (!xh)
   1.273          goto exit;
   1.274 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   1.275 -                                     &thstr, &path, &perms))
   1.276 +    if (!PyArg_ParseTuple(args, "ssO", &thstr, &path, &perms))
   1.277          goto exit;
   1.278  
   1.279      th = (struct xs_transaction_handle *)strtoul(thstr, NULL, 16);
   1.280 @@ -354,15 +335,12 @@ static PyObject *xspy_set_permissions(Py
   1.281      if (!tuple0)
   1.282          goto exit;
   1.283      for (i = 0; i < xsperms_n; i++) {
   1.284 -        /* Domain the permissions apply to. */
   1.285 -        int dom = 0;
   1.286          /* Read/write perms. Set these. */
   1.287          int p_read = 0, p_write = 0;
   1.288          PyObject *p = PyList_GetItem(perms, i);
   1.289          if (!PyArg_ParseTupleAndKeywords(tuple0, p, perm_spec, perm_names,
   1.290 -                                         &dom, &p_read, &p_write))
   1.291 +                                         &xsperms[i].id, &p_read, &p_write))
   1.292              goto exit;
   1.293 -        xsperms[i].id = dom;
   1.294          if (p_read)
   1.295              xsperms[i].perms |= XS_PERM_READ;
   1.296          if (p_write)
   1.297 @@ -375,12 +353,14 @@ static PyObject *xspy_set_permissions(Py
   1.298          PyErr_SetFromErrno(PyExc_RuntimeError);
   1.299          goto exit;
   1.300      }
   1.301 +
   1.302      Py_INCREF(Py_None);
   1.303 -    val = Py_None;
   1.304 +    return Py_None;
   1.305 +
   1.306   exit:
   1.307      Py_XDECREF(tuple0);
   1.308      free(xsperms);
   1.309 -    return val;
   1.310 +    return NULL;
   1.311  }
   1.312  
   1.313  #define xspy_watch_doc "\n"						\
   1.314 @@ -395,23 +375,18 @@ static PyObject *xspy_set_permissions(Py
   1.315  /* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */
   1.316  #define MAX_STRLEN(x) ((sizeof(x) * CHAR_BIT + CHAR_BIT-1) / 10 * 3 + 2)
   1.317  
   1.318 -static PyObject *xspy_watch(PyObject *self, PyObject *args, PyObject *kwds)
   1.319 +static PyObject *xspy_watch(XsHandle *self, PyObject *args)
   1.320  {
   1.321 -    static char *kwd_spec[] = { "path", "token", NULL };
   1.322 -    static char *arg_spec = "sO";
   1.323 -    char *path = NULL;
   1.324 +    struct xs_handle *xh = xshandle(self);
   1.325 +    char *path;
   1.326      PyObject *token;
   1.327      char token_str[MAX_STRLEN(unsigned long) + 1];
   1.328 +    int result;
   1.329      int i;
   1.330  
   1.331 -    XsHandle *xsh = (XsHandle *)self;
   1.332 -    struct xs_handle *xh = xshandle(self);
   1.333 -    int result = 0;
   1.334 -
   1.335      if (!xh)
   1.336          return NULL;
   1.337 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, 
   1.338 -                                     &path, &token))
   1.339 +    if (!PyArg_ParseTuple(args, "sO", &path, &token))
   1.340          return NULL;
   1.341  
   1.342      /* Note that we have to store the watch token in the xs->watches list
   1.343 @@ -419,14 +394,14 @@ static PyObject *xspy_watch(PyObject *se
   1.344         races with xs_read_watch.
   1.345      */
   1.346  
   1.347 -    for (i = 0; i < PyList_Size(xsh->watches); i++) {
   1.348 -        if (PyList_GetItem(xsh->watches, i) == Py_None) {
   1.349 -            PySequence_SetItem(xsh->watches, i, token);
   1.350 +    for (i = 0; i < PyList_Size(self->watches); i++) {
   1.351 +        if (PyList_GetItem(self->watches, i) == Py_None) {
   1.352 +            PySequence_SetItem(self->watches, i, token);
   1.353              break;
   1.354          }
   1.355      }
   1.356 -    if (i == PyList_Size(xsh->watches))
   1.357 -        PyList_Append(xsh->watches, token);
   1.358 +    if (i == PyList_Size(self->watches))
   1.359 +        PyList_Append(self->watches, token);
   1.360  
   1.361      sprintf(token_str, "%li", (unsigned long)token);
   1.362      Py_BEGIN_ALLOW_THREADS
   1.363 @@ -434,7 +409,7 @@ static PyObject *xspy_watch(PyObject *se
   1.364      Py_END_ALLOW_THREADS
   1.365  
   1.366      if (!result)
   1.367 -        remove_watch(xsh, token);
   1.368 +        remove_watch(self, token);
   1.369  
   1.370      return none(result);
   1.371  }
   1.372 @@ -447,24 +422,17 @@ static PyObject *xspy_watch(PyObject *se
   1.373  	"Raises RuntimeError on error.\n"			\
   1.374  	"\n"
   1.375  
   1.376 -static PyObject *xspy_read_watch(PyObject *self, PyObject *args,
   1.377 -                                 PyObject *kwds)
   1.378 +static PyObject *xspy_read_watch(XsHandle *self, PyObject *args)
   1.379  {
   1.380 -    static char *kwd_spec[] = { NULL };
   1.381 -    static char *arg_spec = "";
   1.382 -
   1.383 -    XsHandle *xsh = (XsHandle *)self;
   1.384      struct xs_handle *xh = xshandle(self);
   1.385      PyObject *val = NULL;
   1.386 -    char **xsval = NULL;
   1.387 +    char **xsval;
   1.388      PyObject *token;
   1.389      int i;
   1.390      unsigned int num;
   1.391  
   1.392      if (!xh)
   1.393          return NULL;
   1.394 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
   1.395 -        return NULL;
   1.396  
   1.397  again:
   1.398      Py_BEGIN_ALLOW_THREADS
   1.399 @@ -478,11 +446,11 @@ again:
   1.400          PyErr_SetString(PyExc_RuntimeError, "invalid token");
   1.401          goto exit;
   1.402      }
   1.403 -    for (i = 0; i < PyList_Size(xsh->watches); i++) {
   1.404 -        if (token == PyList_GetItem(xsh->watches, i))
   1.405 +    for (i = 0; i < PyList_Size(self->watches); i++) {
   1.406 +        if (token == PyList_GetItem(self->watches, i))
   1.407              break;
   1.408      }
   1.409 -    if (i == PyList_Size(xsh->watches)) {
   1.410 +    if (i == PyList_Size(self->watches)) {
   1.411        /* We do not have a registered watch for the one that has just fired.
   1.412           Ignore this -- a watch that has been recently deregistered can still
   1.413           have watches in transit.  This is a blocking method, so go back to
   1.414 @@ -507,22 +475,17 @@ again:
   1.415  	"Raises RuntimeError on error.\n"		\
   1.416  	"\n"
   1.417  
   1.418 -static PyObject *xspy_unwatch(PyObject *self, PyObject *args, PyObject *kwds)
   1.419 +static PyObject *xspy_unwatch(XsHandle *self, PyObject *args)
   1.420  {
   1.421 -    static char *kwd_spec[] = { "path", "token", NULL };
   1.422 -    static char *arg_spec = "sO";
   1.423 -    char *path = NULL;
   1.424 +    struct xs_handle *xh = xshandle(self);
   1.425 +    char *path;
   1.426      PyObject *token;
   1.427      char token_str[MAX_STRLEN(unsigned long) + 1];
   1.428 -
   1.429 -    XsHandle *xsh = (XsHandle *)self;
   1.430 -    struct xs_handle *xh = xshandle(self);
   1.431 -    int result = 0;
   1.432 +    int result;
   1.433  
   1.434      if (!xh)
   1.435          return NULL;
   1.436 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path,
   1.437 -                                     &token))
   1.438 +    if (!PyArg_ParseTuple(args, "sO", &path, &token))
   1.439          return NULL;
   1.440  
   1.441      sprintf(token_str, "%li", (unsigned long)token);
   1.442 @@ -530,7 +493,7 @@ static PyObject *xspy_unwatch(PyObject *
   1.443      result = xs_unwatch(xh, path, token_str);
   1.444      Py_END_ALLOW_THREADS
   1.445  
   1.446 -    remove_watch(xsh, token);
   1.447 +    remove_watch(self, token);
   1.448  
   1.449      return none(result);
   1.450  }
   1.451 @@ -542,21 +505,14 @@ static PyObject *xspy_unwatch(PyObject *
   1.452  	"Raises RuntimeError on error.\n"			\
   1.453  	"\n"
   1.454  
   1.455 -static PyObject *xspy_transaction_start(PyObject *self, PyObject *args,
   1.456 -                                        PyObject *kwds)
   1.457 +static PyObject *xspy_transaction_start(XsHandle *self)
   1.458  {
   1.459 -    static char *kwd_spec[] = { NULL };
   1.460 -    static char *arg_spec = "";
   1.461 -    char *path = NULL;
   1.462 -
   1.463      struct xs_handle *xh = xshandle(self);
   1.464      struct xs_transaction_handle *th;
   1.465 -    char thstr[20];
   1.466 +    char thstr[MAX_STRLEN(unsigned long) + 1];
   1.467  
   1.468      if (!xh)
   1.469          return NULL;
   1.470 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec, &path))
   1.471 -        return NULL;
   1.472  
   1.473      Py_BEGIN_ALLOW_THREADS
   1.474      th = xs_transaction_start(xh);
   1.475 @@ -580,7 +536,7 @@ static PyObject *xspy_transaction_start(
   1.476  	"Raises RuntimeError on error.\n"				\
   1.477  	"\n"
   1.478  
   1.479 -static PyObject *xspy_transaction_end(PyObject *self, PyObject *args,
   1.480 +static PyObject *xspy_transaction_end(XsHandle *self, PyObject *args,
   1.481                                        PyObject *kwds)
   1.482  {
   1.483      static char *kwd_spec[] = { "transaction", "abort", NULL };
   1.484 @@ -630,22 +586,18 @@ static PyObject *xspy_transaction_end(Py
   1.485  	"Raises RuntimeError on error.\n"				\
   1.486  	"\n"
   1.487  
   1.488 -static PyObject *xspy_introduce_domain(PyObject *self, PyObject *args,
   1.489 -                                       PyObject *kwds)
   1.490 +static PyObject *xspy_introduce_domain(XsHandle *self, PyObject *args)
   1.491  {
   1.492 -    static char *kwd_spec[] = { "dom", "page", "port", NULL };
   1.493 -    static char *arg_spec = "ili";
   1.494 -    domid_t dom = 0;
   1.495 -    unsigned long page = 0;
   1.496 -    unsigned int port = 0;
   1.497 +    domid_t dom;
   1.498 +    unsigned long page;
   1.499 +    unsigned int port;
   1.500  
   1.501      struct xs_handle *xh = xshandle(self);
   1.502      bool result = 0;
   1.503  
   1.504      if (!xh)
   1.505          return NULL;
   1.506 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   1.507 -                                     &dom, &page, &port))
   1.508 +    if (!PyArg_ParseTuple(args, "ili", &dom, &page, &port))
   1.509          return NULL;
   1.510  
   1.511      Py_BEGIN_ALLOW_THREADS
   1.512 @@ -665,11 +617,8 @@ static PyObject *xspy_introduce_domain(P
   1.513  	"Raises RuntimeError on error.\n"				\
   1.514  	"\n"
   1.515  
   1.516 -static PyObject *xspy_release_domain(PyObject *self, PyObject *args,
   1.517 -                                     PyObject *kwds)
   1.518 +static PyObject *xspy_release_domain(XsHandle *self, PyObject *args)
   1.519  {
   1.520 -    static char *kwd_spec[] = { "dom", NULL };
   1.521 -    static char *arg_spec = "i";
   1.522      domid_t dom;
   1.523  
   1.524      struct xs_handle *xh = xshandle(self);
   1.525 @@ -677,8 +626,7 @@ static PyObject *xspy_release_domain(PyO
   1.526  
   1.527      if (!xh)
   1.528          return NULL;
   1.529 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   1.530 -                                     &dom))
   1.531 +    if (!PyArg_ParseTuple(args, "i", &dom))
   1.532          return NULL;
   1.533  
   1.534      Py_BEGIN_ALLOW_THREADS
   1.535 @@ -696,27 +644,21 @@ static PyObject *xspy_release_domain(PyO
   1.536  	"Raises RuntimeError on error.\n"	\
   1.537  	"\n"
   1.538  
   1.539 -static PyObject *xspy_close(PyObject *self, PyObject *args, PyObject *kwds)
   1.540 +static PyObject *xspy_close(XsHandle *self)
   1.541  {
   1.542 -    static char *kwd_spec[] = { NULL };
   1.543 -    static char *arg_spec = "";
   1.544 +    struct xs_handle *xh = xshandle(self);
   1.545      int i;
   1.546  
   1.547 -    XsHandle *xsh = (XsHandle *)self;
   1.548 -    struct xs_handle *xh = xshandle(self);
   1.549 -
   1.550      if (!xh)
   1.551          return NULL;
   1.552 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
   1.553 -        return NULL;
   1.554  
   1.555 -    for (i = 0; i < PyList_Size(xsh->watches); i++) {
   1.556 +    for (i = 0; i < PyList_Size(self->watches); i++) {
   1.557          /* TODO: xs_unwatch watches */
   1.558 -        PySequence_SetItem(xsh->watches, i, Py_None);
   1.559 +        PySequence_SetItem(self->watches, i, Py_None);
   1.560      }
   1.561  
   1.562      xs_daemon_close(xh);
   1.563 -    xsh->xh = NULL;
   1.564 +    self->xh = NULL;
   1.565  
   1.566      Py_INCREF(Py_None);
   1.567      return Py_None;
   1.568 @@ -731,20 +673,15 @@ static PyObject *xspy_close(PyObject *se
   1.569  	"Raises RuntimeError on error.\n"		\
   1.570  	"\n"
   1.571  
   1.572 -static PyObject *xspy_get_domain_path(PyObject *self, PyObject *args,
   1.573 -				      PyObject *kwds)
   1.574 +static PyObject *xspy_get_domain_path(XsHandle *self, PyObject *args)
   1.575  {
   1.576 -    static char *kwd_spec[] = { "domid", NULL };
   1.577 -    static char *arg_spec = "i";
   1.578 -    int domid = 0;
   1.579 -
   1.580      struct xs_handle *xh = xshandle(self);
   1.581 -    char *xsval = NULL;
   1.582 +    int domid;
   1.583 +    char *xsval;
   1.584  
   1.585      if (!xh)
   1.586          return NULL;
   1.587 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   1.588 -                                     &domid))
   1.589 +    if (!PyArg_ParseTuple(args, "i", &domid))
   1.590          return NULL;
   1.591  
   1.592      Py_BEGIN_ALLOW_THREADS
   1.593 @@ -766,13 +703,13 @@ static PyObject *xspy_get_domain_path(Py
   1.594   * Remove the given token from the watches list belonging to the given
   1.595   * XsHandle, if present.
   1.596   */
   1.597 -static void remove_watch(XsHandle *xsh, PyObject *token)
   1.598 +static void remove_watch(XsHandle *self, PyObject *token)
   1.599  {
   1.600      int i;
   1.601  
   1.602 -    for (i = 0; i < PyList_Size(xsh->watches); i++) {
   1.603 -        if (PyList_GetItem(xsh->watches, i) == token) {
   1.604 -            PySequence_SetItem(xsh->watches, i, Py_None);
   1.605 +    for (i = 0; i < PyList_Size(self->watches); i++) {
   1.606 +        if (PyList_GetItem(self->watches, i) == token) {
   1.607 +            PySequence_SetItem(self->watches, i, Py_None);
   1.608              return;
   1.609          }
   1.610      }
   1.611 @@ -787,14 +724,11 @@ static void remove_watch(XsHandle *xsh, 
   1.612   * @return 1 on success, in which case *xh, *th, and *path are valid, or 0 on
   1.613   * failure.
   1.614   */
   1.615 -static int parse_transaction_path(PyObject *self, PyObject *args,
   1.616 -                                  PyObject *kwds,
   1.617 +static int parse_transaction_path(XsHandle *self, PyObject *args,
   1.618                                    struct xs_handle **xh,
   1.619                                    struct xs_transaction_handle **th,
   1.620                                    char **path)
   1.621  {
   1.622 -    static char *arg_spec = "ss";
   1.623 -    static char *kwd_spec[] = { "transaction", "path", NULL };
   1.624      char *thstr;
   1.625  
   1.626      *xh = xshandle(self);
   1.627 @@ -802,8 +736,7 @@ static int parse_transaction_path(PyObje
   1.628      if (!xh)
   1.629          return 0;
   1.630  
   1.631 -    if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
   1.632 -                                     &thstr, path))
   1.633 +    if (!PyArg_ParseTuple(args, "ss", &thstr, path))
   1.634          return 0;
   1.635  
   1.636      *th = (struct xs_transaction_handle *)strtoul(thstr, NULL, 16);
   1.637 @@ -825,30 +758,30 @@ static PyObject *none(bool result)
   1.638  }
   1.639  
   1.640  
   1.641 -#define XSPY_METH(_name) {			\
   1.642 +#define XSPY_METH(_name, _args) {               \
   1.643      .ml_name  = #_name,				\
   1.644      .ml_meth  = (PyCFunction) xspy_ ## _name,	\
   1.645 -    .ml_flags = (METH_VARARGS | METH_KEYWORDS),	\
   1.646 +    .ml_flags = _args,                          \
   1.647      .ml_doc   = xspy_ ## _name ## _doc }
   1.648  
   1.649  static PyMethodDef xshandle_methods[] = {
   1.650 -     XSPY_METH(read),
   1.651 -     XSPY_METH(write),
   1.652 -     XSPY_METH(ls),
   1.653 -     XSPY_METH(mkdir),
   1.654 -     XSPY_METH(rm),
   1.655 -     XSPY_METH(get_permissions),
   1.656 -     XSPY_METH(set_permissions),
   1.657 -     XSPY_METH(watch),
   1.658 -     XSPY_METH(read_watch),
   1.659 -     XSPY_METH(unwatch),
   1.660 -     XSPY_METH(transaction_start),
   1.661 -     XSPY_METH(transaction_end),
   1.662 -     XSPY_METH(introduce_domain),
   1.663 -     XSPY_METH(release_domain),
   1.664 -     XSPY_METH(close),
   1.665 -     XSPY_METH(get_domain_path),
   1.666 -     { /* Terminator. */ },
   1.667 +    XSPY_METH(read,              METH_VARARGS),
   1.668 +    XSPY_METH(write,             METH_VARARGS),
   1.669 +    XSPY_METH(ls,                METH_VARARGS),
   1.670 +    XSPY_METH(mkdir,             METH_VARARGS),
   1.671 +    XSPY_METH(rm,                METH_VARARGS),
   1.672 +    XSPY_METH(get_permissions,   METH_VARARGS),
   1.673 +    XSPY_METH(set_permissions,   METH_VARARGS),
   1.674 +    XSPY_METH(watch,             METH_VARARGS),
   1.675 +    XSPY_METH(read_watch,        METH_NOARGS),
   1.676 +    XSPY_METH(unwatch,           METH_VARARGS),
   1.677 +    XSPY_METH(transaction_start, METH_NOARGS),
   1.678 +    XSPY_METH(transaction_end,   METH_VARARGS | METH_KEYWORDS),
   1.679 +    XSPY_METH(introduce_domain,  METH_VARARGS),
   1.680 +    XSPY_METH(release_domain,    METH_VARARGS),
   1.681 +    XSPY_METH(close,             METH_NOARGS),
   1.682 +    XSPY_METH(get_domain_path,   METH_VARARGS),
   1.683 +    { NULL /* Sentinel. */ },
   1.684  };
   1.685  
   1.686  static PyObject *xshandle_getattr(PyObject *self, char *name)