bpo-39573: Use Py_SET_SIZE() function (GH-18402)

Replace direct acccess to PyVarObject.ob_size with usage of
the Py_SET_SIZE() function.
This commit is contained in:
Victor Stinner 2020-02-07 23:18:08 +01:00 committed by GitHub
parent de6f38db48
commit 60ac6ed557
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 95 additions and 86 deletions

View file

@ -128,14 +128,14 @@ array_resize(arrayobject *self, Py_ssize_t newsize)
if (self->allocated >= newsize &&
Py_SIZE(self) < newsize + 16 &&
self->ob_item != NULL) {
Py_SIZE(self) = newsize;
Py_SET_SIZE(self, newsize);
return 0;
}
if (newsize == 0) {
PyMem_FREE(self->ob_item);
self->ob_item = NULL;
Py_SIZE(self) = 0;
Py_SET_SIZE(self, 0);
self->allocated = 0;
return 0;
}
@ -165,7 +165,7 @@ array_resize(arrayobject *self, Py_ssize_t newsize)
return -1;
}
self->ob_item = items;
Py_SIZE(self) = newsize;
Py_SET_SIZE(self, newsize);
self->allocated = _new_size;
return 0;
}
@ -593,7 +593,7 @@ newarrayobject(PyTypeObject *type, Py_ssize_t size, const struct arraydescr *des
op->ob_descr = descr;
op->allocated = size;
op->weakreflist = NULL;
Py_SIZE(op) = size;
Py_SET_SIZE(op, size);
if (size <= 0) {
op->ob_item = NULL;
}
@ -2696,7 +2696,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
self->ob_item = item;
Py_SIZE(self) = n / sizeof(Py_UNICODE);
Py_SET_SIZE(self, n / sizeof(Py_UNICODE));
memcpy(item, ustr, n);
self->allocated = Py_SIZE(self);
}