diff options
Diffstat (limited to 'Modules/_struct.c')
| -rw-r--r-- | Modules/_struct.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/Modules/_struct.c b/Modules/_struct.c index ad9959e..1f1bb93 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -85,8 +85,6 @@ typedef struct { char c; _Bool x; } s_bool; #define BOOL_ALIGN 0 #endif -#define STRINGIFY(x) #x - #ifdef __powerc #pragma options align=reset #endif @@ -546,8 +544,8 @@ np_short(char *p, PyObject *v, const formatdef *f) return -1; if (x < SHRT_MIN || x > SHRT_MAX){ PyErr_SetString(StructError, - "short format requires " STRINGIFY(SHRT_MIN) - " <= number <= " STRINGIFY(SHRT_MAX)); + "short format requires " Py_STRINGIFY(SHRT_MIN) + " <= number <= " Py_STRINGIFY(SHRT_MAX)); return -1; } y = (short)x; @@ -564,7 +562,8 @@ np_ushort(char *p, PyObject *v, const formatdef *f) return -1; if (x < 0 || x > USHRT_MAX){ PyErr_SetString(StructError, - "ushort format requires 0 <= number <= " STRINGIFY(USHRT_MAX)); + "ushort format requires 0 <= number <= " + Py_STRINGIFY(USHRT_MAX)); return -1; } y = (unsigned short)x; @@ -1264,7 +1263,8 @@ prepare_s(PyStructObject *self) const char *s; const char *fmt; char c; - Py_ssize_t size, len, ncodes, num, itemsize; + Py_ssize_t size, len, num, itemsize; + size_t ncodes; fmt = PyBytes_AS_STRING(self->s_format); @@ -1320,7 +1320,7 @@ prepare_s(PyStructObject *self) } /* check for overflow */ - if ((ncodes + 1) > (PY_SSIZE_T_MAX / sizeof(formatcode))) { + if ((ncodes + 1) > ((size_t)PY_SSIZE_T_MAX / sizeof(formatcode))) { PyErr_NoMemory(); return -1; } @@ -1437,8 +1437,7 @@ s_init(PyObject *self, PyObject *args, PyObject *kwds) return -1; } - Py_CLEAR(soself->s_format); - soself->s_format = o_format; + Py_SETREF(soself->s_format, o_format); ret = prepare_s(soself); return ret; @@ -1924,7 +1923,7 @@ s_sizeof(PyStructObject *self, void *unused) Py_ssize_t size; formatcode *code; - size = sizeof(PyStructObject) + sizeof(formatcode); + size = _PyObject_SIZE(Py_TYPE(self)) + sizeof(formatcode); for (code = self->s_codes; code->fmtdef != NULL; code++) size += sizeof(formatcode); return PyLong_FromSsize_t(size); |
