[PATCH 2 of 7] osutil.c: Support for py3k added

Matt Mackall mpm at selenic.com
Thu Jun 10 12:18:10 CDT 2010


On Thu, 2010-06-10 at 10:39 -0300, Renato Cunha wrote:
> # HG changeset patch
> # User Renato Cunha <renatoc at gmail.com>
> # Date 1276177147 10800
> # Node ID 8fd3727ae819a37e90be5b0ce7fc342ca24900c0
> # Parent  8530f003b636e75a64eb8b4c7bb283697f829791
> osutil.c: Support for py3k added.
> 
> This patch adds support for py3k in osutil.c. This is accomplished by including
> a header file responsible for abstracting the API differences between python 2
> and python 3.
> 
> listdir_stat_type is also changed in the following way: A previous call to
> PyObject_HEAD_INIT is substituted to a call to PyVarObject_HEAD_INIT, which
> makes the object buildable in both python 2.x and 3.x without weird warnings.
> 
> diff --git a/mercurial/osutil.c b/mercurial/osutil.c
> --- a/mercurial/osutil.c
> +++ b/mercurial/osutil.c
> @@ -23,6 +23,8 @@
>  #include <unistd.h>
>  #endif
>  
> +#include "util.h"
> +
>  /* some platforms lack the PATH_MAX definition (eg. GNU/Hurd) */
>  #ifndef PATH_MAX
>  #define PATH_MAX 4096
> @@ -53,11 +55,19 @@
>  };
>  #endif
>  
> +#ifdef IS_PY3K
> +#define listdir_slot(name) \
> +	static PyObject *listdir_stat_##name(PyObject *self, void *x) \
> +	{ \
> +		return PyLong_FromLong(((struct listdir_stat *)self)->st.name); \
> +	}
> +#else
>  #define listdir_slot(name) \
>  	static PyObject *listdir_stat_##name(PyObject *self, void *x) \
>  	{ \
>  		return PyInt_FromLong(((struct listdir_stat *)self)->st.name); \
>  	}
> +#endif

Um, didn't you just define a PYINT_FROMLONG that fixes that?

 
>  static PyTypeObject listdir_stat_type = {
> -	PyObject_HEAD_INIT(NULL)
> -	0,                         /*ob_size*/
> -	"osutil.stat",             /*tp_name*/
> -	sizeof(struct listdir_stat), /*tp_basicsize*/
> -	0,                         /*tp_itemsize*/
> -	(destructor)listdir_stat_dealloc, /*tp_dealloc*/
> -	0,                         /*tp_print*/
> -	0,                         /*tp_getattr*/
> -	0,                         /*tp_setattr*/
[...]
> -	0,                         /* tp_init */
> -	0,                         /* tp_alloc */
> -	listdir_stat_new,          /* tp_new */
> +    PyVarObject_HEAD_INIT(NULL, 0)
> +    "osutil.stat",             /* tp_name */
> +    sizeof(struct listdir_stat), /* tp_basicsize */
> +    0,                         /* tp_itemsize */
> +    (destructor)listdir_stat_dealloc, /* tp_dealloc */
> +    0,                         /* tp_print */
> +    0,                         /* tp_getattr */

Most of this is gratuitous (and wrong!) reformatting. You should never
mix formatting changes with other changes - it's important that your
semantic changes be as simple as possible so that readers can actually
identify what's changing.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list