Skip to content

Commit 28cb8c5

Browse files
committed
Personal review fixes
1 parent b6f8403 commit 28cb8c5

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Objects/bytearrayobject.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ bytearray_resize_lock_held(PyObject *self, Py_ssize_t requested_size)
230230
alloc = size + (size >> 3) + (size < 9 ? 3 : 6);
231231
}
232232
else {
233-
/* Major upsize; resize up to exact size. Upsize always means size > 0 */
233+
/* Major upsize; resize up to exact size */
234234
alloc = size;
235235
}
236236
}
@@ -246,18 +246,24 @@ bytearray_resize_lock_held(PyObject *self, Py_ssize_t requested_size)
246246
Py_MIN(requested_size, Py_SIZE(self)));
247247
}
248248

249+
int ret;
249250
if (obj->ob_bytes_object == NULL) {
250251
obj->ob_bytes_object = PyBytes_FromStringAndSize(NULL, alloc);
251252
if (obj->ob_bytes_object == NULL) {
253+
/* Object state valid and resize failed. */
252254
return -1;
253255
}
256+
ret = 0;
254257
}
255258
else {
256259
if (_PyBytes_Resize(&obj->ob_bytes_object, alloc) == -1) {
257-
Py_SET_SIZE(self, 0);
258-
obj->ob_bytes = obj->ob_start = NULL;
259-
FT_ATOMIC_STORE_SSIZE_RELAXED(obj->ob_alloc, 0);
260-
return -1;
260+
/* storage gone and resize failed. */
261+
obj->ob_bytes_object = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
262+
size = alloc = 0;
263+
ret = -1;
264+
}
265+
else {
266+
ret = 0;
261267
}
262268
}
263269

@@ -269,7 +275,7 @@ bytearray_resize_lock_held(PyObject *self, Py_ssize_t requested_size)
269275
obj->ob_bytes[size] = '\0';
270276
}
271277

272-
return 0;
278+
return ret;
273279
}
274280

275281
int

0 commit comments

Comments
 (0)