[PATCH 6 of 7] inotify extension: Better implementation of the event string representation

Nicolas Dumazet nicdumz at gmail.com
Thu Jul 1 22:50:04 CDT 2010


2010/7/2 Renato Cunha <renatoc at gmail.com>:
>  hgext/inotify/linux/_inotify.c |  75 ++++++++++++++++++++++++++---------------
>  1 files changed, 48 insertions(+), 27 deletions(-)
>
>
> # HG changeset patch
> # User Renato Cunha <renatoc at gmail.com>
> # Date 1278022747 10800
> # Node ID 791c6d61d084454be7bd8feab04a68df3eeea9ee
> # Parent  de47085e5d2b56a173f2bb25785ef132df1d6a87
> inotify extension: Better implementation of the event string representation.
>
> This patch reimplements the event_repr function. It got mostly rewritten to
> eliminate the need for conditional compilation of the module when building in
> py3k. The trick there (thanks to Antoine Pitrou) is to use the % operator to
> let the python interpreter format the string to be returned.
>

And in the process code gets relatively cleaner. Nice.



>  [...]
>
> +static int init_globals(void)
> +{
> +    join = PyString_FromString("|");
> +    er_wm = PyString_FromString("event(wd=%d, mask=%s)");
> +    er_wmn = PyString_FromString("event(wd=%d, mask=%s, name=%s)");
> +    er_wmc = PyString_FromString("event(wd=%d, mask=%s, cookie=0x%x)");
> +    er_wmcn = PyString_FromString("event(wd=%d, mask=%s, cookie=0x%x, name=%s)");
> +
> +       if (!join || !er_wm || !er_wmn || !er_wmc || !er_wmcn)
> +               return 0;
> +
> +    return 1;
> +}

I like the variable names.

return join && er_wm && er_wmn && er_wmc && er_wmcn; maybe? :)

> +
>  PyDoc_STRVAR(
>        read_doc,
>        "read(fd, bufsize[=65536]) -> list_of_events\n"
> @@ -592,6 +610,9 @@
>        if (PyType_Ready(&event_type) == -1)
>                return;
>
> +    if (init_globals() == 0)
> +        return;
> +

if (!init_globals())
  return;

>        mod = Py_InitModule3("_inotify", methods, doc);
>
>        dict = PyModule_GetDict(mod);
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>



-- 
Nicolas Dumazet — NicDumZ


More information about the Mercurial-devel mailing list