--- a/hgext/inotify/linux/_inotify.c Thu Mar 20 22:46:35 2008 +0100
+++ b/hgext/inotify/linux/_inotify.c Fri Mar 21 00:39:39 2008 +0100
@@ -19,10 +19,10 @@
{
PyObject *ret = NULL;
int fd = -1;
-
+
if (!PyArg_ParseTuple(args, ":init"))
goto bail;
-
+
Py_BEGIN_ALLOW_THREADS
fd = inotify_init();
Py_END_ALLOW_THREADS
@@ -31,19 +31,19 @@
PyErr_SetFromErrno(PyExc_OSError);
goto bail;
}
-
+
ret = PyInt_FromLong(fd);
if (ret == NULL)
goto bail;
goto done;
-
+
bail:
if (fd != -1)
close(fd);
Py_CLEAR(ret);
-
+
done:
return ret;
}
@@ -74,17 +74,17 @@
PyErr_SetFromErrnoWithFilename(PyExc_OSError, path);
goto bail;
}
-
+
ret = PyInt_FromLong(wd);
if (ret == NULL)
goto bail;
-
+
goto done;
-
+
bail:
if (wd != -1)
inotify_rm_watch(fd, wd);
-
+
Py_CLEAR(ret);
done:
@@ -110,7 +110,7 @@
uint32_t wd;
int fd;
int r;
-
+
if (!PyArg_ParseTuple(args, "iI:remove_watch", &fd, &wd))
goto bail;
@@ -122,14 +122,14 @@
PyErr_SetFromErrno(PyExc_OSError);
goto bail;
}
-
+
Py_INCREF(Py_None);
-
+
goto done;
-
+
bail:
Py_CLEAR(ret);
-
+
done:
return ret;
}
@@ -184,7 +184,7 @@
if (ret == NULL)
goto bail;
-
+
for (i = 0; bit_names[i].bit; i++) {
if (mask & bit_names[i].bit) {
if (bit_names[i].pyname == NULL) {
@@ -197,26 +197,26 @@
goto bail;
}
}
-
+
goto done;
-
+
bail:
Py_CLEAR(ret);
done:
return ret;
}
-
+
static PyObject *pydecode_mask(PyObject *self, PyObject *args)
{
int mask;
-
+
if (!PyArg_ParseTuple(args, "i:decode_mask", &mask))
return NULL;
return decode_mask(mask);
}
-
+
PyDoc_STRVAR(
decode_mask_doc,
"decode_mask(mask) -> list_of_strings\n"
@@ -233,7 +233,7 @@
if (!pyname || !pyval)
goto bail;
-
+
PyDict_SetItem(dict, pyname, pyval);
bail:
@@ -278,28 +278,28 @@
PyObject *cookie;
PyObject *name;
};
-
+
static PyObject *event_wd(PyObject *self, void *x)
{
struct event *evt = (struct event *) self;
Py_INCREF(evt->wd);
return evt->wd;
}
-
+
static PyObject *event_mask(PyObject *self, void *x)
{
struct event *evt = (struct event *) self;
Py_INCREF(evt->mask);
return evt->mask;
}
-
+
static PyObject *event_cookie(PyObject *self, void *x)
{
struct event *evt = (struct event *) self;
Py_INCREF(evt->cookie);
return evt->cookie;
}
-
+
static PyObject *event_name(PyObject *self, void *x)
{
struct event *evt = (struct event *) self;
@@ -334,7 +334,7 @@
Py_XDECREF(evt->mask);
Py_XDECREF(evt->cookie);
Py_XDECREF(evt->name);
-
+
(*evt->ob_type->tp_free)(evt);
}
@@ -353,17 +353,17 @@
pymasks = decode_mask(PyInt_AsLong(evt->mask));
if (pymasks == NULL)
goto bail;
-
+
pymask = _PyString_Join(join, pymasks);
if (pymask == NULL)
goto bail;
-
+
maskstr = PyString_AsString(pymask);
-
+
if (evt->name != Py_None) {
PyObject *pyname = PyString_Repr(evt->name, 1);
char *name = pyname ? PyString_AsString(pyname) : "???";
-
+
if (cookie == -1)
ret = PyString_FromFormat("event(wd=%d, mask=%s, name=%s)",
wd, maskstr, name);
@@ -386,7 +386,7 @@
goto done;
bail:
Py_CLEAR(ret);
-
+
done:
Py_XDECREF(pymask);
Py_XDECREF(pymasks);
@@ -436,7 +436,7 @@
0, /* tp_alloc */
event_new, /* tp_new */
};
-
+
PyObject *read_events(PyObject *self, PyObject *args)
{
PyObject *ctor_args = NULL;
@@ -448,22 +448,22 @@
int fd;
if (!PyArg_ParseTuple(args, "i|O:read", &fd, &pybufsize))
- goto bail;
+ goto bail;
if (pybufsize && pybufsize != Py_None)
bufsize = PyInt_AsLong(pybufsize);
-
+
ret = PyList_New(0);
if (ret == NULL)
goto bail;
-
+
if (bufsize <= 0) {
int r;
-
+
Py_BEGIN_ALLOW_THREADS
r = ioctl(fd, FIONREAD, &bufsize);
Py_END_ALLOW_THREADS
-
+
if (r == -1) {
PyErr_SetFromErrno(PyExc_OSError);
goto bail;
@@ -475,16 +475,16 @@
static long name_max;
static long name_fd = -1;
long min;
-
+
if (name_fd != fd) {
name_fd = fd;
Py_BEGIN_ALLOW_THREADS
name_max = fpathconf(fd, _PC_NAME_MAX);
Py_END_ALLOW_THREADS
}
-
+
min = sizeof(struct inotify_event) + name_max + 1;
-
+
if (bufsize < min) {
PyErr_Format(PyExc_ValueError, "bufsize must be at least %d",
(int) min);
@@ -493,7 +493,7 @@
}
buf = alloca(bufsize);
-
+
Py_BEGIN_ALLOW_THREADS
nread = read(fd, buf, bufsize);
Py_END_ALLOW_THREADS
@@ -507,9 +507,9 @@
if (ctor_args == NULL)
goto bail;
-
+
pos = 0;
-
+
while (pos < nread) {
struct inotify_event *in = (struct inotify_event *) (buf + pos);
struct event *evt;
@@ -555,12 +555,12 @@
goto bail;
}
-
+
goto done;
bail:
Py_CLEAR(ret);
-
+
done:
Py_XDECREF(ctor_args);
@@ -597,12 +597,12 @@
PyObject *mod, *dict;
if (PyType_Ready(&event_type) == -1)
- return;
+ return;
mod = Py_InitModule3("_inotify", methods, doc);
dict = PyModule_GetDict(mod);
-
+
if (dict)
define_consts(dict);
}