From 433c58520ad549e79f8233abd9793536d7d6f48d Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Mon, 30 Jun 2008 07:16:53 +0200 Subject: [PATCH] Implement changes needed for PEP 353 compliance It seems the coded wrongly mixed ssize_t and ints in a couple of places, plus not properly using Py_ssize_t as needed. Fix these and ensure backwards compat with python 2.4. --- xattr.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/xattr.c b/xattr.c index 1555c23..31037e6 100644 --- a/xattr.c +++ b/xattr.c @@ -1,6 +1,14 @@ +#define PY_SSIZE_T_CLEAN #include #include +/* Compatibility with python 2.4 regarding python size type (PEP 353) */ +#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) +typedef int Py_ssize_t; +#define PY_SSIZE_T_MAX INT_MAX +#define PY_SSIZE_T_MIN INT_MIN +#endif + typedef enum {T_FD, T_PATH, T_LINK} target_e; typedef struct { @@ -45,7 +53,7 @@ static ssize_t _get_obj(target_t *tgt, char *name, void *value, size_t size) { return getxattr(tgt->name, name, value, size); } -static ssize_t _set_obj(target_t *tgt, char *name, void *value, size_t size, +static int _set_obj(target_t *tgt, char *name, void *value, size_t size, int flags) { if(tgt->type == T_FD) return fsetxattr(tgt->fd, name, value, size, flags); @@ -55,7 +63,7 @@ static ssize_t _set_obj(target_t *tgt, char *name, void *value, size_t size, return setxattr(tgt->name, name, value, size, flags); } -static ssize_t _remove_obj(target_t *tgt, char *name) { +static int _remove_obj(target_t *tgt, char *name) { if(tgt->type == T_FD) return fremovexattr(tgt->fd, name); else if (tgt->type == T_LINK) @@ -88,7 +96,7 @@ pygetxattr(PyObject *self, PyObject *args) int nofollow=0; char *attrname; char *buf; - int nalloc, nret; + ssize_t nalloc, nret; PyObject *res; /* Parse the arguments */ @@ -159,7 +167,8 @@ pysetxattr(PyObject *self, PyObject *args) int nofollow=0; char *attrname; char *buf; - int bufsize, nret; + Py_ssize_t bufsize; + int nret; int flags = 0; target_t tgt; @@ -239,10 +248,10 @@ pylistxattr(PyObject *self, PyObject *args) { char *buf; int nofollow=0; - int nalloc, nret; + ssize_t nalloc, nret; PyObject *myarg; PyObject *mylist; - int nattrs; + Py_ssize_t nattrs; char *s; target_t tgt; -- 2.39.5