summaryrefslogtreecommitdiffstats
path: root/Modules/_pickle.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-02-07 22:18:08 (GMT)
committerGitHub <noreply@github.com>2020-02-07 22:18:08 (GMT)
commit60ac6ed5579f6666130fc264d3b748ee9575e3aa (patch)
treec21d06611bea34d88dd5922850223837fa6ae733 /Modules/_pickle.c
parentde6f38db4859f7b8fe4da4556f06c52675fff24a (diff)
downloadcpython-60ac6ed5579f6666130fc264d3b748ee9575e3aa.zip
cpython-60ac6ed5579f6666130fc264d3b748ee9575e3aa.tar.gz
cpython-60ac6ed5579f6666130fc264d3b748ee9575e3aa.tar.bz2
bpo-39573: Use Py_SET_SIZE() function (GH-18402)
Replace direct acccess to PyVarObject.ob_size with usage of the Py_SET_SIZE() function.
Diffstat (limited to 'Modules/_pickle.c')
-rw-r--r--Modules/_pickle.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index f67fb6a..5f11fe5 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -461,7 +461,7 @@ Pdata_New(void)
if (!(self = PyObject_New(Pdata, &Pdata_Type)))
return NULL;
- Py_SIZE(self) = 0;
+ Py_SET_SIZE(self, 0);
self->mark_set = 0;
self->fence = 0;
self->allocated = 8;
@@ -488,7 +488,7 @@ Pdata_clear(Pdata *self, Py_ssize_t clearto)
while (--i >= clearto) {
Py_CLEAR(self->data[i]);
}
- Py_SIZE(self) = clearto;
+ Py_SET_SIZE(self, clearto);
return 0;
}
@@ -539,7 +539,8 @@ Pdata_pop(Pdata *self)
Pdata_stack_underflow(self);
return NULL;
}
- return self->data[--Py_SIZE(self)];
+ Py_SET_SIZE(self, Py_SIZE(self) - 1);
+ return self->data[Py_SIZE(self)];
}
#define PDATA_POP(D, V) do { (V) = Pdata_pop((D)); } while (0)
@@ -549,7 +550,8 @@ Pdata_push(Pdata *self, PyObject *obj)
if (Py_SIZE(self) == self->allocated && Pdata_grow(self) < 0) {
return -1;
}
- self->data[Py_SIZE(self)++] = obj;
+ self->data[Py_SIZE(self)] = obj;
+ Py_SET_SIZE(self, Py_SIZE(self) + 1);
return 0;
}
@@ -579,7 +581,7 @@ Pdata_poptuple(Pdata *self, Py_ssize_t start)
for (i = start, j = 0; j < len; i++, j++)
PyTuple_SET_ITEM(tuple, j, self->data[i]);
- Py_SIZE(self) = start;
+ Py_SET_SIZE(self, start);
return tuple;
}
@@ -596,7 +598,7 @@ Pdata_poplist(Pdata *self, Py_ssize_t start)
for (i = start, j = 0; j < len; i++, j++)
PyList_SET_ITEM(list, j, self->data[i]);
- Py_SIZE(self) = start;
+ Py_SET_SIZE(self, start);
return list;
}
@@ -6134,7 +6136,7 @@ load_pop(UnpicklerObject *self)
else {
len--;
Py_DECREF(self->stack->data[len]);
- Py_SIZE(self->stack) = len;
+ Py_SET_SIZE(self->stack, len);
}
return 0;
}
@@ -6495,13 +6497,13 @@ do_append(UnpicklerObject *self, Py_ssize_t x)
result = _Pickle_FastCall(append_func, value);
if (result == NULL) {
Pdata_clear(self->stack, i + 1);
- Py_SIZE(self->stack) = x;
+ Py_SET_SIZE(self->stack, x);
Py_DECREF(append_func);
return -1;
}
Py_DECREF(result);
}
- Py_SIZE(self->stack) = x;
+ Py_SET_SIZE(self->stack, x);
Py_DECREF(append_func);
}
}
@@ -6623,12 +6625,12 @@ load_additems(UnpicklerObject *self)
result = _Pickle_FastCall(add_func, item);
if (result == NULL) {
Pdata_clear(self->stack, i + 1);
- Py_SIZE(self->stack) = mark;
+ Py_SET_SIZE(self->stack, mark);
return -1;
}
Py_DECREF(result);
}
- Py_SIZE(self->stack) = mark;
+ Py_SET_SIZE(self->stack, mark);
}
return 0;